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

Migrate error messages, part 8.

R=mvstanton@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#28250}
parent f192f4ca
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "src/frames-inl.h" #include "src/frames-inl.h"
#include "src/isolate.h" #include "src/isolate.h"
#include "src/list-inl.h" #include "src/list-inl.h"
#include "src/messages.h"
#include "src/property-details.h" #include "src/property-details.h"
#include "src/prototype.h" #include "src/prototype.h"
...@@ -260,8 +261,8 @@ void Accessors::ArrayLengthSetter( ...@@ -260,8 +261,8 @@ void Accessors::ArrayLengthSetter(
return; return;
} }
Handle<Object> exception = isolate->factory()->NewRangeError( Handle<Object> exception =
"invalid_array_length", HandleVector<Object>(NULL, 0)); isolate->factory()->NewRangeError(MessageTemplate::kInvalidArrayLength);
isolate->ScheduleThrow(*exception); isolate->ScheduleThrow(*exception);
} }
......
...@@ -15,7 +15,7 @@ var GlobalObject = global.Object; ...@@ -15,7 +15,7 @@ var GlobalObject = global.Object;
function ArrayBufferConstructor(length) { // length = 1 function ArrayBufferConstructor(length) { // length = 1
if (%_IsConstructCall()) { if (%_IsConstructCall()) {
var byteLength = ToPositiveInteger(length, 'invalid_array_buffer_length'); var byteLength = ToPositiveInteger(length, kInvalidArrayBufferLength);
%ArrayBufferInitialize(this, byteLength); %ArrayBufferInitialize(this, byteLength);
} else { } else {
throw MakeTypeError(kConstructorNotFunction, "ArrayBuffer"); throw MakeTypeError(kConstructorNotFunction, "ArrayBuffer");
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "src/arguments.h" #include "src/arguments.h"
#include "src/conversions.h" #include "src/conversions.h"
#include "src/elements.h" #include "src/elements.h"
#include "src/messages.h"
#include "src/objects.h" #include "src/objects.h"
#include "src/utils.h" #include "src/utils.h"
...@@ -141,8 +142,7 @@ static bool HasKey(Handle<FixedArray> array, Handle<Object> key_handle) { ...@@ -141,8 +142,7 @@ static bool HasKey(Handle<FixedArray> array, Handle<Object> key_handle) {
MUST_USE_RESULT MUST_USE_RESULT
static MaybeHandle<Object> ThrowArrayLengthRangeError(Isolate* isolate) { static MaybeHandle<Object> ThrowArrayLengthRangeError(Isolate* isolate) {
THROW_NEW_ERROR(isolate, NewRangeError("invalid_array_length", THROW_NEW_ERROR(isolate, NewRangeError(MessageTemplate::kInvalidArrayLength),
HandleVector<Object>(NULL, 0)),
Object); Object);
} }
......
...@@ -1193,6 +1193,13 @@ Handle<Object> Factory::NewTypeError(MessageTemplate::Template template_index, ...@@ -1193,6 +1193,13 @@ Handle<Object> Factory::NewTypeError(MessageTemplate::Template template_index,
} }
Handle<Object> Factory::NewRangeError(MessageTemplate::Template template_index,
Handle<Object> arg0, Handle<Object> arg1,
Handle<Object> arg2) {
return NewError("MakeRangeError", template_index, arg0, arg1, arg2);
}
Handle<Object> Factory::NewEvalError(MessageTemplate::Template template_index, Handle<Object> Factory::NewEvalError(MessageTemplate::Template template_index,
Handle<Object> arg0, Handle<Object> arg1, Handle<Object> arg0, Handle<Object> arg1,
Handle<Object> arg2) { Handle<Object> arg2) {
......
...@@ -556,8 +556,7 @@ class Factory final { ...@@ -556,8 +556,7 @@ class Factory final {
Handle<Object> NewRangeError(Handle<String> message); Handle<Object> NewRangeError(Handle<String> message);
Handle<Object> NewInvalidStringLengthError() { Handle<Object> NewInvalidStringLengthError() {
return NewRangeError("invalid_string_length", return NewRangeError(MessageTemplate::kInvalidStringLength);
HandleVector<Object>(NULL, 0));
} }
Handle<Object> NewSyntaxError(const char* message, Handle<JSArray> args); Handle<Object> NewSyntaxError(const char* message, Handle<JSArray> args);
...@@ -586,6 +585,11 @@ class Factory final { ...@@ -586,6 +585,11 @@ class Factory final {
Handle<Object> arg1 = Handle<Object>(), Handle<Object> arg1 = Handle<Object>(),
Handle<Object> arg2 = Handle<Object>()); Handle<Object> arg2 = Handle<Object>());
Handle<Object> NewRangeError(MessageTemplate::Template template_index,
Handle<Object> arg0 = Handle<Object>(),
Handle<Object> arg1 = Handle<Object>(),
Handle<Object> arg2 = Handle<Object>());
Handle<Object> NewEvalError(MessageTemplate::Template template_index, Handle<Object> NewEvalError(MessageTemplate::Template template_index,
Handle<Object> arg0 = Handle<Object>(), Handle<Object> arg0 = Handle<Object>(),
Handle<Object> arg1 = Handle<Object>(), Handle<Object> arg1 = Handle<Object>(),
......
...@@ -132,6 +132,8 @@ class CallSite { ...@@ -132,6 +132,8 @@ class CallSite {
T(CannotConvertToPrimitive, "Cannot convert object to primitive value") \ T(CannotConvertToPrimitive, "Cannot convert object to primitive value") \
T(ConstructorNotFunction, "Constructor % requires 'new'") \ T(ConstructorNotFunction, "Constructor % requires 'new'") \
T(CurrencyCode, "Currency code is required with currency style.") \ T(CurrencyCode, "Currency code is required with currency style.") \
T(DataViewNotArrayBuffer, \
"First argument to DataView constructor must be an ArrayBuffer") \
T(DateType, "this is not a Date object.") \ T(DateType, "this is not a Date object.") \
T(DefineDisallowed, "Cannot define property:%, object is not extensible.") \ T(DefineDisallowed, "Cannot define property:%, object is not extensible.") \
T(FirstArgumentNotRegExp, \ T(FirstArgumentNotRegExp, \
...@@ -145,6 +147,7 @@ class CallSite { ...@@ -145,6 +147,7 @@ class CallSite {
"Expecting a function in instanceof check, but got %") \ "Expecting a function in instanceof check, but got %") \
T(InstanceofNonobjectProto, \ T(InstanceofNonobjectProto, \
"Function has non-object prototype '%' in instanceof check") \ "Function has non-object prototype '%' in instanceof check") \
T(InvalidArgument, "invalid_argument") \
T(InvalidInOperatorUse, "Cannot use 'in' operator to search for '%' in %") \ T(InvalidInOperatorUse, "Cannot use 'in' operator to search for '%' in %") \
T(IteratorResultNotAnObject, "Iterator result % is not an object") \ T(IteratorResultNotAnObject, "Iterator result % is not an object") \
T(IteratorValueNotAnObject, "Iterator value % is not an entry object") \ T(IteratorValueNotAnObject, "Iterator value % is not an entry object") \
...@@ -155,6 +158,7 @@ class CallSite { ...@@ -155,6 +158,7 @@ class CallSite {
"Method invoked on undefined or null value.") \ "Method invoked on undefined or null value.") \
T(MethodInvokedOnWrongType, "Method invoked on an object that is not %.") \ T(MethodInvokedOnWrongType, "Method invoked on an object that is not %.") \
T(NotAnIterator, "% is not an iterator") \ T(NotAnIterator, "% is not an iterator") \
T(NotAPromise, "% is not a promise") \
T(NotConstructor, "% is not a constructor") \ T(NotConstructor, "% is not a constructor") \
T(NotGeneric, "% is not generic") \ T(NotGeneric, "% is not generic") \
T(NotIterable, "% is not iterable") \ T(NotIterable, "% is not iterable") \
...@@ -179,24 +183,30 @@ class CallSite { ...@@ -179,24 +183,30 @@ class CallSite {
"Invalid changeRecord with non-string 'type' property") \ "Invalid changeRecord with non-string 'type' property") \
T(OrdinaryFunctionCalledAsConstructor, \ T(OrdinaryFunctionCalledAsConstructor, \
"Function object that's not a constructor was created with new") \ "Function object that's not a constructor was created with new") \
T(PromiseCyclic, "Chaining cycle detected for promise %") \
T(PropertyDescObject, "Property description must be an object: %") \ T(PropertyDescObject, "Property description must be an object: %") \
T(PropertyNotFunction, "Property '%' of object % is not a function") \ T(PropertyNotFunction, "Property '%' of object % is not a function") \
T(ProtoObjectOrNull, "Object prototype may only be an Object or null: %") \ T(ProtoObjectOrNull, "Object prototype may only be an Object or null: %") \
T(ProxyHandlerNonObject, "Proxy.% called with non-object as handler") \
T(ProxyHandlerReturned, "Proxy handler % returned % from '%' trap") \ T(ProxyHandlerReturned, "Proxy handler % returned % from '%' trap") \
T(ProxyHandlerTrapMissing, "Proxy handler % has no '%' trap") \ T(ProxyHandlerTrapMissing, "Proxy handler % has no '%' trap") \
T(ProxyHandlerTrapMustBeCallable, \ T(ProxyHandlerTrapMustBeCallable, \
"Proxy handler %0 has non-callable '%' trap") \ "Proxy handler %0 has non-callable '%' trap") \
T(ProxyNonObjectPropNames, "Trap '%' returned non-object %") \ T(ProxyNonObjectPropNames, "Trap '%' returned non-object %") \
T(ProxyRepeatedPropName, "Trap '%' returned repeated property name '%'") \ T(ProxyProtoNonObject, "Proxy.create called with no-object as prototype") \
T(ProxyPropNotConfigurable, \ T(ProxyPropNotConfigurable, \
"Proxy handler % returned non-configurable descriptor for property '%' " \ "Proxy handler % returned non-configurable descriptor for property '%' " \
"from '%' trap") \ "from '%' trap") \
T(ProxyRepeatedPropName, "Trap '%' returned repeated property name '%'") \
T(ProxyTrapFunctionExpected, \
"Proxy.createFunction called with non-function for '%' trap") \
T(RedefineDisallowed, "Cannot redefine property: %") \ T(RedefineDisallowed, "Cannot redefine property: %") \
T(ReduceNoInitial, "Reduce of empty array with no initial value") \ T(ReduceNoInitial, "Reduce of empty array with no initial value") \
T(ReinitializeIntl, "Trying to re-initialize % object.") \ T(ReinitializeIntl, "Trying to re-initialize % object.") \
T(ResolvedOptionsCalledOnNonObject, \ T(ResolvedOptionsCalledOnNonObject, \
"resolvedOptions method called on a non-object or on a object that is " \ "resolvedOptions method called on a non-object or on a object that is " \
"not Intl.%.") \ "not Intl.%.") \
T(ResolverNotAFunction, "Promise resolver % is not a function") \
T(SymbolToPrimitive, \ T(SymbolToPrimitive, \
"Cannot convert a Symbol wrapper object to a primitive value") \ "Cannot convert a Symbol wrapper object to a primitive value") \
T(SymbolToNumber, "Cannot convert a Symbol value to a number") \ T(SymbolToNumber, "Cannot convert a Symbol value to a number") \
...@@ -211,11 +221,21 @@ class CallSite { ...@@ -211,11 +221,21 @@ class CallSite {
T(ArrayLengthOutOfRange, "defineProperty() array length out of range") \ T(ArrayLengthOutOfRange, "defineProperty() array length out of range") \
T(DateRange, "Provided date is not in valid range.") \ T(DateRange, "Provided date is not in valid range.") \
T(ExpectedLocation, "Expected Area/Location for time zone, got %") \ T(ExpectedLocation, "Expected Area/Location for time zone, got %") \
T(InvalidArrayBufferLength, "Invalid array buffer length") \
T(InvalidArrayLength, "Invalid array length") \
T(InvalidCodePoint, "Invalid code point %") \ T(InvalidCodePoint, "Invalid code point %") \
T(InvalidCountValue, "Invalid count value") \ T(InvalidCountValue, "Invalid count value") \
T(InvalidCurrencyCode, "Invalid currency code: %") \ T(InvalidCurrencyCode, "Invalid currency code: %") \
T(InvalidDataViewAccessorOffset, \
"Offset is outside the bounds of the DataView") \
T(InvalidDataViewLength, "Invalid data view length") \
T(InvalidDataViewOffset, "Start offset is outside the bounds of the buffer") \
T(InvalidLanguageTag, "Invalid language tag: %") \ T(InvalidLanguageTag, "Invalid language tag: %") \
T(InvalidStringLength, "Invalid string length") \
T(InvalidTimeValue, "Invalid time value") \ T(InvalidTimeValue, "Invalid time value") \
T(InvalidTypedArrayAlignment, "% of % should be a multiple of %") \
T(InvalidTypedArrayLength, "Invalid typed array length") \
T(InvalidTypedArrayOffset, "Start offset is too large:") \
T(LocaleMatcher, "Illegal value for localeMatcher:%") \ T(LocaleMatcher, "Illegal value for localeMatcher:%") \
T(NormalizationForm, "The normalization form should be one of %.") \ T(NormalizationForm, "The normalization form should be one of %.") \
T(NumberFormatRange, "% argument must be between 0 and 20") \ T(NumberFormatRange, "% argument must be between 0 and 20") \
...@@ -223,6 +243,8 @@ class CallSite { ...@@ -223,6 +243,8 @@ class CallSite {
T(StackOverflow, "Maximum call stack size exceeded") \ T(StackOverflow, "Maximum call stack size exceeded") \
T(ToPrecisionFormatRange, "toPrecision() argument must be between 1 and 21") \ T(ToPrecisionFormatRange, "toPrecision() argument must be between 1 and 21") \
T(ToRadixFormatRange, "toString() radix argument must be between 2 and 36") \ T(ToRadixFormatRange, "toString() radix argument must be between 2 and 36") \
T(TypedArraySetNegativeOffset, "Start offset is negative") \
T(TypedArraySetSourceTooLarge, "Source is too large") \
T(UnsupportedTimeZone, "Unsupported time zone specified %") \ T(UnsupportedTimeZone, "Unsupported time zone specified %") \
T(ValueOutOfRange, "Value % out of range for % options property %") \ T(ValueOutOfRange, "Value % out of range for % options property %") \
/* SyntaxError */ \ /* SyntaxError */ \
......
...@@ -85,34 +85,10 @@ var kMessages = { ...@@ -85,34 +85,10 @@ var kMessages = {
value_and_accessor: ["Invalid property. A property cannot both have accessors and be writable or have a value, ", "%0"], value_and_accessor: ["Invalid property. A property cannot both have accessors and be writable or have a value, ", "%0"],
proto_object_or_null: ["Object prototype may only be an Object or null: ", "%0"], proto_object_or_null: ["Object prototype may only be an Object or null: ", "%0"],
non_extensible_proto: ["%0", " is not extensible"], non_extensible_proto: ["%0", " is not extensible"],
handler_non_object: ["Proxy.", "%0", " called with non-object as handler"],
proto_non_object: ["Proxy.", "%0", " called with non-object as prototype"],
trap_function_expected: ["Proxy.", "%0", " called with non-function for '", "%1", "' trap"],
proxy_repeated_prop_name: ["Trap '", "%1", "' returned repeated property name '", "%2", "'"],
invalid_weakmap_key: ["Invalid value used as weak map key"], invalid_weakmap_key: ["Invalid value used as weak map key"],
invalid_weakset_value: ["Invalid value used in weak set"], invalid_weakset_value: ["Invalid value used in weak set"],
not_date_object: ["this is not a Date object."], not_date_object: ["this is not a Date object."],
invalid_argument: ["invalid_argument"],
data_view_not_array_buffer: ["First argument to DataView constructor must be an ArrayBuffer"],
not_a_symbol: ["%0", " is not a symbol"], not_a_symbol: ["%0", " is not a symbol"],
not_a_promise: ["%0", " is not a promise"],
resolver_not_a_function: ["Promise resolver ", "%0", " is not a function"],
promise_cyclic: ["Chaining cycle detected for promise ", "%0"],
// RangeError
invalid_array_length: ["Invalid array length"],
invalid_array_buffer_length: ["Invalid array buffer length"],
invalid_string_length: ["Invalid string length"],
invalid_typed_array_offset: ["Start offset is too large:"],
invalid_typed_array_length: ["Invalid typed array length"],
invalid_typed_array_alignment: ["%0", " of ", "%1", " should be a multiple of ", "%2"],
typed_array_set_source_too_large:
["Source is too large"],
typed_array_set_negative_offset:
["Start offset is negative"],
invalid_data_view_offset: ["Start offset is outside the bounds of the buffer"],
invalid_data_view_length: ["Invalid data view length"],
invalid_data_view_accessor_offset:
["Offset is outside the bounds of the DataView"],
// ReferenceError // ReferenceError
invalid_lhs_in_assignment: ["Invalid left-hand side in assignment"], invalid_lhs_in_assignment: ["Invalid left-hand side in assignment"],
invalid_lhs_in_for: ["Invalid left-hand side in for-loop"], invalid_lhs_in_for: ["Invalid left-hand side in for-loop"],
......
...@@ -31,9 +31,9 @@ var lastMicrotaskId = 0; ...@@ -31,9 +31,9 @@ var lastMicrotaskId = 0;
var GlobalPromise = function Promise(resolver) { var GlobalPromise = function Promise(resolver) {
if (resolver === promiseRaw) return; if (resolver === promiseRaw) return;
if (!%_IsConstructCall()) throw MakeTypeError('not_a_promise', [this]); if (!%_IsConstructCall()) throw MakeTypeError(kNotAPromise, this);
if (!IS_SPEC_FUNCTION(resolver)) if (!IS_SPEC_FUNCTION(resolver))
throw MakeTypeError('resolver_not_a_function', [resolver]); throw MakeTypeError(kResolverNotAFunction, resolver);
var promise = PromiseInit(this); var promise = PromiseInit(this);
try { try {
%DebugPushPromise(promise, Promise); %DebugPushPromise(promise, Promise);
...@@ -106,7 +106,7 @@ function PromiseHandle(value, handler, deferred) { ...@@ -106,7 +106,7 @@ function PromiseHandle(value, handler, deferred) {
DEBUG_PREPARE_STEP_IN_IF_STEPPING(handler); DEBUG_PREPARE_STEP_IN_IF_STEPPING(handler);
var result = handler(value); var result = handler(value);
if (result === deferred.promise) if (result === deferred.promise)
throw MakeTypeError('promise_cyclic', [result]); throw MakeTypeError(kPromiseCyclic, result);
else if (IsPromise(result)) else if (IsPromise(result))
%_CallFunction(result, deferred.resolve, deferred.reject, PromiseChain); %_CallFunction(result, deferred.resolve, deferred.reject, PromiseChain);
else else
...@@ -224,7 +224,7 @@ function PromiseChain(onResolve, onReject) { // a.k.a. flatMap ...@@ -224,7 +224,7 @@ function PromiseChain(onResolve, onReject) { // a.k.a. flatMap
var deferred = %_CallFunction(this.constructor, PromiseDeferred); var deferred = %_CallFunction(this.constructor, PromiseDeferred);
switch (GET_PRIVATE(this, promiseStatus)) { switch (GET_PRIVATE(this, promiseStatus)) {
case UNDEFINED: case UNDEFINED:
throw MakeTypeError('not_a_promise', [this]); throw MakeTypeError(kNotAPromise, this);
case 0: // Pending case 0: // Pending
GET_PRIVATE(this, promiseOnResolve).push(onResolve, deferred); GET_PRIVATE(this, promiseOnResolve).push(onResolve, deferred);
GET_PRIVATE(this, promiseOnReject).push(onReject, deferred); GET_PRIVATE(this, promiseOnReject).push(onReject, deferred);
...@@ -272,7 +272,7 @@ function PromiseThen(onResolve, onReject) { ...@@ -272,7 +272,7 @@ function PromiseThen(onResolve, onReject) {
x = PromiseCoerce(constructor, x); x = PromiseCoerce(constructor, x);
if (x === that) { if (x === that) {
DEBUG_PREPARE_STEP_IN_IF_STEPPING(onReject); DEBUG_PREPARE_STEP_IN_IF_STEPPING(onReject);
return onReject(MakeTypeError('promise_cyclic', [x])); return onReject(MakeTypeError(kPromiseCyclic, x));
} else if (IsPromise(x)) { } else if (IsPromise(x)) {
return x.then(onResolve, onReject); return x.then(onResolve, onReject);
} else { } else {
......
...@@ -23,19 +23,19 @@ var GlobalObject = global.Object; ...@@ -23,19 +23,19 @@ var GlobalObject = global.Object;
function ProxyCreate(handler, proto) { function ProxyCreate(handler, proto) {
if (!IS_SPEC_OBJECT(handler)) if (!IS_SPEC_OBJECT(handler))
throw MakeTypeError("handler_non_object", ["create"]) throw MakeTypeError(kProxyHandlerNonObject, "create")
if (IS_UNDEFINED(proto)) if (IS_UNDEFINED(proto))
proto = null proto = null
else if (!(IS_SPEC_OBJECT(proto) || IS_NULL(proto))) else if (!(IS_SPEC_OBJECT(proto) || IS_NULL(proto)))
throw MakeTypeError("proto_non_object", ["create"]) throw MakeTypeError(kProxyProtoNonObject)
return %CreateJSProxy(handler, proto) return %CreateJSProxy(handler, proto)
} }
function ProxyCreateFunction(handler, callTrap, constructTrap) { function ProxyCreateFunction(handler, callTrap, constructTrap) {
if (!IS_SPEC_OBJECT(handler)) if (!IS_SPEC_OBJECT(handler))
throw MakeTypeError("handler_non_object", ["create"]) throw MakeTypeError(kProxyHandlerNonObject, "createFunction")
if (!IS_SPEC_FUNCTION(callTrap)) if (!IS_SPEC_FUNCTION(callTrap))
throw MakeTypeError("trap_function_expected", ["createFunction", "call"]) throw MakeTypeError(kProxyTrapFunctionExpected, "call")
if (IS_UNDEFINED(constructTrap)) { if (IS_UNDEFINED(constructTrap)) {
constructTrap = DerivedConstructTrap(callTrap) constructTrap = DerivedConstructTrap(callTrap)
} else if (IS_SPEC_FUNCTION(constructTrap)) { } else if (IS_SPEC_FUNCTION(constructTrap)) {
...@@ -45,8 +45,7 @@ function ProxyCreateFunction(handler, callTrap, constructTrap) { ...@@ -45,8 +45,7 @@ function ProxyCreateFunction(handler, callTrap, constructTrap) {
return %Apply(construct, UNDEFINED, arguments, 0, %_ArgumentsLength()); return %Apply(construct, UNDEFINED, arguments, 0, %_ArgumentsLength());
} }
} else { } else {
throw MakeTypeError("trap_function_expected", throw MakeTypeError(kProxyTrapFunctionExpected, "construct")
["createFunction", "construct"])
} }
return %CreateJSFunctionProxy( return %CreateJSFunctionProxy(
handler, callTrap, constructTrap, GlobalFunction.prototype) handler, callTrap, constructTrap, GlobalFunction.prototype)
......
...@@ -876,9 +876,9 @@ function DefaultString(x) { ...@@ -876,9 +876,9 @@ function DefaultString(x) {
throw %MakeTypeError(kCannotConvertToPrimitive); throw %MakeTypeError(kCannotConvertToPrimitive);
} }
function ToPositiveInteger(x, rangeErrorName) { function ToPositiveInteger(x, rangeErrorIndex) {
var i = TO_INTEGER_MAP_MINUS_ZERO(x); var i = TO_INTEGER_MAP_MINUS_ZERO(x);
if (i < 0) throw MakeRangeError(rangeErrorName); if (i < 0) throw MakeRangeError(rangeErrorIndex);
return i; return i;
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "src/v8.h" #include "src/v8.h"
#include "src/arguments.h" #include "src/arguments.h"
#include "src/messages.h"
#include "src/runtime/runtime-utils.h" #include "src/runtime/runtime-utils.h"
namespace v8 { namespace v8 {
...@@ -906,8 +907,7 @@ RUNTIME_FUNCTION(Runtime_ArrayConcat) { ...@@ -906,8 +907,7 @@ RUNTIME_FUNCTION(Runtime_ArrayConcat) {
if (visitor.exceeds_array_limit()) { if (visitor.exceeds_array_limit()) {
THROW_NEW_ERROR_RETURN_FAILURE( THROW_NEW_ERROR_RETURN_FAILURE(
isolate, isolate, NewRangeError(MessageTemplate::kInvalidArrayLength));
NewRangeError("invalid_array_length", HandleVector<Object>(NULL, 0)));
} }
return *visitor.ToArray(); return *visitor.ToArray();
} }
......
...@@ -80,14 +80,12 @@ RUNTIME_FUNCTION(Runtime_ArrayBufferInitialize) { ...@@ -80,14 +80,12 @@ RUNTIME_FUNCTION(Runtime_ArrayBufferInitialize) {
size_t allocated_length = 0; size_t allocated_length = 0;
if (!TryNumberToSize(isolate, *byteLength, &allocated_length)) { if (!TryNumberToSize(isolate, *byteLength, &allocated_length)) {
THROW_NEW_ERROR_RETURN_FAILURE( THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewRangeError("invalid_array_buffer_length", isolate, NewRangeError(MessageTemplate::kInvalidArrayBufferLength));
HandleVector<Object>(NULL, 0)));
} }
if (!Runtime::SetupArrayBufferAllocatingData(isolate, holder, if (!Runtime::SetupArrayBufferAllocatingData(isolate, holder,
allocated_length)) { allocated_length)) {
THROW_NEW_ERROR_RETURN_FAILURE( THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewRangeError("invalid_array_buffer_length", isolate, NewRangeError(MessageTemplate::kInvalidArrayBufferLength));
HandleVector<Object>(NULL, 0)));
} }
return *holder; return *holder;
} }
...@@ -214,8 +212,7 @@ RUNTIME_FUNCTION(Runtime_TypedArrayInitialize) { ...@@ -214,8 +212,7 @@ RUNTIME_FUNCTION(Runtime_TypedArrayInitialize) {
if (length > static_cast<unsigned>(Smi::kMaxValue)) { if (length > static_cast<unsigned>(Smi::kMaxValue)) {
THROW_NEW_ERROR_RETURN_FAILURE( THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewRangeError("invalid_typed_array_length", isolate, NewRangeError(MessageTemplate::kInvalidTypedArrayLength));
HandleVector<Object>(NULL, 0)));
} }
// All checks are done, now we can modify objects. // All checks are done, now we can modify objects.
...@@ -291,8 +288,7 @@ RUNTIME_FUNCTION(Runtime_TypedArrayInitializeFromArrayLike) { ...@@ -291,8 +288,7 @@ RUNTIME_FUNCTION(Runtime_TypedArrayInitializeFromArrayLike) {
if ((length > static_cast<unsigned>(Smi::kMaxValue)) || if ((length > static_cast<unsigned>(Smi::kMaxValue)) ||
(length > (kMaxInt / element_size))) { (length > (kMaxInt / element_size))) {
THROW_NEW_ERROR_RETURN_FAILURE( THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewRangeError("invalid_typed_array_length", isolate, NewRangeError(MessageTemplate::kInvalidTypedArrayLength));
HandleVector<Object>(NULL, 0)));
} }
size_t byte_length = length * element_size; size_t byte_length = length * element_size;
...@@ -321,8 +317,7 @@ RUNTIME_FUNCTION(Runtime_TypedArrayInitializeFromArrayLike) { ...@@ -321,8 +317,7 @@ RUNTIME_FUNCTION(Runtime_TypedArrayInitializeFromArrayLike) {
if (!Runtime::SetupArrayBufferAllocatingData(isolate, buffer, byte_length, if (!Runtime::SetupArrayBufferAllocatingData(isolate, buffer, byte_length,
false)) { false)) {
THROW_NEW_ERROR_RETURN_FAILURE( THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewRangeError("invalid_array_buffer_length", isolate, NewRangeError(MessageTemplate::kInvalidArrayBufferLength));
HandleVector<Object>(NULL, 0)));
} }
holder->set_buffer(*buffer); holder->set_buffer(*buffer);
...@@ -421,8 +416,7 @@ RUNTIME_FUNCTION(Runtime_TypedArraySetFastCases) { ...@@ -421,8 +416,7 @@ RUNTIME_FUNCTION(Runtime_TypedArraySetFastCases) {
if (offset > target_length || offset + source_length > target_length || if (offset > target_length || offset + source_length > target_length ||
offset + source_length < offset) { // overflow offset + source_length < offset) { // overflow
THROW_NEW_ERROR_RETURN_FAILURE( THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewRangeError("typed_array_set_source_too_large", isolate, NewRangeError(MessageTemplate::kTypedArraySetSourceTooLarge));
HandleVector<Object>(NULL, 0)));
} }
size_t target_offset = NumberToSize(isolate, target->byte_offset()); size_t target_offset = NumberToSize(isolate, target->byte_offset());
...@@ -627,8 +621,8 @@ static bool DataViewSetValue(Isolate* isolate, Handle<JSDataView> data_view, ...@@ -627,8 +621,8 @@ static bool DataViewSetValue(Isolate* isolate, Handle<JSDataView> data_view,
return *isolate->factory()->Converter(result); \ return *isolate->factory()->Converter(result); \
} else { \ } else { \
THROW_NEW_ERROR_RETURN_FAILURE( \ THROW_NEW_ERROR_RETURN_FAILURE( \
isolate, NewRangeError("invalid_data_view_accessor_offset", \ isolate, \
HandleVector<Object>(NULL, 0))); \ NewRangeError(MessageTemplate::kInvalidDataViewAccessorOffset)); \
} \ } \
} }
...@@ -709,8 +703,8 @@ double DataViewConvertValue<double>(double value) { ...@@ -709,8 +703,8 @@ double DataViewConvertValue<double>(double value) {
return isolate->heap()->undefined_value(); \ return isolate->heap()->undefined_value(); \
} else { \ } else { \
THROW_NEW_ERROR_RETURN_FAILURE( \ THROW_NEW_ERROR_RETURN_FAILURE( \
isolate, NewRangeError("invalid_data_view_accessor_offset", \ isolate, \
HandleVector<Object>(NULL, 0))); \ NewRangeError(MessageTemplate::kInvalidDataViewAccessorOffset)); \
} \ } \
} }
......
...@@ -38,10 +38,10 @@ macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE) ...@@ -38,10 +38,10 @@ macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE)
function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) { function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) {
if (!IS_UNDEFINED(byteOffset)) { if (!IS_UNDEFINED(byteOffset)) {
byteOffset = byteOffset =
ToPositiveInteger(byteOffset, "invalid_typed_array_length"); ToPositiveInteger(byteOffset, kInvalidTypedArrayLength);
} }
if (!IS_UNDEFINED(length)) { if (!IS_UNDEFINED(length)) {
length = ToPositiveInteger(length, "invalid_typed_array_length"); length = ToPositiveInteger(length, kInvalidTypedArrayLength);
} }
var bufferByteLength = %_ArrayBufferGetByteLength(buffer); var bufferByteLength = %_ArrayBufferGetByteLength(buffer);
...@@ -52,11 +52,11 @@ function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) { ...@@ -52,11 +52,11 @@ function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) {
offset = byteOffset; offset = byteOffset;
if (offset % ELEMENT_SIZE !== 0) { if (offset % ELEMENT_SIZE !== 0) {
throw MakeRangeError("invalid_typed_array_alignment", throw MakeRangeError(kInvalidTypedArrayAlignment,
["start offset", "NAME", ELEMENT_SIZE]); "start offset", "NAME", ELEMENT_SIZE);
} }
if (offset > bufferByteLength) { if (offset > bufferByteLength) {
throw MakeRangeError("invalid_typed_array_offset"); throw MakeRangeError(kInvalidTypedArrayOffset);
} }
} }
...@@ -64,8 +64,8 @@ function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) { ...@@ -64,8 +64,8 @@ function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) {
var newLength; var newLength;
if (IS_UNDEFINED(length)) { if (IS_UNDEFINED(length)) {
if (bufferByteLength % ELEMENT_SIZE !== 0) { if (bufferByteLength % ELEMENT_SIZE !== 0) {
throw MakeRangeError("invalid_typed_array_alignment", throw MakeRangeError(kInvalidTypedArrayAlignment,
["byte length", "NAME", ELEMENT_SIZE]); "byte length", "NAME", ELEMENT_SIZE);
} }
newByteLength = bufferByteLength - offset; newByteLength = bufferByteLength - offset;
newLength = newByteLength / ELEMENT_SIZE; newLength = newByteLength / ELEMENT_SIZE;
...@@ -75,16 +75,16 @@ function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) { ...@@ -75,16 +75,16 @@ function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) {
} }
if ((offset + newByteLength > bufferByteLength) if ((offset + newByteLength > bufferByteLength)
|| (newLength > %_MaxSmi())) { || (newLength > %_MaxSmi())) {
throw MakeRangeError("invalid_typed_array_length"); throw MakeRangeError(kInvalidTypedArrayLength);
} }
%_TypedArrayInitialize(obj, ARRAY_ID, buffer, offset, newByteLength); %_TypedArrayInitialize(obj, ARRAY_ID, buffer, offset, newByteLength);
} }
function NAMEConstructByLength(obj, length) { function NAMEConstructByLength(obj, length) {
var l = IS_UNDEFINED(length) ? var l = IS_UNDEFINED(length) ?
0 : ToPositiveInteger(length, "invalid_typed_array_length"); 0 : ToPositiveInteger(length, kInvalidTypedArrayLength);
if (l > %_MaxSmi()) { if (l > %_MaxSmi()) {
throw MakeRangeError("invalid_typed_array_length"); throw MakeRangeError(kInvalidTypedArrayLength);
} }
var byteLength = l * ELEMENT_SIZE; var byteLength = l * ELEMENT_SIZE;
if (byteLength > %_TypedArrayMaxSizeInHeap()) { if (byteLength > %_TypedArrayMaxSizeInHeap()) {
...@@ -97,10 +97,10 @@ function NAMEConstructByLength(obj, length) { ...@@ -97,10 +97,10 @@ function NAMEConstructByLength(obj, length) {
function NAMEConstructByArrayLike(obj, arrayLike) { function NAMEConstructByArrayLike(obj, arrayLike) {
var length = arrayLike.length; var length = arrayLike.length;
var l = ToPositiveInteger(length, "invalid_typed_array_length"); var l = ToPositiveInteger(length, kInvalidTypedArrayLength);
if (l > %_MaxSmi()) { if (l > %_MaxSmi()) {
throw MakeRangeError("invalid_typed_array_length"); throw MakeRangeError(kInvalidTypedArrayLength);
} }
if(!%TypedArrayInitializeFromArrayLike(obj, ARRAY_ID, arrayLike, l)) { if(!%TypedArrayInitializeFromArrayLike(obj, ARRAY_ID, arrayLike, l)) {
for (var i = 0; i < l; i++) { for (var i = 0; i < l; i++) {
...@@ -257,12 +257,10 @@ function TypedArraySetFromOverlappingTypedArray(target, source, offset) { ...@@ -257,12 +257,10 @@ function TypedArraySetFromOverlappingTypedArray(target, source, offset) {
function TypedArraySet(obj, offset) { function TypedArraySet(obj, offset) {
var intOffset = IS_UNDEFINED(offset) ? 0 : TO_INTEGER(offset); var intOffset = IS_UNDEFINED(offset) ? 0 : TO_INTEGER(offset);
if (intOffset < 0) { if (intOffset < 0) throw MakeTypeError(kTypedArraySetNegativeOffset);
throw MakeTypeError("typed_array_set_negative_offset");
}
if (intOffset > %_MaxSmi()) { if (intOffset > %_MaxSmi()) {
throw MakeRangeError("typed_array_set_source_too_large"); throw MakeRangeError(kTypedArraySetSourceTooLarge);
} }
switch (%TypedArraySetFastCases(this, obj, intOffset)) { switch (%TypedArraySetFastCases(this, obj, intOffset)) {
// These numbers should be synchronized with runtime.cc. // These numbers should be synchronized with runtime.cc.
...@@ -282,12 +280,12 @@ function TypedArraySet(obj, offset) { ...@@ -282,12 +280,12 @@ function TypedArraySet(obj, offset) {
// instead of silently ignoring the call, so that // instead of silently ignoring the call, so that
// the user knows (s)he did something wrong. // the user knows (s)he did something wrong.
// (Consistent with Firefox and Blink/WebKit) // (Consistent with Firefox and Blink/WebKit)
throw MakeTypeError("invalid_argument"); throw MakeTypeError(kInvalidArgument);
} }
return; return;
} }
if (intOffset + l > this.length) { if (intOffset + l > this.length) {
throw MakeRangeError("typed_array_set_source_too_large"); throw MakeRangeError(kTypedArraySetSourceTooLarge);
} }
TypedArraySetFromArrayLike(this, obj, l, intOffset); TypedArraySetFromArrayLike(this, obj, l, intOffset);
return; return;
...@@ -335,11 +333,9 @@ TYPED_ARRAYS(SETUP_TYPED_ARRAY) ...@@ -335,11 +333,9 @@ TYPED_ARRAYS(SETUP_TYPED_ARRAY)
function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3 function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3
if (%_IsConstructCall()) { if (%_IsConstructCall()) {
if (!IS_ARRAYBUFFER(buffer)) { if (!IS_ARRAYBUFFER(buffer)) throw MakeTypeError(kDataViewNotArrayBuffer);
throw MakeTypeError('data_view_not_array_buffer', []);
}
if (!IS_UNDEFINED(byteOffset)) { if (!IS_UNDEFINED(byteOffset)) {
byteOffset = ToPositiveInteger(byteOffset, 'invalid_data_view_offset'); byteOffset = ToPositiveInteger(byteOffset, kInvalidDataViewOffset);
} }
if (!IS_UNDEFINED(byteLength)) { if (!IS_UNDEFINED(byteLength)) {
byteLength = TO_INTEGER(byteLength); byteLength = TO_INTEGER(byteLength);
...@@ -348,15 +344,13 @@ function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3 ...@@ -348,15 +344,13 @@ function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3
var bufferByteLength = %_ArrayBufferGetByteLength(buffer); var bufferByteLength = %_ArrayBufferGetByteLength(buffer);
var offset = IS_UNDEFINED(byteOffset) ? 0 : byteOffset; var offset = IS_UNDEFINED(byteOffset) ? 0 : byteOffset;
if (offset > bufferByteLength) { if (offset > bufferByteLength) throw MakeRangeError(kInvalidDataViewOffset);
throw MakeRangeError('invalid_data_view_offset');
}
var length = IS_UNDEFINED(byteLength) var length = IS_UNDEFINED(byteLength)
? bufferByteLength - offset ? bufferByteLength - offset
: byteLength; : byteLength;
if (length < 0 || offset + length > bufferByteLength) { if (length < 0 || offset + length > bufferByteLength) {
throw new MakeRangeError('invalid_data_view_length'); throw new MakeRangeError(kInvalidDataViewLength);
} }
%_DataViewInitialize(this, buffer, offset, length); %_DataViewInitialize(this, buffer, offset, length);
} else { } else {
...@@ -399,7 +393,7 @@ macro DATA_VIEW_TYPES(FUNCTION) ...@@ -399,7 +393,7 @@ macro DATA_VIEW_TYPES(FUNCTION)
endmacro endmacro
function ToPositiveDataViewOffset(offset) { function ToPositiveDataViewOffset(offset) {
return ToPositiveInteger(offset, 'invalid_data_view_accessor_offset'); return ToPositiveInteger(offset, kInvalidDataViewAccessorOffset);
} }
...@@ -409,9 +403,7 @@ function DataViewGetTYPENAMEJS(offset, little_endian) { ...@@ -409,9 +403,7 @@ function DataViewGetTYPENAMEJS(offset, little_endian) {
throw MakeTypeError(kIncompatibleMethodReceiver, throw MakeTypeError(kIncompatibleMethodReceiver,
'DataView.getTYPENAME', this); 'DataView.getTYPENAME', this);
} }
if (%_ArgumentsLength() < 1) { if (%_ArgumentsLength() < 1) throw MakeTypeError(kInvalidArgument);
throw MakeTypeError('invalid_argument');
}
return %DataViewGetTYPENAME(this, return %DataViewGetTYPENAME(this,
ToPositiveDataViewOffset(offset), ToPositiveDataViewOffset(offset),
!!little_endian); !!little_endian);
...@@ -422,9 +414,7 @@ function DataViewSetTYPENAMEJS(offset, value, little_endian) { ...@@ -422,9 +414,7 @@ function DataViewSetTYPENAMEJS(offset, value, little_endian) {
throw MakeTypeError(kIncompatibleMethodReceiver, throw MakeTypeError(kIncompatibleMethodReceiver,
'DataView.setTYPENAME', this); 'DataView.setTYPENAME', this);
} }
if (%_ArgumentsLength() < 2) { if (%_ArgumentsLength() < 2) throw MakeTypeError(kInvalidArgument);
throw MakeTypeError('invalid_argument');
}
%DataViewSetTYPENAME(this, %DataViewSetTYPENAME(this,
ToPositiveDataViewOffset(offset), ToPositiveDataViewOffset(offset),
TO_NUMBER_INLINE(value), TO_NUMBER_INLINE(value),
......
...@@ -72,6 +72,11 @@ test(function() { ...@@ -72,6 +72,11 @@ test(function() {
Uint16Array(1); Uint16Array(1);
}, "Constructor Uint16Array requires 'new'", TypeError); }, "Constructor Uint16Array requires 'new'", TypeError);
// kDataViewNotArrayBuffer
test(function() {
new DataView(1);
}, "First argument to DataView constructor must be an ArrayBuffer", TypeError);
// kDateType // kDateType
test(function() { test(function() {
Date.prototype.setYear.call({}, 1); Date.prototype.setYear.call({}, 1);
...@@ -145,6 +150,11 @@ test(function() { ...@@ -145,6 +150,11 @@ test(function() {
new Map([1]); new Map([1]);
}, "Iterator value 1 is not an entry object", TypeError); }, "Iterator value 1 is not an entry object", TypeError);
// kNotAPromise
test(function() {
Promise.prototype.chain.call(1);
}, "1 is not a promise", TypeError);
// kNotConstructor // kNotConstructor
test(function() { test(function() {
new Symbol(); new Symbol();
...@@ -233,6 +243,11 @@ test(function() { ...@@ -233,6 +243,11 @@ test(function() {
[].reduce(function() {}); [].reduce(function() {});
}, "Reduce of empty array with no initial value", TypeError); }, "Reduce of empty array with no initial value", TypeError);
// kResolverNotAFunction
test(function() {
new Promise(1);
}, "Promise resolver 1 is not a function", TypeError);
// kSymbolToPrimitive // kSymbolToPrimitive
test(function() { test(function() {
1 + Object(Symbol()); 1 + Object(Symbol());
...@@ -293,6 +308,16 @@ test(function() { ...@@ -293,6 +308,16 @@ test(function() {
Object.defineProperty([], "length", { value: 1E100 }); Object.defineProperty([], "length", { value: 1E100 });
}, "defineProperty() array length out of range", RangeError); }, "defineProperty() array length out of range", RangeError);
// kInvalidArrayBufferLength
test(function() {
new ArrayBuffer(-1);
}, "Invalid array buffer length", RangeError);
// kInvalidArrayLength
test(function() {
[].length = -1;
}, "Invalid array length", RangeError);
// kInvalidCodePoint // kInvalidCodePoint
test(function() { test(function() {
String.fromCodePoint(-1); String.fromCodePoint(-1);
...@@ -303,6 +328,11 @@ test(function() { ...@@ -303,6 +328,11 @@ test(function() {
"a".repeat(-1); "a".repeat(-1);
}, "Invalid count value", RangeError); }, "Invalid count value", RangeError);
// kInvalidArrayBufferLength
test(function() {
new Uint16Array(-1);
}, "Invalid typed array length", RangeError);
// kNormalizationForm // kNormalizationForm
test(function() { test(function() {
"".normalize("ABC"); "".normalize("ABC");
......
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