var byteLength = ToPositiveInteger(length, 'invalid_array_buffer_length');
%ArrayBufferInitialize(this, byteLength);
} else {
- throw MakeTypeError('constructor_not_function', ["ArrayBuffer"]);
+ throw MakeTypeError(kConstructorNotFunction, "ArrayBuffer");
}
}
function SetConstructor(iterable) {
if (!%_IsConstructCall()) {
- throw MakeTypeError('constructor_not_function', ['Set']);
+ throw MakeTypeError(kConstructorNotFunction, "Set");
}
%_SetInitialize(this);
function MapConstructor(iterable) {
if (!%_IsConstructCall()) {
- throw MakeTypeError('constructor_not_function', ['Map']);
+ throw MakeTypeError(kConstructorNotFunction, "Map");
}
%_MapInitialize(this);
for (var nextItem of iterable) {
if (!IS_SPEC_OBJECT(nextItem)) {
- throw MakeTypeError('iterator_value_not_an_object', [nextItem]);
+ throw MakeTypeError(kIteratorValueNotAnObject, nextItem);
}
%_CallFunction(this, nextItem[0], nextItem[1], adder);
}
var next = iterator.next();
if (!IS_OBJECT(next)) {
- throw MakeTypeError("iterator_result_not_an_object", [next]);
+ throw MakeTypeError(kIteratorResultNotAnObject, next);
}
if (next.done) {
// + https://bugs.ecmascript.org/show_bug.cgi?id=3423
function RegExpGetFlags() {
if (!IS_SPEC_OBJECT(this)) {
- throw MakeTypeError('flags_getter_non_object',
- [%ToString(this)]);
+ throw MakeTypeError(kFlagsGetterNonObject, %ToString(this));
}
var result = '';
if (this.global) result += 'g';
// ES6 draft 08-24-14, section 22.2.3.12
function NAMEForEach(f /* thisArg */) { // length == 1
- if (!%IsTypedArray(this)) {
- throw MakeTypeError('not_typed_array', []);
- }
+ if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray);
if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f);
var length = %_TypedArrayGetLength(this);
T(CalledNonCallable, "% is not a function") \
T(CalledOnNonObject, "% called on non-object") \
T(CalledOnNullOrUndefined, "% called on null or undefined") \
- T(CurrencyCode, "Currency code is required with currency style.") \
T(CannotConvertToPrimitive, "Cannot convert object to primitive value") \
+ T(ConstructorNotFunction, "Constructor % requires 'new'") \
+ T(CurrencyCode, "Currency code is required with currency style.") \
T(DateType, "this is not a Date object.") \
T(DefineDisallowed, "Cannot define property:%, object is not extensible.") \
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(IncompatibleMethodReceiver, "Method % called on incompatible receiver %") \
T(InstanceofNonobjectProto, \
"Function has non-object prototype '%' in instanceof check") \
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") \
T(LanguageID, "Language ID should be string or object.") \
T(MethodCalledOnWrongObject, \
"Method % called on a non-object or on a wrong type of object.") \
T(NotConstructor, "% is not a constructor") \
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(ObjectSetterExpectingFunction, \
"Object.prototype.__defineSetter__: Expecting function") \
T(ObjectSetterCallable, "Setter must be a function: %") \
+ T(ObserveCallbackFrozen, \
+ "Object.observe cannot deliver to a frozen function object") \
+ T(ObserveGlobalProxy, "% cannot be called on the global proxy object") \
+ T(ObserveInvalidAccept, \
+ "Third argument to Object.observe must be an array of strings.") \
+ T(ObserveNonFunction, "Object.% cannot deliver to non-function") \
+ T(ObserveNonObject, "Object.% cannot % non-object") \
+ T(ObserveNotifyNonNotifier, "notify called on non-notifier object") \
+ T(ObservePerformNonFunction, "Cannot perform non-function") \
+ T(ObservePerformNonString, "Invalid non-string changeType") \
+ T(ObserveTypeNonString, \
+ "Invalid changeRecord with non-string 'type' property") \
T(OrdinaryFunctionCalledAsConstructor, \
"Function object that's not a constructor was created with new") \
T(PropertyDescObject, "Property description must be an object: %") \
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"],
- flags_getter_non_object: ["RegExp.prototype.flags getter called on non-object ", "%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"],
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."],
- observe_non_object: ["Object.", "%0", " cannot ", "%0", " non-object"],
- observe_non_function: ["Object.", "%0", " cannot deliver to non-function"],
- observe_callback_frozen: ["Object.observe cannot deliver to a frozen function object"],
- observe_invalid_accept: ["Third argument to Object.observe must be an array of strings."],
- observe_type_non_string: ["Invalid changeRecord with non-string 'type' property"],
- observe_perform_non_string: ["Invalid non-string changeType"],
- observe_perform_non_function: ["Cannot perform non-function"],
- observe_notify_non_notifier: ["notify called on non-notifier object"],
- observe_global_proxy: ["%0", " cannot be called on the global proxy object"],
- not_typed_array: ["this is not a typed array."],
invalid_argument: ["invalid_argument"],
data_view_not_array_buffer: ["First argument to DataView constructor must be an ArrayBuffer"],
- constructor_not_function: ["Constructor ", "%0", " requires 'new'"],
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"],
- iterator_result_not_an_object: ["Iterator result ", "%0", " is not an object"],
- iterator_value_not_an_object: ["Iterator value ", "%0", " is not an entry object"],
// RangeError
invalid_array_length: ["Invalid array length"],
invalid_array_buffer_length: ["Invalid array buffer length"],
if (IS_UNDEFINED(arg))
return arg;
- if (!IS_SPEC_OBJECT(arg))
- throw MakeTypeError("observe_invalid_accept");
+ if (!IS_SPEC_OBJECT(arg)) throw MakeTypeError(kObserveInvalidAccept);
var len = ToInteger(arg.length);
if (len < 0) len = 0;
function ObjectObserve(object, callback, acceptList) {
if (!IS_SPEC_OBJECT(object))
- throw MakeTypeError("observe_non_object", ["observe"]);
+ throw MakeTypeError(kObserveNonObject, "observe", "observe");
if (%IsJSGlobalProxy(object))
- throw MakeTypeError("observe_global_proxy", ["observe"]);
+ throw MakeTypeError(kObserveGlobalProxy, "observe");
if (!IS_SPEC_FUNCTION(callback))
- throw MakeTypeError("observe_non_function", ["observe"]);
+ throw MakeTypeError(kObserveNonFunction, "observe");
if (ObjectIsFrozen(callback))
- throw MakeTypeError("observe_callback_frozen");
+ throw MakeTypeError(kObserveCallbackFrozen);
var objectObserveFn = %GetObjectContextObjectObserve(object);
return objectObserveFn(object, callback, acceptList);
function ObjectUnobserve(object, callback) {
if (!IS_SPEC_OBJECT(object))
- throw MakeTypeError("observe_non_object", ["unobserve"]);
+ throw MakeTypeError(kObserveNonObject, "unobserve", "unobserve");
if (%IsJSGlobalProxy(object))
- throw MakeTypeError("observe_global_proxy", ["unobserve"]);
+ throw MakeTypeError(kObserveGlobalProxy, "unobserve");
if (!IS_SPEC_FUNCTION(callback))
- throw MakeTypeError("observe_non_function", ["unobserve"]);
+ throw MakeTypeError(kObserveNonFunction, "unobserve");
var objectInfo = ObjectInfoGet(object);
if (IS_UNDEFINED(objectInfo))
var objectInfo = ObjectInfoGetFromNotifier(this);
if (IS_UNDEFINED(objectInfo))
- throw MakeTypeError("observe_notify_non_notifier");
+ throw MakeTypeError(kObserveNotifyNonNotifier);
if (!IS_STRING(changeRecord.type))
- throw MakeTypeError("observe_type_non_string");
+ throw MakeTypeError(kObserveTypeNonString);
ObjectInfoEnqueueExternalChangeRecord(objectInfo, changeRecord);
}
var objectInfo = ObjectInfoGetFromNotifier(this);
if (IS_UNDEFINED(objectInfo))
- throw MakeTypeError("observe_notify_non_notifier");
+ throw MakeTypeError(kObserveNotifyNonNotifier);
if (!IS_STRING(changeType))
- throw MakeTypeError("observe_perform_non_string");
+ throw MakeTypeError(kObservePerformNonString);
if (!IS_SPEC_FUNCTION(changeFn))
- throw MakeTypeError("observe_perform_non_function");
+ throw MakeTypeError(kObservePerformNonFunction);
var performChangeFn = %GetObjectContextNotifierPerformChange(objectInfo);
performChangeFn(objectInfo, changeType, changeFn);
function ObjectGetNotifier(object) {
if (!IS_SPEC_OBJECT(object))
- throw MakeTypeError("observe_non_object", ["getNotifier"]);
+ throw MakeTypeError(kObserveNonObject, "getNotifier", "getNotifier");
if (%IsJSGlobalProxy(object))
- throw MakeTypeError("observe_global_proxy", ["getNotifier"]);
+ throw MakeTypeError(kObserveGlobalProxy, "getNotifier");
if (ObjectIsFrozen(object)) return null;
function ObjectDeliverChangeRecords(callback) {
if (!IS_SPEC_FUNCTION(callback))
- throw MakeTypeError("observe_non_function", ["deliverChangeRecords"]);
+ throw MakeTypeError(kObserveNonFunction, "deliverChangeRecords");
while (CallbackDeliverPending(callback)) {}
}
CONVERT_ARG_HANDLE_CHECKED(Object, value, 0);
THROW_NEW_ERROR_RETURN_FAILURE(
isolate,
- NewTypeError("iterator_result_not_an_object", HandleVector(&value, 1)));
+ NewTypeError(MessageTemplate::kIteratorResultNotAnObject, value));
}
#include "src/v8.h"
#include "src/arguments.h"
+#include "src/messages.h"
#include "src/runtime/runtime.h"
#include "src/runtime/runtime-utils.h"
DCHECK(args.length() == 3);
if (!args[0]->IsJSTypedArray()) {
THROW_NEW_ERROR_RETURN_FAILURE(
- isolate,
- NewTypeError("not_typed_array", HandleVector<Object>(NULL, 0)));
+ isolate, NewTypeError(MessageTemplate::kNotTypedArray));
}
if (!args[1]->IsJSTypedArray())
NAMEConstructByArrayLike(this, arg1);
}
} else {
- throw MakeTypeError("constructor_not_function", ["NAME"])
+ throw MakeTypeError(kConstructorNotFunction, "NAME")
}
}
function WeakMapConstructor(iterable) {
if (!%_IsConstructCall()) {
- throw MakeTypeError('constructor_not_function', ['WeakMap']);
+ throw MakeTypeError(kConstructorNotFunction, "WeakMap");
}
%WeakCollectionInitialize(this);
}
for (var nextItem of iterable) {
if (!IS_SPEC_OBJECT(nextItem)) {
- throw MakeTypeError('iterator_value_not_an_object', [nextItem]);
+ throw MakeTypeError(kIteratorValueNotAnObject, nextItem);
}
%_CallFunction(this, nextItem[0], nextItem[1], adder);
}
function WeakSetConstructor(iterable) {
if (!%_IsConstructCall()) {
- throw MakeTypeError('constructor_not_function', ['WeakSet']);
+ throw MakeTypeError(kConstructorNotFunction, "WeakSet");
}
%WeakCollectionInitialize(this);
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Flags: --stack-size=100 --harmony --harmony-reflect
+// Flags: --stack-size=100 --harmony --harmony-reflect --harmony-arrays
+// Flags: --harmony-regexps
function test(f, expected, type) {
try {
[].join(Object(Symbol(1)));
}, "Cannot convert object to primitive value", TypeError);
+// kConstructorNotFunction
+test(function() {
+ Uint16Array(1);
+}, "Constructor Uint16Array requires 'new'", TypeError);
+
// kDateType
test(function() {
Date.prototype.setYear.call({}, 1);
}, "First argument to String.prototype.startsWith " +
"must not be a regular expression", TypeError);
+// kFlagsGetterNonObject
+test(function() {
+ Object.getOwnPropertyDescriptor(RegExp.prototype, "flags").get.call(1);
+}, "RegExp.prototype.flags getter called on non-object 1", TypeError);
+
// kFunctionBind
test(function() {
Function.prototype.bind.call(1);
1 in 1;
}, "Cannot use 'in' operator to search for '1' in 1", TypeError);
+// kIteratorResultNotAnObject
+test(function() {
+ var obj = {};
+ obj[Symbol.iterator] = function() { return { next: function() { return 1 }}};
+ Array.from(obj);
+}, "Iterator result 1 is not an object", TypeError);
+
+// kIteratorValueNotAnObject
+test(function() {
+ new Map([1]);
+}, "Iterator value 1 is not an entry object", TypeError);
+
// kNotConstructor
test(function() {
new Symbol();
Function.prototype.toString.call(1);
}, "Function.prototype.toString is not generic", TypeError);
+// kNotTypedArray
+test(function() {
+ Uint16Array.prototype.forEach.call(1);
+}, "this is not a typed array.", TypeError);
+
// kObjectGetterExpectingFunction
test(function() {
({}).__defineGetter__("x", 0);