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);
}
......
......@@ -88,34 +88,66 @@ class MessageHandler {
};
#define MESSAGE_TEMPLATES(T) \
/* Error */ \
T(CyclicProto, "Cyclic __proto__ value") \
/* TypeError */ \
T(ApplyNonFunction, \
"Function.prototype.apply was called on %, which is a % and not a " \
"function") \
T(CalledNonCallable, "% is not a function") \
T(CannotConvertToPrimitive, "Cannot convert object to primitive value") \
T(GeneratorRunning, "Generator is already running") \
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(NotConstructor, "% is not a constructor") \
T(PropertyNotFunction, "Property '%' of object % is not a function") \
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(WithExpression, "% has no properties") \
T(WrongArgs, "%: Arguments list has wrong type") \
/* RangeError */ \
T(StackOverflow, "Maximum call stack size exceeded") \
/* EvalError */ \
#define MESSAGE_TEMPLATES(T) \
/* Error */ \
T(CyclicProto, "Cyclic __proto__ value") \
/* TypeError */ \
T(ApplyNonFunction, \
"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, "%")
class MessageTemplate {
......
......@@ -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);
}
......
This diff is collapsed.
......@@ -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