Commit 9b2fe70d authored by yangguo's avatar yangguo Committed by Commit bot

Migrate error messages, part 4 (v8natives.js).

Goal is to reduce native context size.

R=mvstanton@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#27953}
parent c15ca44b
...@@ -22,7 +22,7 @@ function SpreadArguments() { ...@@ -22,7 +22,7 @@ function SpreadArguments() {
function SpreadIterable(collection) { function SpreadIterable(collection) {
if (IS_NULL_OR_UNDEFINED(collection)) { if (IS_NULL_OR_UNDEFINED(collection)) {
throw MakeTypeError("not_iterable", [collection]); throw MakeTypeError(kNotIterable, collection);
} }
var args = new InternalArray(); var args = new InternalArray();
......
...@@ -189,8 +189,8 @@ MaybeHandle<String> MessageTemplate::FormatMessage(int template_index, ...@@ -189,8 +189,8 @@ MaybeHandle<String> MessageTemplate::FormatMessage(int template_index,
Handle<String> args[] = {arg0, arg1, arg2}; Handle<String> args[] = {arg0, arg1, arg2};
for (const char* c = template_string; *c != '\0'; c++) { for (const char* c = template_string; *c != '\0'; c++) {
if (*c == '%') { if (*c == '%') {
builder.AppendString(args[i++]);
DCHECK(i < arraysize(args)); DCHECK(i < arraysize(args));
builder.AppendString(args[i++]);
} else { } else {
builder.AppendCharacter(*c); builder.AppendCharacter(*c);
} }
......
...@@ -88,34 +88,66 @@ class MessageHandler { ...@@ -88,34 +88,66 @@ class MessageHandler {
}; };
#define MESSAGE_TEMPLATES(T) \ #define MESSAGE_TEMPLATES(T) \
/* Error */ \ /* Error */ \
T(CyclicProto, "Cyclic __proto__ value") \ T(CyclicProto, "Cyclic __proto__ value") \
/* TypeError */ \ /* TypeError */ \
T(ApplyNonFunction, \ T(ApplyNonFunction, \
"Function.prototype.apply was called on %, which is a % and not a " \ "Function.prototype.apply was called on %, which is a % and not a " \
"function") \ "function") \
T(CalledNonCallable, "% is not a function") \ T(CalledNonCallable, "% is not a function") \
T(CannotConvertToPrimitive, "Cannot convert object to primitive value") \ T(CalledOnNonObject, "% called on non-object") \
T(GeneratorRunning, "Generator is already running") \ T(CannotConvertToPrimitive, "Cannot convert object to primitive value") \
T(IncompatibleMethodReceiver, "Method % called on incompatible receiver %") \ T(DefineDisallowed, "Cannot define property:%, object is not extensible.") \
T(InstanceofFunctionExpected, \ T(GeneratorRunning, "Generator is already running") \
"Expecting a function in instanceof check, but got %") \ T(FunctionBind, "Bind must be called on a function") \
T(InstanceofNonobjectProto, \ T(IncompatibleMethodReceiver, "Method % called on incompatible receiver %") \
"Function has non-object prototype '%' in instanceof check") \ T(InstanceofFunctionExpected, \
T(InvalidInOperatorUse, "Cannot use 'in' operator to search for '%' in %") \ "Expecting a function in instanceof check, but got %") \
T(NotConstructor, "% is not a constructor") \ T(InstanceofNonobjectProto, \
T(PropertyNotFunction, "Property '%' of object % is not a function") \ "Function has non-object prototype '%' in instanceof check") \
T(SymbolToPrimitive, \ T(InvalidInOperatorUse, "Cannot use 'in' operator to search for '%' in %") \
"Cannot convert a Symbol wrapper object to a primitive value") \ T(NotAnIterator, "% is not an iterator") \
T(SymbolToNumber, "Cannot convert a Symbol value to a number") \ T(NotConstructor, "% is not a constructor") \
T(SymbolToString, "Cannot convert a Symbol value to a string") \ T(NotGeneric, "% is not generic") \
T(UndefinedOrNullToObject, "Cannot convert undefined or null to object") \ T(NotIterable, "% is not iterable") \
T(WithExpression, "% has no properties") \ T(ObjectGetterExpectingFunction, \
T(WrongArgs, "%: Arguments list has wrong type") \ "Object.prototype.__defineGetter__: Expecting function") \
/* RangeError */ \ T(ObjectGetterCallable, "Getter must be a function: %") \
T(StackOverflow, "Maximum call stack size exceeded") \ T(ObjectSetterExpectingFunction, \
/* EvalError */ \ "Object.prototype.__defineSetter__: Expecting function") \
T(ObjectSetterCallable, "Setter must be a function: %") \
T(PropertyDescObject, "Property description must be an object: %") \
T(PropertyNotFunction, "Property '%' of object % is not a function") \
T(ProtoObjectOrNull, "Object prototype may only be an Object or null: %") \
T(ProxyHandlerReturned, "Proxy handler % returned % from '%' trap") \
T(ProxyHandlerTrapMissing, "Proxy handler % has no '%' trap") \
T(ProxyHandlerTrapMustBeCallable, \
"Proxy handler %0 has non-callable '%' trap") \
T(ProxyNonObjectPropNames, "Trap '%' returned non-object %") \
T(ProxyRepeatedPropName, "Trap '%' returned repeated property name '%'") \
T(ProxyPropNotConfigurable, \
"Proxy handler % returned non-configurable descriptor for property '%' " \
"from '%' trap") \
T(RedefineDisallowed, "Cannot redefine property: %") \
T(SymbolToPrimitive, \
"Cannot convert a Symbol wrapper object to a primitive value") \
T(SymbolToNumber, "Cannot convert a Symbol value to a number") \
T(SymbolToString, "Cannot convert a Symbol value to a string") \
T(UndefinedOrNullToObject, "Cannot convert undefined or null to object") \
T(ValueAndAccessor, \
"Invalid property. A property cannot both have accessors and be " \
"writable or have a value, %") \
T(WithExpression, "% has no properties") \
T(WrongArgs, "%: Arguments list has wrong type") \
/* RangeError */ \
T(ArrayLengthOutOfRange, "defineProperty() array length out of range") \
T(NumberFormatRange, "% argument must be between 0 and 20") \
T(StackOverflow, "Maximum call stack size exceeded") \
T(ToPrecisionFormatRange, "toPrecision() argument must be between 1 and 21") \
/* SyntaxError */ \
T(ParenthesisInArgString, "Function arg string contains parenthesis") \
/* EvalError */ \
T(CodeGenFromStrings, "%") T(CodeGenFromStrings, "%")
class MessageTemplate { class MessageTemplate {
......
...@@ -42,23 +42,12 @@ var kMessages = { ...@@ -42,23 +42,12 @@ var kMessages = {
no_setter_in_callback: ["Cannot set property ", "%0", " of ", "%1", " which has only a getter"], no_setter_in_callback: ["Cannot set property ", "%0", " of ", "%1", " which has only a getter"],
flags_getter_non_object: ["RegExp.prototype.flags getter called on non-object ", "%0"], flags_getter_non_object: ["RegExp.prototype.flags getter called on non-object ", "%0"],
reduce_no_initial: ["Reduce of empty array with no initial value"], reduce_no_initial: ["Reduce of empty array with no initial value"],
getter_must_be_callable: ["Getter must be a function: ", "%0"],
setter_must_be_callable: ["Setter must be a function: ", "%0"],
value_and_accessor: ["Invalid property. A property cannot both have accessors and be writable or have a value, ", "%0"], value_and_accessor: ["Invalid property. A property cannot both have accessors and be writable or have a value, ", "%0"],
proto_object_or_null: ["Object prototype may only be an Object or null: ", "%0"], proto_object_or_null: ["Object prototype may only be an Object or null: ", "%0"],
property_desc_object: ["Property description must be an object: ", "%0"],
redefine_disallowed: ["Cannot redefine property: ", "%0"],
define_disallowed: ["Cannot define property:", "%0", ", object is not extensible."],
non_extensible_proto: ["%0", " is not extensible"], non_extensible_proto: ["%0", " is not extensible"],
handler_non_object: ["Proxy.", "%0", " called with non-object as handler"], handler_non_object: ["Proxy.", "%0", " called with non-object as handler"],
proto_non_object: ["Proxy.", "%0", " called with non-object as prototype"], proto_non_object: ["Proxy.", "%0", " called with non-object as prototype"],
trap_function_expected: ["Proxy.", "%0", " called with non-function for '", "%1", "' trap"], trap_function_expected: ["Proxy.", "%0", " called with non-function for '", "%1", "' trap"],
handler_trap_missing: ["Proxy handler ", "%0", " has no '", "%1", "' trap"],
handler_trap_must_be_callable: ["Proxy handler ", "%0", " has non-callable '", "%1", "' trap"],
handler_returned_false: ["Proxy handler ", "%0", " returned false from '", "%1", "' trap"],
handler_returned_undefined: ["Proxy handler ", "%0", " returned undefined from '", "%1", "' trap"],
proxy_prop_not_configurable: ["Proxy handler ", "%0", " returned non-configurable descriptor for property '", "%2", "' from '", "%1", "' trap"],
proxy_non_object_prop_names: ["Trap '", "%1", "' returned non-object ", "%0"],
proxy_repeated_prop_name: ["Trap '", "%1", "' returned repeated property name '", "%2", "'"], proxy_repeated_prop_name: ["Trap '", "%1", "' returned repeated property name '", "%2", "'"],
invalid_weakmap_key: ["Invalid value used as weak map key"], invalid_weakmap_key: ["Invalid value used as weak map key"],
invalid_weakset_value: ["Invalid value used in weak set"], invalid_weakset_value: ["Invalid value used in weak set"],
...@@ -83,8 +72,6 @@ var kMessages = { ...@@ -83,8 +72,6 @@ var kMessages = {
array_functions_on_frozen: ["Cannot modify frozen array elements"], array_functions_on_frozen: ["Cannot modify frozen array elements"],
array_functions_change_sealed: ["Cannot add/remove sealed array elements"], array_functions_change_sealed: ["Cannot add/remove sealed array elements"],
first_argument_not_regexp: ["First argument to ", "%0", " must not be a regular expression"], first_argument_not_regexp: ["First argument to ", "%0", " must not be a regular expression"],
not_iterable: ["%0", " is not iterable"],
not_an_iterator: ["%0", " is not an iterator"],
iterator_result_not_an_object: ["Iterator result ", "%0", " is not an object"], iterator_result_not_an_object: ["Iterator result ", "%0", " is not an object"],
iterator_value_not_an_object: ["Iterator value ", "%0", " is not an entry object"], iterator_value_not_an_object: ["Iterator value ", "%0", " is not an entry object"],
// RangeError // RangeError
...@@ -112,7 +99,6 @@ var kMessages = { ...@@ -112,7 +99,6 @@ var kMessages = {
invalid_lhs_in_postfix_op: ["Invalid left-hand side expression in postfix operation"], invalid_lhs_in_postfix_op: ["Invalid left-hand side expression in postfix operation"],
invalid_lhs_in_prefix_op: ["Invalid left-hand side expression in prefix operation"], invalid_lhs_in_prefix_op: ["Invalid left-hand side expression in prefix operation"],
// SyntaxError // SyntaxError
paren_in_arg_string: ["Function arg string contains parenthesis"],
not_isvar: ["builtin %IS_VAR: not a variable"], not_isvar: ["builtin %IS_VAR: not a variable"],
single_function_literal: ["Single function literal required"], single_function_literal: ["Single function literal required"],
invalid_regexp_flags: ["Invalid flags supplied to RegExp constructor '", "%0", "'"], invalid_regexp_flags: ["Invalid flags supplied to RegExp constructor '", "%0", "'"],
...@@ -121,10 +107,7 @@ var kMessages = { ...@@ -121,10 +107,7 @@ var kMessages = {
illegal_continue: ["Illegal continue statement"], illegal_continue: ["Illegal continue statement"],
illegal_return: ["Illegal return statement"], illegal_return: ["Illegal return statement"],
error_loading_debugger: ["Error loading debugger"], error_loading_debugger: ["Error loading debugger"],
no_input_to_regexp: ["No input to ", "%0"],
invalid_json: ["String '", "%0", "' is not valid JSON"],
circular_structure: ["Converting circular structure to JSON"], circular_structure: ["Converting circular structure to JSON"],
called_on_non_object: ["%0", " called on non-object"],
called_on_null_or_undefined: ["%0", " called on null or undefined"], called_on_null_or_undefined: ["%0", " called on null or undefined"],
array_indexof_not_defined: ["Array.getIndexOf: Argument undefined"], array_indexof_not_defined: ["Array.getIndexOf: Argument undefined"],
object_not_extensible: ["Can't add property ", "%0", ", object is not extensible"], object_not_extensible: ["Can't add property ", "%0", ", object is not extensible"],
...@@ -1252,7 +1235,7 @@ function ErrorToStringDetectCycle(error) { ...@@ -1252,7 +1235,7 @@ function ErrorToStringDetectCycle(error) {
function ErrorToString() { function ErrorToString() {
if (!IS_SPEC_OBJECT(this)) { if (!IS_SPEC_OBJECT(this)) {
throw MakeTypeError("called_on_non_object", ["Error.prototype.toString"]); throw MakeTypeError(kCalledOnNonObject, "Error.prototype.toString");
} }
try { try {
......
...@@ -554,7 +554,7 @@ function NotifyChange(type, object, name, oldValue) { ...@@ -554,7 +554,7 @@ function NotifyChange(type, object, name, oldValue) {
function ObjectNotifierNotify(changeRecord) { function ObjectNotifierNotify(changeRecord) {
if (!IS_SPEC_OBJECT(this)) if (!IS_SPEC_OBJECT(this))
throw MakeTypeError("called_on_non_object", ["notify"]); throw MakeTypeError(kCalledOnNonObject, "notify");
var objectInfo = ObjectInfoGetFromNotifier(this); var objectInfo = ObjectInfoGetFromNotifier(this);
if (IS_UNDEFINED(objectInfo)) if (IS_UNDEFINED(objectInfo))
...@@ -568,7 +568,7 @@ function ObjectNotifierNotify(changeRecord) { ...@@ -568,7 +568,7 @@ function ObjectNotifierNotify(changeRecord) {
function ObjectNotifierPerformChange(changeType, changeFn) { function ObjectNotifierPerformChange(changeType, changeFn) {
if (!IS_SPEC_OBJECT(this)) if (!IS_SPEC_OBJECT(this))
throw MakeTypeError("called_on_non_object", ["performChange"]); throw MakeTypeError(kCalledOnNonObject, "performChange");
var objectInfo = ObjectInfoGetFromNotifier(this); var objectInfo = ObjectInfoGetFromNotifier(this);
if (IS_UNDEFINED(objectInfo)) if (IS_UNDEFINED(objectInfo))
......
...@@ -3315,9 +3315,8 @@ MaybeHandle<Object> Object::RedefineNonconfigurableProperty( ...@@ -3315,9 +3315,8 @@ MaybeHandle<Object> Object::RedefineNonconfigurableProperty(
Isolate* isolate, Handle<Object> name, Handle<Object> value, Isolate* isolate, Handle<Object> name, Handle<Object> value,
LanguageMode language_mode) { LanguageMode language_mode) {
if (is_sloppy(language_mode)) return value; if (is_sloppy(language_mode)) return value;
Handle<Object> args[] = {name}; THROW_NEW_ERROR(isolate,
THROW_NEW_ERROR(isolate, NewTypeError("redefine_disallowed", NewTypeError(MessageTemplate::kRedefineDisallowed, name),
HandleVector(args, arraysize(args))),
Object); Object);
} }
...@@ -3904,9 +3903,9 @@ MaybeHandle<Object> JSProxy::SetPropertyViaPrototypesWithHandler( ...@@ -3904,9 +3903,9 @@ MaybeHandle<Object> JSProxy::SetPropertyViaPrototypesWithHandler(
if (configurable->IsFalse()) { if (configurable->IsFalse()) {
Handle<String> trap = isolate->factory()->InternalizeOneByteString( Handle<String> trap = isolate->factory()->InternalizeOneByteString(
STATIC_CHAR_VECTOR("getPropertyDescriptor")); STATIC_CHAR_VECTOR("getPropertyDescriptor"));
Handle<Object> args[] = { handler, trap, name }; THROW_NEW_ERROR(isolate,
THROW_NEW_ERROR(isolate, NewTypeError("proxy_prop_not_configurable", NewTypeError(MessageTemplate::kProxyPropNotConfigurable,
HandleVector(args, arraysize(args))), handler, name, trap),
Object); Object);
} }
DCHECK(configurable->IsTrue()); DCHECK(configurable->IsTrue());
...@@ -4046,9 +4045,8 @@ Maybe<PropertyAttributes> JSProxy::GetPropertyAttributesWithHandler( ...@@ -4046,9 +4045,8 @@ Maybe<PropertyAttributes> JSProxy::GetPropertyAttributesWithHandler(
Handle<Object> handler(proxy->handler(), isolate); Handle<Object> handler(proxy->handler(), isolate);
Handle<String> trap = isolate->factory()->InternalizeOneByteString( Handle<String> trap = isolate->factory()->InternalizeOneByteString(
STATIC_CHAR_VECTOR("getPropertyDescriptor")); STATIC_CHAR_VECTOR("getPropertyDescriptor"));
Handle<Object> args[] = { handler, trap, name };
Handle<Object> error = isolate->factory()->NewTypeError( Handle<Object> error = isolate->factory()->NewTypeError(
"proxy_prop_not_configurable", HandleVector(args, arraysize(args))); MessageTemplate::kProxyPropNotConfigurable, handler, name, trap);
isolate->Throw(*error); isolate->Throw(*error);
return Just(NONE); return Just(NONE);
} }
...@@ -4108,10 +4106,9 @@ MaybeHandle<Object> JSProxy::CallTrap(Handle<JSProxy> proxy, ...@@ -4108,10 +4106,9 @@ MaybeHandle<Object> JSProxy::CallTrap(Handle<JSProxy> proxy,
if (trap->IsUndefined()) { if (trap->IsUndefined()) {
if (derived.is_null()) { if (derived.is_null()) {
Handle<Object> args[] = { handler, trap_name };
THROW_NEW_ERROR(isolate, THROW_NEW_ERROR(isolate,
NewTypeError("handler_trap_missing", NewTypeError(MessageTemplate::kProxyHandlerTrapMissing,
HandleVector(args, arraysize(args))), handler, trap_name),
Object); Object);
} }
trap = Handle<Object>(derived); trap = Handle<Object>(derived);
......
...@@ -162,8 +162,8 @@ function DerivedEnumerateTrap() { ...@@ -162,8 +162,8 @@ function DerivedEnumerateTrap() {
var desc = this.getPropertyDescriptor(TO_STRING_INLINE(name)) var desc = this.getPropertyDescriptor(TO_STRING_INLINE(name))
if (!IS_UNDEFINED(desc)) { if (!IS_UNDEFINED(desc)) {
if (!desc.configurable) { if (!desc.configurable) {
throw MakeTypeError("proxy_prop_not_configurable", throw MakeTypeError(kProxyPropNotConfigurable,
[this, "getPropertyDescriptor", name]) this, name, "getPropertyDescriptor")
} }
if (desc.enumerable) enumerableNames[count++] = names[i] if (desc.enumerable) enumerableNames[count++] = names[i]
} }
......
...@@ -29,7 +29,7 @@ function StringConstructor(x) { ...@@ -29,7 +29,7 @@ function StringConstructor(x) {
// ECMA-262 section 15.5.4.2 // ECMA-262 section 15.5.4.2
function StringToString() { function StringToString() {
if (!IS_STRING(this) && !IS_STRING_WRAPPER(this)) { if (!IS_STRING(this) && !IS_STRING_WRAPPER(this)) {
throw new $TypeError('String.prototype.toString is not generic'); throw MakeTypeError(kNotGeneric, 'String.prototype.toString');
} }
return %_ValueOf(this); return %_ValueOf(this);
} }
...@@ -38,7 +38,7 @@ function StringToString() { ...@@ -38,7 +38,7 @@ function StringToString() {
// ECMA-262 section 15.5.4.3 // ECMA-262 section 15.5.4.3
function StringValueOf() { function StringValueOf() {
if (!IS_STRING(this) && !IS_STRING_WRAPPER(this)) { if (!IS_STRING(this) && !IS_STRING_WRAPPER(this)) {
throw new $TypeError('String.prototype.valueOf is not generic'); throw MakeTypeError(kNotGeneric, 'String.prototype.valueOf');
} }
return %_ValueOf(this); return %_ValueOf(this);
} }
......
...@@ -300,8 +300,7 @@ function ObjectDefineGetter(name, fun) { ...@@ -300,8 +300,7 @@ function ObjectDefineGetter(name, fun) {
receiver = %GlobalProxy(global); receiver = %GlobalProxy(global);
} }
if (!IS_SPEC_FUNCTION(fun)) { if (!IS_SPEC_FUNCTION(fun)) {
throw new $TypeError( throw MakeTypeError(kObjectGetterExpectingFunction);
'Object.prototype.__defineGetter__: Expecting function');
} }
var desc = new PropertyDescriptor(); var desc = new PropertyDescriptor();
desc.setGet(fun); desc.setGet(fun);
...@@ -326,8 +325,7 @@ function ObjectDefineSetter(name, fun) { ...@@ -326,8 +325,7 @@ function ObjectDefineSetter(name, fun) {
receiver = %GlobalProxy(global); receiver = %GlobalProxy(global);
} }
if (!IS_SPEC_FUNCTION(fun)) { if (!IS_SPEC_FUNCTION(fun)) {
throw new $TypeError( throw MakeTypeError(kObjectSetterExpectingFunction);
'Object.prototype.__defineSetter__: Expecting function');
} }
var desc = new PropertyDescriptor(); var desc = new PropertyDescriptor();
desc.setSet(fun); desc.setSet(fun);
...@@ -430,9 +428,8 @@ function FromGenericPropertyDescriptor(desc) { ...@@ -430,9 +428,8 @@ function FromGenericPropertyDescriptor(desc) {
// ES5 8.10.5. // ES5 8.10.5.
function ToPropertyDescriptor(obj) { function ToPropertyDescriptor(obj) {
if (!IS_SPEC_OBJECT(obj)) { if (!IS_SPEC_OBJECT(obj)) throw MakeTypeError(kPropertyDescObject, obj);
throw MakeTypeError("property_desc_object", [obj]);
}
var desc = new PropertyDescriptor(); var desc = new PropertyDescriptor();
if ("enumerable" in obj) { if ("enumerable" in obj) {
...@@ -454,7 +451,7 @@ function ToPropertyDescriptor(obj) { ...@@ -454,7 +451,7 @@ function ToPropertyDescriptor(obj) {
if ("get" in obj) { if ("get" in obj) {
var get = obj.get; var get = obj.get;
if (!IS_UNDEFINED(get) && !IS_SPEC_FUNCTION(get)) { if (!IS_UNDEFINED(get) && !IS_SPEC_FUNCTION(get)) {
throw MakeTypeError("getter_must_be_callable", [get]); throw MakeTypeError(kObjectGetterCallable, get);
} }
desc.setGet(get); desc.setGet(get);
} }
...@@ -462,13 +459,13 @@ function ToPropertyDescriptor(obj) { ...@@ -462,13 +459,13 @@ function ToPropertyDescriptor(obj) {
if ("set" in obj) { if ("set" in obj) {
var set = obj.set; var set = obj.set;
if (!IS_UNDEFINED(set) && !IS_SPEC_FUNCTION(set)) { if (!IS_UNDEFINED(set) && !IS_SPEC_FUNCTION(set)) {
throw MakeTypeError("setter_must_be_callable", [set]); throw MakeTypeError(kObjectSetterCallable, set);
} }
desc.setSet(set); desc.setSet(set);
} }
if (IsInconsistentDescriptor(desc)) { if (IsInconsistentDescriptor(desc)) {
throw MakeTypeError("value_and_accessor", [obj]); throw MakeTypeError(kValueAndAccessor, obj);
} }
return desc; return desc;
} }
...@@ -618,11 +615,11 @@ function GetTrap(handler, name, defaultTrap) { ...@@ -618,11 +615,11 @@ function GetTrap(handler, name, defaultTrap) {
var trap = handler[name]; var trap = handler[name];
if (IS_UNDEFINED(trap)) { if (IS_UNDEFINED(trap)) {
if (IS_UNDEFINED(defaultTrap)) { if (IS_UNDEFINED(defaultTrap)) {
throw MakeTypeError("handler_trap_missing", [handler, name]); throw MakeTypeError(kProxyHandlerTrapMissing, handler, name);
} }
trap = defaultTrap; trap = defaultTrap;
} else if (!IS_SPEC_FUNCTION(trap)) { } else if (!IS_SPEC_FUNCTION(trap)) {
throw MakeTypeError("handler_trap_must_be_callable", [handler, name]); throw MakeTypeError(kProxyHandlerTrapMustBeCallable, handler, name);
} }
return trap; return trap;
} }
...@@ -656,8 +653,8 @@ function GetOwnPropertyJS(obj, v) { ...@@ -656,8 +653,8 @@ function GetOwnPropertyJS(obj, v) {
if (IS_UNDEFINED(descriptor)) return descriptor; if (IS_UNDEFINED(descriptor)) return descriptor;
var desc = ToCompletePropertyDescriptor(descriptor); var desc = ToCompletePropertyDescriptor(descriptor);
if (!desc.isConfigurable()) { if (!desc.isConfigurable()) {
throw MakeTypeError("proxy_prop_not_configurable", throw MakeTypeError(kProxyPropNotConfigurable,
[handler, "getOwnPropertyDescriptor", p, descriptor]); handler, p, "getOwnPropertyDescriptor");
} }
return desc; return desc;
} }
...@@ -679,7 +676,7 @@ function Delete(obj, p, should_throw) { ...@@ -679,7 +676,7 @@ function Delete(obj, p, should_throw) {
%DeleteProperty(obj, p, 0); %DeleteProperty(obj, p, 0);
return true; return true;
} else if (should_throw) { } else if (should_throw) {
throw MakeTypeError("define_disallowed", [p]); throw MakeTypeError(kDefineDisallowed, p);
} else { } else {
return; return;
} }
...@@ -704,8 +701,8 @@ function DefineProxyProperty(obj, p, attributes, should_throw) { ...@@ -704,8 +701,8 @@ function DefineProxyProperty(obj, p, attributes, should_throw) {
var result = CallTrap2(handler, "defineProperty", UNDEFINED, p, attributes); var result = CallTrap2(handler, "defineProperty", UNDEFINED, p, attributes);
if (!ToBoolean(result)) { if (!ToBoolean(result)) {
if (should_throw) { if (should_throw) {
throw MakeTypeError("handler_returned_false", throw MakeTypeError(kProxyHandlerReturned,
[handler, "defineProperty"]); handler, "false", "defineProperty");
} else { } else {
return false; return false;
} }
...@@ -724,7 +721,7 @@ function DefineObjectProperty(obj, p, desc, should_throw) { ...@@ -724,7 +721,7 @@ function DefineObjectProperty(obj, p, desc, should_throw) {
// Step 3 // Step 3
if (IS_UNDEFINED(current) && !extensible) { if (IS_UNDEFINED(current) && !extensible) {
if (should_throw) { if (should_throw) {
throw MakeTypeError("define_disallowed", [p]); throw MakeTypeError(kDefineDisallowed, p);
} else { } else {
return false; return false;
} }
...@@ -754,7 +751,7 @@ function DefineObjectProperty(obj, p, desc, should_throw) { ...@@ -754,7 +751,7 @@ function DefineObjectProperty(obj, p, desc, should_throw) {
(desc.hasEnumerable() && (desc.hasEnumerable() &&
desc.isEnumerable() != current.isEnumerable())) { desc.isEnumerable() != current.isEnumerable())) {
if (should_throw) { if (should_throw) {
throw MakeTypeError("redefine_disallowed", [p]); throw MakeTypeError(kRedefineDisallowed, p);
} else { } else {
return false; return false;
} }
...@@ -764,7 +761,7 @@ function DefineObjectProperty(obj, p, desc, should_throw) { ...@@ -764,7 +761,7 @@ function DefineObjectProperty(obj, p, desc, should_throw) {
// Step 9a // Step 9a
if (IsDataDescriptor(current) != IsDataDescriptor(desc)) { if (IsDataDescriptor(current) != IsDataDescriptor(desc)) {
if (should_throw) { if (should_throw) {
throw MakeTypeError("redefine_disallowed", [p]); throw MakeTypeError(kRedefineDisallowed, p);
} else { } else {
return false; return false;
} }
...@@ -773,7 +770,7 @@ function DefineObjectProperty(obj, p, desc, should_throw) { ...@@ -773,7 +770,7 @@ function DefineObjectProperty(obj, p, desc, should_throw) {
if (IsDataDescriptor(current) && IsDataDescriptor(desc)) { if (IsDataDescriptor(current) && IsDataDescriptor(desc)) {
if (!current.isWritable() && desc.isWritable()) { if (!current.isWritable() && desc.isWritable()) {
if (should_throw) { if (should_throw) {
throw MakeTypeError("redefine_disallowed", [p]); throw MakeTypeError(kRedefineDisallowed, p);
} else { } else {
return false; return false;
} }
...@@ -781,7 +778,7 @@ function DefineObjectProperty(obj, p, desc, should_throw) { ...@@ -781,7 +778,7 @@ function DefineObjectProperty(obj, p, desc, should_throw) {
if (!current.isWritable() && desc.hasValue() && if (!current.isWritable() && desc.hasValue() &&
!SameValue(desc.getValue(), current.getValue())) { !SameValue(desc.getValue(), current.getValue())) {
if (should_throw) { if (should_throw) {
throw MakeTypeError("redefine_disallowed", [p]); throw MakeTypeError(kRedefineDisallowed, p);
} else { } else {
return false; return false;
} }
...@@ -791,14 +788,14 @@ function DefineObjectProperty(obj, p, desc, should_throw) { ...@@ -791,14 +788,14 @@ function DefineObjectProperty(obj, p, desc, should_throw) {
if (IsAccessorDescriptor(desc) && IsAccessorDescriptor(current)) { if (IsAccessorDescriptor(desc) && IsAccessorDescriptor(current)) {
if (desc.hasSetter() && !SameValue(desc.getSet(), current.getSet())) { if (desc.hasSetter() && !SameValue(desc.getSet(), current.getSet())) {
if (should_throw) { if (should_throw) {
throw MakeTypeError("redefine_disallowed", [p]); throw MakeTypeError(kRedefineDisallowed, p);
} else { } else {
return false; return false;
} }
} }
if (desc.hasGetter() && !SameValue(desc.getGet(),current.getGet())) { if (desc.hasGetter() && !SameValue(desc.getGet(),current.getGet())) {
if (should_throw) { if (should_throw) {
throw MakeTypeError("redefine_disallowed", [p]); throw MakeTypeError(kRedefineDisallowed, p);
} else { } else {
return false; return false;
} }
...@@ -894,12 +891,12 @@ function DefineArrayProperty(obj, p, desc, should_throw) { ...@@ -894,12 +891,12 @@ function DefineArrayProperty(obj, p, desc, should_throw) {
} }
var new_length = ToUint32(desc.getValue()); var new_length = ToUint32(desc.getValue());
if (new_length != ToNumber(desc.getValue())) { if (new_length != ToNumber(desc.getValue())) {
throw new $RangeError('defineProperty() array length out of range'); throw MakeRangeError(kArrayLengthOutOfRange);
} }
var length_desc = GetOwnPropertyJS(obj, "length"); var length_desc = GetOwnPropertyJS(obj, "length");
if (new_length != length && !length_desc.isWritable()) { if (new_length != length && !length_desc.isWritable()) {
if (should_throw) { if (should_throw) {
throw MakeTypeError("redefine_disallowed", [p]); throw MakeTypeError(kRedefineDisallowed, p);
} else { } else {
return false; return false;
} }
...@@ -938,7 +935,7 @@ function DefineArrayProperty(obj, p, desc, should_throw) { ...@@ -938,7 +935,7 @@ function DefineArrayProperty(obj, p, desc, should_throw) {
} }
if (threw) { if (threw) {
if (should_throw) { if (should_throw) {
throw MakeTypeError("redefine_disallowed", [p]); throw MakeTypeError(kRedefineDisallowed, p);
} else { } else {
return false; return false;
} }
...@@ -963,7 +960,7 @@ function DefineArrayProperty(obj, p, desc, should_throw) { ...@@ -963,7 +960,7 @@ function DefineArrayProperty(obj, p, desc, should_throw) {
if (emit_splice) if (emit_splice)
$observeEndPerformSplice(obj); $observeEndPerformSplice(obj);
if (should_throw) { if (should_throw) {
throw MakeTypeError("define_disallowed", [p]); throw MakeTypeError(kDefineDisallowed, p);
} else { } else {
return false; return false;
} }
...@@ -1010,7 +1007,7 @@ function ObjectSetPrototypeOf(obj, proto) { ...@@ -1010,7 +1007,7 @@ function ObjectSetPrototypeOf(obj, proto) {
CHECK_OBJECT_COERCIBLE(obj, "Object.setPrototypeOf"); CHECK_OBJECT_COERCIBLE(obj, "Object.setPrototypeOf");
if (proto !== null && !IS_SPEC_OBJECT(proto)) { if (proto !== null && !IS_SPEC_OBJECT(proto)) {
throw MakeTypeError("proto_object_or_null", [proto]); throw MakeTypeError(kProtoObjectOrNull, proto);
} }
if (IS_SPEC_OBJECT(obj)) { if (IS_SPEC_OBJECT(obj)) {
...@@ -1031,7 +1028,7 @@ function ObjectGetOwnPropertyDescriptor(obj, p) { ...@@ -1031,7 +1028,7 @@ function ObjectGetOwnPropertyDescriptor(obj, p) {
// For Harmony proxies // For Harmony proxies
function ToNameArray(obj, trap, includeSymbols) { function ToNameArray(obj, trap, includeSymbols) {
if (!IS_SPEC_OBJECT(obj)) { if (!IS_SPEC_OBJECT(obj)) {
throw MakeTypeError("proxy_non_object_prop_names", [obj, trap]); throw MakeTypeError(kProxyNonObjectPropNames, trap, obj);
} }
var n = ToUint32(obj.length); var n = ToUint32(obj.length);
var array = new $Array(n); var array = new $Array(n);
...@@ -1042,7 +1039,7 @@ function ToNameArray(obj, trap, includeSymbols) { ...@@ -1042,7 +1039,7 @@ function ToNameArray(obj, trap, includeSymbols) {
// TODO(rossberg): adjust once there is a story for symbols vs proxies. // TODO(rossberg): adjust once there is a story for symbols vs proxies.
if (IS_SYMBOL(s) && !includeSymbols) continue; if (IS_SYMBOL(s) && !includeSymbols) continue;
if (%HasOwnProperty(names, s)) { if (%HasOwnProperty(names, s)) {
throw MakeTypeError("proxy_repeated_prop_name", [obj, trap, s]); throw MakeTypeError(kProxyRepeatedPropName, trap, s);
} }
array[index] = s; array[index] = s;
++realLength; ++realLength;
...@@ -1137,7 +1134,7 @@ function ObjectGetOwnPropertyNames(obj) { ...@@ -1137,7 +1134,7 @@ function ObjectGetOwnPropertyNames(obj) {
// ES5 section 15.2.3.5. // ES5 section 15.2.3.5.
function ObjectCreate(proto, properties) { function ObjectCreate(proto, properties) {
if (!IS_SPEC_OBJECT(proto) && proto !== null) { if (!IS_SPEC_OBJECT(proto) && proto !== null) {
throw MakeTypeError("proto_object_or_null", [proto]); throw MakeTypeError(kProtoObjectOrNull, proto);
} }
var obj = {}; var obj = {};
%InternalSetPrototype(obj, proto); %InternalSetPrototype(obj, proto);
...@@ -1149,7 +1146,7 @@ function ObjectCreate(proto, properties) { ...@@ -1149,7 +1146,7 @@ function ObjectCreate(proto, properties) {
// ES5 section 15.2.3.6. // ES5 section 15.2.3.6.
function ObjectDefineProperty(obj, p, attributes) { function ObjectDefineProperty(obj, p, attributes) {
if (!IS_SPEC_OBJECT(obj)) { if (!IS_SPEC_OBJECT(obj)) {
throw MakeTypeError("called_on_non_object", ["Object.defineProperty"]); throw MakeTypeError(kCalledOnNonObject, "Object.defineProperty");
} }
var name = ToName(p); var name = ToName(p);
if (%_IsJSProxy(obj)) { if (%_IsJSProxy(obj)) {
...@@ -1212,7 +1209,7 @@ function GetOwnEnumerablePropertyNames(object) { ...@@ -1212,7 +1209,7 @@ function GetOwnEnumerablePropertyNames(object) {
// ES5 section 15.2.3.7. // ES5 section 15.2.3.7.
function ObjectDefineProperties(obj, properties) { function ObjectDefineProperties(obj, properties) {
if (!IS_SPEC_OBJECT(obj)) { if (!IS_SPEC_OBJECT(obj)) {
throw MakeTypeError("called_on_non_object", ["Object.defineProperties"]); throw MakeTypeError(kCalledOnNonObject, "Object.defineProperties");
} }
var props = TO_OBJECT_INLINE(properties); var props = TO_OBJECT_INLINE(properties);
var names = GetOwnEnumerablePropertyNames(props); var names = GetOwnEnumerablePropertyNames(props);
...@@ -1232,7 +1229,7 @@ function ProxyFix(obj) { ...@@ -1232,7 +1229,7 @@ function ProxyFix(obj) {
var handler = %GetHandler(obj); var handler = %GetHandler(obj);
var props = CallTrap0(handler, "fix", UNDEFINED); var props = CallTrap0(handler, "fix", UNDEFINED);
if (IS_UNDEFINED(props)) { if (IS_UNDEFINED(props)) {
throw MakeTypeError("handler_returned_undefined", [handler, "fix"]); throw MakeTypeError(kProxyHandlerReturned, handler, "undefined", "fix");
} }
if (%IsJSFunctionProxy(obj)) { if (%IsJSFunctionProxy(obj)) {
...@@ -1259,7 +1256,7 @@ function ProxyFix(obj) { ...@@ -1259,7 +1256,7 @@ function ProxyFix(obj) {
// ES5 section 15.2.3.8. // ES5 section 15.2.3.8.
function ObjectSealJS(obj) { function ObjectSealJS(obj) {
if (!IS_SPEC_OBJECT(obj)) { if (!IS_SPEC_OBJECT(obj)) {
throw MakeTypeError("called_on_non_object", ["Object.seal"]); throw MakeTypeError(kCalledOnNonObject, "Object.seal");
} }
var isProxy = %_IsJSProxy(obj); var isProxy = %_IsJSProxy(obj);
if (isProxy || %HasSloppyArgumentsElements(obj) || %IsObserved(obj)) { if (isProxy || %HasSloppyArgumentsElements(obj) || %IsObserved(obj)) {
...@@ -1288,7 +1285,7 @@ function ObjectSealJS(obj) { ...@@ -1288,7 +1285,7 @@ function ObjectSealJS(obj) {
// ES5 section 15.2.3.9. // ES5 section 15.2.3.9.
function ObjectFreezeJS(obj) { function ObjectFreezeJS(obj) {
if (!IS_SPEC_OBJECT(obj)) { if (!IS_SPEC_OBJECT(obj)) {
throw MakeTypeError("called_on_non_object", ["Object.freeze"]); throw MakeTypeError(kCalledOnNonObject, "Object.freeze");
} }
var isProxy = %_IsJSProxy(obj); var isProxy = %_IsJSProxy(obj);
if (isProxy || %HasSloppyArgumentsElements(obj) || %IsObserved(obj)) { if (isProxy || %HasSloppyArgumentsElements(obj) || %IsObserved(obj)) {
...@@ -1318,7 +1315,7 @@ function ObjectFreezeJS(obj) { ...@@ -1318,7 +1315,7 @@ function ObjectFreezeJS(obj) {
// ES5 section 15.2.3.10 // ES5 section 15.2.3.10
function ObjectPreventExtension(obj) { function ObjectPreventExtension(obj) {
if (!IS_SPEC_OBJECT(obj)) { if (!IS_SPEC_OBJECT(obj)) {
throw MakeTypeError("called_on_non_object", ["Object.preventExtension"]); throw MakeTypeError(kCalledOnNonObject, "Object.preventExtension");
} }
if (%_IsJSProxy(obj)) { if (%_IsJSProxy(obj)) {
ProxyFix(obj); ProxyFix(obj);
...@@ -1331,7 +1328,7 @@ function ObjectPreventExtension(obj) { ...@@ -1331,7 +1328,7 @@ function ObjectPreventExtension(obj) {
// ES5 section 15.2.3.11 // ES5 section 15.2.3.11
function ObjectIsSealed(obj) { function ObjectIsSealed(obj) {
if (!IS_SPEC_OBJECT(obj)) { if (!IS_SPEC_OBJECT(obj)) {
throw MakeTypeError("called_on_non_object", ["Object.isSealed"]); throw MakeTypeError(kCalledOnNonObject, "Object.isSealed");
} }
if (%_IsJSProxy(obj)) { if (%_IsJSProxy(obj)) {
return false; return false;
...@@ -1354,7 +1351,7 @@ function ObjectIsSealed(obj) { ...@@ -1354,7 +1351,7 @@ function ObjectIsSealed(obj) {
// ES5 section 15.2.3.12 // ES5 section 15.2.3.12
function ObjectIsFrozen(obj) { function ObjectIsFrozen(obj) {
if (!IS_SPEC_OBJECT(obj)) { if (!IS_SPEC_OBJECT(obj)) {
throw MakeTypeError("called_on_non_object", ["Object.isFrozen"]); throw MakeTypeError(kCalledOnNonObject, "Object.isFrozen");
} }
if (%_IsJSProxy(obj)) { if (%_IsJSProxy(obj)) {
return false; return false;
...@@ -1376,7 +1373,7 @@ function ObjectIsFrozen(obj) { ...@@ -1376,7 +1373,7 @@ function ObjectIsFrozen(obj) {
// ES5 section 15.2.3.13 // ES5 section 15.2.3.13
function ObjectIsExtensible(obj) { function ObjectIsExtensible(obj) {
if (!IS_SPEC_OBJECT(obj)) { if (!IS_SPEC_OBJECT(obj)) {
throw MakeTypeError("called_on_non_object", ["Object.isExtensible"]); throw MakeTypeError(kCalledOnNonObject, "Object.isExtensible");
} }
if (%_IsJSProxy(obj)) { if (%_IsJSProxy(obj)) {
return true; return true;
...@@ -1489,7 +1486,7 @@ function BooleanToString() { ...@@ -1489,7 +1486,7 @@ function BooleanToString() {
var b = this; var b = this;
if (!IS_BOOLEAN(b)) { if (!IS_BOOLEAN(b)) {
if (!IS_BOOLEAN_WRAPPER(b)) { if (!IS_BOOLEAN_WRAPPER(b)) {
throw new $TypeError('Boolean.prototype.toString is not generic'); throw MakeTypeError(kNotGeneric, 'Boolean.prototype.toString');
} }
b = %_ValueOf(b); b = %_ValueOf(b);
} }
...@@ -1501,7 +1498,7 @@ function BooleanValueOf() { ...@@ -1501,7 +1498,7 @@ function BooleanValueOf() {
// NOTE: Both Boolean objects and values can enter here as // NOTE: Both Boolean objects and values can enter here as
// 'this'. This is not as dictated by ECMA-262. // 'this'. This is not as dictated by ECMA-262.
if (!IS_BOOLEAN(this) && !IS_BOOLEAN_WRAPPER(this)) { if (!IS_BOOLEAN(this) && !IS_BOOLEAN_WRAPPER(this)) {
throw new $TypeError('Boolean.prototype.valueOf is not generic'); throw MakeTypeError(kNotGeneric, 'Boolean.prototype.valueOf');
} }
return %_ValueOf(this); return %_ValueOf(this);
} }
...@@ -1545,7 +1542,7 @@ function NumberToStringJS(radix) { ...@@ -1545,7 +1542,7 @@ function NumberToStringJS(radix) {
var number = this; var number = this;
if (!IS_NUMBER(this)) { if (!IS_NUMBER(this)) {
if (!IS_NUMBER_WRAPPER(this)) { if (!IS_NUMBER_WRAPPER(this)) {
throw new $TypeError('Number.prototype.toString is not generic'); throw MakeTypeError(kNotGeneric, 'Number.prototype.toString');
} }
// Get the value of this number in case it's an object. // Get the value of this number in case it's an object.
number = %_ValueOf(this); number = %_ValueOf(this);
...@@ -1576,7 +1573,7 @@ function NumberValueOf() { ...@@ -1576,7 +1573,7 @@ function NumberValueOf() {
// NOTE: Both Number objects and values can enter here as // NOTE: Both Number objects and values can enter here as
// 'this'. This is not as dictated by ECMA-262. // 'this'. This is not as dictated by ECMA-262.
if (!IS_NUMBER(this) && !IS_NUMBER_WRAPPER(this)) { if (!IS_NUMBER(this) && !IS_NUMBER_WRAPPER(this)) {
throw new $TypeError('Number.prototype.valueOf is not generic'); throw MakeTypeError(kNotGeneric, 'Number.prototype.valueOf');
} }
return %_ValueOf(this); return %_ValueOf(this);
} }
...@@ -1596,7 +1593,7 @@ function NumberToFixedJS(fractionDigits) { ...@@ -1596,7 +1593,7 @@ function NumberToFixedJS(fractionDigits) {
var f = TO_INTEGER(fractionDigits); var f = TO_INTEGER(fractionDigits);
if (f < 0 || f > 20) { if (f < 0 || f > 20) {
throw new $RangeError("toFixed() digits argument must be between 0 and 20"); throw MakeRangeError(kNumberFormatRange, "toFixed() digits");
} }
if (NUMBER_IS_NAN(x)) return "NaN"; if (NUMBER_IS_NAN(x)) return "NaN";
...@@ -1627,7 +1624,7 @@ function NumberToExponentialJS(fractionDigits) { ...@@ -1627,7 +1624,7 @@ function NumberToExponentialJS(fractionDigits) {
if (IS_UNDEFINED(f)) { if (IS_UNDEFINED(f)) {
f = -1; // Signal for runtime function that f is not defined. f = -1; // Signal for runtime function that f is not defined.
} else if (f < 0 || f > 20) { } else if (f < 0 || f > 20) {
throw new $RangeError("toExponential() argument must be between 0 and 20"); throw MakeRangeError(kNumberFormatRange, "toExponential()");
} }
return %NumberToExponential(x, f); return %NumberToExponential(x, f);
} }
...@@ -1652,7 +1649,7 @@ function NumberToPrecisionJS(precision) { ...@@ -1652,7 +1649,7 @@ function NumberToPrecisionJS(precision) {
if (x == -INFINITY) return "-Infinity"; if (x == -INFINITY) return "-Infinity";
if (p < 1 || p > 21) { if (p < 1 || p > 21) {
throw new $RangeError("toPrecision() argument must be between 1 and 21"); throw MakeRangeError(kToPrecisionFormatRange);
} }
return %NumberToPrecision(x, p); return %NumberToPrecision(x, p);
} }
...@@ -1752,7 +1749,7 @@ function FunctionSourceString(func) { ...@@ -1752,7 +1749,7 @@ function FunctionSourceString(func) {
} }
if (!IS_FUNCTION(func)) { if (!IS_FUNCTION(func)) {
throw new $TypeError('Function.prototype.toString is not generic'); throw MakeTypeError(kNotGeneric, 'Function.prototype.toString');
} }
var classSource = %ClassGetSourceCode(func); var classSource = %ClassGetSourceCode(func);
...@@ -1794,9 +1791,8 @@ function FunctionToString() { ...@@ -1794,9 +1791,8 @@ function FunctionToString() {
// ES5 15.3.4.5 // ES5 15.3.4.5
function FunctionBind(this_arg) { // Length is 1. function FunctionBind(this_arg) { // Length is 1.
if (!IS_SPEC_FUNCTION(this)) { if (!IS_SPEC_FUNCTION(this)) throw MakeTypeError(kFunctionBind);
throw new $TypeError('Bind must be called on a function');
}
var boundFunction = function () { var boundFunction = function () {
// Poison .arguments and .caller, but is otherwise not detectable. // Poison .arguments and .caller, but is otherwise not detectable.
"use strict"; "use strict";
...@@ -1863,7 +1859,7 @@ function NewFunctionString(arguments, function_token) { ...@@ -1863,7 +1859,7 @@ function NewFunctionString(arguments, function_token) {
// character - it may make the combined function expression // character - it may make the combined function expression
// compile. We avoid this problem by checking for this early on. // compile. We avoid this problem by checking for this early on.
if (%_CallFunction(p, ')', $stringIndexOf) != -1) { if (%_CallFunction(p, ')', $stringIndexOf) != -1) {
throw MakeSyntaxError('paren_in_arg_string', []); throw MakeSyntaxError(kParenthesisInArgString);
} }
// If the formal parameters include an unbalanced block comment, the // If the formal parameters include an unbalanced block comment, the
// function must be rejected. Since JavaScript does not allow nested // function must be rejected. Since JavaScript does not allow nested
...@@ -1913,11 +1909,11 @@ function GetIterator(obj, method) { ...@@ -1913,11 +1909,11 @@ function GetIterator(obj, method) {
method = obj[symbolIterator]; method = obj[symbolIterator];
} }
if (!IS_SPEC_FUNCTION(method)) { if (!IS_SPEC_FUNCTION(method)) {
throw MakeTypeError('not_iterable', [obj]); throw MakeTypeError(kNotIterable, obj);
} }
var iterator = %_CallFunction(obj, method); var iterator = %_CallFunction(obj, method);
if (!IS_SPEC_OBJECT(iterator)) { if (!IS_SPEC_OBJECT(iterator)) {
throw MakeTypeError('not_an_iterator', [iterator]); throw MakeTypeError(kNotAnIterator, iterator);
} }
return iterator; return iterator;
} }
...@@ -12,7 +12,7 @@ function test(f, expected, type) { ...@@ -12,7 +12,7 @@ function test(f, expected, type) {
assertEquals(expected, e.message); assertEquals(expected, e.message);
return; return;
} }
assertUnreachable(); assertUnreachable("Exception expected");
} }
// === Error === // === Error ===
...@@ -32,11 +32,29 @@ test(function() { ...@@ -32,11 +32,29 @@ test(function() {
}, "Function.prototype.apply was called on 1, which is a number " + }, "Function.prototype.apply was called on 1, which is a number " +
"and not a function", TypeError); "and not a function", TypeError);
// kCalledNonCallable
test(function() {
[].forEach(1);
}, "1 is not a function", TypeError);
// kCalledOnNonObject
test(function() {
Object.freeze(1)
}, "Object.freeze called on non-object", TypeError);
// kCannotConvertToPrimitive // kCannotConvertToPrimitive
test(function() { test(function() {
[].join(Object(Symbol(1))); [].join(Object(Symbol(1)));
}, "Cannot convert object to primitive value", TypeError); }, "Cannot convert object to primitive value", TypeError);
// kDefineDisallowed
test(function() {
"use strict";
var o = {};
Object.preventExtensions(o);
Object.defineProperty(o, "x", { value: 1 });
}, "Cannot define property:x, object is not extensible.", TypeError);
// kGeneratorRunning // kGeneratorRunning
test(function() { test(function() {
var iter; var iter;
...@@ -45,10 +63,10 @@ test(function() { ...@@ -45,10 +63,10 @@ test(function() {
iter.next(); iter.next();
}, "Generator is already running", TypeError); }, "Generator is already running", TypeError);
// kCalledNonCallable // kFunctionBind
test(function() { test(function() {
[].forEach(1); Function.prototype.bind.call(1);
}, "1 is not a function", TypeError); }, "Bind must be called on a function", TypeError);
// kIncompatibleMethodReceiver // kIncompatibleMethodReceiver
test(function() { test(function() {
...@@ -79,12 +97,80 @@ test(function() { ...@@ -79,12 +97,80 @@ test(function() {
new Symbol(); new Symbol();
}, "Symbol is not a constructor", TypeError); }, "Symbol is not a constructor", TypeError);
// kNotGeneric
test(function() {
String.prototype.toString.call(1);
}, "String.prototype.toString is not generic", TypeError);
test(function() {
String.prototype.valueOf.call(1);
}, "String.prototype.valueOf is not generic", TypeError);
test(function() {
Boolean.prototype.toString.call(1);
}, "Boolean.prototype.toString is not generic", TypeError);
test(function() {
Boolean.prototype.valueOf.call(1);
}, "Boolean.prototype.valueOf is not generic", TypeError);
test(function() {
Number.prototype.toString.call({});
}, "Number.prototype.toString is not generic", TypeError);
test(function() {
Number.prototype.valueOf.call({});
}, "Number.prototype.valueOf is not generic", TypeError);
test(function() {
Function.prototype.toString.call(1);
}, "Function.prototype.toString is not generic", TypeError);
// kObjectGetterExpectingFunction
test(function() {
({}).__defineGetter__("x", 0);
}, "Object.prototype.__defineGetter__: Expecting function", TypeError);
// kObjectGetterCallable
test(function() {
Object.defineProperty({}, "x", { get: 1 });
}, "Getter must be a function: 1", TypeError);
// kObjectSetterExpectingFunction
test(function() {
({}).__defineSetter__("x", 0);
}, "Object.prototype.__defineSetter__: Expecting function", TypeError);
// kObjectSetterCallable
test(function() {
Object.defineProperty({}, "x", { set: 1 });
}, "Setter must be a function: 1", TypeError);
// kPropertyDescObject
test(function() {
Object.defineProperty({}, "x", 1);
}, "Property description must be an object: 1", TypeError);
// kPropertyNotFunction // kPropertyNotFunction
test(function() { test(function() {
Set.prototype.add = 0; Set.prototype.add = 0;
new Set(1); new Set(1);
}, "Property 'add' of object #<Set> is not a function", TypeError); }, "Property 'add' of object #<Set> is not a function", TypeError);
// kProtoObjectOrNull
test(function() {
Object.setPrototypeOf({}, 1);
}, "Object prototype may only be an Object or null: 1", TypeError);
// kRedefineDisallowed
test(function() {
"use strict";
var o = {};
Object.defineProperty(o, "x", { value: 1, configurable: false });
Object.defineProperty(o, "x", { value: 2 });
}, "Cannot redefine property: x", TypeError);
// kSymbolToPrimitive // kSymbolToPrimitive
test(function() { test(function() {
1 + Object(Symbol()); 1 + Object(Symbol());
...@@ -105,6 +191,12 @@ test(function() { ...@@ -105,6 +191,12 @@ test(function() {
Array.prototype.toString.call(null); Array.prototype.toString.call(null);
}, "Cannot convert undefined or null to object", TypeError); }, "Cannot convert undefined or null to object", TypeError);
// kValueAndAccessor
test(function() {
Object.defineProperty({}, "x", { get: function(){}, value: 1});
}, "Invalid property. A property cannot both have accessors and be " +
"writable or have a value, #<Object>", TypeError);
// kWithExpression // kWithExpression
test(function() { test(function() {
with (null) {} with (null) {}
...@@ -124,10 +216,37 @@ test(function() { ...@@ -124,10 +216,37 @@ test(function() {
}, "Reflect.construct: Arguments list has wrong type", TypeError); }, "Reflect.construct: Arguments list has wrong type", TypeError);
//=== SyntaxError ===
test(function() {
new Function(")", "");
}, "Function arg string contains parenthesis", SyntaxError);
// === RangeError === // === RangeError ===
// kArrayLengthOutOfRange
test(function() {
"use strict";
Object.defineProperty([], "length", { value: 1E100 });
}, "defineProperty() array length out of range", RangeError);
//kNumberFormatRange
test(function() {
Number(1).toFixed(100);
}, "toFixed() digits argument must be between 0 and 20", RangeError);
test(function() {
Number(1).toExponential(100);
}, "toExponential() argument must be between 0 and 20", RangeError);
// kStackOverflow // kStackOverflow
test(function() { test(function() {
function f() { f(Array(1000)); } function f() { f(Array(1000)); }
f(); f();
}, "Maximum call stack size exceeded", RangeError); }, "Maximum call stack size exceeded", RangeError);
// kToPrecisionFormatRange
test(function() {
Number(1).toPrecision(100);
}, "toPrecision() argument must be between 1 and 21", RangeError);
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