diff --git a/src/array-iterator.js b/src/array-iterator.js index 7cf0db4c0be..95635cd4bf7 100644 --- a/src/array-iterator.js +++ b/src/array-iterator.js @@ -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); diff --git a/src/array.js b/src/array.js index b2e26e03054..68796dda353 100644 --- a/src/array.js +++ b/src/array.js @@ -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); diff --git a/src/arraybuffer.js b/src/arraybuffer.js index 2a6ef802975..86b13927aa4 100644 --- a/src/arraybuffer.js +++ b/src/arraybuffer.js @@ -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); diff --git a/src/collection-iterator.js b/src/collection-iterator.js index c99947b47ca..e66b4434041 100644 --- a/src/collection-iterator.js +++ b/src/collection-iterator.js @@ -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); } diff --git a/src/collection.js b/src/collection.js index 206aaa79134..af1b22347bb 100644 --- a/src/collection.js +++ b/src/collection.js @@ -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; diff --git a/src/execution.cc b/src/execution.cc index ad7d7f6020b..0a45ee77c57 100644 --- a/src/execution.cc +++ b/src/execution.cc @@ -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 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(&object, 1)), Object); } @@ -336,8 +335,8 @@ MaybeHandle 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(&object, 1)), Object); } diff --git a/src/factory.cc b/src/factory.cc index 106f3d75d3d..9f359bbc6d3 100644 --- a/src/factory.cc +++ b/src/factory.cc @@ -1080,6 +1080,13 @@ Handle Factory::NewTypeError(const char* message, } +Handle Factory::NewTypeError(MessageTemplate::Template template_index, + Handle arg0, Handle arg1, + Handle arg2) { + return NewError("MakeTypeError2", template_index, arg0, arg1, arg2); +} + + Handle Factory::NewTypeError(Handle message) { return NewError("$TypeError", message); } @@ -1177,24 +1184,9 @@ Handle Factory::NewEvalError(const char* message, } -Handle Factory::NewError(MessageTemplate::Template template_index, - Handle arg0, Handle arg1, - Handle arg2) { - return NewError("MakeError", template_index, arg0, arg1, arg2); -} - - -Handle Factory::NewTypeError(MessageTemplate::Template template_index, - Handle arg0, Handle arg1, - Handle arg2) { - return NewError("MakeTypeError", template_index, arg0, arg1, arg2); -} - - -Handle Factory::NewEvalError(MessageTemplate::Template template_index, - Handle arg0, Handle arg1, - Handle arg2) { - return NewError("MakeEvalError", template_index, arg0, arg1, arg2); +Handle Factory::NewError(const char* message, + Vector > args) { + return NewError("MakeError", message, args); } diff --git a/src/factory.h b/src/factory.h index 9ecf3206ea9..13a5c3e6e15 100644 --- a/src/factory.h +++ b/src/factory.h @@ -537,12 +537,20 @@ class Factory FINAL { Handle NewError(const char* maker, const char* message, Vector > args); Handle NewError(const char* message, Vector > args); + Handle NewError(const char* maker, + MessageTemplate::Template template_index, + Handle arg0, Handle arg1, + Handle arg2); Handle NewError(Handle message); Handle NewError(const char* constructor, Handle message); Handle NewTypeError(const char* message, Vector > args); + Handle NewTypeError(MessageTemplate::Template template_index, + Handle arg0 = Handle(), + Handle arg1 = Handle(), + Handle arg2 = Handle()); Handle NewTypeError(Handle message); Handle NewRangeError(const char* message, @@ -565,26 +573,6 @@ class Factory FINAL { Handle NewEvalError(const char* message, Vector > args); - Handle NewError(const char* maker, - MessageTemplate::Template template_index, - Handle arg0, Handle arg1, - Handle arg2); - - Handle NewError(MessageTemplate::Template template_index, - Handle arg0 = Handle(), - Handle arg1 = Handle(), - Handle arg2 = Handle()); - - Handle NewTypeError(MessageTemplate::Template template_index, - Handle arg0 = Handle(), - Handle arg1 = Handle(), - Handle arg2 = Handle()); - - Handle NewEvalError(MessageTemplate::Template template_index, - Handle arg0 = Handle(), - Handle arg1 = Handle(), - Handle arg2 = Handle()); - Handle NumberToString(Handle number, bool check_number_string_cache = true); diff --git a/src/generator.js b/src/generator.js index 484afd8d6a5..031d56e37e3 100644 --- a/src/generator.js +++ b/src/generator.js @@ -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', []); } } diff --git a/src/harmony-array.js b/src/harmony-array.js index dc7d71fcb4d..cdd63be4161 100644 --- a/src/harmony-array.js +++ b/src/harmony-array.js @@ -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)) { diff --git a/src/harmony-typedarray.js b/src/harmony-typedarray.js index a3bbf1a9b1f..d692a5f1bc5 100644 --- a/src/harmony-typedarray.js +++ b/src/harmony-typedarray.js @@ -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; diff --git a/src/messages.h b/src/messages.h index fb3e50caf80..ba130427225 100644 --- a/src/messages.h +++ b/src/messages.h @@ -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: diff --git a/src/messages.js b/src/messages.js index 757e6f68296..a0f366b10b2 100644 --- a/src/messages.js +++ b/src/messages.js @@ -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) { diff --git a/src/objects.cc b/src/objects.cc index c6d5266bf78..037d33c5039 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -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::GetPropertyWithAccessor(Handle receiver, if (structure->IsAccessorInfo()) { Handle info = Handle::cast(structure); if (!info->IsCompatibleReceiver(*receiver)) { + Handle 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::SetPropertyWithAccessor( // api style callbacks ExecutableAccessorInfo* info = ExecutableAccessorInfo::cast(*structure); if (!info->IsCompatibleReceiver(*receiver)) { + Handle 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 JSObject::SetPrototype(Handle 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(NULL, 0)), + Object); } } diff --git a/src/regexp.js b/src/regexp.js index 9db8e995b05..a344b31f8a6 100644 --- a/src/regexp.js +++ b/src/regexp.js @@ -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'; diff --git a/src/runtime.js b/src/runtime.js index b20639cde61..e4cb4ff312a 100644 --- a/src/runtime.js +++ b/src/runtime.js @@ -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) ]); } diff --git a/src/runtime/runtime-compiler.cc b/src/runtime/runtime-compiler.cc index 2cbb732004a..16175803f05 100644 --- a/src/runtime/runtime-compiler.cc +++ b/src/runtime/runtime-compiler.cc @@ -398,7 +398,7 @@ static ObjectPair CompileGlobalEval(Isolate* isolate, Handle source, native_context->ErrorMessageForCodeGenerationFromStrings(); Handle error; MaybeHandle maybe_error = isolate->factory()->NewEvalError( - MessageTemplate::kCodeGenFromStrings, error_message); + "code_gen_from_strings", HandleVector(&error_message, 1)); if (maybe_error.ToHandle(&error)) isolate->Throw(*error); return MakePair(isolate->heap()->exception(), NULL); } diff --git a/src/string-iterator.js b/src/string-iterator.js index cb3a90abc5f..dea81e57254 100644 --- a/src/string-iterator.js +++ b/src/string-iterator.js @@ -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); diff --git a/src/symbol.js b/src/symbol.js index 0f5ecb7984d..4ea77979c23 100644 --- a/src/symbol.js +++ b/src/symbol.js @@ -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); } diff --git a/src/typedarray.js b/src/typedarray.js index 4e3b9385863..2086fc3a820 100644 --- a/src/typedarray.js +++ b/src/typedarray.js @@ -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'); diff --git a/src/v8natives.js b/src/v8natives.js index d050a9e2c47..6b0aa205884 100644 --- a/src/v8natives.js +++ b/src/v8natives.js @@ -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); diff --git a/src/weak-collection.js b/src/weak-collection.js index 02804aff72e..44faa3ecd88 100644 --- a/src/weak-collection.js +++ b/src/weak-collection.js @@ -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); diff --git a/test/mjsunit/messages.js b/test/mjsunit/messages.js deleted file mode 100644 index c2ba73600a5..00000000000 --- a/test/mjsunit/messages.js +++ /dev/null @@ -1,54 +0,0 @@ -// 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 # is not a function", TypeError); - -// kWithExpression -test(function() { - with (null) {} -}, "null has no properties", TypeError);