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