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