]> git.saurik.com Git - apple/javascriptcore.git/blob - tests/stress/object-get-own-property-descriptor-perform-to-object.js
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / tests / stress / object-get-own-property-descriptor-perform-to-object.js
1 var primitives = [
2 ["string", 6],
3 [42, undefined],
4 [Symbol("symbol"), undefined],
5 [true, undefined],
6 [false, undefined]
7 ];
8
9 for (var [primitive, expected] of primitives) {
10 var ret = Object.getOwnPropertyDescriptor(primitive, 'length');
11 if (expected === undefined) {
12 if (ret !== expected)
13 throw new Error("bad value for " + String(primitive) + ": " + String(ret));
14 } else if (ret.value !== expected)
15 throw new Error("bad value for " + String(primitive) + ": " + String(ret));
16 }
17
18 function canary() {
19 return {
20 called: false,
21 toString() {
22 this.called = true;
23 throw new Error("out");
24 }
25 };
26 }
27
28 [
29 [ null, "TypeError: null is not an object (evaluating 'Object.getOwnPropertyDescriptor(value, property)')" ],
30 [ undefined, "TypeError: undefined is not an object (evaluating 'Object.getOwnPropertyDescriptor(value, property)')" ]
31 ].forEach(function ([value, message]) {
32 var property = canary();
33 var error = null;
34 try {
35 Object.getOwnPropertyDescriptor(value, property);
36 } catch (e) {
37 error = e;
38 }
39 if (!error)
40 throw new Error("error not thrown");
41 if (String(error) !== message)
42 throw new Error("bad error: " + String(error));
43 });