2015-04-17 08:35:59 +00:00
|
|
|
// Copyright 2015 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2015-04-17 13:27:41 +00:00
|
|
|
// Flags: --stack-size=100 --harmony --harmony-reflect
|
|
|
|
|
2015-04-17 08:35:59 +00:00
|
|
|
function test(f, expected, type) {
|
|
|
|
try {
|
|
|
|
f();
|
|
|
|
} catch (e) {
|
|
|
|
assertInstanceof(e, type);
|
|
|
|
assertEquals(expected, e.message);
|
2015-04-17 13:27:41 +00:00
|
|
|
return;
|
2015-04-17 08:35:59 +00:00
|
|
|
}
|
2015-04-21 09:03:24 +00:00
|
|
|
assertUnreachable("Exception expected");
|
2015-04-17 08:35:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// === Error ===
|
|
|
|
|
|
|
|
// kCyclicProto
|
|
|
|
test(function() {
|
|
|
|
var o = {};
|
|
|
|
o.__proto__ = o;
|
|
|
|
}, "Cyclic __proto__ value", Error);
|
|
|
|
|
|
|
|
|
|
|
|
// === TypeError ===
|
|
|
|
|
2015-04-17 13:27:41 +00:00
|
|
|
// kApplyNonFunction
|
|
|
|
test(function() {
|
|
|
|
Function.prototype.apply.call(1, []);
|
|
|
|
}, "Function.prototype.apply was called on 1, which is a number " +
|
|
|
|
"and not a function", TypeError);
|
|
|
|
|
2015-04-24 10:22:00 +00:00
|
|
|
// kArrayFunctionsOnFrozen
|
|
|
|
test(function() {
|
|
|
|
var a = [1, 2];
|
|
|
|
Object.freeze(a);
|
|
|
|
a.splice(1, 1, [1]);
|
|
|
|
}, "Cannot modify frozen array elements", TypeError);
|
|
|
|
|
|
|
|
// kArrayFunctionsOnSealed
|
|
|
|
test(function() {
|
|
|
|
var a = [1];
|
|
|
|
Object.seal(a);
|
|
|
|
a.shift();
|
|
|
|
}, "Cannot add/remove sealed array elements", TypeError);
|
|
|
|
|
2015-04-21 09:03:24 +00:00
|
|
|
// kCalledNonCallable
|
|
|
|
test(function() {
|
|
|
|
[].forEach(1);
|
|
|
|
}, "1 is not a function", TypeError);
|
|
|
|
|
2015-04-24 10:22:00 +00:00
|
|
|
// kCalledOnNonObject
|
|
|
|
test(function() {
|
|
|
|
Object.defineProperty(1, "x", {});
|
|
|
|
}, "Object.defineProperty called on non-object", TypeError);
|
|
|
|
|
|
|
|
// kCalledOnNullOrUndefined
|
|
|
|
test(function() {
|
|
|
|
Array.prototype.shift.call(null);
|
|
|
|
}, "Array.prototype.shift called on null or undefined", TypeError);
|
|
|
|
|
2015-04-17 13:27:41 +00:00
|
|
|
// kCannotConvertToPrimitive
|
|
|
|
test(function() {
|
|
|
|
[].join(Object(Symbol(1)));
|
|
|
|
}, "Cannot convert object to primitive value", TypeError);
|
|
|
|
|
2015-04-24 10:22:00 +00:00
|
|
|
// kDateType
|
|
|
|
test(function() {
|
|
|
|
Date.prototype.setYear.call({}, 1);
|
|
|
|
}, "this is not a Date object.", TypeError);
|
|
|
|
|
2015-04-21 09:03:24 +00:00
|
|
|
// kDefineDisallowed
|
|
|
|
test(function() {
|
|
|
|
"use strict";
|
|
|
|
var o = {};
|
|
|
|
Object.preventExtensions(o);
|
|
|
|
Object.defineProperty(o, "x", { value: 1 });
|
|
|
|
}, "Cannot define property:x, object is not extensible.", TypeError);
|
|
|
|
|
2015-04-17 08:35:59 +00:00
|
|
|
// kGeneratorRunning
|
|
|
|
test(function() {
|
|
|
|
var iter;
|
|
|
|
function* generator() { yield iter.next(); }
|
|
|
|
var iter = generator();
|
|
|
|
iter.next();
|
|
|
|
}, "Generator is already running", TypeError);
|
|
|
|
|
2015-04-21 09:03:24 +00:00
|
|
|
// kFunctionBind
|
2015-04-17 08:35:59 +00:00
|
|
|
test(function() {
|
2015-04-21 09:03:24 +00:00
|
|
|
Function.prototype.bind.call(1);
|
|
|
|
}, "Bind must be called on a function", TypeError);
|
2015-04-17 08:35:59 +00:00
|
|
|
|
|
|
|
// kIncompatibleMethodReceiver
|
|
|
|
test(function() {
|
|
|
|
RegExp.prototype.compile.call(RegExp.prototype);
|
|
|
|
}, "Method RegExp.prototype.compile called on incompatible receiver " +
|
|
|
|
"[object RegExp]", TypeError);
|
|
|
|
|
2015-04-17 13:27:41 +00:00
|
|
|
// kInstanceofFunctionExpected
|
|
|
|
test(function() {
|
|
|
|
1 instanceof 1;
|
|
|
|
}, "Expecting a function in instanceof check, but got 1", TypeError);
|
|
|
|
|
|
|
|
// kInstanceofNonobjectProto
|
|
|
|
test(function() {
|
|
|
|
function f() {}
|
|
|
|
var o = new f();
|
|
|
|
f.prototype = 1;
|
|
|
|
o instanceof f;
|
|
|
|
}, "Function has non-object prototype '1' in instanceof check", TypeError);
|
|
|
|
|
|
|
|
// kInvalidInOperatorUse
|
|
|
|
test(function() {
|
|
|
|
1 in 1;
|
|
|
|
}, "Cannot use 'in' operator to search for '1' in 1", TypeError);
|
|
|
|
|
|
|
|
// kNotConstructor
|
|
|
|
test(function() {
|
|
|
|
new Symbol();
|
|
|
|
}, "Symbol is not a constructor", TypeError);
|
|
|
|
|
2015-04-21 09:03:24 +00:00
|
|
|
// kNotGeneric
|
|
|
|
test(function() {
|
|
|
|
String.prototype.toString.call(1);
|
|
|
|
}, "String.prototype.toString is not generic", TypeError);
|
|
|
|
|
|
|
|
test(function() {
|
|
|
|
String.prototype.valueOf.call(1);
|
|
|
|
}, "String.prototype.valueOf is not generic", TypeError);
|
|
|
|
|
|
|
|
test(function() {
|
|
|
|
Boolean.prototype.toString.call(1);
|
|
|
|
}, "Boolean.prototype.toString is not generic", TypeError);
|
|
|
|
|
|
|
|
test(function() {
|
|
|
|
Boolean.prototype.valueOf.call(1);
|
|
|
|
}, "Boolean.prototype.valueOf is not generic", TypeError);
|
|
|
|
|
|
|
|
test(function() {
|
|
|
|
Number.prototype.toString.call({});
|
|
|
|
}, "Number.prototype.toString is not generic", TypeError);
|
|
|
|
|
|
|
|
test(function() {
|
|
|
|
Number.prototype.valueOf.call({});
|
|
|
|
}, "Number.prototype.valueOf is not generic", TypeError);
|
|
|
|
|
|
|
|
test(function() {
|
|
|
|
Function.prototype.toString.call(1);
|
|
|
|
}, "Function.prototype.toString is not generic", TypeError);
|
|
|
|
|
|
|
|
// kObjectGetterExpectingFunction
|
|
|
|
test(function() {
|
|
|
|
({}).__defineGetter__("x", 0);
|
|
|
|
}, "Object.prototype.__defineGetter__: Expecting function", TypeError);
|
|
|
|
|
|
|
|
// kObjectGetterCallable
|
|
|
|
test(function() {
|
|
|
|
Object.defineProperty({}, "x", { get: 1 });
|
|
|
|
}, "Getter must be a function: 1", TypeError);
|
|
|
|
|
|
|
|
// kObjectSetterExpectingFunction
|
|
|
|
test(function() {
|
|
|
|
({}).__defineSetter__("x", 0);
|
|
|
|
}, "Object.prototype.__defineSetter__: Expecting function", TypeError);
|
|
|
|
|
|
|
|
// kObjectSetterCallable
|
|
|
|
test(function() {
|
|
|
|
Object.defineProperty({}, "x", { set: 1 });
|
|
|
|
}, "Setter must be a function: 1", TypeError);
|
|
|
|
|
|
|
|
// kPropertyDescObject
|
|
|
|
test(function() {
|
|
|
|
Object.defineProperty({}, "x", 1);
|
|
|
|
}, "Property description must be an object: 1", TypeError);
|
|
|
|
|
2015-04-17 08:35:59 +00:00
|
|
|
// kPropertyNotFunction
|
|
|
|
test(function() {
|
|
|
|
Set.prototype.add = 0;
|
|
|
|
new Set(1);
|
|
|
|
}, "Property 'add' of object #<Set> is not a function", TypeError);
|
|
|
|
|
2015-04-21 09:03:24 +00:00
|
|
|
// kProtoObjectOrNull
|
|
|
|
test(function() {
|
|
|
|
Object.setPrototypeOf({}, 1);
|
|
|
|
}, "Object prototype may only be an Object or null: 1", TypeError);
|
|
|
|
|
|
|
|
// kRedefineDisallowed
|
|
|
|
test(function() {
|
|
|
|
"use strict";
|
|
|
|
var o = {};
|
|
|
|
Object.defineProperty(o, "x", { value: 1, configurable: false });
|
|
|
|
Object.defineProperty(o, "x", { value: 2 });
|
|
|
|
}, "Cannot redefine property: x", TypeError);
|
|
|
|
|
2015-04-24 10:22:00 +00:00
|
|
|
// kReduceNoInitial
|
|
|
|
test(function() {
|
|
|
|
[].reduce(function() {});
|
|
|
|
}, "Reduce of empty array with no initial value", TypeError);
|
|
|
|
|
2015-04-17 13:27:41 +00:00
|
|
|
// kSymbolToPrimitive
|
|
|
|
test(function() {
|
|
|
|
1 + Object(Symbol());
|
|
|
|
}, "Cannot convert a Symbol wrapper object to a primitive value", TypeError);
|
|
|
|
|
|
|
|
// kSymbolToString
|
|
|
|
test(function() {
|
|
|
|
"" + Symbol();
|
|
|
|
}, "Cannot convert a Symbol value to a string", TypeError);
|
|
|
|
|
|
|
|
// kSymbolToNumber
|
|
|
|
test(function() {
|
|
|
|
1 + Symbol();
|
|
|
|
}, "Cannot convert a Symbol value to a number", TypeError);
|
|
|
|
|
|
|
|
// kUndefinedOrNullToObject
|
|
|
|
test(function() {
|
|
|
|
Array.prototype.toString.call(null);
|
|
|
|
}, "Cannot convert undefined or null to object", TypeError);
|
|
|
|
|
2015-04-21 09:03:24 +00:00
|
|
|
// kValueAndAccessor
|
|
|
|
test(function() {
|
|
|
|
Object.defineProperty({}, "x", { get: function(){}, value: 1});
|
|
|
|
}, "Invalid property. A property cannot both have accessors and be " +
|
|
|
|
"writable or have a value, #<Object>", TypeError);
|
|
|
|
|
2015-04-17 08:35:59 +00:00
|
|
|
// kWithExpression
|
|
|
|
test(function() {
|
|
|
|
with (null) {}
|
|
|
|
}, "null has no properties", TypeError);
|
2015-04-17 13:27:41 +00:00
|
|
|
|
|
|
|
// kWrongArgs
|
|
|
|
test(function() {
|
|
|
|
(function() {}).apply({}, 1);
|
|
|
|
}, "Function.prototype.apply: Arguments list has wrong type", TypeError);
|
|
|
|
|
|
|
|
test(function() {
|
|
|
|
Reflect.apply(function() {}, {}, 1);
|
|
|
|
}, "Reflect.apply: Arguments list has wrong type", TypeError);
|
|
|
|
|
|
|
|
test(function() {
|
|
|
|
Reflect.construct(function() {}, 1);
|
|
|
|
}, "Reflect.construct: Arguments list has wrong type", TypeError);
|
|
|
|
|
|
|
|
|
2015-04-21 09:03:24 +00:00
|
|
|
//=== SyntaxError ===
|
|
|
|
|
|
|
|
test(function() {
|
|
|
|
new Function(")", "");
|
|
|
|
}, "Function arg string contains parenthesis", SyntaxError);
|
|
|
|
|
|
|
|
|
2015-04-17 13:27:41 +00:00
|
|
|
// === RangeError ===
|
|
|
|
|
2015-04-21 09:03:24 +00:00
|
|
|
// kArrayLengthOutOfRange
|
|
|
|
test(function() {
|
|
|
|
"use strict";
|
|
|
|
Object.defineProperty([], "length", { value: 1E100 });
|
|
|
|
}, "defineProperty() array length out of range", RangeError);
|
|
|
|
|
2015-04-24 10:22:00 +00:00
|
|
|
// kNormalizationForm
|
|
|
|
test(function() {
|
|
|
|
"".normalize("ABC");
|
|
|
|
}, "The normalization form should be one of NFC, NFD, NFKC, NFKD.", RangeError);
|
|
|
|
|
|
|
|
// kNumberFormatRange
|
2015-04-21 09:03:24 +00:00
|
|
|
test(function() {
|
|
|
|
Number(1).toFixed(100);
|
|
|
|
}, "toFixed() digits argument must be between 0 and 20", RangeError);
|
|
|
|
|
|
|
|
test(function() {
|
|
|
|
Number(1).toExponential(100);
|
|
|
|
}, "toExponential() argument must be between 0 and 20", RangeError);
|
|
|
|
|
2015-04-17 13:27:41 +00:00
|
|
|
// kStackOverflow
|
|
|
|
test(function() {
|
|
|
|
function f() { f(Array(1000)); }
|
|
|
|
f();
|
|
|
|
}, "Maximum call stack size exceeded", RangeError);
|
2015-04-21 09:03:24 +00:00
|
|
|
|
|
|
|
// kToPrecisionFormatRange
|
|
|
|
test(function() {
|
|
|
|
Number(1).toPrecision(100);
|
|
|
|
}, "toPrecision() argument must be between 1 and 21", RangeError);
|
2015-04-24 10:22:00 +00:00
|
|
|
|
|
|
|
// kToPrecisionFormatRange
|
|
|
|
test(function() {
|
|
|
|
Number(1).toString(100);
|
|
|
|
}, "toString() radix argument must be between 2 and 36", RangeError);
|
|
|
|
|
|
|
|
|
|
|
|
// === URIError ===
|
|
|
|
|
|
|
|
// kURIMalformed
|
|
|
|
test(function() {
|
|
|
|
decodeURI("%%");
|
|
|
|
}, "URI malformed", URIError);
|