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 [].join(Object(Symbol(1)));
80 }, "Cannot convert object to primitive value", TypeError);
87 }, "Converting circular structure to JSON", TypeError);
89 // kConstructorNotFunction
92 }, "Constructor Uint16Array requires 'new'", TypeError);
94 // kDataViewNotArrayBuffer
97 }, "First argument to DataView constructor must be an ArrayBuffer", TypeError);
101 Date.prototype.setYear.call({}, 1);
102 }, "this is not a Date object.", TypeError);
108 Object.preventExtensions(o);
109 Object.defineProperty(o, "x", { value: 1 });
110 }, "Cannot define property:x, object is not extensible.", TypeError);
112 // kFirstArgumentNotRegExp
115 }, "First argument to String.prototype.startsWith " +
116 "must not be a regular expression", TypeError);
118 // kFlagsGetterNonObject
120 Object.getOwnPropertyDescriptor(RegExp.prototype, "flags").get.call(1);
121 }, "RegExp.prototype.flags getter called on non-object 1", TypeError);
125 Function.prototype.bind.call(1);
126 }, "Bind must be called on a function", TypeError);
131 function* generator() { yield iter.next(); }
132 var iter = generator();
134 }, "Generator is already running", TypeError);
136 // kIncompatibleMethodReceiver
138 RegExp.prototype.compile.call(RegExp.prototype);
139 }, "Method RegExp.prototype.compile called on incompatible receiver " +
140 "[object RegExp]", TypeError);
142 // kInstanceofFunctionExpected
145 }, "Expecting a function in instanceof check, but got 1", TypeError);
147 // kInstanceofNonobjectProto
153 }, "Function has non-object prototype '1' in instanceof check", TypeError);
155 // kInvalidInOperatorUse
158 }, "Cannot use 'in' operator to search for '1' in 1", TypeError);
160 // kIteratorResultNotAnObject
163 obj[Symbol.iterator] = function() { return { next: function() { return 1 }}};
165 }, "Iterator result 1 is not an object", TypeError);
167 // kIteratorValueNotAnObject
170 }, "Iterator value 1 is not an entry object", TypeError);
174 Promise.prototype.chain.call(1);
175 }, "1 is not a promise", TypeError);
180 }, "Symbol is not a constructor", TypeError);
184 Date.prototype.setHours.call(1);
185 }, "this is not a Date object.", TypeError);
189 String.prototype.toString.call(1);
190 }, "String.prototype.toString is not generic", TypeError);
193 String.prototype.valueOf.call(1);
194 }, "String.prototype.valueOf is not generic", TypeError);
197 Boolean.prototype.toString.call(1);
198 }, "Boolean.prototype.toString is not generic", TypeError);
201 Boolean.prototype.valueOf.call(1);
202 }, "Boolean.prototype.valueOf is not generic", TypeError);
205 Number.prototype.toString.call({});
206 }, "Number.prototype.toString is not generic", TypeError);
209 Number.prototype.valueOf.call({});
210 }, "Number.prototype.valueOf is not generic", TypeError);
213 Function.prototype.toString.call(1);
214 }, "Function.prototype.toString is not generic", TypeError);
218 Uint16Array.prototype.forEach.call(1);
219 }, "this is not a typed array.", TypeError);
221 // kObjectGetterExpectingFunction
223 ({}).__defineGetter__("x", 0);
224 }, "Object.prototype.__defineGetter__: Expecting function", TypeError);
226 // kObjectGetterCallable
228 Object.defineProperty({}, "x", { get: 1 });
229 }, "Getter must be a function: 1", TypeError);
231 // kObjectNotExtensible
237 }, "Can't add property a, object is not extensible", TypeError);
239 // kObjectSetterExpectingFunction
241 ({}).__defineSetter__("x", 0);
242 }, "Object.prototype.__defineSetter__: Expecting function", TypeError);
244 // kObjectSetterCallable
246 Object.defineProperty({}, "x", { set: 1 });
247 }, "Setter must be a function: 1", TypeError);
249 // kPropertyDescObject
251 Object.defineProperty({}, "x", 1);
252 }, "Property description must be an object: 1", TypeError);
254 // kPropertyNotFunction
256 Set.prototype.add = 0;
258 }, "Property 'add' of object #<Set> is not a function", TypeError);
260 // kProtoObjectOrNull
262 Object.setPrototypeOf({}, 1);
263 }, "Object prototype may only be an Object or null: 1", TypeError);
265 // kRedefineDisallowed
269 Object.defineProperty(o, "x", { value: 1, configurable: false });
270 Object.defineProperty(o, "x", { value: 2 });
271 }, "Cannot redefine property: x", TypeError);
275 [].reduce(function() {});
276 }, "Reduce of empty array with no initial value", TypeError);
278 // kResolverNotAFunction
281 }, "Promise resolver 1 is not a function", TypeError);
283 // kStrictDeleteProperty
287 Object.defineProperty(o, "p", { value: 1, writable: false });
289 }, "Cannot delete property 'p' of #<Object>", TypeError);
295 }, "'caller', 'callee', and 'arguments' properties may not be accessed on " +
296 "strict mode functions or the arguments objects for calls to them",
299 // kStrictReadOnlyProperty
303 }, "Cannot assign to read only property 'a' of 1", TypeError);
305 // kStrongImplicitCast
309 }, "In strong mode, implicit conversions are deprecated", TypeError);
314 }, "Cannot convert a Symbol value to a string", TypeError);
319 }, "Cannot convert a Symbol value to a number", TypeError);
323 1 + SIMD.Float32x4(1, 2, 3, 4);
324 }, "Cannot convert a SIMD value to a number", TypeError);
326 // kUndefinedOrNullToObject
328 Array.prototype.toString.call(null);
329 }, "Cannot convert undefined or null to object", TypeError);
333 Object.defineProperty({}, "x", { get: function(){}, value: 1});
334 }, "Invalid property. A property cannot both have accessors and be " +
335 "writable or have a value, #<Object>", TypeError);
340 }, "null has no properties", TypeError);
344 (function() {}).apply({}, 1);
345 }, "Function.prototype.apply: Arguments list has wrong type", TypeError);
348 Reflect.apply(function() {}, {}, 1);
349 }, "Reflect.apply: Arguments list has wrong type", TypeError);
352 Reflect.construct(function() {}, 1);
353 }, "Reflect.construct: Arguments list has wrong type", TypeError);
356 // === SyntaxError ===
358 // kInvalidRegExpFlags
361 }, "Invalid flags supplied to RegExp constructor 'x'", SyntaxError);
366 }, "Invalid regular expression: /(/: Unterminated group", SyntaxError);
368 // kParenthesisInArgString
370 new Function(")", "");
371 }, "Function arg string contains parenthesis", SyntaxError);
376 }, "Unexpected end of input", SyntaxError);
381 }, "Unexpected token /", SyntaxError);
383 // kUnexpectedTokenNumber
386 }, "Unexpected number", SyntaxError);
388 // kUnexpectedTokenString
391 }, "Unexpected string", SyntaxError);
394 // === ReferenceError ===
400 }, "o is not defined", ReferenceError);
402 // === RangeError ===
404 // kArrayLengthOutOfRange
407 Object.defineProperty([], "length", { value: 1E100 });
408 }, "Invalid array length", RangeError);
410 // kInvalidArrayBufferLength
413 }, "Invalid array buffer length", RangeError);
415 // kInvalidArrayLength
418 }, "Invalid array length", RangeError);
422 String.fromCodePoint(-1);
423 }, "Invalid code point -1", RangeError);
425 // kInvalidCountValue
428 }, "Invalid count value", RangeError);
430 // kInvalidArrayBufferLength
433 }, "Invalid typed array length", RangeError);
435 // kNormalizationForm
438 }, "The normalization form should be one of NFC, NFD, NFKC, NFKD.", RangeError);
440 // kNumberFormatRange
442 Number(1).toFixed(100);
443 }, "toFixed() digits argument must be between 0 and 20", RangeError);
446 Number(1).toExponential(100);
447 }, "toExponential() argument must be between 0 and 20", RangeError);
451 function f() { f(Array(1000)); }
453 }, "Maximum call stack size exceeded", RangeError);
455 // kToPrecisionFormatRange
457 Number(1).toPrecision(100);
458 }, "toPrecision() argument must be between 1 and 21", RangeError);
460 // kToPrecisionFormatRange
462 Number(1).toString(100);
463 }, "toString() radix argument must be between 2 and 36", RangeError);
471 }, "URI malformed", URIError);