OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
| 5 // Flags: --stack-size=100 --harmony --harmony-reflect |
| 6 |
5 function test(f, expected, type) { | 7 function test(f, expected, type) { |
6 try { | 8 try { |
7 f(); | 9 f(); |
8 assertUnreachable(); | |
9 } catch (e) { | 10 } catch (e) { |
10 assertInstanceof(e, type); | 11 assertInstanceof(e, type); |
11 assertEquals(expected, e.message); | 12 assertEquals(expected, e.message); |
| 13 return; |
12 } | 14 } |
| 15 assertUnreachable(); |
13 } | 16 } |
14 | 17 |
15 // === Error === | 18 // === Error === |
16 | 19 |
17 // kCyclicProto | 20 // kCyclicProto |
18 test(function() { | 21 test(function() { |
19 var o = {}; | 22 var o = {}; |
20 o.__proto__ = o; | 23 o.__proto__ = o; |
21 }, "Cyclic __proto__ value", Error); | 24 }, "Cyclic __proto__ value", Error); |
22 | 25 |
23 | 26 |
24 // === TypeError === | 27 // === TypeError === |
25 | 28 |
| 29 // kApplyNonFunction |
| 30 test(function() { |
| 31 Function.prototype.apply.call(1, []); |
| 32 }, "Function.prototype.apply was called on 1, which is a number " + |
| 33 "and not a function", TypeError); |
| 34 |
| 35 // kCannotConvertToPrimitive |
| 36 test(function() { |
| 37 [].join(Object(Symbol(1))); |
| 38 }, "Cannot convert object to primitive value", TypeError); |
| 39 |
26 // kGeneratorRunning | 40 // kGeneratorRunning |
27 test(function() { | 41 test(function() { |
28 var iter; | 42 var iter; |
29 function* generator() { yield iter.next(); } | 43 function* generator() { yield iter.next(); } |
30 var iter = generator(); | 44 var iter = generator(); |
31 iter.next(); | 45 iter.next(); |
32 }, "Generator is already running", TypeError); | 46 }, "Generator is already running", TypeError); |
33 | 47 |
34 // kCalledNonCallable | 48 // kCalledNonCallable |
35 test(function() { | 49 test(function() { |
36 [].forEach(1); | 50 [].forEach(1); |
37 }, "1 is not a function", TypeError); | 51 }, "1 is not a function", TypeError); |
38 | 52 |
39 // kIncompatibleMethodReceiver | 53 // kIncompatibleMethodReceiver |
40 test(function() { | 54 test(function() { |
41 RegExp.prototype.compile.call(RegExp.prototype); | 55 RegExp.prototype.compile.call(RegExp.prototype); |
42 }, "Method RegExp.prototype.compile called on incompatible receiver " + | 56 }, "Method RegExp.prototype.compile called on incompatible receiver " + |
43 "[object RegExp]", TypeError); | 57 "[object RegExp]", TypeError); |
44 | 58 |
| 59 // kInstanceofFunctionExpected |
| 60 test(function() { |
| 61 1 instanceof 1; |
| 62 }, "Expecting a function in instanceof check, but got 1", TypeError); |
| 63 |
| 64 // kInstanceofNonobjectProto |
| 65 test(function() { |
| 66 function f() {} |
| 67 var o = new f(); |
| 68 f.prototype = 1; |
| 69 o instanceof f; |
| 70 }, "Function has non-object prototype '1' in instanceof check", TypeError); |
| 71 |
| 72 // kInvalidInOperatorUse |
| 73 test(function() { |
| 74 1 in 1; |
| 75 }, "Cannot use 'in' operator to search for '1' in 1", TypeError); |
| 76 |
| 77 // kNotConstructor |
| 78 test(function() { |
| 79 new Symbol(); |
| 80 }, "Symbol is not a constructor", TypeError); |
| 81 |
45 // kPropertyNotFunction | 82 // kPropertyNotFunction |
46 test(function() { | 83 test(function() { |
47 Set.prototype.add = 0; | 84 Set.prototype.add = 0; |
48 new Set(1); | 85 new Set(1); |
49 }, "Property 'add' of object #<Set> is not a function", TypeError); | 86 }, "Property 'add' of object #<Set> is not a function", TypeError); |
50 | 87 |
| 88 // kSymbolToPrimitive |
| 89 test(function() { |
| 90 1 + Object(Symbol()); |
| 91 }, "Cannot convert a Symbol wrapper object to a primitive value", TypeError); |
| 92 |
| 93 // kSymbolToString |
| 94 test(function() { |
| 95 "" + Symbol(); |
| 96 }, "Cannot convert a Symbol value to a string", TypeError); |
| 97 |
| 98 // kSymbolToNumber |
| 99 test(function() { |
| 100 1 + Symbol(); |
| 101 }, "Cannot convert a Symbol value to a number", TypeError); |
| 102 |
| 103 // kUndefinedOrNullToObject |
| 104 test(function() { |
| 105 Array.prototype.toString.call(null); |
| 106 }, "Cannot convert undefined or null to object", TypeError); |
| 107 |
51 // kWithExpression | 108 // kWithExpression |
52 test(function() { | 109 test(function() { |
53 with (null) {} | 110 with (null) {} |
54 }, "null has no properties", TypeError); | 111 }, "null has no properties", TypeError); |
| 112 |
| 113 // kWrongArgs |
| 114 test(function() { |
| 115 (function() {}).apply({}, 1); |
| 116 }, "Function.prototype.apply: Arguments list has wrong type", TypeError); |
| 117 |
| 118 test(function() { |
| 119 Reflect.apply(function() {}, {}, 1); |
| 120 }, "Reflect.apply: Arguments list has wrong type", TypeError); |
| 121 |
| 122 test(function() { |
| 123 Reflect.construct(function() {}, 1); |
| 124 }, "Reflect.construct: Arguments list has wrong type", TypeError); |
| 125 |
| 126 |
| 127 // === RangeError === |
| 128 |
| 129 // kStackOverflow |
| 130 test(function() { |
| 131 function f() { f(Array(1000)); } |
| 132 f(); |
| 133 }, "Maximum call stack size exceeded", RangeError); |
OLD | NEW |