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 | 5 // Flags: --stack-size=100 --harmony --harmony-reflect |
6 | 6 |
7 function test(f, expected, type) { | 7 function test(f, expected, type) { |
8 try { | 8 try { |
9 f(); | 9 f(); |
10 } catch (e) { | 10 } catch (e) { |
11 assertInstanceof(e, type); | 11 assertInstanceof(e, type); |
12 assertEquals(expected, e.message); | 12 assertEquals(expected, e.message); |
13 return; | 13 return; |
14 } | 14 } |
15 assertUnreachable(); | 15 assertUnreachable("Exception expected"); |
16 } | 16 } |
17 | 17 |
18 // === Error === | 18 // === Error === |
19 | 19 |
20 // kCyclicProto | 20 // kCyclicProto |
21 test(function() { | 21 test(function() { |
22 var o = {}; | 22 var o = {}; |
23 o.__proto__ = o; | 23 o.__proto__ = o; |
24 }, "Cyclic __proto__ value", Error); | 24 }, "Cyclic __proto__ value", Error); |
25 | 25 |
26 | 26 |
27 // === TypeError === | 27 // === TypeError === |
28 | 28 |
29 // kApplyNonFunction | 29 // kApplyNonFunction |
30 test(function() { | 30 test(function() { |
31 Function.prototype.apply.call(1, []); | 31 Function.prototype.apply.call(1, []); |
32 }, "Function.prototype.apply was called on 1, which is a number " + | 32 }, "Function.prototype.apply was called on 1, which is a number " + |
33 "and not a function", TypeError); | 33 "and not a function", TypeError); |
34 | 34 |
| 35 // kCalledNonCallable |
| 36 test(function() { |
| 37 [].forEach(1); |
| 38 }, "1 is not a function", TypeError); |
| 39 |
| 40 // kCalledOnNonObject |
| 41 test(function() { |
| 42 Object.freeze(1) |
| 43 }, "Object.freeze called on non-object", TypeError); |
| 44 |
35 // kCannotConvertToPrimitive | 45 // kCannotConvertToPrimitive |
36 test(function() { | 46 test(function() { |
37 [].join(Object(Symbol(1))); | 47 [].join(Object(Symbol(1))); |
38 }, "Cannot convert object to primitive value", TypeError); | 48 }, "Cannot convert object to primitive value", TypeError); |
39 | 49 |
| 50 // kDefineDisallowed |
| 51 test(function() { |
| 52 "use strict"; |
| 53 var o = {}; |
| 54 Object.preventExtensions(o); |
| 55 Object.defineProperty(o, "x", { value: 1 }); |
| 56 }, "Cannot define property:x, object is not extensible.", TypeError); |
| 57 |
40 // kGeneratorRunning | 58 // kGeneratorRunning |
41 test(function() { | 59 test(function() { |
42 var iter; | 60 var iter; |
43 function* generator() { yield iter.next(); } | 61 function* generator() { yield iter.next(); } |
44 var iter = generator(); | 62 var iter = generator(); |
45 iter.next(); | 63 iter.next(); |
46 }, "Generator is already running", TypeError); | 64 }, "Generator is already running", TypeError); |
47 | 65 |
48 // kCalledNonCallable | 66 // kFunctionBind |
49 test(function() { | 67 test(function() { |
50 [].forEach(1); | 68 Function.prototype.bind.call(1); |
51 }, "1 is not a function", TypeError); | 69 }, "Bind must be called on a function", TypeError); |
52 | 70 |
53 // kIncompatibleMethodReceiver | 71 // kIncompatibleMethodReceiver |
54 test(function() { | 72 test(function() { |
55 RegExp.prototype.compile.call(RegExp.prototype); | 73 RegExp.prototype.compile.call(RegExp.prototype); |
56 }, "Method RegExp.prototype.compile called on incompatible receiver " + | 74 }, "Method RegExp.prototype.compile called on incompatible receiver " + |
57 "[object RegExp]", TypeError); | 75 "[object RegExp]", TypeError); |
58 | 76 |
59 // kInstanceofFunctionExpected | 77 // kInstanceofFunctionExpected |
60 test(function() { | 78 test(function() { |
61 1 instanceof 1; | 79 1 instanceof 1; |
(...skipping 10 matching lines...) Expand all Loading... |
72 // kInvalidInOperatorUse | 90 // kInvalidInOperatorUse |
73 test(function() { | 91 test(function() { |
74 1 in 1; | 92 1 in 1; |
75 }, "Cannot use 'in' operator to search for '1' in 1", TypeError); | 93 }, "Cannot use 'in' operator to search for '1' in 1", TypeError); |
76 | 94 |
77 // kNotConstructor | 95 // kNotConstructor |
78 test(function() { | 96 test(function() { |
79 new Symbol(); | 97 new Symbol(); |
80 }, "Symbol is not a constructor", TypeError); | 98 }, "Symbol is not a constructor", TypeError); |
81 | 99 |
| 100 // kNotGeneric |
| 101 test(function() { |
| 102 String.prototype.toString.call(1); |
| 103 }, "String.prototype.toString is not generic", TypeError); |
| 104 |
| 105 test(function() { |
| 106 String.prototype.valueOf.call(1); |
| 107 }, "String.prototype.valueOf is not generic", TypeError); |
| 108 |
| 109 test(function() { |
| 110 Boolean.prototype.toString.call(1); |
| 111 }, "Boolean.prototype.toString is not generic", TypeError); |
| 112 |
| 113 test(function() { |
| 114 Boolean.prototype.valueOf.call(1); |
| 115 }, "Boolean.prototype.valueOf is not generic", TypeError); |
| 116 |
| 117 test(function() { |
| 118 Number.prototype.toString.call({}); |
| 119 }, "Number.prototype.toString is not generic", TypeError); |
| 120 |
| 121 test(function() { |
| 122 Number.prototype.valueOf.call({}); |
| 123 }, "Number.prototype.valueOf is not generic", TypeError); |
| 124 |
| 125 test(function() { |
| 126 Function.prototype.toString.call(1); |
| 127 }, "Function.prototype.toString is not generic", TypeError); |
| 128 |
| 129 |
| 130 // kObjectGetterExpectingFunction |
| 131 test(function() { |
| 132 ({}).__defineGetter__("x", 0); |
| 133 }, "Object.prototype.__defineGetter__: Expecting function", TypeError); |
| 134 |
| 135 // kObjectGetterCallable |
| 136 test(function() { |
| 137 Object.defineProperty({}, "x", { get: 1 }); |
| 138 }, "Getter must be a function: 1", TypeError); |
| 139 |
| 140 // kObjectSetterExpectingFunction |
| 141 test(function() { |
| 142 ({}).__defineSetter__("x", 0); |
| 143 }, "Object.prototype.__defineSetter__: Expecting function", TypeError); |
| 144 |
| 145 // kObjectSetterCallable |
| 146 test(function() { |
| 147 Object.defineProperty({}, "x", { set: 1 }); |
| 148 }, "Setter must be a function: 1", TypeError); |
| 149 |
| 150 // kPropertyDescObject |
| 151 test(function() { |
| 152 Object.defineProperty({}, "x", 1); |
| 153 }, "Property description must be an object: 1", TypeError); |
| 154 |
82 // kPropertyNotFunction | 155 // kPropertyNotFunction |
83 test(function() { | 156 test(function() { |
84 Set.prototype.add = 0; | 157 Set.prototype.add = 0; |
85 new Set(1); | 158 new Set(1); |
86 }, "Property 'add' of object #<Set> is not a function", TypeError); | 159 }, "Property 'add' of object #<Set> is not a function", TypeError); |
87 | 160 |
| 161 // kProtoObjectOrNull |
| 162 test(function() { |
| 163 Object.setPrototypeOf({}, 1); |
| 164 }, "Object prototype may only be an Object or null: 1", TypeError); |
| 165 |
| 166 // kRedefineDisallowed |
| 167 test(function() { |
| 168 "use strict"; |
| 169 var o = {}; |
| 170 Object.defineProperty(o, "x", { value: 1, configurable: false }); |
| 171 Object.defineProperty(o, "x", { value: 2 }); |
| 172 }, "Cannot redefine property: x", TypeError); |
| 173 |
88 // kSymbolToPrimitive | 174 // kSymbolToPrimitive |
89 test(function() { | 175 test(function() { |
90 1 + Object(Symbol()); | 176 1 + Object(Symbol()); |
91 }, "Cannot convert a Symbol wrapper object to a primitive value", TypeError); | 177 }, "Cannot convert a Symbol wrapper object to a primitive value", TypeError); |
92 | 178 |
93 // kSymbolToString | 179 // kSymbolToString |
94 test(function() { | 180 test(function() { |
95 "" + Symbol(); | 181 "" + Symbol(); |
96 }, "Cannot convert a Symbol value to a string", TypeError); | 182 }, "Cannot convert a Symbol value to a string", TypeError); |
97 | 183 |
98 // kSymbolToNumber | 184 // kSymbolToNumber |
99 test(function() { | 185 test(function() { |
100 1 + Symbol(); | 186 1 + Symbol(); |
101 }, "Cannot convert a Symbol value to a number", TypeError); | 187 }, "Cannot convert a Symbol value to a number", TypeError); |
102 | 188 |
103 // kUndefinedOrNullToObject | 189 // kUndefinedOrNullToObject |
104 test(function() { | 190 test(function() { |
105 Array.prototype.toString.call(null); | 191 Array.prototype.toString.call(null); |
106 }, "Cannot convert undefined or null to object", TypeError); | 192 }, "Cannot convert undefined or null to object", TypeError); |
107 | 193 |
| 194 // kValueAndAccessor |
| 195 test(function() { |
| 196 Object.defineProperty({}, "x", { get: function(){}, value: 1}); |
| 197 }, "Invalid property. A property cannot both have accessors and be " + |
| 198 "writable or have a value, #<Object>", TypeError); |
| 199 |
108 // kWithExpression | 200 // kWithExpression |
109 test(function() { | 201 test(function() { |
110 with (null) {} | 202 with (null) {} |
111 }, "null has no properties", TypeError); | 203 }, "null has no properties", TypeError); |
112 | 204 |
113 // kWrongArgs | 205 // kWrongArgs |
114 test(function() { | 206 test(function() { |
115 (function() {}).apply({}, 1); | 207 (function() {}).apply({}, 1); |
116 }, "Function.prototype.apply: Arguments list has wrong type", TypeError); | 208 }, "Function.prototype.apply: Arguments list has wrong type", TypeError); |
117 | 209 |
118 test(function() { | 210 test(function() { |
119 Reflect.apply(function() {}, {}, 1); | 211 Reflect.apply(function() {}, {}, 1); |
120 }, "Reflect.apply: Arguments list has wrong type", TypeError); | 212 }, "Reflect.apply: Arguments list has wrong type", TypeError); |
121 | 213 |
122 test(function() { | 214 test(function() { |
123 Reflect.construct(function() {}, 1); | 215 Reflect.construct(function() {}, 1); |
124 }, "Reflect.construct: Arguments list has wrong type", TypeError); | 216 }, "Reflect.construct: Arguments list has wrong type", TypeError); |
125 | 217 |
126 | 218 |
| 219 //=== SyntaxError === |
| 220 |
| 221 test(function() { |
| 222 new Function(")", ""); |
| 223 }, "Function arg string contains parenthesis", SyntaxError); |
| 224 |
| 225 |
127 // === RangeError === | 226 // === RangeError === |
128 | 227 |
| 228 // kArrayLengthOutOfRange |
| 229 test(function() { |
| 230 "use strict"; |
| 231 Object.defineProperty([], "length", { value: 1E100 }); |
| 232 }, "defineProperty() array length out of range", RangeError); |
| 233 |
| 234 //kNumberFormatRange |
| 235 test(function() { |
| 236 Number(1).toFixed(100); |
| 237 }, "toFixed() digits argument must be between 0 and 20", RangeError); |
| 238 |
| 239 test(function() { |
| 240 Number(1).toExponential(100); |
| 241 }, "toExponential() argument must be between 0 and 20", RangeError); |
| 242 |
129 // kStackOverflow | 243 // kStackOverflow |
130 test(function() { | 244 test(function() { |
131 function f() { f(Array(1000)); } | 245 function f() { f(Array(1000)); } |
132 f(); | 246 f(); |
133 }, "Maximum call stack size exceeded", RangeError); | 247 }, "Maximum call stack size exceeded", RangeError); |
| 248 |
| 249 // kToPrecisionFormatRange |
| 250 test(function() { |
| 251 Number(1).toPrecision(100); |
| 252 }, "toPrecision() argument must be between 1 and 21", RangeError); |
OLD | NEW |