From 0bbe7874483f46a275aa3201aafa33a0655d76b0 Mon Sep 17 00:00:00 2001 From: yangguo Date: Tue, 12 May 2015 06:52:26 -0700 Subject: [PATCH] Migrate error messages, part 10. R=mvstanton@chromium.org Committed: https://crrev.com/8608e619afe2b4514b0577bfb73a153b1550d41f Cr-Commit-Position: refs/heads/master@{#28357} Review URL: https://codereview.chromium.org/1126043004 Cr-Commit-Position: refs/heads/master@{#28366} --- src/api-natives.cc | 8 +-- src/api.cc | 4 +- src/builtins.cc | 14 ++--- src/debug.cc | 8 +-- src/elements.cc | 8 +-- src/factory.cc | 12 ---- src/factory.h | 4 -- src/hydrogen.cc | 2 +- src/ic/ic.cc | 14 ++--- src/ic/ic.h | 5 +- src/isolate.cc | 17 +++--- src/json-stringifier.h | 5 +- src/json.js | 8 +-- src/messages.cc | 4 +- src/messages.h | 37 ++++++++++++ src/messages.js | 21 ------- src/objects.cc | 125 +++++++++++++++++----------------------- src/objects.h | 9 +-- src/runtime.js | 26 ++++----- src/runtime/runtime-classes.cc | 13 ++--- src/runtime/runtime-date.cc | 8 +-- src/runtime/runtime-function.cc | 5 +- src/runtime/runtime-i18n.cc | 19 +++--- src/runtime/runtime-internal.cc | 4 +- src/runtime/runtime-object.cc | 20 +++---- src/runtime/runtime-scopes.cc | 14 ++--- test/cctest/test-serialize.cc | 8 +-- test/mjsunit/messages.js | 62 +++++++++++++++++++- 28 files changed, 256 insertions(+), 228 deletions(-) diff --git a/src/api-natives.cc b/src/api-natives.cc index c95f2ce..71a039f 100644 --- a/src/api-natives.cc +++ b/src/api-natives.cc @@ -7,6 +7,7 @@ #include "src/api.h" #include "src/isolate.h" #include "src/lookup.h" +#include "src/messages.h" namespace v8 { namespace internal { @@ -95,10 +96,9 @@ MaybeHandle DefineDataProperty(Isolate* isolate, duplicate = maybe.FromJust(); } if (duplicate) { - Handle args[1] = {key}; - THROW_NEW_ERROR(isolate, NewTypeError("duplicate_template_property", - HandleVector(args, 1)), - Object); + THROW_NEW_ERROR( + isolate, NewTypeError(MessageTemplate::kDuplicateTemplateProperty, key), + Object); } #endif diff --git a/src/api.cc b/src/api.cc index 200dc5f..c147632 100644 --- a/src/api.cc +++ b/src/api.cc @@ -4400,7 +4400,7 @@ Handle Function::GetDisplayName() const { i::Handle property_name = isolate->factory()->NewStringFromStaticChars("displayName"); i::Handle value = - i::JSObject::GetDataProperty(func, property_name); + i::JSReceiver::GetDataProperty(func, property_name); if (value->IsString()) { i::Handle name = i::Handle::cast(value); if (name->length() > 0) return Utils::ToLocal(name); @@ -6239,7 +6239,7 @@ bool Promise::HasHandler() { LOG_API(isolate, "Promise::HasRejectHandler"); ENTER_V8(isolate); i::Handle key = isolate->factory()->promise_has_handler_symbol(); - return i::JSObject::GetDataProperty(promise, key)->IsTrue(); + return i::JSReceiver::GetDataProperty(promise, key)->IsTrue(); } diff --git a/src/builtins.cc b/src/builtins.cc index 5b1eeed..66d942c 100644 --- a/src/builtins.cc +++ b/src/builtins.cc @@ -16,6 +16,7 @@ #include "src/heap-profiler.h" #include "src/ic/handler-compiler.h" #include "src/ic/ic.h" +#include "src/messages.h" #include "src/prototype.h" #include "src/vm-state-inl.h" @@ -1026,17 +1027,15 @@ BUILTIN(ArrayConcat) { BUILTIN(RestrictedFunctionPropertiesThrower) { HandleScope scope(isolate); - THROW_NEW_ERROR_RETURN_FAILURE(isolate, - NewTypeError("restricted_function_properties", - HandleVector(NULL, 0))); + THROW_NEW_ERROR_RETURN_FAILURE( + isolate, NewTypeError(MessageTemplate::kRestrictedFunctionProperties)); } BUILTIN(RestrictedStrictArgumentsPropertiesThrower) { HandleScope scope(isolate); THROW_NEW_ERROR_RETURN_FAILURE( - isolate, - NewTypeError("strict_poison_pill", HandleVector(NULL, 0))); + isolate, NewTypeError(MessageTemplate::kStrictPoisonPill)); } @@ -1080,9 +1079,8 @@ MUST_USE_RESULT static MaybeHandle HandleApiCallHelper( if (raw_holder->IsNull()) { // This function cannot be called with the given receiver. Abort! - THROW_NEW_ERROR( - isolate, NewTypeError("illegal_invocation", HandleVector(&function, 1)), - Object); + THROW_NEW_ERROR(isolate, NewTypeError(MessageTemplate::kIllegalInvocation), + Object); } Object* raw_call_data = fun_data->call_code(); diff --git a/src/debug.cc b/src/debug.cc index 5c396cb..82fab36 100644 --- a/src/debug.cc +++ b/src/debug.cc @@ -2507,7 +2507,7 @@ void Debug::OnPromiseReject(Handle promise, Handle value) { HandleScope scope(isolate_); // Check whether the promise has been marked as having triggered a message. Handle key = isolate_->factory()->promise_debug_marker_symbol(); - if (JSObject::GetDataProperty(promise, key)->IsUndefined()) { + if (JSReceiver::GetDataProperty(promise, key)->IsUndefined()) { OnException(value, promise); } } @@ -2516,9 +2516,9 @@ void Debug::OnPromiseReject(Handle promise, Handle value) { MaybeHandle Debug::PromiseHasUserDefinedRejectHandler( Handle promise) { Handle fun = Handle::cast( - JSObject::GetDataProperty(isolate_->js_builtins_object(), - isolate_->factory()->NewStringFromStaticChars( - "$promiseHasUserDefinedRejectHandler"))); + JSReceiver::GetDataProperty(isolate_->js_builtins_object(), + isolate_->factory()->NewStringFromStaticChars( + "$promiseHasUserDefinedRejectHandler"))); return Execution::Call(isolate_, fun, promise, 0, NULL); } diff --git a/src/elements.cc b/src/elements.cc index ce32cb2..7f9691b 100644 --- a/src/elements.cc +++ b/src/elements.cc @@ -1409,10 +1409,10 @@ class DictionaryElementsAccessor if (is_strict(language_mode)) { // Deleting a non-configurable property in strict mode. Handle name = isolate->factory()->NewNumberFromUint(key); - Handle args[2] = { name, obj }; - THROW_NEW_ERROR(isolate, NewTypeError("strict_delete_property", - HandleVector(args, 2)), - Object); + THROW_NEW_ERROR( + isolate, + NewTypeError(MessageTemplate::kStrictDeleteProperty, name, obj), + Object); } return isolate->factory()->false_value(); } diff --git a/src/factory.cc b/src/factory.cc index 0e66ec6..fca1e1c 100644 --- a/src/factory.cc +++ b/src/factory.cc @@ -1076,23 +1076,11 @@ Handle Factory::NewHeapNumber(double value, } -Handle Factory::NewTypeError(const char* message, - Vector > args) { - return NewError("MakeTypeError", message, args); -} - - Handle Factory::NewTypeError(Handle message) { return NewError("$TypeError", message); } -Handle Factory::NewRangeError(const char* message, - Vector > args) { - return NewError("MakeRangeError", message, args); -} - - Handle Factory::NewRangeError(Handle message) { return NewError("$RangeError", message); } diff --git a/src/factory.h b/src/factory.h index 44aec28..600f312 100644 --- a/src/factory.h +++ b/src/factory.h @@ -547,12 +547,8 @@ class Factory final { Handle NewError(Handle message); Handle NewError(const char* constructor, Handle message); - Handle NewTypeError(const char* message, - Vector > args); Handle NewTypeError(Handle message); - Handle NewRangeError(const char* message, - Vector > args); Handle NewRangeError(Handle message); Handle NewInvalidStringLengthError() { diff --git a/src/hydrogen.cc b/src/hydrogen.cc index af25700..4510e8d 100644 --- a/src/hydrogen.cc +++ b/src/hydrogen.cc @@ -5917,7 +5917,7 @@ HInstruction* HOptimizedGraphBuilder::BuildLoadNamedField( if (object->IsJSObject()) { LookupIterator it(object, info->name(), LookupIterator::OWN_SKIP_INTERCEPTOR); - Handle value = JSObject::GetDataProperty(&it); + Handle value = JSReceiver::GetDataProperty(&it); if (it.IsFound() && it.IsReadOnly() && !it.IsConfigurable()) { return New(value); } diff --git a/src/ic/ic.cc b/src/ic/ic.cc index daf7704..628da7d 100644 --- a/src/ic/ic.cc +++ b/src/ic/ic.cc @@ -16,7 +16,6 @@ #include "src/ic/ic-inl.h" #include "src/ic/ic-compiler.h" #include "src/ic/stub-cache.h" -#include "src/messages.h" #include "src/prototype.h" #include "src/runtime/runtime.h" @@ -362,11 +361,10 @@ void IC::UpdateState(Handle receiver, Handle name) { } -MaybeHandle IC::TypeError(const char* type, Handle object, - Handle key) { +MaybeHandle IC::TypeError(MessageTemplate::Template index, + Handle object, Handle key) { HandleScope scope(isolate()); - Handle args[2] = {key, object}; - THROW_NEW_ERROR(isolate(), NewTypeError(type, HandleVector(args, 2)), Object); + THROW_NEW_ERROR(isolate(), NewTypeError(index, key, object), Object); } @@ -696,7 +694,7 @@ MaybeHandle LoadIC::Load(Handle object, Handle name) { // If the object is undefined or null it's illegal to try to get any // of its properties; throw a TypeError in that case. if (object->IsUndefined() || object->IsNull()) { - return TypeError("non_object_property_load", object, name); + return TypeError(MessageTemplate::kNonObjectPropertyLoad, object, name); } // Check if the name is trivially convertible to an index and get @@ -1558,7 +1556,7 @@ MaybeHandle StoreIC::Store(Handle object, Handle name, Handle script_context = ScriptContextTable::GetContext( script_contexts, lookup_result.context_index); if (lookup_result.mode == CONST) { - return TypeError("const_assign", object, name); + return TypeError(MessageTemplate::kConstAssign, object, name); } Handle previous_value = @@ -1594,7 +1592,7 @@ MaybeHandle StoreIC::Store(Handle object, Handle name, // If the object is undefined or null it's illegal to try to set any // properties on it; throw a TypeError in that case. if (object->IsUndefined() || object->IsNull()) { - return TypeError("non_object_property_store", object, name); + return TypeError(MessageTemplate::kNonObjectPropertyStore, object, name); } // Check if the given name is an array index. diff --git a/src/ic/ic.h b/src/ic/ic.h index d51309c..6f2a36b 100644 --- a/src/ic/ic.h +++ b/src/ic/ic.h @@ -7,6 +7,7 @@ #include "src/ic/ic-state.h" #include "src/macro-assembler.h" +#include "src/messages.h" namespace v8 { namespace internal { @@ -162,8 +163,8 @@ class IC { void TraceIC(const char* type, Handle name, State old_state, State new_state); - MaybeHandle TypeError(const char* type, Handle object, - Handle key); + MaybeHandle TypeError(MessageTemplate::Template, + Handle object, Handle key); MaybeHandle ReferenceError(Handle name); // Access the target code for the given IC address. diff --git a/src/isolate.cc b/src/isolate.cc index 69a4f8d..f958da5 100644 --- a/src/isolate.cc +++ b/src/isolate.cc @@ -341,9 +341,8 @@ Handle Isolate::CaptureSimpleStackTrace(Handle error_object, Handle stackTraceLimit = factory()->InternalizeUtf8String("stackTraceLimit"); DCHECK(!stackTraceLimit.is_null()); - Handle stack_trace_limit = - JSObject::GetDataProperty(Handle::cast(error), - stackTraceLimit); + Handle stack_trace_limit = JSReceiver::GetDataProperty( + Handle::cast(error), stackTraceLimit); if (!stack_trace_limit->IsNumber()) return factory()->undefined_value(); int limit = FastD2IChecked(stack_trace_limit->Number()); limit = Max(limit, 0); // Ensure that limit is not negative. @@ -446,7 +445,7 @@ MaybeHandle Isolate::CaptureAndSetSimpleStackTrace( Handle Isolate::GetDetailedStackTrace(Handle error_object) { Handle key_detailed = factory()->detailed_stack_trace_symbol(); Handle stack_trace = - JSObject::GetDataProperty(error_object, key_detailed); + JSReceiver::GetDataProperty(error_object, key_detailed); if (stack_trace->IsJSArray()) return Handle::cast(stack_trace); if (!capture_stack_trace_for_uncaught_exceptions_) return Handle(); @@ -600,7 +599,7 @@ int PositionFromStackTrace(Handle elements, int index) { Handle Isolate::GetDetailedFromSimpleStackTrace( Handle error_object) { Handle key = factory()->stack_trace_symbol(); - Handle property = JSObject::GetDataProperty(error_object, key); + Handle property = JSReceiver::GetDataProperty(error_object, key); if (!property->IsJSArray()) return Handle(); Handle simple_stack_trace = Handle::cast(property); @@ -1272,19 +1271,19 @@ bool Isolate::ComputeLocationFromException(MessageLocation* target, if (!exception->IsJSObject()) return false; Handle start_pos_symbol = factory()->error_start_pos_symbol(); - Handle start_pos = JSObject::GetDataProperty( + Handle start_pos = JSReceiver::GetDataProperty( Handle::cast(exception), start_pos_symbol); if (!start_pos->IsSmi()) return false; int start_pos_value = Handle::cast(start_pos)->value(); Handle end_pos_symbol = factory()->error_end_pos_symbol(); - Handle end_pos = JSObject::GetDataProperty( + Handle end_pos = JSReceiver::GetDataProperty( Handle::cast(exception), end_pos_symbol); if (!end_pos->IsSmi()) return false; int end_pos_value = Handle::cast(end_pos)->value(); Handle script_symbol = factory()->error_script_symbol(); - Handle script = JSObject::GetDataProperty( + Handle script = JSReceiver::GetDataProperty( Handle::cast(exception), script_symbol); if (!script->IsScript()) return false; @@ -1301,7 +1300,7 @@ bool Isolate::ComputeLocationFromStackTrace(MessageLocation* target, if (!exception->IsJSObject()) return false; Handle key = factory()->stack_trace_symbol(); Handle property = - JSObject::GetDataProperty(Handle::cast(exception), key); + JSReceiver::GetDataProperty(Handle::cast(exception), key); if (!property->IsJSArray()) return false; Handle simple_stack_trace = Handle::cast(property); diff --git a/src/json-stringifier.h b/src/json-stringifier.h index efb71e5..9579c78 100644 --- a/src/json-stringifier.h +++ b/src/json-stringifier.h @@ -8,6 +8,7 @@ #include "src/v8.h" #include "src/conversions.h" +#include "src/messages.h" #include "src/string-builder.h" #include "src/utils.h" @@ -272,8 +273,8 @@ BasicJsonStringifier::Result BasicJsonStringifier::StackPush( for (int i = 0; i < length; i++) { if (elements->get(i) == *object) { AllowHeapAllocation allow_to_return_error; - Handle error = factory()->NewTypeError( - "circular_structure", HandleVector(NULL, 0)); + Handle error = + factory()->NewTypeError(MessageTemplate::kCircularStructure); isolate_->Throw(*error); return EXCEPTION; } diff --git a/src/json.js b/src/json.js index f5ac6cb..f093e5c 100644 --- a/src/json.js +++ b/src/json.js @@ -51,9 +51,7 @@ function JSONParse(text, reviver) { function SerializeArray(value, replacer, stack, indent, gap) { - if (!%PushIfAbsent(stack, value)) { - throw MakeTypeError('circular_structure', []); - } + if (!%PushIfAbsent(stack, value)) throw MakeTypeError(kCircularStructure); var stepback = indent; indent += gap; var partial = new InternalArray(); @@ -82,9 +80,7 @@ function SerializeArray(value, replacer, stack, indent, gap) { function SerializeObject(value, replacer, stack, indent, gap) { - if (!%PushIfAbsent(stack, value)) { - throw MakeTypeError('circular_structure', []); - } + if (!%PushIfAbsent(stack, value)) throw MakeTypeError(kCircularStructure); var stepback = indent; indent += gap; var partial = new InternalArray(); diff --git a/src/messages.cc b/src/messages.cc index 81fcdec..62bcad1 100644 --- a/src/messages.cc +++ b/src/messages.cc @@ -306,8 +306,8 @@ bool CallSite::IsEval(Isolate* isolate) { bool CallSite::IsConstructor(Isolate* isolate) { if (!receiver_->IsJSObject()) return false; Handle constructor = - JSObject::GetDataProperty(Handle::cast(receiver_), - isolate->factory()->constructor_string()); + JSReceiver::GetDataProperty(Handle::cast(receiver_), + isolate->factory()->constructor_string()); return constructor.is_identical_to(fun_); } diff --git a/src/messages.h b/src/messages.h index 930ea92..5b538c6 100644 --- a/src/messages.h +++ b/src/messages.h @@ -131,6 +131,10 @@ class CallSite { T(CalledOnNonObject, "% called on non-object") \ T(CalledOnNullOrUndefined, "% called on null or undefined") \ T(CannotConvertToPrimitive, "Cannot convert object to primitive value") \ + T(CannotPreventExtExternalArray, \ + "Cannot prevent extension of an object with external array elements") \ + T(CircularStructure, "Converting circular structure to JSON") \ + T(ConstAssign, "Assignment to constant variable.") \ T(ConstructorNonCallable, \ "Class constructors cannot be invoked without 'new'") \ T(ConstructorNotFunction, "Constructor % requires 'new'") \ @@ -139,12 +143,18 @@ class CallSite { "First argument to DataView constructor must be an ArrayBuffer") \ T(DateType, "this is not a Date object.") \ T(DefineDisallowed, "Cannot define property:%, object is not extensible.") \ + T(DuplicateTemplateProperty, "Object template has duplicate property '%'") \ + T(ExtendsValueGenerator, \ + "Class extends value % may not be a generator function") \ + T(ExtendsValueNotFunction, \ + "Class extends value % is not a function or null") \ T(FirstArgumentNotRegExp, \ "First argument to % must not be a regular expression") \ T(FlagsGetterNonObject, \ "RegExp.prototype.flags getter called on non-object %") \ T(FunctionBind, "Bind must be called on a function") \ T(GeneratorRunning, "Generator is already running") \ + T(IllegalInvocation, "Illegal invocation") \ T(IncompatibleMethodReceiver, "Method % called on incompatible receiver %") \ T(InstanceofFunctionExpected, \ "Expecting a function in instanceof check, but got %") \ @@ -160,15 +170,22 @@ class CallSite { T(MethodInvokedOnNullOrUndefined, \ "Method invoked on undefined or null value.") \ T(MethodInvokedOnWrongType, "Method invoked on an object that is not %.") \ + T(NonExtensibleProto, "% is not extensible") \ + T(NonObjectPropertyLoad, "Cannot read property '%' of %") \ + T(NonObjectPropertyStore, "Cannot set property '%' of %") \ + T(NoSetterInCallback, "Cannot set property % of % which has only a getter") \ T(NotAnIterator, "% is not an iterator") \ T(NotAPromise, "% is not a promise") \ T(NotConstructor, "% is not a constructor") \ + T(NotDateObject, "this is not a Date object.") \ + T(NotIntlObject, "% is not an i18n object.") \ T(NotGeneric, "% is not generic") \ T(NotIterable, "% is not iterable") \ T(NotTypedArray, "this is not a typed array.") \ T(ObjectGetterExpectingFunction, \ "Object.prototype.__defineGetter__: Expecting function") \ T(ObjectGetterCallable, "Getter must be a function: %") \ + T(ObjectNotExtensible, "Can't add property %, object is not extensible") \ T(ObjectSetterExpectingFunction, \ "Object.prototype.__defineSetter__: Expecting function") \ T(ObjectSetterCallable, "Setter must be a function: %") \ @@ -190,6 +207,10 @@ class CallSite { 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(PrototypeParentNotAnObject, \ + "Class extends value does not have valid prototype property %") \ + T(ProxyHandlerDeleteFailed, \ + "Proxy handler % did not return a boolean value from 'delete' trap") \ T(ProxyHandlerNonObject, "Proxy.% called with non-object as handler") \ T(ProxyHandlerReturned, "Proxy handler % returned % from '%' trap") \ T(ProxyHandlerTrapMissing, "Proxy handler % has no '%' trap") \ @@ -204,12 +225,27 @@ class CallSite { T(ProxyTrapFunctionExpected, \ "Proxy.createFunction called with non-function for '%' trap") \ T(RedefineDisallowed, "Cannot redefine property: %") \ + T(RedefineExternalArray, \ + "Cannot redefine a property of an object with external array elements") \ T(ReduceNoInitial, "Reduce of empty array with no initial value") \ T(ReinitializeIntl, "Trying to re-initialize % object.") \ T(ResolvedOptionsCalledOnNonObject, \ "resolvedOptions method called on a non-object or on a object that is " \ "not Intl.%.") \ T(ResolverNotAFunction, "Promise resolver % is not a function") \ + T(RestrictedFunctionProperties, \ + "'caller' and 'arguments' are restricted function properties and cannot " \ + "be accessed in this context.") \ + T(StaticPrototype, "Classes may not have static property named prototype") \ + T(StrictCannotAssign, "Cannot assign to read only '% in strict mode") \ + T(StrictDeleteProperty, "Cannot delete property '%' of %") \ + T(StrictPoisonPill, \ + "'caller', 'callee', and 'arguments' properties may not be accessed on " \ + "strict mode functions or the arguments objects for calls to them") \ + T(StrictReadOnlyProperty, "Cannot assign to read only property '%' of %") \ + T(StrongArity, \ + "In strong mode, calling a function with too few arguments is deprecated") \ + T(StrongImplicitCast, "In strong mode, implicit conversions are deprecated") \ T(SymbolToPrimitive, \ "Cannot convert a Symbol wrapper object to a primitive value") \ T(SymbolToNumber, "Cannot convert a Symbol value to a number") \ @@ -218,6 +254,7 @@ class CallSite { T(ValueAndAccessor, \ "Invalid property. A property cannot both have accessors and be " \ "writable or have a value, %") \ + T(VarRedeclaration, "Identifier '%' has already been declared") \ T(WithExpression, "% has no properties") \ T(WrongArgs, "%: Arguments list has wrong type") \ /* ReferenceError */ \ diff --git a/src/messages.js b/src/messages.js index b9503cf..4b67c2e 100644 --- a/src/messages.js +++ b/src/messages.js @@ -70,21 +70,15 @@ var kMessages = { newline_after_throw: ["Illegal newline after throw"], label_redeclaration: ["Label '", "%0", "' has already been declared"], var_redeclaration: ["Identifier '", "%0", "' has already been declared"], - duplicate_template_property: ["Object template has duplicate property '", "%0", "'"], no_catch_or_finally: ["Missing catch or finally after try"], unknown_label: ["Undefined label '", "%0", "'"], uncaught_exception: ["Uncaught ", "%0"], undefined_method: ["Object ", "%1", " has no method '", "%0", "'"], - non_object_property_load: ["Cannot read property '", "%0", "' of ", "%1"], non_object_property_store: ["Cannot set property '", "%0", "' of ", "%1"], - illegal_invocation: ["Illegal invocation"], - no_setter_in_callback: ["Cannot set property ", "%0", " of ", "%1", " which has only a getter"], 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"], - non_extensible_proto: ["%0", " is not extensible"], invalid_weakmap_key: ["Invalid value used as weak map key"], invalid_weakset_value: ["Invalid value used in weak set"], - not_date_object: ["this is not a Date object."], not_a_symbol: ["%0", " is not a symbol"], // ReferenceError invalid_lhs_in_assignment: ["Invalid left-hand side in assignment"], @@ -100,9 +94,7 @@ var kMessages = { illegal_continue: ["Illegal continue statement"], illegal_return: ["Illegal return statement"], error_loading_debugger: ["Error loading debugger"], - circular_structure: ["Converting circular structure to JSON"], array_indexof_not_defined: ["Array.getIndexOf: Argument undefined"], - object_not_extensible: ["Can't add property ", "%0", ", object is not extensible"], illegal_access: ["Illegal access"], static_prototype: ["Classes may not have static property named prototype"], strict_mode_with: ["Strict mode code may not include a with statement"], @@ -114,17 +106,11 @@ var kMessages = { strict_octal_literal: ["Octal literals are not allowed in strict mode."], template_octal_literal: ["Octal literals are not allowed in template strings."], strict_delete: ["Delete of an unqualified identifier in strict mode."], - strict_delete_property: ["Cannot delete property '", "%0", "' of ", "%1"], strict_function: ["In strict mode code, functions can only be declared at top level or immediately within another function." ], - strict_read_only_property: ["Cannot assign to read only property '", "%0", "' of ", "%1"], - strict_cannot_assign: ["Cannot assign to read only '", "%0", "' in strict mode"], - restricted_function_properties: ["'caller' and 'arguments' are restricted function properties and cannot be accessed in this context."], - strict_poison_pill: ["'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them"], strict_caller: ["Illegal access to a strict mode caller function."], strong_ellision: ["In strong mode, arrays with holes are deprecated, use maps instead"], strong_arguments: ["In strong mode, 'arguments' is deprecated, use '...args' instead"], strong_undefined: ["In strong mode, binding or assigning to 'undefined' is deprecated"], - strong_implicit_cast: ["In strong mode, implicit conversions are deprecated"], strong_direct_eval: ["In strong mode, direct calls to eval are deprecated"], strong_switch_fallthrough : ["In strong mode, switch fall-through is deprecated, terminate each case with 'break', 'continue', 'return' or 'throw'"], strong_equal: ["In strong mode, '==' and '!=' are deprecated, use '===' and '!==' instead"], @@ -141,18 +127,11 @@ var kMessages = { strong_constructor_this: ["In strong mode, 'this' can only be used to initialize properties, and cannot be nested inside another statement or expression"], strong_constructor_return_value: ["In strong mode, returning a value from a constructor is deprecated"], strong_constructor_return_misplaced: ["In strong mode, returning from a constructor before its super constructor invocation or all assignments to 'this' is deprecated"], - strong_arity: ["In strong mode, calling a function with too few arguments is deprecated"], sloppy_lexical: ["Block-scoped declarations (let, const, function, class) not yet supported outside strict mode"], malformed_arrow_function_parameter_list: ["Malformed arrow function parameter list"], - cant_prevent_ext_external_array_elements: ["Cannot prevent extension of an object with external array elements"], - redef_external_array_element: ["Cannot redefine a property of an object with external array elements"], - const_assign: ["Assignment to constant variable."], module_export_undefined: ["Export '", "%0", "' is not defined in module"], duplicate_export: ["Duplicate export of '", "%0", "'"], unexpected_super: ["'super' keyword unexpected here"], - extends_value_not_a_function: ["Class extends value ", "%0", " is not a function or null"], - extends_value_generator: ["Class extends value ", "%0", " may not be a generator function"], - prototype_parent_not_an_object: ["Class extends value does not have valid prototype property ", "%0"], duplicate_constructor: ["A class may only have one constructor"], super_constructor_call: ["A 'super' constructor call may only appear as the first statement of a function, and its arguments may not access 'this'. Other forms are not yet supported."], duplicate_proto: ["Duplicate __proto__ fields are not allowed in object literals"], diff --git a/src/objects.cc b/src/objects.cc index 9a5353f..8d984e3 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -145,15 +145,15 @@ MaybeHandle Object::GetProperty(LookupIterator* it) { } -Handle JSObject::GetDataProperty(Handle object, - Handle key) { +Handle JSReceiver::GetDataProperty(Handle object, + Handle key) { LookupIterator it(object, key, LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR); return GetDataProperty(&it); } -Handle JSObject::GetDataProperty(LookupIterator* it) { +Handle JSReceiver::GetDataProperty(LookupIterator* it) { for (; it->IsFound(); it->Next()) { switch (it->state()) { case LookupIterator::INTERCEPTOR: @@ -389,11 +389,10 @@ MaybeHandle Object::SetPropertyWithAccessor( receiver, Handle::cast(setter), value); } else { if (is_sloppy(language_mode)) return value; - Handle args[] = {name, holder}; - THROW_NEW_ERROR(isolate, - NewTypeError("no_setter_in_callback", - HandleVector(args, arraysize(args))), - Object); + THROW_NEW_ERROR( + isolate, + NewTypeError(MessageTemplate::kNoSetterInCallback, name, holder), + Object); } } @@ -3322,10 +3321,10 @@ MaybeHandle Object::WriteToReadOnlyProperty( Isolate* isolate, Handle receiver, Handle name, Handle value, LanguageMode language_mode) { if (is_sloppy(language_mode)) return value; - Handle args[] = {name, receiver}; - THROW_NEW_ERROR(isolate, NewTypeError("strict_read_only_property", - HandleVector(args, arraysize(args))), - Object); + THROW_NEW_ERROR( + isolate, + NewTypeError(MessageTemplate::kStrictReadOnlyProperty, name, receiver), + Object); } @@ -3410,12 +3409,10 @@ MaybeHandle Object::AddDataProperty(LookupIterator* it, it->PrepareTransitionToDataProperty(value, attributes, store_mode); if (it->state() != LookupIterator::TRANSITION) { if (is_sloppy(language_mode)) return value; - - Handle args[] = {it->name()}; - THROW_NEW_ERROR(it->isolate(), - NewTypeError("object_not_extensible", - HandleVector(args, arraysize(args))), - Object); + THROW_NEW_ERROR( + it->isolate(), + NewTypeError(MessageTemplate::kObjectNotExtensible, it->name()), + Object); } it->ApplyTransitionToDataProperty(); @@ -3969,10 +3966,9 @@ MaybeHandle JSProxy::SetPropertyViaPrototypesWithHandler( } if (is_sloppy(language_mode)) return value; - Handle args2[] = { name, proxy }; - THROW_NEW_ERROR(isolate, NewTypeError("no_setter_in_callback", - HandleVector(args2, arraysize(args2))), - Object); + THROW_NEW_ERROR( + isolate, NewTypeError(MessageTemplate::kNoSetterInCallback, name, proxy), + Object); } @@ -3997,12 +3993,10 @@ MaybeHandle JSProxy::DeletePropertyWithHandler( bool result_bool = result->BooleanValue(); if (is_strict(language_mode) && !result_bool) { Handle handler(proxy->handler(), isolate); - Handle trap_name = isolate->factory()->InternalizeOneByteString( - STATIC_CHAR_VECTOR("delete")); - Handle args[] = { handler, trap_name }; - THROW_NEW_ERROR(isolate, NewTypeError("handler_failed", - HandleVector(args, arraysize(args))), - Object); + THROW_NEW_ERROR( + isolate, + NewTypeError(MessageTemplate::kProxyHandlerDeleteFailed, handler), + Object); } return isolate->factory()->ToBoolean(result_bool); } @@ -5313,11 +5307,10 @@ MaybeHandle JSObject::DeleteElement(Handle object, if (is_strict(language_mode)) { // Deleting a non-configurable property in strict mode. Handle name = factory->NewNumberFromUint(index); - Handle args[] = {name, object}; - THROW_NEW_ERROR(isolate, - NewTypeError("strict_delete_property", - HandleVector(args, arraysize(args))), - Object); + THROW_NEW_ERROR( + isolate, + NewTypeError(MessageTemplate::kStrictDeleteProperty, name, object), + Object); } return factory->false_value(); } @@ -5447,10 +5440,9 @@ MaybeHandle JSObject::DeleteProperty(Handle object, if (!it.IsConfigurable()) { // Fail if the property is not configurable. if (is_strict(language_mode)) { - Handle args[] = {name, object}; THROW_NEW_ERROR(it.isolate(), - NewTypeError("strict_delete_property", - HandleVector(args, arraysize(args))), + NewTypeError(MessageTemplate::kStrictDeleteProperty, + name, object), Object); } return it.isolate()->factory()->false_value(); @@ -5671,10 +5663,9 @@ MaybeHandle JSObject::PreventExtensions(Handle object) { // It's not possible to seal objects with external array elements if (object->HasExternalArrayElements() || object->HasFixedTypedArrayElements()) { - THROW_NEW_ERROR(isolate, - NewTypeError("cant_prevent_ext_external_array_elements", - HandleVector(&object, 1)), - Object); + THROW_NEW_ERROR( + isolate, NewTypeError(MessageTemplate::kCannotPreventExtExternalArray), + Object); } // If there are fast elements we normalize. @@ -5780,10 +5771,9 @@ MaybeHandle JSObject::PreventExtensionsWithTransition( // It's not possible to seal or freeze objects with external array elements if (object->HasExternalArrayElements() || object->HasFixedTypedArrayElements()) { - THROW_NEW_ERROR(isolate, - NewTypeError("cant_prevent_ext_external_array_elements", - HandleVector(&object, 1)), - Object); + THROW_NEW_ERROR( + isolate, NewTypeError(MessageTemplate::kCannotPreventExtExternalArray), + Object); } Handle new_element_dictionary; @@ -10522,7 +10512,7 @@ bool JSFunction::PassesFilter(const char* raw_filter) { Handle JSFunction::GetDebugName(Handle function) { Isolate* isolate = function->GetIsolate(); Handle name = - JSObject::GetDataProperty(function, isolate->factory()->name_string()); + JSReceiver::GetDataProperty(function, isolate->factory()->name_string()); if (name->IsString()) return Handle::cast(name); return handle(function->shared()->DebugName(), isolate); } @@ -12597,9 +12587,8 @@ MaybeHandle JSObject::SetPrototype(Handle object, // or [[Extensible]] must not violate the invariants defined in the preceding // paragraph. if (!object->map()->is_extensible()) { - Handle args[] = { object }; - THROW_NEW_ERROR(isolate, NewTypeError("non_extensible_proto", - HandleVector(args, arraysize(args))), + THROW_NEW_ERROR(isolate, + NewTypeError(MessageTemplate::kNonExtensibleProto, object), Object); } @@ -12629,11 +12618,9 @@ MaybeHandle JSObject::SetPrototype(Handle object, Handle::cast(PrototypeIterator::GetCurrent(iter)); iter.Advance(); if (!real_receiver->map()->is_extensible()) { - Handle args[] = {object}; - THROW_NEW_ERROR(isolate, - NewTypeError("non_extensible_proto", - HandleVector(args, arraysize(args))), - Object); + THROW_NEW_ERROR( + isolate, NewTypeError(MessageTemplate::kNonExtensibleProto, object), + Object); } } } @@ -12813,11 +12800,10 @@ MaybeHandle JSObject::SetElementWithCallback( } else { if (is_sloppy(language_mode)) return value; Handle key(isolate->factory()->NewNumberFromUint(index)); - Handle args[] = {key, holder}; - THROW_NEW_ERROR(isolate, - NewTypeError("no_setter_in_callback", - HandleVector(args, arraysize(args))), - Object); + THROW_NEW_ERROR( + isolate, + NewTypeError(MessageTemplate::kNoSetterInCallback, key, holder), + Object); } } @@ -13056,11 +13042,9 @@ MaybeHandle JSObject::SetDictionaryElement( } else { Handle number = isolate->factory()->NewNumberFromUint(index); Handle name = isolate->factory()->NumberToString(number); - Handle args[] = {name}; - THROW_NEW_ERROR(isolate, - NewTypeError("object_not_extensible", - HandleVector(args, arraysize(args))), - Object); + THROW_NEW_ERROR( + isolate, NewTypeError(MessageTemplate::kObjectNotExtensible, name), + Object); } } @@ -13277,11 +13261,8 @@ MaybeHandle JSObject::SetElement(Handle object, if ((object->HasExternalArrayElements() || object->HasFixedTypedArrayElements()) && set_mode == DEFINE_PROPERTY) { - Handle number = isolate->factory()->NewNumberFromUint(index); - Handle args[] = { object, number }; - THROW_NEW_ERROR(isolate, NewTypeError("redef_external_array_element", - HandleVector(args, arraysize(args))), - Object); + THROW_NEW_ERROR( + isolate, NewTypeError(MessageTemplate::kRedefineExternalArray), Object); } // Normalize the elements to enable attributes on the property. @@ -13724,10 +13705,10 @@ bool JSArray::WouldChangeReadOnlyLength(Handle array, MaybeHandle JSArray::ReadOnlyLengthError(Handle array) { Isolate* isolate = array->GetIsolate(); Handle length = isolate->factory()->length_string(); - Handle args[] = {length, array}; - THROW_NEW_ERROR(isolate, NewTypeError("strict_read_only_property", - HandleVector(args, arraysize(args))), - Object); + THROW_NEW_ERROR( + isolate, + NewTypeError(MessageTemplate::kStrictReadOnlyProperty, length, array), + Object); } diff --git a/src/objects.h b/src/objects.h index eb978b9..f27ce21 100644 --- a/src/objects.h +++ b/src/objects.h @@ -1671,6 +1671,11 @@ class JSReceiver: public HeapObject { MUST_USE_RESULT static inline Maybe GetOwnElementAttribute(Handle object, uint32_t index); + static Handle GetDataProperty(Handle object, + Handle key); + static Handle GetDataProperty(LookupIterator* it); + + // Retrieves a permanent object identity hash code. The undefined value might // be returned in case no hash was created yet. inline Object* GetIdentityHash(); @@ -2167,10 +2172,6 @@ class JSObject: public JSReceiver { Handle object, AllocationSiteCreationContext* site_context); - static Handle GetDataProperty(Handle object, - Handle key); - static Handle GetDataProperty(LookupIterator* it); - DECLARE_CAST(JSObject) // Dispatched behavior. diff --git a/src/runtime.js b/src/runtime.js index 7fab3ca..0d40064 100644 --- a/src/runtime.js +++ b/src/runtime.js @@ -236,7 +236,7 @@ ADD_STRONG = function ADD_STRONG(x) { if (IS_NUMBER(this) && IS_NUMBER(x)) return %NumberAdd(this, x); if (IS_STRING(this) && IS_STRING(x)) return %_StringAdd(this, x); - throw %MakeTypeError('strong_implicit_cast'); + throw %MakeTypeError(kStrongImplicitCast); } @@ -260,7 +260,7 @@ STRING_ADD_LEFT_STRONG = function STRING_ADD_LEFT_STRONG(y) { if (IS_STRING(y)) { return %_StringAdd(this, y); } - throw %MakeTypeError('strong_implicit_cast'); + throw %MakeTypeError(kStrongImplicitCast); } @@ -285,7 +285,7 @@ STRING_ADD_RIGHT_STRONG = function STRING_ADD_RIGHT_STRONG(y) { if (IS_STRING(this)) { return %_StringAdd(this, y); } - throw %MakeTypeError('strong_implicit_cast'); + throw %MakeTypeError(kStrongImplicitCast); } @@ -302,7 +302,7 @@ SUB_STRONG = function SUB_STRONG(y) { if (IS_NUMBER(this) && IS_NUMBER(y)) { return %NumberSub(this, y); } - throw %MakeTypeError('strong_implicit_cast'); + throw %MakeTypeError(kStrongImplicitCast); } @@ -319,7 +319,7 @@ MUL_STRONG = function MUL_STRONG(y) { if (IS_NUMBER(this) && IS_NUMBER(y)) { return %NumberMul(this, y); } - throw %MakeTypeError('strong_implicit_cast'); + throw %MakeTypeError(kStrongImplicitCast); } @@ -336,7 +336,7 @@ DIV_STRONG = function DIV_STRONG(y) { if (IS_NUMBER(this) && IS_NUMBER(y)) { return %NumberDiv(this, y); } - throw %MakeTypeError('strong_implicit_cast'); + throw %MakeTypeError(kStrongImplicitCast); } @@ -353,7 +353,7 @@ MOD_STRONG = function MOD_STRONG(y) { if (IS_NUMBER(this) && IS_NUMBER(y)) { return %NumberMod(this, y); } - throw %MakeTypeError('strong_implicit_cast'); + throw %MakeTypeError(kStrongImplicitCast); } @@ -375,7 +375,7 @@ BIT_OR_STRONG = function BIT_OR_STRONG(y) { if (IS_NUMBER(this) && IS_NUMBER(y)) { return %NumberOr(this, y); } - throw %MakeTypeError('strong_implicit_cast'); + throw %MakeTypeError(kStrongImplicitCast); } @@ -406,7 +406,7 @@ BIT_AND_STRONG = function BIT_AND_STRONG(y) { if (IS_NUMBER(this) && IS_NUMBER(y)) { return %NumberAnd(this, y); } - throw %MakeTypeError('strong_implicit_cast'); + throw %MakeTypeError(kStrongImplicitCast); } @@ -423,7 +423,7 @@ BIT_XOR_STRONG = function BIT_XOR_STRONG(y) { if (IS_NUMBER(this) && IS_NUMBER(y)) { return %NumberXor(this, y); } - throw %MakeTypeError('strong_implicit_cast'); + throw %MakeTypeError(kStrongImplicitCast); } @@ -440,7 +440,7 @@ SHL_STRONG = function SHL_STRONG(y) { if (IS_NUMBER(this) && IS_NUMBER(y)) { return %NumberShl(this, y); } - throw %MakeTypeError('strong_implicit_cast'); + throw %MakeTypeError(kStrongImplicitCast); } @@ -471,7 +471,7 @@ SAR_STRONG = function SAR_STRONG(y) { if (IS_NUMBER(this) && IS_NUMBER(y)) { return %NumberSar(this, y); } - throw %MakeTypeError('strong_implicit_cast'); + throw %MakeTypeError(kStrongImplicitCast); } @@ -488,7 +488,7 @@ SHR_STRONG = function SHR_STRONG(y) { if (IS_NUMBER(this) && IS_NUMBER(y)) { return %NumberShr(this, y); } - throw %MakeTypeError('strong_implicit_cast'); + throw %MakeTypeError(kStrongImplicitCast); } diff --git a/src/runtime/runtime-classes.cc b/src/runtime/runtime-classes.cc index 3dc3a24..f084fd6 100644 --- a/src/runtime/runtime-classes.cc +++ b/src/runtime/runtime-classes.cc @@ -52,7 +52,7 @@ RUNTIME_FUNCTION(Runtime_ThrowArrayNotSubclassableError) { static Object* ThrowStaticPrototypeError(Isolate* isolate) { THROW_NEW_ERROR_RETURN_FAILURE( - isolate, NewTypeError("static_prototype", HandleVector(NULL, 0))); + isolate, NewTypeError(MessageTemplate::kStaticPrototype)); } @@ -113,28 +113,25 @@ RUNTIME_FUNCTION(Runtime_DefineClass) { prototype_parent = isolate->factory()->null_value(); } else if (super_class->IsSpecFunction()) { if (Handle::cast(super_class)->shared()->is_generator()) { - Handle args[1] = {super_class}; THROW_NEW_ERROR_RETURN_FAILURE( isolate, - NewTypeError("extends_value_generator", HandleVector(args, 1))); + NewTypeError(MessageTemplate::kExtendsValueGenerator, super_class)); } ASSIGN_RETURN_FAILURE_ON_EXCEPTION( isolate, prototype_parent, Runtime::GetObjectProperty(isolate, super_class, isolate->factory()->prototype_string())); if (!prototype_parent->IsNull() && !prototype_parent->IsSpecObject()) { - Handle args[1] = {prototype_parent}; THROW_NEW_ERROR_RETURN_FAILURE( - isolate, NewTypeError("prototype_parent_not_an_object", - HandleVector(args, 1))); + isolate, NewTypeError(MessageTemplate::kPrototypeParentNotAnObject, + prototype_parent)); } constructor_parent = super_class; } else { // TODO(arv): Should be IsConstructor. - Handle args[1] = {super_class}; THROW_NEW_ERROR_RETURN_FAILURE( isolate, - NewTypeError("extends_value_not_a_function", HandleVector(args, 1))); + NewTypeError(MessageTemplate::kExtendsValueNotFunction, super_class)); } } diff --git a/src/runtime/runtime-date.cc b/src/runtime/runtime-date.cc index 844ca25..7c634c2 100644 --- a/src/runtime/runtime-date.cc +++ b/src/runtime/runtime-date.cc @@ -7,6 +7,7 @@ #include "src/arguments.h" #include "src/date.h" #include "src/dateparser-inl.h" +#include "src/messages.h" #include "src/runtime/runtime-utils.h" namespace v8 { @@ -62,8 +63,8 @@ RUNTIME_FUNCTION(Runtime_DateSetValue) { RUNTIME_FUNCTION(Runtime_ThrowNotDateError) { HandleScope scope(isolate); DCHECK(args.length() == 0); - THROW_NEW_ERROR_RETURN_FAILURE( - isolate, NewTypeError("not_date_object", HandleVector(NULL, 0))); + THROW_NEW_ERROR_RETURN_FAILURE(isolate, + NewTypeError(MessageTemplate::kNotDateObject)); } @@ -179,8 +180,7 @@ RUNTIME_FUNCTION(Runtime_DateField) { if (!obj->IsJSDate()) { HandleScope scope(isolate); THROW_NEW_ERROR_RETURN_FAILURE( - isolate, - NewTypeError("not_date_object", HandleVector(NULL, 0))); + isolate, NewTypeError(MessageTemplate::kNotDateObject)); } JSDate* date = JSDate::cast(obj); if (index == 0) return date->value(); diff --git a/src/runtime/runtime-function.cc b/src/runtime/runtime-function.cc index 12d880b..ade955c 100644 --- a/src/runtime/runtime-function.cc +++ b/src/runtime/runtime-function.cc @@ -10,6 +10,7 @@ #include "src/cpu-profiler.h" #include "src/deoptimizer.h" #include "src/frames.h" +#include "src/messages.h" #include "src/runtime/runtime-utils.h" namespace v8 { @@ -610,8 +611,8 @@ RUNTIME_FUNCTION(Runtime_IsFunction) { RUNTIME_FUNCTION(Runtime_ThrowStrongModeTooFewArguments) { HandleScope scope(isolate); DCHECK(args.length() == 0); - THROW_NEW_ERROR_RETURN_FAILURE( - isolate, NewTypeError("strong_arity", HandleVector(NULL, 0))); + THROW_NEW_ERROR_RETURN_FAILURE(isolate, + NewTypeError(MessageTemplate::kStrongArity)); } } } // namespace v8::internal diff --git a/src/runtime/runtime-i18n.cc b/src/runtime/runtime-i18n.cc index 5e01651..c39dbe3 100644 --- a/src/runtime/runtime-i18n.cc +++ b/src/runtime/runtime-i18n.cc @@ -9,6 +9,7 @@ #include "src/api-natives.h" #include "src/arguments.h" #include "src/i18n.h" +#include "src/messages.h" #include "src/runtime/runtime-utils.h" #include "unicode/brkiter.h" @@ -234,7 +235,7 @@ RUNTIME_FUNCTION(Runtime_IsInitializedIntlObject) { Handle obj = Handle::cast(input); Handle marker = isolate->factory()->intl_initialized_marker_symbol(); - Handle tag = JSObject::GetDataProperty(obj, marker); + Handle tag = JSReceiver::GetDataProperty(obj, marker); return isolate->heap()->ToBoolean(!tag->IsUndefined()); } @@ -251,7 +252,7 @@ RUNTIME_FUNCTION(Runtime_IsInitializedIntlObjectOfType) { Handle obj = Handle::cast(input); Handle marker = isolate->factory()->intl_initialized_marker_symbol(); - Handle tag = JSObject::GetDataProperty(obj, marker); + Handle tag = JSReceiver::GetDataProperty(obj, marker); return isolate->heap()->ToBoolean(tag->IsString() && String::cast(*tag)->Equals(*expected_type)); } @@ -281,23 +282,21 @@ RUNTIME_FUNCTION(Runtime_GetImplFromInitializedIntlObject) { DCHECK(args.length() == 1); - CONVERT_ARG_HANDLE_CHECKED(Object, input, 0); + CONVERT_ARG_HANDLE_CHECKED(JSObject, input, 0); if (!input->IsJSObject()) { - Vector > arguments = HandleVector(&input, 1); - THROW_NEW_ERROR_RETURN_FAILURE(isolate, - NewTypeError("not_intl_object", arguments)); + THROW_NEW_ERROR_RETURN_FAILURE( + isolate, NewTypeError(MessageTemplate::kNotIntlObject, input)); } Handle obj = Handle::cast(input); Handle marker = isolate->factory()->intl_impl_object_symbol(); - Handle impl = JSObject::GetDataProperty(obj, marker); + Handle impl = JSReceiver::GetDataProperty(obj, marker); if (impl->IsTheHole()) { - Vector > arguments = HandleVector(&obj, 1); - THROW_NEW_ERROR_RETURN_FAILURE(isolate, - NewTypeError("not_intl_object", arguments)); + THROW_NEW_ERROR_RETURN_FAILURE( + isolate, NewTypeError(MessageTemplate::kNotIntlObject, obj)); } return *impl; } diff --git a/src/runtime/runtime-internal.cc b/src/runtime/runtime-internal.cc index b10350d..c7ce16e 100644 --- a/src/runtime/runtime-internal.cc +++ b/src/runtime/runtime-internal.cc @@ -79,7 +79,7 @@ RUNTIME_FUNCTION(Runtime_PromiseRejectEvent) { if (debug_event) isolate->debug()->OnPromiseReject(promise, value); Handle key = isolate->factory()->promise_has_handler_symbol(); // Do not report if we actually have a handler. - if (JSObject::GetDataProperty(promise, key)->IsUndefined()) { + if (JSReceiver::GetDataProperty(promise, key)->IsUndefined()) { isolate->ReportPromiseReject(promise, value, v8::kPromiseRejectWithNoHandler); } @@ -93,7 +93,7 @@ RUNTIME_FUNCTION(Runtime_PromiseRevokeReject) { CONVERT_ARG_HANDLE_CHECKED(JSObject, promise, 0); Handle key = isolate->factory()->promise_has_handler_symbol(); // At this point, no revocation has been issued before - RUNTIME_ASSERT(JSObject::GetDataProperty(promise, key)->IsUndefined()); + RUNTIME_ASSERT(JSReceiver::GetDataProperty(promise, key)->IsUndefined()); isolate->ReportPromiseReject(promise, Handle(), v8::kPromiseHandlerAddedAfterReject); return isolate->heap()->undefined_value(); diff --git a/src/runtime/runtime-object.cc b/src/runtime/runtime-object.cc index 79950c6..ca35c10 100644 --- a/src/runtime/runtime-object.cc +++ b/src/runtime/runtime-object.cc @@ -70,10 +70,10 @@ MaybeHandle Runtime::GetObjectProperty(Isolate* isolate, Handle object, Handle key) { if (object->IsUndefined() || object->IsNull()) { - Handle args[2] = {key, object}; - THROW_NEW_ERROR(isolate, NewTypeError("non_object_property_load", - HandleVector(args, 2)), - Object); + THROW_NEW_ERROR( + isolate, + NewTypeError(MessageTemplate::kNonObjectPropertyLoad, key, object), + Object); } // Check if the given key is an array index. @@ -102,10 +102,10 @@ MaybeHandle Runtime::SetObjectProperty(Isolate* isolate, Handle value, LanguageMode language_mode) { if (object->IsUndefined() || object->IsNull()) { - Handle args[2] = {key, object}; - THROW_NEW_ERROR(isolate, NewTypeError("non_object_property_store", - HandleVector(args, 2)), - Object); + THROW_NEW_ERROR( + isolate, + NewTypeError(MessageTemplate::kNonObjectPropertyStore, key, object), + Object); } if (object->IsJSProxy()) { @@ -1419,9 +1419,9 @@ RUNTIME_FUNCTION(Runtime_DefineDataPropertyUnchecked) { RUNTIME_FUNCTION(Runtime_GetDataProperty) { HandleScope scope(isolate); DCHECK(args.length() == 2); - CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); + CONVERT_ARG_HANDLE_CHECKED(JSReceiver, object, 0); CONVERT_ARG_HANDLE_CHECKED(Name, key, 1); - return *JSObject::GetDataProperty(object, key); + return *JSReceiver::GetDataProperty(object, key); } diff --git a/src/runtime/runtime-scopes.cc b/src/runtime/runtime-scopes.cc index 911958d..b5c46bf 100644 --- a/src/runtime/runtime-scopes.cc +++ b/src/runtime/runtime-scopes.cc @@ -17,17 +17,15 @@ namespace internal { static Object* ThrowRedeclarationError(Isolate* isolate, Handle name) { HandleScope scope(isolate); - Handle args[1] = {name}; THROW_NEW_ERROR_RETURN_FAILURE( - isolate, NewTypeError("var_redeclaration", HandleVector(args, 1))); + isolate, NewTypeError(MessageTemplate::kVarRedeclaration, name)); } RUNTIME_FUNCTION(Runtime_ThrowConstAssignError) { HandleScope scope(isolate); - THROW_NEW_ERROR_RETURN_FAILURE( - isolate, - NewTypeError("const_assign", HandleVector(NULL, 0))); + THROW_NEW_ERROR_RETURN_FAILURE(isolate, + NewTypeError(MessageTemplate::kConstAssign)); } @@ -1019,8 +1017,7 @@ RUNTIME_FUNCTION(Runtime_StoreLookupSlot) { } else if (is_strict(language_mode)) { // Setting read only property in strict mode. THROW_NEW_ERROR_RETURN_FAILURE( - isolate, - NewTypeError("strict_cannot_assign", HandleVector(&name, 1))); + isolate, NewTypeError(MessageTemplate::kStrictCannotAssign, name)); } return *value; } @@ -1111,8 +1108,7 @@ RUNTIME_FUNCTION(Runtime_GetArgumentsProperty) { JSFunction* function = frame->function(); if (is_strict(function->shared()->language_mode())) { THROW_NEW_ERROR_RETURN_FAILURE( - isolate, NewTypeError("strict_arguments_callee", - HandleVector(NULL, 0))); + isolate, NewTypeError(MessageTemplate::kStrictPoisonPill)); } return function; } diff --git a/test/cctest/test-serialize.cc b/test/cctest/test-serialize.cc index 72eb194..7ec5e05 100644 --- a/test/cctest/test-serialize.cc +++ b/test/cctest/test-serialize.cc @@ -634,7 +634,7 @@ UNINITIALIZED_DEPENDENT_TEST(CustomContextDeserialization, CHECK(context->global_proxy() == *global_proxy); Handle o = isolate->factory()->NewStringFromAsciiChecked("o"); Handle global_object(context->global_object(), isolate); - Handle property = JSObject::GetDataProperty(global_object, o); + Handle property = JSReceiver::GetDataProperty(global_object, o); CHECK(property.is_identical_to(global_proxy)); v8::Handle v8_context = v8::Utils::ToLocal(context); @@ -1009,11 +1009,11 @@ TEST(SerializeToplevelLargeStrings) { Execution::Call(isolate, copy_fun, global, 0, NULL).ToHandleChecked(); CHECK_EQ(6 * 1999999, Handle::cast(copy_result)->length()); - Handle property = JSObject::GetDataProperty( + Handle property = JSReceiver::GetDataProperty( isolate->global_object(), f->NewStringFromAsciiChecked("s")); CHECK(isolate->heap()->InSpace(HeapObject::cast(*property), LO_SPACE)); - property = JSObject::GetDataProperty(isolate->global_object(), - f->NewStringFromAsciiChecked("t")); + property = JSReceiver::GetDataProperty(isolate->global_object(), + f->NewStringFromAsciiChecked("t")); CHECK(isolate->heap()->InSpace(HeapObject::cast(*property), LO_SPACE)); // Make sure we do not serialize too much, e.g. include the source string. CHECK_LT(cache->length(), 13000000); diff --git a/test/mjsunit/messages.js b/test/mjsunit/messages.js index 73cc15a..56470b1 100644 --- a/test/mjsunit/messages.js +++ b/test/mjsunit/messages.js @@ -3,7 +3,7 @@ // found in the LICENSE file. // Flags: --stack-size=100 --harmony --harmony-reflect --harmony-arrays -// Flags: --harmony-regexps +// Flags: --harmony-regexps --strong-mode function test(f, expected, type) { try { @@ -62,11 +62,30 @@ test(function() { Array.prototype.shift.call(null); }, "Array.prototype.shift called on null or undefined", TypeError); +// kCannotPreventExtExternalArray +test(function() { + Object.preventExtensions(new Uint16Array(1)); +}, "Cannot prevent extension of an object with external array elements", TypeError); + +// kConstAssign +test(function() { + "use strict"; + const a = 1; + a = 2; +}, "Assignment to constant variable.", TypeError); + // kCannotConvertToPrimitive test(function() { [].join(Object(Symbol(1))); }, "Cannot convert object to primitive value", TypeError); +// kCircularStructure +test(function() { + var o = {}; + o.o = o; + JSON.stringify(o); +}, "Converting circular structure to JSON", TypeError); + // kConstructorNotFunction test(function() { Uint16Array(1); @@ -160,6 +179,11 @@ test(function() { new Symbol(); }, "Symbol is not a constructor", TypeError); +// kNotDateObject +test(function() { + Date.prototype.setHours.call(1); +}, "this is not a Date object.", TypeError); + // kNotGeneric test(function() { String.prototype.toString.call(1); @@ -204,6 +228,14 @@ test(function() { Object.defineProperty({}, "x", { get: 1 }); }, "Getter must be a function: 1", TypeError); +// kObjectNotExtensible +test(function() { + "use strict"; + var o = {}; + Object.freeze(o); + o.a = 1; +}, "Can't add property a, object is not extensible", TypeError); + // kObjectSetterExpectingFunction test(function() { ({}).__defineSetter__("x", 0); @@ -248,6 +280,34 @@ test(function() { new Promise(1); }, "Promise resolver 1 is not a function", TypeError); +// kStrictDeleteProperty +test(function() { + "use strict"; + var o = {}; + Object.defineProperty(o, "p", { value: 1, writable: false }); + delete o.p; +}, "Cannot delete property 'p' of #", TypeError); + +// kStrictPoisonPill +test(function() { + "use strict"; + arguments.callee; +}, "'caller', 'callee', and 'arguments' properties may not be accessed on " + + "strict mode functions or the arguments objects for calls to them", + TypeError); + +// kStrictReadOnlyProperty +test(function() { + "use strict"; + (1).a = 1; +}, "Cannot assign to read only property 'a' of 1", TypeError); + +// kStrongImplicitCast +test(function() { + "use strong"; + "a" + 1; +}, "In strong mode, implicit conversions are deprecated", TypeError); + // kSymbolToPrimitive test(function() { 1 + Object(Symbol()); -- 2.7.4