Commit d881baac authored by machenbach's avatar machenbach Committed by Commit bot

Revert of Migrate error messages, part 2. (patchset #1 id:1 of...

Revert of Migrate error messages, part 2. (patchset #1 id:1 of https://codereview.chromium.org/1086313003/)

Reason for revert:
[Sheriff]: This changes layout test expectations e.g.
http://build.chromium.org/p/client.v8/builders/V8-Blink%20Win/builds/2964

Original issue's description:
> Migrate error messages, part 2.
>
> Motivation for this is reducing the size of the native context.
>
> Committed: https://crrev.com/d3b788df0a4ccfedbe6e1df5e214cb6ba2792a65
> Cr-Commit-Position: refs/heads/master@{#27878}

TBR=mvstanton@chromium.org,yangguo@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true

Review URL: https://codereview.chromium.org/1095573002

Cr-Commit-Position: refs/heads/master@{#27889}
parent 2dc0f2ec
......@@ -73,8 +73,8 @@ function ArrayIteratorNext() {
var iterator = ToObject(this);
if (!HAS_DEFINED_PRIVATE(iterator, arrayIteratorNextIndexSymbol)) {
throw MakeTypeError(kIncompatibleMethodReceiver,
'Array Iterator.prototype.next', this);
throw MakeTypeError('incompatible_method_receiver',
['Array Iterator.prototype.next']);
}
var array = GET_PRIVATE(iterator, arrayIteratorObjectSymbol);
......
......@@ -1142,7 +1142,9 @@ function ArrayFilter(f, receiver) {
var array = ToObject(this);
var length = ToUint32(array.length);
if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f);
if (!IS_SPEC_FUNCTION(f)) {
throw MakeTypeError('called_non_callable', [ f ]);
}
var needs_wrapper = false;
if (IS_NULL_OR_UNDEFINED(receiver)) {
receiver = %GetDefaultReceiver(f) || receiver;
......@@ -1179,7 +1181,9 @@ function ArrayForEach(f, receiver) {
var array = ToObject(this);
var length = TO_UINT32(array.length);
if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f);
if (!IS_SPEC_FUNCTION(f)) {
throw MakeTypeError('called_non_callable', [ f ]);
}
var needs_wrapper = false;
if (IS_NULL_OR_UNDEFINED(receiver)) {
receiver = %GetDefaultReceiver(f) || receiver;
......@@ -1211,7 +1215,9 @@ function ArraySome(f, receiver) {
var array = ToObject(this);
var length = TO_UINT32(array.length);
if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f);
if (!IS_SPEC_FUNCTION(f)) {
throw MakeTypeError('called_non_callable', [ f ]);
}
var needs_wrapper = false;
if (IS_NULL_OR_UNDEFINED(receiver)) {
receiver = %GetDefaultReceiver(f) || receiver;
......@@ -1242,7 +1248,9 @@ function ArrayEvery(f, receiver) {
var array = ToObject(this);
var length = TO_UINT32(array.length);
if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f);
if (!IS_SPEC_FUNCTION(f)) {
throw MakeTypeError('called_non_callable', [ f ]);
}
var needs_wrapper = false;
if (IS_NULL_OR_UNDEFINED(receiver)) {
receiver = %GetDefaultReceiver(f) || receiver;
......@@ -1272,7 +1280,9 @@ function ArrayMap(f, receiver) {
var array = ToObject(this);
var length = TO_UINT32(array.length);
if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f);
if (!IS_SPEC_FUNCTION(f)) {
throw MakeTypeError('called_non_callable', [ f ]);
}
var needs_wrapper = false;
if (IS_NULL_OR_UNDEFINED(receiver)) {
receiver = %GetDefaultReceiver(f) || receiver;
......@@ -1417,7 +1427,7 @@ function ArrayReduce(callback, current) {
var length = ToUint32(array.length);
if (!IS_SPEC_FUNCTION(callback)) {
throw MakeTypeError(kCalledNonCallable, callback);
throw MakeTypeError('called_non_callable', [callback]);
}
var is_array = IS_ARRAY(array);
......@@ -1454,7 +1464,7 @@ function ArrayReduceRight(callback, current) {
var length = ToUint32(array.length);
if (!IS_SPEC_FUNCTION(callback)) {
throw MakeTypeError(kCalledNonCallable, callback);
throw MakeTypeError('called_non_callable', [callback]);
}
var is_array = IS_ARRAY(array);
......
......@@ -24,8 +24,8 @@ function ArrayBufferConstructor(length) { // length = 1
function ArrayBufferGetByteLen() {
if (!IS_ARRAYBUFFER(this)) {
throw MakeTypeError(kIncompatibleMethodReceiver,
'ArrayBuffer.prototype.byteLength', this);
throw MakeTypeError('incompatible_method_receiver',
['ArrayBuffer.prototype.byteLength', this]);
}
return %_ArrayBufferGetByteLength(this);
}
......@@ -33,8 +33,8 @@ function ArrayBufferGetByteLen() {
// ES6 Draft 15.13.5.5.3
function ArrayBufferSlice(start, end) {
if (!IS_ARRAYBUFFER(this)) {
throw MakeTypeError(kIncompatibleMethodReceiver,
'ArrayBuffer.prototype.slice', this);
throw MakeTypeError('incompatible_method_receiver',
['ArrayBuffer.prototype.slice', this]);
}
var relativeStart = TO_INTEGER(start);
......
......@@ -26,8 +26,8 @@ function SetIteratorConstructor(set, kind) {
function SetIteratorNextJS() {
if (!IS_SET_ITERATOR(this)) {
throw MakeTypeError(kIncompatibleMethodReceiver,
'Set Iterator.prototype.next', this);
throw MakeTypeError('incompatible_method_receiver',
['Set Iterator.prototype.next', this]);
}
var value_array = [UNDEFINED, UNDEFINED];
......@@ -56,8 +56,8 @@ function SetIteratorSymbolIterator() {
function SetEntries() {
if (!IS_SET(this)) {
throw MakeTypeError(kIncompatibleMethodReceiver,
'Set.prototype.entries', this);
throw MakeTypeError('incompatible_method_receiver',
['Set.prototype.entries', this]);
}
return new SetIterator(this, ITERATOR_KIND_ENTRIES);
}
......@@ -65,8 +65,8 @@ function SetEntries() {
function SetValues() {
if (!IS_SET(this)) {
throw MakeTypeError(kIncompatibleMethodReceiver,
'Set.prototype.values', this);
throw MakeTypeError('incompatible_method_receiver',
['Set.prototype.values', this]);
}
return new SetIterator(this, ITERATOR_KIND_VALUES);
}
......@@ -111,8 +111,8 @@ function MapIteratorSymbolIterator() {
function MapIteratorNextJS() {
if (!IS_MAP_ITERATOR(this)) {
throw MakeTypeError(kIncompatibleMethodReceiver,
'Map Iterator.prototype.next', this);
throw MakeTypeError('incompatible_method_receiver',
['Map Iterator.prototype.next', this]);
}
var value_array = [UNDEFINED, UNDEFINED];
......@@ -137,8 +137,8 @@ function MapIteratorNextJS() {
function MapEntries() {
if (!IS_MAP(this)) {
throw MakeTypeError(kIncompatibleMethodReceiver,
'Map.prototype.entries', this);
throw MakeTypeError('incompatible_method_receiver',
['Map.prototype.entries', this]);
}
return new MapIterator(this, ITERATOR_KIND_ENTRIES);
}
......@@ -146,8 +146,8 @@ function MapEntries() {
function MapKeys() {
if (!IS_MAP(this)) {
throw MakeTypeError(kIncompatibleMethodReceiver,
'Map.prototype.keys', this);
throw MakeTypeError('incompatible_method_receiver',
['Map.prototype.keys', this]);
}
return new MapIterator(this, ITERATOR_KIND_KEYS);
}
......@@ -155,8 +155,8 @@ function MapKeys() {
function MapValues() {
if (!IS_MAP(this)) {
throw MakeTypeError(kIncompatibleMethodReceiver,
'Map.prototype.values', this);
throw MakeTypeError('incompatible_method_receiver',
['Map.prototype.values', this]);
}
return new MapIterator(this, ITERATOR_KIND_VALUES);
}
......
......@@ -99,7 +99,7 @@ function SetConstructor(iterable) {
if (!IS_NULL_OR_UNDEFINED(iterable)) {
var adder = this.add;
if (!IS_SPEC_FUNCTION(adder)) {
throw MakeTypeError(kPropertyNotFunction, 'add', this);
throw MakeTypeError(kPropertyNotFunction, ['add', this]);
}
for (var value of iterable) {
......@@ -111,7 +111,8 @@ function SetConstructor(iterable) {
function SetAdd(key) {
if (!IS_SET(this)) {
throw MakeTypeError(kIncompatibleMethodReceiver, 'Set.prototype.add', this);
throw MakeTypeError('incompatible_method_receiver',
['Set.prototype.add', this]);
}
// Normalize -0 to +0 as required by the spec.
// Even though we use SameValueZero as the comparison for the keys we don't
......@@ -151,7 +152,8 @@ function SetAdd(key) {
function SetHas(key) {
if (!IS_SET(this)) {
throw MakeTypeError(kIncompatibleMethodReceiver, 'Set.prototype.has', this);
throw MakeTypeError('incompatible_method_receiver',
['Set.prototype.has', this]);
}
var table = %_JSCollectionGetTable(this);
var numBuckets = ORDERED_HASH_TABLE_BUCKET_COUNT(table);
......@@ -162,8 +164,8 @@ function SetHas(key) {
function SetDelete(key) {
if (!IS_SET(this)) {
throw MakeTypeError(kIncompatibleMethodReceiver,
'Set.prototype.delete', this);
throw MakeTypeError('incompatible_method_receiver',
['Set.prototype.delete', this]);
}
var table = %_JSCollectionGetTable(this);
var numBuckets = ORDERED_HASH_TABLE_BUCKET_COUNT(table);
......@@ -184,8 +186,8 @@ function SetDelete(key) {
function SetGetSize() {
if (!IS_SET(this)) {
throw MakeTypeError(kIncompatibleMethodReceiver,
'Set.prototype.size', this);
throw MakeTypeError('incompatible_method_receiver',
['Set.prototype.size', this]);
}
var table = %_JSCollectionGetTable(this);
return ORDERED_HASH_TABLE_ELEMENT_COUNT(table);
......@@ -194,8 +196,8 @@ function SetGetSize() {
function SetClearJS() {
if (!IS_SET(this)) {
throw MakeTypeError(kIncompatibleMethodReceiver,
'Set.prototype.clear', this);
throw MakeTypeError('incompatible_method_receiver',
['Set.prototype.clear', this]);
}
%_SetClear(this);
}
......@@ -203,11 +205,13 @@ function SetClearJS() {
function SetForEach(f, receiver) {
if (!IS_SET(this)) {
throw MakeTypeError(kIncompatibleMethodReceiver,
'Set.prototype.forEach', this);
throw MakeTypeError('incompatible_method_receiver',
['Set.prototype.forEach', this]);
}
if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f);
if (!IS_SPEC_FUNCTION(f)) {
throw MakeTypeError('called_non_callable', [f]);
}
var needs_wrapper = false;
if (IS_NULL_OR_UNDEFINED(receiver)) {
receiver = %GetDefaultReceiver(f) || receiver;
......@@ -262,7 +266,7 @@ function MapConstructor(iterable) {
if (!IS_NULL_OR_UNDEFINED(iterable)) {
var adder = this.set;
if (!IS_SPEC_FUNCTION(adder)) {
throw MakeTypeError(kPropertyNotFunction, 'set', this);
throw MakeTypeError(kPropertyNotFunction, ['set', this]);
}
for (var nextItem of iterable) {
......@@ -277,8 +281,8 @@ function MapConstructor(iterable) {
function MapGet(key) {
if (!IS_MAP(this)) {
throw MakeTypeError(kIncompatibleMethodReceiver,
'Map.prototype.get', this);
throw MakeTypeError('incompatible_method_receiver',
['Map.prototype.get', this]);
}
var table = %_JSCollectionGetTable(this);
var numBuckets = ORDERED_HASH_TABLE_BUCKET_COUNT(table);
......@@ -291,8 +295,8 @@ function MapGet(key) {
function MapSet(key, value) {
if (!IS_MAP(this)) {
throw MakeTypeError(kIncompatibleMethodReceiver,
'Map.prototype.set', this);
throw MakeTypeError('incompatible_method_receiver',
['Map.prototype.set', this]);
}
// Normalize -0 to +0 as required by the spec.
// Even though we use SameValueZero as the comparison for the keys we don't
......@@ -339,8 +343,8 @@ function MapSet(key, value) {
function MapHas(key) {
if (!IS_MAP(this)) {
throw MakeTypeError(kIncompatibleMethodReceiver,
'Map.prototype.has', this);
throw MakeTypeError('incompatible_method_receiver',
['Map.prototype.has', this]);
}
var table = %_JSCollectionGetTable(this);
var numBuckets = ORDERED_HASH_TABLE_BUCKET_COUNT(table);
......@@ -351,8 +355,8 @@ function MapHas(key) {
function MapDelete(key) {
if (!IS_MAP(this)) {
throw MakeTypeError(kIncompatibleMethodReceiver,
'Map.prototype.delete', this);
throw MakeTypeError('incompatible_method_receiver',
['Map.prototype.delete', this]);
}
var table = %_JSCollectionGetTable(this);
var numBuckets = ORDERED_HASH_TABLE_BUCKET_COUNT(table);
......@@ -374,8 +378,8 @@ function MapDelete(key) {
function MapGetSize() {
if (!IS_MAP(this)) {
throw MakeTypeError(kIncompatibleMethodReceiver,
'Map.prototype.size', this);
throw MakeTypeError('incompatible_method_receiver',
['Map.prototype.size', this]);
}
var table = %_JSCollectionGetTable(this);
return ORDERED_HASH_TABLE_ELEMENT_COUNT(table);
......@@ -384,8 +388,8 @@ function MapGetSize() {
function MapClearJS() {
if (!IS_MAP(this)) {
throw MakeTypeError(kIncompatibleMethodReceiver,
'Map.prototype.clear', this);
throw MakeTypeError('incompatible_method_receiver',
['Map.prototype.clear', this]);
}
%_MapClear(this);
}
......@@ -393,11 +397,13 @@ function MapClearJS() {
function MapForEach(f, receiver) {
if (!IS_MAP(this)) {
throw MakeTypeError(kIncompatibleMethodReceiver,
'Map.prototype.forEach', this);
throw MakeTypeError('incompatible_method_receiver',
['Map.prototype.forEach', this]);
}
if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f);
if (!IS_SPEC_FUNCTION(f)) {
throw MakeTypeError('called_non_callable', [f]);
}
var needs_wrapper = false;
if (IS_NULL_OR_UNDEFINED(receiver)) {
receiver = %GetDefaultReceiver(f) || receiver;
......
......@@ -8,7 +8,6 @@
#include "src/codegen.h"
#include "src/deoptimizer.h"
#include "src/isolate-inl.h"
#include "src/messages.h"
#include "src/vm-state-inl.h"
namespace v8 {
......@@ -280,8 +279,8 @@ MaybeHandle<Object> Execution::TryGetFunctionDelegate(Isolate* isolate,
// If the Object doesn't have an instance-call handler we should
// throw a non-callable exception.
THROW_NEW_ERROR(isolate,
NewTypeError(MessageTemplate::kCalledNonCallable, object),
THROW_NEW_ERROR(isolate, NewTypeError("called_non_callable",
i::HandleVector<i::Object>(&object, 1)),
Object);
}
......@@ -336,8 +335,8 @@ MaybeHandle<Object> Execution::TryGetConstructorDelegate(
// If the Object doesn't have an instance-call handler we should
// throw a non-callable exception.
THROW_NEW_ERROR(isolate,
NewTypeError(MessageTemplate::kCalledNonCallable, object),
THROW_NEW_ERROR(isolate, NewTypeError("called_non_callable",
i::HandleVector<i::Object>(&object, 1)),
Object);
}
......
......@@ -1080,6 +1080,13 @@ Handle<Object> Factory::NewTypeError(const char* message,
}
Handle<Object> Factory::NewTypeError(MessageTemplate::Template template_index,
Handle<Object> arg0, Handle<Object> arg1,
Handle<Object> arg2) {
return NewError("MakeTypeError2", template_index, arg0, arg1, arg2);
}
Handle<Object> Factory::NewTypeError(Handle<String> message) {
return NewError("$TypeError", message);
}
......@@ -1177,24 +1184,9 @@ Handle<Object> Factory::NewEvalError(const char* message,
}
Handle<Object> Factory::NewError(MessageTemplate::Template template_index,
Handle<Object> arg0, Handle<Object> arg1,
Handle<Object> arg2) {
return NewError("MakeError", template_index, arg0, arg1, arg2);
}
Handle<Object> Factory::NewTypeError(MessageTemplate::Template template_index,
Handle<Object> arg0, Handle<Object> arg1,
Handle<Object> arg2) {
return NewError("MakeTypeError", template_index, arg0, arg1, arg2);
}
Handle<Object> Factory::NewEvalError(MessageTemplate::Template template_index,
Handle<Object> arg0, Handle<Object> arg1,
Handle<Object> arg2) {
return NewError("MakeEvalError", template_index, arg0, arg1, arg2);
Handle<Object> Factory::NewError(const char* message,
Vector<Handle<Object> > args) {
return NewError("MakeError", message, args);
}
......
......@@ -537,12 +537,20 @@ class Factory FINAL {
Handle<Object> NewError(const char* maker, const char* message,
Vector<Handle<Object> > args);
Handle<Object> NewError(const char* message, Vector<Handle<Object> > args);
Handle<Object> NewError(const char* maker,
MessageTemplate::Template template_index,
Handle<Object> arg0, Handle<Object> arg1,
Handle<Object> arg2);
Handle<Object> NewError(Handle<String> message);
Handle<Object> NewError(const char* constructor, Handle<String> message);
Handle<Object> NewTypeError(const char* message,
Vector<Handle<Object> > args);
Handle<Object> NewTypeError(MessageTemplate::Template template_index,
Handle<Object> arg0 = Handle<Object>(),
Handle<Object> arg1 = Handle<Object>(),
Handle<Object> arg2 = Handle<Object>());
Handle<Object> NewTypeError(Handle<String> message);
Handle<Object> NewRangeError(const char* message,
......@@ -565,26 +573,6 @@ class Factory FINAL {
Handle<Object> NewEvalError(const char* message,
Vector<Handle<Object> > args);
Handle<Object> NewError(const char* maker,
MessageTemplate::Template template_index,
Handle<Object> arg0, Handle<Object> arg1,
Handle<Object> arg2);
Handle<Object> NewError(MessageTemplate::Template template_index,
Handle<Object> arg0 = Handle<Object>(),
Handle<Object> arg1 = Handle<Object>(),
Handle<Object> arg2 = Handle<Object>());
Handle<Object> NewTypeError(MessageTemplate::Template template_index,
Handle<Object> arg0 = Handle<Object>(),
Handle<Object> arg1 = Handle<Object>(),
Handle<Object> arg2 = Handle<Object>());
Handle<Object> NewEvalError(MessageTemplate::Template template_index,
Handle<Object> arg0 = Handle<Object>(),
Handle<Object> arg1 = Handle<Object>(),
Handle<Object> arg2 = Handle<Object>());
Handle<String> NumberToString(Handle<Object> number,
bool check_number_string_cache = true);
......
......@@ -16,8 +16,8 @@
function GeneratorObjectNext(value) {
if (!IS_GENERATOR(this)) {
throw MakeTypeError(kIncompatibleMethodReceiver,
'[Generator].prototype.next', this);
throw MakeTypeError('incompatible_method_receiver',
['[Generator].prototype.next', this]);
}
var continuation = %GeneratorGetContinuation(this);
......@@ -35,14 +35,14 @@ function GeneratorObjectNext(value) {
return { value: void 0, done: true };
} else {
// Generator is running.
throw MakeTypeError(kGeneratorRunning);
throw MakeTypeError('generator_running', []);
}
}
function GeneratorObjectThrow(exn) {
if (!IS_GENERATOR(this)) {
throw MakeTypeError(kIncompatibleMethodReceiver,
'[Generator].prototype.throw', this);
throw MakeTypeError('incompatible_method_receiver',
['[Generator].prototype.throw', this]);
}
var continuation = %GeneratorGetContinuation(this);
......@@ -59,7 +59,7 @@ function GeneratorObjectThrow(exn) {
throw exn;
} else {
// Generator is running.
throw MakeTypeError(kGeneratorRunning);
throw MakeTypeError('generator_running', []);
}
}
......
......@@ -18,7 +18,7 @@ function ArrayFind(predicate /* thisArg */) { // length == 1
var length = ToInteger(array.length);
if (!IS_SPEC_FUNCTION(predicate)) {
throw MakeTypeError(kCalledNonCallable, predicate);
throw MakeTypeError('called_non_callable', [predicate]);
}
var thisArg;
......@@ -55,7 +55,7 @@ function ArrayFindIndex(predicate /* thisArg */) { // length == 1
var length = ToInteger(array.length);
if (!IS_SPEC_FUNCTION(predicate)) {
throw MakeTypeError(kCalledNonCallable, predicate);
throw MakeTypeError('called_non_callable', [predicate]);
}
var thisArg;
......@@ -134,7 +134,7 @@ function ArrayFrom(arrayLike, mapfn, receiver) {
if (mapping) {
if (!IS_SPEC_FUNCTION(mapfn)) {
throw MakeTypeError(kCalledNonCallable, mapfn);
throw MakeTypeError('called_non_callable', [ mapfn ]);
} else if (IS_NULL_OR_UNDEFINED(receiver)) {
receiver = %GetDefaultReceiver(mapfn) || receiver;
} else if (!IS_SPEC_OBJECT(receiver) && %IsSloppyModeFunction(mapfn)) {
......
......@@ -31,7 +31,9 @@ function NAMEForEach(f /* thisArg */) { // length == 1
if (!%IsTypedArray(this)) {
throw MakeTypeError('not_typed_array', []);
}
if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f);
if (!IS_SPEC_FUNCTION(f)) {
throw MakeTypeError('called_non_callable', [ f ]);
}
var length = %_TypedArrayGetLength(this);
var receiver;
......
......@@ -88,17 +88,9 @@ class MessageHandler {
};
#define MESSAGE_TEMPLATES(T) \
/* Error */ \
T(CyclicProto, "Cyclic __proto__ value") \
/* TypeError */ \
T(CalledNonCallable, "% is not a function") \
T(GeneratorRunning, "Generator is already running") \
T(IncompatibleMethodReceiver, "Method % called on incompatible receiver %") \
T(PropertyNotFunction, "Property '%' of object % is not a function") \
T(WithExpression, "% has no properties") \
/* EvalError */ \
T(CodeGenFromStrings, "%")
#define MESSAGE_TEMPLATES(T) \
T(PropertyNotFunction, "Property '%' of object % is not a function") \
T(WithExpression, "% has no properties")
class MessageTemplate {
public:
......
......@@ -6,9 +6,12 @@
var kMessages = {
// Error
cyclic_proto: ["Cyclic __proto__ value"],
code_gen_from_strings: ["%0"],
constructor_is_generator: ["Class constructor may not be a generator"],
constructor_is_accessor: ["Class constructor may not be an accessor"],
// TypeError
generator_running: ["Generator is already running"],
unexpected_token: ["Unexpected token ", "%0"],
unexpected_token_number: ["Unexpected number"],
unexpected_token_string: ["Unexpected string"],
......@@ -24,6 +27,7 @@ var kMessages = {
unterminated_template_expr: ["Missing } in template expression"],
unterminated_arg_list: ["missing ) after argument list"],
regexp_flags: ["Cannot supply flags when constructing one RegExp from another"],
incompatible_method_receiver: ["Method ", "%0", " called on incompatible receiver ", "%1"],
multiple_defaults_in_switch: ["More than one default clause in switch statement"],
newline_after_throw: ["Illegal newline after throw"],
label_redeclaration: ["Label '", "%0", "' has already been declared"],
......@@ -32,6 +36,8 @@ var kMessages = {
no_catch_or_finally: ["Missing catch or finally after try"],
unknown_label: ["Undefined label '", "%0", "'"],
uncaught_exception: ["Uncaught ", "%0"],
stack_trace: ["Stack Trace:\n", "%0"],
called_non_callable: ["%0", " is not a function"],
undefined_method: ["Object ", "%1", " has no method '", "%0", "'"],
cannot_convert_to_primitive: ["Cannot convert object to primitive value"],
not_constructor: ["%0", " is not a constructor"],
......@@ -312,8 +318,13 @@ function ToDetailString(obj) {
}
function MakeGenericError(constructor, type, arg0, arg1, arg2) {
if (IS_UNDEFINED(arg0) && IS_STRING(type)) arg0 = [];
function MakeGenericError(constructor, type, args) {
if (IS_UNDEFINED(args)) args = [];
return new constructor(FormatMessage(type, args));
}
function MakeGenericError2(constructor, type, arg0, arg1, arg2) {
return new constructor(FormatMessage(type, arg0, arg1, arg2));
}
......@@ -370,35 +381,42 @@ function GetSourceLine(message) {
}
function MakeError(type, arg0, arg1, arg2) {
return MakeGenericError($Error, type, arg0, arg1, arg2);
function MakeTypeError(type, args) {
return MakeGenericError($TypeError, type, args);
}
function MakeTypeError(type, arg0, arg1, arg2) {
return MakeGenericError($TypeError, type, arg0, arg1, arg2);
// TODO(yangguo): rename this once we migrated all messages.
function MakeTypeError2(type, arg0, arg1, arg2) {
return MakeGenericError2($TypeError, type, arg0, arg1, arg2);
}
function MakeRangeError(type, arg0, arg1, arg2) {
return MakeGenericError($RangeError, type, arg0, arg1, arg2);
function MakeRangeError(type, args) {
return MakeGenericError($RangeError, type, args);
}
function MakeSyntaxError(type, arg0, arg1, arg2) {
return MakeGenericError($SyntaxError, type, arg0, arg1, arg2);
function MakeSyntaxError(type, args) {
return MakeGenericError($SyntaxError, type, args);
}
function MakeReferenceError(type, arg0, arg1, arg2) {
return MakeGenericError($ReferenceError, type, arg0, arg1, arg2);
function MakeReferenceError(type, args) {
return MakeGenericError($ReferenceError, type, args);
}
function MakeEvalError(type, arg0, arg1, arg2) {
return MakeGenericError($EvalError, type, arg0, arg1, arg2);
function MakeEvalError(type, args) {
return MakeGenericError($EvalError, type, args);
}
function MakeError(type, args) {
return MakeGenericError($Error, type, args);
}
// The embedded versions are called from unoptimized code, with embedded
// arguments. Those arguments cannot be arrays, which are context-dependent.
function MakeTypeErrorEmbedded(type, arg) {
......
......@@ -33,7 +33,6 @@
#include "src/log.h"
#include "src/lookup.h"
#include "src/macro-assembler.h"
#include "src/messages.h"
#include "src/objects-inl.h"
#include "src/prototype.h"
#include "src/safepoint-table.h"
......@@ -298,9 +297,10 @@ MaybeHandle<Object> Object::GetPropertyWithAccessor(Handle<Object> receiver,
if (structure->IsAccessorInfo()) {
Handle<AccessorInfo> info = Handle<AccessorInfo>::cast(structure);
if (!info->IsCompatibleReceiver(*receiver)) {
Handle<Object> args[] = {name, receiver};
THROW_NEW_ERROR(isolate,
NewTypeError(MessageTemplate::kIncompatibleMethodReceiver,
name, receiver),
NewTypeError("incompatible_method_receiver",
HandleVector(args, arraysize(args))),
Object);
}
......@@ -362,9 +362,10 @@ MaybeHandle<Object> Object::SetPropertyWithAccessor(
// api style callbacks
ExecutableAccessorInfo* info = ExecutableAccessorInfo::cast(*structure);
if (!info->IsCompatibleReceiver(*receiver)) {
Handle<Object> args[] = {name, receiver};
THROW_NEW_ERROR(isolate,
NewTypeError(MessageTemplate::kIncompatibleMethodReceiver,
name, receiver),
NewTypeError("incompatible_method_receiver",
HandleVector(args, arraysize(args))),
Object);
}
Object* call_obj = info->setter();
......@@ -12488,7 +12489,9 @@ MaybeHandle<Object> JSObject::SetPrototype(Handle<JSObject> object,
!iter.IsAtEnd(); iter.Advance()) {
if (JSReceiver::cast(iter.GetCurrent()) == *object) {
// Cycle detected.
THROW_NEW_ERROR(isolate, NewError(MessageTemplate::kCyclicProto), Object);
THROW_NEW_ERROR(isolate,
NewError("cyclic_proto", HandleVector<Object>(NULL, 0)),
Object);
}
}
......
......@@ -88,8 +88,8 @@ function RegExpCompileJS(pattern, flags) {
// behavior.
if (this == GlobalRegExp.prototype) {
// We don't allow recompiling RegExp.prototype.
throw MakeTypeError(kIncompatibleMethodReceiver,
'RegExp.prototype.compile', this);
throw MakeTypeError('incompatible_method_receiver',
['RegExp.prototype.compile', this]);
}
if (IS_UNDEFINED(pattern) && %_ArgumentsLength() != 0) {
DoConstructRegExp(this, 'undefined', flags);
......@@ -146,8 +146,8 @@ function RegExpExecNoTests(regexp, string, start) {
function RegExpExecJS(string) {
if (!IS_REGEXP(this)) {
throw MakeTypeError(kIncompatibleMethodReceiver,
'RegExp.prototype.exec', this);
throw MakeTypeError('incompatible_method_receiver',
['RegExp.prototype.exec', this]);
}
string = TO_STRING_INLINE(string);
......@@ -194,8 +194,8 @@ var regexp_val;
// else implements.
function RegExpTest(string) {
if (!IS_REGEXP(this)) {
throw MakeTypeError(kIncompatibleMethodReceiver,
'RegExp.prototype.test', this);
throw MakeTypeError('incompatible_method_receiver',
['RegExp.prototype.test', this]);
}
string = TO_STRING_INLINE(string);
......@@ -256,8 +256,8 @@ function TrimRegExp(regexp) {
function RegExpToString() {
if (!IS_REGEXP(this)) {
throw MakeTypeError(kIncompatibleMethodReceiver,
'RegExp.prototype.toString', this);
throw MakeTypeError('incompatible_method_receiver',
['RegExp.prototype.toString', this]);
}
var result = '/' + this.source + '/';
if (this.global) result += 'g';
......
......@@ -379,7 +379,7 @@ function CALL_NON_FUNCTION() {
if (!IS_FUNCTION(delegate)) {
var callsite = %RenderCallSite();
if (callsite == "") callsite = typeof this;
throw %MakeTypeError(kCalledNonCallable, callsite);
throw %MakeTypeError('called_non_callable', [callsite]);
}
return %Apply(delegate, this, arguments, 0, %_ArgumentsLength());
}
......@@ -390,7 +390,7 @@ function CALL_NON_FUNCTION_AS_CONSTRUCTOR() {
if (!IS_FUNCTION(delegate)) {
var callsite = %RenderCallSite();
if (callsite == "") callsite = typeof this;
throw %MakeTypeError(kCalledNonCallable, callsite);
throw %MakeTypeError('called_non_callable', [callsite]);
}
return %Apply(delegate, this, arguments, 0, %_ArgumentsLength());
}
......@@ -463,7 +463,7 @@ function REFLECT_APPLY_PREPARE(args) {
}
if (!IS_SPEC_FUNCTION(this)) {
throw %MakeTypeError(kCalledNonCallable, %ToString(this));
throw %MakeTypeError('called_non_callable', [ %ToString(this) ]);
}
if (!IS_SPEC_OBJECT(args)) {
......@@ -503,7 +503,7 @@ function REFLECT_CONSTRUCT_PREPARE(args, newTarget) {
if (!ctorOk) {
if (!IS_SPEC_FUNCTION(this)) {
throw %MakeTypeError(kCalledNonCallable, %ToString(this));
throw %MakeTypeError('called_non_callable', [ %ToString(this) ]);
} else {
throw %MakeTypeError('not_constructor', [ %ToString(this) ]);
}
......@@ -511,7 +511,7 @@ function REFLECT_CONSTRUCT_PREPARE(args, newTarget) {
if (!newTargetOk) {
if (!IS_SPEC_FUNCTION(newTarget)) {
throw %MakeTypeError(kCalledNonCallable, %ToString(newTarget));
throw %MakeTypeError('called_non_callable', [ %ToString(newTarget) ]);
} else {
throw %MakeTypeError('not_constructor', [ %ToString(newTarget) ]);
}
......
......@@ -398,7 +398,7 @@ static ObjectPair CompileGlobalEval(Isolate* isolate, Handle<String> source,
native_context->ErrorMessageForCodeGenerationFromStrings();
Handle<Object> error;
MaybeHandle<Object> maybe_error = isolate->factory()->NewEvalError(
MessageTemplate::kCodeGenFromStrings, error_message);
"code_gen_from_strings", HandleVector<Object>(&error_message, 1));
if (maybe_error.ToHandle(&error)) isolate->Throw(*error);
return MakePair(isolate->heap()->exception(), NULL);
}
......
......@@ -42,8 +42,8 @@ function StringIteratorNext() {
var iterator = ToObject(this);
if (!HAS_DEFINED_PRIVATE(iterator, stringIteratorNextIndexSymbol)) {
throw MakeTypeError(kIncompatibleMethodReceiver,
'String Iterator.prototype.next');
throw MakeTypeError('incompatible_method_receiver',
['String Iterator.prototype.next']);
}
var s = GET_PRIVATE(iterator, stringIteratorIteratedStringSymbol);
......
......@@ -34,8 +34,8 @@ function SymbolConstructor(x) {
function SymbolToString() {
if (!(IS_SYMBOL(this) || IS_SYMBOL_WRAPPER(this))) {
throw MakeTypeError(kIncompatibleMethodReceiver,
"Symbol.prototype.toString", this);
throw MakeTypeError(
'incompatible_method_receiver', ["Symbol.prototype.toString", this]);
}
var description = %SymbolDescription(%_ValueOf(this));
return "Symbol(" + (IS_UNDEFINED(description) ? "" : description) + ")";
......@@ -44,8 +44,8 @@ function SymbolToString() {
function SymbolValueOf() {
if (!(IS_SYMBOL(this) || IS_SYMBOL_WRAPPER(this))) {
throw MakeTypeError(kIncompatibleMethodReceiver,
"Symbol.prototype.valueOf", this);
throw MakeTypeError(
'incompatible_method_receiver', ["Symbol.prototype.valueOf", this]);
}
return %_ValueOf(this);
}
......
......@@ -119,28 +119,32 @@ function NAMEConstructor(arg1, arg2, arg3) {
function NAME_GetBuffer() {
if (!(%_ClassOf(this) === 'NAME')) {
throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.buffer", this);
throw MakeTypeError('incompatible_method_receiver',
["NAME.buffer", this]);
}
return %TypedArrayGetBuffer(this);
}
function NAME_GetByteLength() {
if (!(%_ClassOf(this) === 'NAME')) {
throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.byteLength", this);
throw MakeTypeError('incompatible_method_receiver',
["NAME.byteLength", this]);
}
return %_ArrayBufferViewGetByteLength(this);
}
function NAME_GetByteOffset() {
if (!(%_ClassOf(this) === 'NAME')) {
throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.byteOffset", this);
throw MakeTypeError('incompatible_method_receiver',
["NAME.byteOffset", this]);
}
return %_ArrayBufferViewGetByteOffset(this);
}
function NAME_GetLength() {
if (!(%_ClassOf(this) === 'NAME')) {
throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.length", this);
throw MakeTypeError('incompatible_method_receiver',
["NAME.length", this]);
}
return %_TypedArrayGetLength(this);
}
......@@ -149,7 +153,8 @@ var $NAME = global.NAME;
function NAMESubArray(begin, end) {
if (!(%_ClassOf(this) === 'NAME')) {
throw MakeTypeError(kIncompatibleMethodReceiver, "NAME.subarray", this);
throw MakeTypeError('incompatible_method_receiver',
["NAME.subarray", this]);
}
var beginInt = TO_INTEGER(begin);
if (!IS_UNDEFINED(end)) {
......@@ -361,23 +366,24 @@ function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3
function DataViewGetBufferJS() {
if (!IS_DATAVIEW(this)) {
throw MakeTypeError(kIncompatibleMethodReceiver, 'DataView.buffer', this);
throw MakeTypeError('incompatible_method_receiver',
['DataView.buffer', this]);
}
return %DataViewGetBuffer(this);
}
function DataViewGetByteOffset() {
if (!IS_DATAVIEW(this)) {
throw MakeTypeError(kIncompatibleMethodReceiver,
'DataView.byteOffset', this);
throw MakeTypeError('incompatible_method_receiver',
['DataView.byteOffset', this]);
}
return %_ArrayBufferViewGetByteOffset(this);
}
function DataViewGetByteLength() {
if (!IS_DATAVIEW(this)) {
throw MakeTypeError(kIncompatibleMethodReceiver,
'DataView.byteLength', this);
throw MakeTypeError('incompatible_method_receiver',
['DataView.byteLength', this]);
}
return %_ArrayBufferViewGetByteLength(this);
}
......@@ -401,8 +407,8 @@ function ToPositiveDataViewOffset(offset) {
macro DATA_VIEW_GETTER_SETTER(TYPENAME)
function DataViewGetTYPENAMEJS(offset, little_endian) {
if (!IS_DATAVIEW(this)) {
throw MakeTypeError(kIncompatibleMethodReceiver,
'DataView.getTYPENAME', this);
throw MakeTypeError('incompatible_method_receiver',
['DataView.getTYPENAME', this]);
}
if (%_ArgumentsLength() < 1) {
throw MakeTypeError('invalid_argument');
......@@ -414,8 +420,8 @@ function DataViewGetTYPENAMEJS(offset, little_endian) {
function DataViewSetTYPENAMEJS(offset, value, little_endian) {
if (!IS_DATAVIEW(this)) {
throw MakeTypeError(kIncompatibleMethodReceiver,
'DataView.setTYPENAME', this);
throw MakeTypeError('incompatible_method_receiver',
['DataView.setTYPENAME', this]);
}
if (%_ArgumentsLength() < 2) {
throw MakeTypeError('invalid_argument');
......
......@@ -691,7 +691,7 @@ function GetMethod(obj, p) {
var func = obj[p];
if (IS_NULL_OR_UNDEFINED(func)) return UNDEFINED;
if (IS_SPEC_FUNCTION(func)) return func;
throw MakeTypeError(kCalledNonCallable, typeof func);
throw MakeTypeError('called_non_callable', [typeof func]);
}
......@@ -1587,8 +1587,8 @@ function NumberToFixedJS(fractionDigits) {
var x = this;
if (!IS_NUMBER(this)) {
if (!IS_NUMBER_WRAPPER(this)) {
throw MakeTypeError(kIncompatibleMethodReceiver,
"Number.prototype.toFixed", this);
throw MakeTypeError("incompatible_method_receiver",
["Number.prototype.toFixed", this]);
}
// Get the value of this number in case it's an object.
x = %_ValueOf(this);
......@@ -1612,8 +1612,8 @@ function NumberToExponentialJS(fractionDigits) {
var x = this;
if (!IS_NUMBER(this)) {
if (!IS_NUMBER_WRAPPER(this)) {
throw MakeTypeError(kIncompatibleMethodReceiver,
"Number.prototype.toExponential", this);
throw MakeTypeError("incompatible_method_receiver",
["Number.prototype.toExponential", this]);
}
// Get the value of this number in case it's an object.
x = %_ValueOf(this);
......@@ -1638,8 +1638,8 @@ function NumberToPrecisionJS(precision) {
var x = this;
if (!IS_NUMBER(this)) {
if (!IS_NUMBER_WRAPPER(this)) {
throw MakeTypeError(kIncompatibleMethodReceiver,
"Number.prototype.toPrecision", this);
throw MakeTypeError("incompatible_method_receiver",
["Number.prototype.toPrecision", this]);
}
// Get the value of this number in case it's an object.
x = %_ValueOf(this);
......
......@@ -25,7 +25,7 @@ function WeakMapConstructor(iterable) {
if (!IS_NULL_OR_UNDEFINED(iterable)) {
var adder = this.set;
if (!IS_SPEC_FUNCTION(adder)) {
throw MakeTypeError(kPropertyNotFunction, 'set', this);
throw MakeTypeError(kPropertyNotFunction, ['set', this]);
}
for (var nextItem of iterable) {
if (!IS_SPEC_OBJECT(nextItem)) {
......@@ -39,8 +39,8 @@ function WeakMapConstructor(iterable) {
function WeakMapGet(key) {
if (!IS_WEAKMAP(this)) {
throw MakeTypeError(kIncompatibleMethodReceiver,
'WeakMap.prototype.get', this);
throw MakeTypeError('incompatible_method_receiver',
['WeakMap.prototype.get', this]);
}
if (!IS_SPEC_OBJECT(key)) return UNDEFINED;
return %WeakCollectionGet(this, key);
......@@ -49,8 +49,8 @@ function WeakMapGet(key) {
function WeakMapSet(key, value) {
if (!IS_WEAKMAP(this)) {
throw MakeTypeError(kIncompatibleMethodReceiver,
'WeakMap.prototype.set', this);
throw MakeTypeError('incompatible_method_receiver',
['WeakMap.prototype.set', this]);
}
if (!IS_SPEC_OBJECT(key)) {
throw %MakeTypeError('invalid_weakmap_key', [this, key]);
......@@ -61,8 +61,8 @@ function WeakMapSet(key, value) {
function WeakMapHas(key) {
if (!IS_WEAKMAP(this)) {
throw MakeTypeError(kIncompatibleMethodReceiver,
'WeakMap.prototype.has', this);
throw MakeTypeError('incompatible_method_receiver',
['WeakMap.prototype.has', this]);
}
if (!IS_SPEC_OBJECT(key)) return false;
return %WeakCollectionHas(this, key);
......@@ -71,8 +71,8 @@ function WeakMapHas(key) {
function WeakMapDelete(key) {
if (!IS_WEAKMAP(this)) {
throw MakeTypeError(kIncompatibleMethodReceiver,
'WeakMap.prototype.delete', this);
throw MakeTypeError('incompatible_method_receiver',
['WeakMap.prototype.delete', this]);
}
if (!IS_SPEC_OBJECT(key)) return false;
return %WeakCollectionDelete(this, key);
......@@ -110,7 +110,7 @@ function WeakSetConstructor(iterable) {
if (!IS_NULL_OR_UNDEFINED(iterable)) {
var adder = this.add;
if (!IS_SPEC_FUNCTION(adder)) {
throw MakeTypeError(kPropertyNotFunction, 'add', this);
throw MakeTypeError(kPropertyNotFunction, ['add', this]);
}
for (var value of iterable) {
%_CallFunction(this, value, adder);
......@@ -121,8 +121,8 @@ function WeakSetConstructor(iterable) {
function WeakSetAdd(value) {
if (!IS_WEAKSET(this)) {
throw MakeTypeError(kIncompatibleMethodReceiver,
'WeakSet.prototype.add', this);
throw MakeTypeError('incompatible_method_receiver',
['WeakSet.prototype.add', this]);
}
if (!IS_SPEC_OBJECT(value)) {
throw %MakeTypeError('invalid_weakset_value', [this, value]);
......@@ -133,8 +133,8 @@ function WeakSetAdd(value) {
function WeakSetHas(value) {
if (!IS_WEAKSET(this)) {
throw MakeTypeError(kIncompatibleMethodReceiver,
'WeakSet.prototype.has', this);
throw MakeTypeError('incompatible_method_receiver',
['WeakSet.prototype.has', this]);
}
if (!IS_SPEC_OBJECT(value)) return false;
return %WeakCollectionHas(this, value);
......@@ -143,8 +143,8 @@ function WeakSetHas(value) {
function WeakSetDelete(value) {
if (!IS_WEAKSET(this)) {
throw MakeTypeError(kIncompatibleMethodReceiver,
'WeakSet.prototype.delete', this);
throw MakeTypeError('incompatible_method_receiver',
['WeakSet.prototype.delete', this]);
}
if (!IS_SPEC_OBJECT(value)) return false;
return %WeakCollectionDelete(this, value);
......
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
function test(f, expected, type) {
try {
f();
assertUnreachable();
} catch (e) {
assertInstanceof(e, type);
assertEquals(expected, e.message);
}
}
// === Error ===
// kCyclicProto
test(function() {
var o = {};
o.__proto__ = o;
}, "Cyclic __proto__ value", Error);
// === TypeError ===
// kGeneratorRunning
test(function() {
var iter;
function* generator() { yield iter.next(); }
var iter = generator();
iter.next();
}, "Generator is already running", TypeError);
// kCalledNonCallable
test(function() {
[].forEach(1);
}, "1 is not a function", TypeError);
// kIncompatibleMethodReceiver
test(function() {
RegExp.prototype.compile.call(RegExp.prototype);
}, "Method RegExp.prototype.compile called on incompatible receiver " +
"[object RegExp]", TypeError);
// kPropertyNotFunction
test(function() {
Set.prototype.add = 0;
new Set(1);
}, "Property 'add' of object #<Set> is not a function", TypeError);
// kWithExpression
test(function() {
with (null) {}
}, "null has no properties", TypeError);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment