Commit ae2057e8 authored by yangguo's avatar yangguo Committed by Commit bot

Reland "Migrate error messages, part 2."

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

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