Debian Codegraph @

js/src/tests/test262/built-ins/Reflect/apply/arguments-list-is-not-array-like-but-still-valid.js

raw
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 Let len be ? LengthOfArrayLike(obj).
20 Let list be a new empty List.
21 Let index be 0.
22 Repeat, while index < len,
23 Let indexName be ! ToString(index).
24 Let next be ? Get(obj, indexName).
25 If Type(next) is not an element of elementTypes, throw a TypeError exception.
26 Append next as the last element of list.
27 Set index to index + 1.
28 Return list.
29 includes: [compareArray.js]
30 features: [Reflect, arrow-function, Symbol]
31 ---*/
32
33 let count = 0;
34
35 function fn(...args) {
36 count++;
37 return args;
38 }
39
40 let f_unction = new Function();
41
42 Object.defineProperty(f_unction, "length", {
43 get() {
44 return 1;
45 }
46 });
47
48 assert.compareArray(Reflect.apply(fn, null, f_unction), [undefined]);
49
50 let object = new Object();
51
52 Object.defineProperty(object, "length", {
53 get() {
54 return 1;
55 }
56 });
57
58 assert.compareArray(Reflect.apply(fn, null, object), [undefined]);
59
60 let number = new Number();
61
62 Object.defineProperty(number, "length", {
63 get() {
64 return 1;
65 }
66 });
67
68 assert.compareArray(Reflect.apply(fn, null, number), [undefined]);
69
70 let boolean = new Boolean();
71
72 Object.defineProperty(boolean, "length", {
73 get() {
74 return 1;
75 }
76 });
77
78 assert.compareArray(Reflect.apply(fn, null, boolean), [undefined]);
79
80 assert.sameValue(count, 4, 'The value of `count` is 1');
81
82 reportCompare(0, 0);