1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Flags: --stack-size=100 --harmony --harmony-reflect --harmony-regexps
6 // Flags: --harmony-simd --strong-mode
8 function test(f, expected, type) {
12 assertInstanceof(e, type);
13 assertEquals(expected, e.message);
16 assertUnreachable("Exception expected");
25 }, "Cyclic __proto__ value", Error);
32 Function.prototype.apply.call(1, []);
33 }, "Function.prototype.apply was called on 1, which is a number " +
34 "and not a function", TypeError);
36 // kArrayFunctionsOnFrozen
41 }, "Cannot modify frozen array elements", TypeError);
43 // kArrayFunctionsOnSealed
48 }, "Cannot add/remove sealed array elements", TypeError);
53 }, "1 is not a function", TypeError);
57 Object.defineProperty(1, "x", {});
58 }, "Object.defineProperty called on non-object", TypeError);
60 // kCalledOnNullOrUndefined
62 Array.prototype.shift.call(null);
63 }, "Array.prototype.shift called on null or undefined", TypeError);
65 // kCannotPreventExtExternalArray
67 Object.preventExtensions(new Uint16Array(1));
68 }, "Cannot prevent extension of an object with external array elements", TypeError);
75 }, "Assignment to constant variable.", TypeError);
77 // kCannotConvertToPrimitive
79 var o = { toString: function() { return this } };
81 }, "Cannot convert object to primitive value", TypeError);
88 }, "Converting circular structure to JSON", TypeError);
90 // kConstructorNotFunction
93 }, "Constructor Uint16Array requires 'new'", TypeError);
95 // kDataViewNotArrayBuffer
98 }, "First argument to DataView constructor must be an ArrayBuffer", TypeError);
102 Date.prototype.setYear.call({}, 1);
103 }, "this is not a Date object.", TypeError);
109 Object.preventExtensions(o);
110 Object.defineProperty(o, "x", { value: 1 });
111 }, "Cannot define property:x, object is not extensible.", TypeError);
113 // kFirstArgumentNotRegExp
116 }, "First argument to String.prototype.startsWith " +
117 "must not be a regular expression", TypeError);
119 // kFlagsGetterNonObject
121 Object.getOwnPropertyDescriptor(RegExp.prototype, "flags").get.call(1);
122 }, "RegExp.prototype.flags getter called on non-object 1", TypeError);
126 Function.prototype.bind.call(1);
127 }, "Bind must be called on a function", TypeError);
132 function* generator() { yield iter.next(); }
133 var iter = generator();
135 }, "Generator is already running", TypeError);
137 // kIncompatibleMethodReceiver
139 RegExp.prototype.compile.call(RegExp.prototype);
140 }, "Method RegExp.prototype.compile called on incompatible receiver " +
141 "[object RegExp]", TypeError);
143 // kInstanceofFunctionExpected
146 }, "Expecting a function in instanceof check, but got 1", TypeError);
148 // kInstanceofNonobjectProto
154 }, "Function has non-object prototype '1' in instanceof check", TypeError);
156 // kInvalidInOperatorUse
159 }, "Cannot use 'in' operator to search for '1' in 1", TypeError);
161 // kIteratorResultNotAnObject
164 obj[Symbol.iterator] = function() { return { next: function() { return 1 }}};
166 }, "Iterator result 1 is not an object", TypeError);
168 // kIteratorValueNotAnObject
171 }, "Iterator value 1 is not an entry object", TypeError);
175 Promise.prototype.chain.call(1);
176 }, "1 is not a promise", TypeError);
181 }, "Symbol is not a constructor", TypeError);
185 Date.prototype.setHours.call(1);
186 }, "this is not a Date object.", TypeError);
190 String.prototype.toString.call(1);
191 }, "String.prototype.toString is not generic", TypeError);
194 String.prototype.valueOf.call(1);
195 }, "String.prototype.valueOf is not generic", TypeError);
198 Boolean.prototype.toString.call(1);
199 }, "Boolean.prototype.toString is not generic", TypeError);
202 Boolean.prototype.valueOf.call(1);
203 }, "Boolean.prototype.valueOf is not generic", TypeError);
206 Number.prototype.toString.call({});
207 }, "Number.prototype.toString is not generic", TypeError);
210 Number.prototype.valueOf.call({});
211 }, "Number.prototype.valueOf is not generic", TypeError);
214 Function.prototype.toString.call(1);
215 }, "Function.prototype.toString is not generic", TypeError);
219 Uint16Array.prototype.forEach.call(1);
220 }, "this is not a typed array.", TypeError);
222 // kObjectGetterExpectingFunction
224 ({}).__defineGetter__("x", 0);
225 }, "Object.prototype.__defineGetter__: Expecting function", TypeError);
227 // kObjectGetterCallable
229 Object.defineProperty({}, "x", { get: 1 });
230 }, "Getter must be a function: 1", TypeError);
232 // kObjectNotExtensible
238 }, "Can't add property a, object is not extensible", TypeError);
240 // kObjectSetterExpectingFunction
242 ({}).__defineSetter__("x", 0);
243 }, "Object.prototype.__defineSetter__: Expecting function", TypeError);
245 // kObjectSetterCallable
247 Object.defineProperty({}, "x", { set: 1 });
248 }, "Setter must be a function: 1", TypeError);
250 // kPropertyDescObject
252 Object.defineProperty({}, "x", 1);
253 }, "Property description must be an object: 1", TypeError);
255 // kPropertyNotFunction
257 Set.prototype.add = 0;
259 }, "Property 'add' of object #<Set> is not a function", TypeError);
261 // kProtoObjectOrNull
263 Object.setPrototypeOf({}, 1);
264 }, "Object prototype may only be an Object or null: 1", TypeError);
266 // kRedefineDisallowed
270 Object.defineProperty(o, "x", { value: 1, configurable: false });
271 Object.defineProperty(o, "x", { value: 2 });
272 }, "Cannot redefine property: x", TypeError);
276 [].reduce(function() {});
277 }, "Reduce of empty array with no initial value", TypeError);
279 // kResolverNotAFunction
282 }, "Promise resolver 1 is not a function", TypeError);
284 // kStrictDeleteProperty
288 Object.defineProperty(o, "p", { value: 1, writable: false });
290 }, "Cannot delete property 'p' of #<Object>", TypeError);
296 }, "'caller', 'callee', and 'arguments' properties may not be accessed on " +
297 "strict mode functions or the arguments objects for calls to them",
300 // kStrictReadOnlyProperty
304 }, "Cannot assign to read only property 'a' of 1", TypeError);
306 // kStrongImplicitCast
310 }, "In strong mode, implicit conversions are deprecated", TypeError);
315 }, "Cannot convert a Symbol value to a string", TypeError);
320 }, "Cannot convert a Symbol value to a number", TypeError);
324 1 + SIMD.Float32x4(1, 2, 3, 4);
325 }, "Cannot convert a SIMD value to a number", TypeError);
327 // kUndefinedOrNullToObject
329 Array.prototype.toString.call(null);
330 }, "Cannot convert undefined or null to object", TypeError);
334 Object.defineProperty({}, "x", { get: function(){}, value: 1});
335 }, "Invalid property. A property cannot both have accessors and be " +
336 "writable or have a value, #<Object>", TypeError);
341 }, "null has no properties", TypeError);
345 (function() {}).apply({}, 1);
346 }, "Function.prototype.apply: Arguments list has wrong type", TypeError);
349 Reflect.apply(function() {}, {}, 1);
350 }, "Reflect.apply: Arguments list has wrong type", TypeError);
353 Reflect.construct(function() {}, 1);
354 }, "Reflect.construct: Arguments list has wrong type", TypeError);
357 // === SyntaxError ===
359 // kInvalidRegExpFlags
362 }, "Invalid flags supplied to RegExp constructor 'x'", SyntaxError);
367 }, "Invalid regular expression: /(/: Unterminated group", SyntaxError);
369 // kParenthesisInArgString
371 new Function(")", "");
372 }, "Function arg string contains parenthesis", SyntaxError);
377 }, "Unexpected end of input", SyntaxError);
382 }, "Unexpected token /", SyntaxError);
384 // kUnexpectedTokenNumber
387 }, "Unexpected number", SyntaxError);
389 // kUnexpectedTokenString
392 }, "Unexpected string", SyntaxError);
395 // === ReferenceError ===
401 }, "o is not defined", ReferenceError);
403 // === RangeError ===
405 // kArrayLengthOutOfRange
408 Object.defineProperty([], "length", { value: 1E100 });
409 }, "Invalid array length", RangeError);
411 // kInvalidArrayBufferLength
414 }, "Invalid array buffer length", RangeError);
416 // kInvalidArrayLength
419 }, "Invalid array length", RangeError);
423 String.fromCodePoint(-1);
424 }, "Invalid code point -1", RangeError);
426 // kInvalidCountValue
429 }, "Invalid count value", RangeError);
431 // kInvalidArrayBufferLength
434 }, "Invalid typed array length", RangeError);
436 // kNormalizationForm
439 }, "The normalization form should be one of NFC, NFD, NFKC, NFKD.", RangeError);
441 // kNumberFormatRange
443 Number(1).toFixed(100);
444 }, "toFixed() digits argument must be between 0 and 20", RangeError);
447 Number(1).toExponential(100);
448 }, "toExponential() argument must be between 0 and 20", RangeError);
452 function f() { f(Array(1000)); }
454 }, "Maximum call stack size exceeded", RangeError);
456 // kToPrecisionFormatRange
458 Number(1).toPrecision(100);
459 }, "toPrecision() argument must be between 1 and 21", RangeError);
461 // kToPrecisionFormatRange
463 Number(1).toString(100);
464 }, "toString() radix argument must be between 2 and 36", RangeError);
472 }, "URI malformed", URIError);