arguments-list-is-not-array-like.js (2207B)
1 // Copyright (C) 2015 the V8 project authors. All rights reserved. 2 // Copyright (C) 2020 Rick Waldron. All rights reserved. 3 // This code is governed by the BSD license found in the LICENSE file. 4 /*--- 5 esid: sec-reflect.apply 6 description: > 7 Return abrupt if argumentsList is not an ArrayLike object. 8 info: | 9 Reflect.apply ( target, thisArgument, argumentsList ) 10 11 ... 12 Let args be ? CreateListFromArrayLike(argumentsList). 13 14 15 CreateListFromArrayLike (obj [, elementTypes] ) 16 17 ... 18 If Type(obj) is not Object, throw a TypeError exception. 19 features: [Reflect, arrow-function, Symbol] 20 ---*/ 21 22 let count = 0; 23 24 function fn() { 25 count++; 26 } 27 28 assert.throws(Test262Error, () => { 29 Reflect.apply(fn, null, { 30 get length() { 31 throw new Test262Error(); 32 } 33 }); 34 }, '`Reflect.apply(fn, null, {get length() {throw new Test262Error();}})` throws a Test262Error exception'); 35 36 assert.throws(TypeError, () => { 37 Reflect.apply(fn, null /* empty */); 38 }, '`Reflect.apply(fn, null /* empty */)` throws a TypeError exception'); 39 40 assert.throws(TypeError, () => { 41 Reflect.apply(fn, null, Symbol()); 42 }, '`Reflect.apply(fn, null, Symbol())` throws a TypeError exception'); 43 44 assert.throws(TypeError, () => { 45 Reflect.apply(fn, null, 1); 46 }, '`Reflect.apply(fn, null, 1)` throws a TypeError exception'); 47 48 assert.throws(TypeError, () => { 49 Reflect.apply(fn, null, Infinity); 50 }, '`Reflect.apply(fn, null, Infinity)` throws a TypeError exception'); 51 52 assert.throws(TypeError, () => { 53 Reflect.apply(fn, null, null); 54 }, '`Reflect.apply(fn, null, null)` throws a TypeError exception'); 55 56 assert.throws(TypeError, () => { 57 Reflect.apply(fn, null, undefined); 58 }, '`Reflect.apply(fn, null, undefined)` throws a TypeError exception'); 59 60 assert.throws(TypeError, () => { 61 Reflect.apply(fn, null, false); 62 }, '`Reflect.apply(fn, null, false)` throws a TypeError exception'); 63 64 assert.throws(TypeError, () => { 65 Reflect.apply(fn, null, true); 66 }, '`Reflect.apply(fn, null, true)` throws a TypeError exception'); 67 68 assert.throws(TypeError, () => { 69 Reflect.apply(fn, null, NaN); 70 }, '`Reflect.apply(fn, null, NaN)` throws a TypeError exception'); 71 72 73 assert.sameValue(count, 0, 'The value of `count` is 0'); 74 75 reportCompare(0, 0);