]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/stress/unscopables.js
1 function test(actual
, expected
) {
2 if (actual
!== expected
)
3 throw new Error('bad value: ' + actual
);
8 var unscopables
= array
[Symbol
.unscopables
];
10 test(typeof unscopables
, "object");
11 test(unscopables
.__proto__
, undefined);
12 test(String(Object
.keys(unscopables
).sort()), "copyWithin,entries,fill,find,findIndex,keys,values");
17 var forEach
= "Hidden";
19 test(typeof array
.find
, "function");
22 test(typeof find
, "string");
24 test(typeof forEach
, "function");
25 test(__proto__
, Array
.prototype); // array's unscopables.__proto__ is undefined => false.
31 [Symbol
.unscopables
]: {
41 var Cappuccino
= "Cappuccino";
42 var toString
= "toString";
46 test(Cappuccino
, "Cappuccino");
47 test(toString
, "toString"); // object.toString is hidden by unscopables.toString.
50 object
[Symbol
.unscopables
].Cocoa
= true;
54 test(Cappuccino
, "Cappuccino");
59 var unscopables
= Object
.create(null);
60 unscopables
.Cocoa
= false;
61 unscopables
.Cappuccino
= true;
64 [Symbol
.unscopables
]: unscopables
,
71 var Cappuccino
= "Cappuccino";
72 var Matcha
= "Matcha";
73 var toString
= "toString";
77 test(Cappuccino
, "Cappuccino");
79 test(toString
, Object
.prototype.toString
);
82 object
[Symbol
.unscopables
].Cocoa
= true;
83 object
[Symbol
.unscopables
].Cappuccino
= false;
84 object
[Symbol
.unscopables
].toString
= true;
88 test(Cappuccino
, null);
89 test(toString
, "toString");
95 var proto
= Object
.create(null);
96 var unscopables
= Object
.create(proto
);
97 unscopables
.Cocoa
= false;
98 unscopables
.Cappuccino
= true;
101 [Symbol
.unscopables
]: unscopables
,
108 var Cappuccino
= "Cappuccino";
109 var Matcha
= "Matcha";
110 var toString
= "toString";
114 test(Cappuccino
, "Cappuccino");
116 test(toString
, Object
.prototype.toString
);
119 object
[Symbol
.unscopables
].Cocoa
= true;
120 object
[Symbol
.unscopables
].Cappuccino
= false;
121 object
[Symbol
.unscopables
].toString
= true;
124 test(Cocoa
, "Cocoa");
125 test(Cappuccino
, null);
126 test(toString
, "toString");
133 test(Cocoa
, "Cocoa");
134 test(Cappuccino
, null);
135 test(toString
, "toString");
136 test(Matcha
, "Matcha");
143 throw new Error("bad trap");
148 object
[Symbol
.unscopables
] = {
154 var Cappuccino
= "Cappuccino";
155 var toString
= "toString";
158 test(Cocoa
, "Cocoa");
161 object
[Symbol
.unscopables
].Cocoa
= false;
171 test(String(error
), "Error: bad trap");
178 Object
.defineProperty(object
, Symbol
.unscopables
, {
180 throw new Error("unscopables trap");
185 var Cappuccino
= "Cappuccino";
195 test(String(error
), "Error: unscopables trap");
198 test(Cappuccino
, "Cappuccino");
204 [Symbol
.unscopables
]: {
206 throw new Error("unscopables trap");
212 var Cappuccino
= "Cappuccino";
222 test(String(error
), "Error: unscopables trap");
225 test(Cappuccino
, "Cappuccino");
231 [Symbol
.unscopables
]: 42,