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 --harmony-arrays | 5 // Flags: --stack-size=100 --harmony --harmony-reflect --harmony-arrays |
6 // Flags: --harmony-regexps | 6 // Flags: --harmony-regexps --strong-mode |
7 | 7 |
8 function test(f, expected, type) { | 8 function test(f, expected, type) { |
9 try { | 9 try { |
10 f(); | 10 f(); |
11 } catch (e) { | 11 } catch (e) { |
12 assertInstanceof(e, type); | 12 assertInstanceof(e, type); |
13 assertEquals(expected, e.message); | 13 assertEquals(expected, e.message); |
14 return; | 14 return; |
15 } | 15 } |
16 assertUnreachable("Exception expected"); | 16 assertUnreachable("Exception expected"); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 // kCalledOnNonObject | 55 // kCalledOnNonObject |
56 test(function() { | 56 test(function() { |
57 Object.defineProperty(1, "x", {}); | 57 Object.defineProperty(1, "x", {}); |
58 }, "Object.defineProperty called on non-object", TypeError); | 58 }, "Object.defineProperty called on non-object", TypeError); |
59 | 59 |
60 // kCalledOnNullOrUndefined | 60 // kCalledOnNullOrUndefined |
61 test(function() { | 61 test(function() { |
62 Array.prototype.shift.call(null); | 62 Array.prototype.shift.call(null); |
63 }, "Array.prototype.shift called on null or undefined", TypeError); | 63 }, "Array.prototype.shift called on null or undefined", TypeError); |
64 | 64 |
| 65 // kCannotPreventExtExternalArray |
| 66 test(function() { |
| 67 Object.preventExtensions(new Uint16Array(1)); |
| 68 }, "Cannot prevent extension of an object with external array elements", TypeErr
or); |
| 69 |
| 70 // kConstAssign |
| 71 test(function() { |
| 72 "use strict"; |
| 73 const a = 1; |
| 74 a = 2; |
| 75 }, "Assignment to constant variable.", TypeError); |
| 76 |
65 // kCannotConvertToPrimitive | 77 // kCannotConvertToPrimitive |
66 test(function() { | 78 test(function() { |
67 [].join(Object(Symbol(1))); | 79 [].join(Object(Symbol(1))); |
68 }, "Cannot convert object to primitive value", TypeError); | 80 }, "Cannot convert object to primitive value", TypeError); |
69 | 81 |
| 82 // kCircularStructure |
| 83 test(function() { |
| 84 var o = {}; |
| 85 o.o = o; |
| 86 JSON.stringify(o); |
| 87 }, "Converting circular structure to JSON", TypeError); |
| 88 |
70 // kConstructorNotFunction | 89 // kConstructorNotFunction |
71 test(function() { | 90 test(function() { |
72 Uint16Array(1); | 91 Uint16Array(1); |
73 }, "Constructor Uint16Array requires 'new'", TypeError); | 92 }, "Constructor Uint16Array requires 'new'", TypeError); |
74 | 93 |
75 // kDataViewNotArrayBuffer | 94 // kDataViewNotArrayBuffer |
76 test(function() { | 95 test(function() { |
77 new DataView(1); | 96 new DataView(1); |
78 }, "First argument to DataView constructor must be an ArrayBuffer", TypeError); | 97 }, "First argument to DataView constructor must be an ArrayBuffer", TypeError); |
79 | 98 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 // kNotAPromise | 172 // kNotAPromise |
154 test(function() { | 173 test(function() { |
155 Promise.prototype.chain.call(1); | 174 Promise.prototype.chain.call(1); |
156 }, "1 is not a promise", TypeError); | 175 }, "1 is not a promise", TypeError); |
157 | 176 |
158 // kNotConstructor | 177 // kNotConstructor |
159 test(function() { | 178 test(function() { |
160 new Symbol(); | 179 new Symbol(); |
161 }, "Symbol is not a constructor", TypeError); | 180 }, "Symbol is not a constructor", TypeError); |
162 | 181 |
| 182 // kNotDateObject |
| 183 test(function() { |
| 184 Date.prototype.setHours.call(1); |
| 185 }, "this is not a Date object.", TypeError); |
| 186 |
163 // kNotGeneric | 187 // kNotGeneric |
164 test(function() { | 188 test(function() { |
165 String.prototype.toString.call(1); | 189 String.prototype.toString.call(1); |
166 }, "String.prototype.toString is not generic", TypeError); | 190 }, "String.prototype.toString is not generic", TypeError); |
167 | 191 |
168 test(function() { | 192 test(function() { |
169 String.prototype.valueOf.call(1); | 193 String.prototype.valueOf.call(1); |
170 }, "String.prototype.valueOf is not generic", TypeError); | 194 }, "String.prototype.valueOf is not generic", TypeError); |
171 | 195 |
172 test(function() { | 196 test(function() { |
(...skipping 24 matching lines...) Expand all Loading... |
197 // kObjectGetterExpectingFunction | 221 // kObjectGetterExpectingFunction |
198 test(function() { | 222 test(function() { |
199 ({}).__defineGetter__("x", 0); | 223 ({}).__defineGetter__("x", 0); |
200 }, "Object.prototype.__defineGetter__: Expecting function", TypeError); | 224 }, "Object.prototype.__defineGetter__: Expecting function", TypeError); |
201 | 225 |
202 // kObjectGetterCallable | 226 // kObjectGetterCallable |
203 test(function() { | 227 test(function() { |
204 Object.defineProperty({}, "x", { get: 1 }); | 228 Object.defineProperty({}, "x", { get: 1 }); |
205 }, "Getter must be a function: 1", TypeError); | 229 }, "Getter must be a function: 1", TypeError); |
206 | 230 |
| 231 // kObjectNotExtensible |
| 232 test(function() { |
| 233 "use strict"; |
| 234 var o = {}; |
| 235 Object.freeze(o); |
| 236 o.a = 1; |
| 237 }, "Can't add property a, object is not extensible", TypeError); |
| 238 |
207 // kObjectSetterExpectingFunction | 239 // kObjectSetterExpectingFunction |
208 test(function() { | 240 test(function() { |
209 ({}).__defineSetter__("x", 0); | 241 ({}).__defineSetter__("x", 0); |
210 }, "Object.prototype.__defineSetter__: Expecting function", TypeError); | 242 }, "Object.prototype.__defineSetter__: Expecting function", TypeError); |
211 | 243 |
212 // kObjectSetterCallable | 244 // kObjectSetterCallable |
213 test(function() { | 245 test(function() { |
214 Object.defineProperty({}, "x", { set: 1 }); | 246 Object.defineProperty({}, "x", { set: 1 }); |
215 }, "Setter must be a function: 1", TypeError); | 247 }, "Setter must be a function: 1", TypeError); |
216 | 248 |
(...skipping 24 matching lines...) Expand all Loading... |
241 // kReduceNoInitial | 273 // kReduceNoInitial |
242 test(function() { | 274 test(function() { |
243 [].reduce(function() {}); | 275 [].reduce(function() {}); |
244 }, "Reduce of empty array with no initial value", TypeError); | 276 }, "Reduce of empty array with no initial value", TypeError); |
245 | 277 |
246 // kResolverNotAFunction | 278 // kResolverNotAFunction |
247 test(function() { | 279 test(function() { |
248 new Promise(1); | 280 new Promise(1); |
249 }, "Promise resolver 1 is not a function", TypeError); | 281 }, "Promise resolver 1 is not a function", TypeError); |
250 | 282 |
| 283 // kStrictDeleteProperty |
| 284 test(function() { |
| 285 "use strict"; |
| 286 var o = {}; |
| 287 Object.defineProperty(o, "p", { value: 1, writable: false }); |
| 288 delete o.p; |
| 289 }, "Cannot delete property 'p' of #<Object>", TypeError); |
| 290 |
| 291 // kStrictPoisonPill |
| 292 test(function() { |
| 293 "use strict"; |
| 294 arguments.callee; |
| 295 }, "'caller', 'callee', and 'arguments' properties may not be accessed on " + |
| 296 "strict mode functions or the arguments objects for calls to them", |
| 297 TypeError); |
| 298 |
| 299 // kStrictReadOnlyProperty |
| 300 test(function() { |
| 301 "use strict"; |
| 302 (1).a = 1; |
| 303 }, "Cannot assign to read only property 'a' of 1", TypeError); |
| 304 |
| 305 // kStrongImplicitCast |
| 306 test(function() { |
| 307 "use strong"; |
| 308 "a" + 1; |
| 309 }, "In strong mode, implicit conversions are deprecated", TypeError); |
| 310 |
251 // kSymbolToPrimitive | 311 // kSymbolToPrimitive |
252 test(function() { | 312 test(function() { |
253 1 + Object(Symbol()); | 313 1 + Object(Symbol()); |
254 }, "Cannot convert a Symbol wrapper object to a primitive value", TypeError); | 314 }, "Cannot convert a Symbol wrapper object to a primitive value", TypeError); |
255 | 315 |
256 // kSymbolToString | 316 // kSymbolToString |
257 test(function() { | 317 test(function() { |
258 "" + Symbol(); | 318 "" + Symbol(); |
259 }, "Cannot convert a Symbol value to a string", TypeError); | 319 }, "Cannot convert a Symbol value to a string", TypeError); |
260 | 320 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 Number(1).toString(100); | 430 Number(1).toString(100); |
371 }, "toString() radix argument must be between 2 and 36", RangeError); | 431 }, "toString() radix argument must be between 2 and 36", RangeError); |
372 | 432 |
373 | 433 |
374 // === URIError === | 434 // === URIError === |
375 | 435 |
376 // kURIMalformed | 436 // kURIMalformed |
377 test(function() { | 437 test(function() { |
378 decodeURI("%%"); | 438 decodeURI("%%"); |
379 }, "URI malformed", URIError); | 439 }, "URI malformed", URIError); |
OLD | NEW |