]>
Commit | Line | Data |
---|---|---|
ed1e77d3 A |
1 | // This tests Object.getOwnPropertySymbols. |
2 | ||
3 | var global = (Function("return this")()); | |
4 | ||
5 | // private names for privileged code should not be exposed. | |
6 | if (Object.getOwnPropertySymbols(global).length !== 0) | |
7 | throw "Error: bad value " + Object.getOwnPropertySymbols(global).length; | |
8 | ||
9 | var object = {}; | |
10 | var symbol = Symbol("Cocoa"); | |
11 | object[symbol] = "Cappuccino"; | |
12 | if (Object.getOwnPropertyNames(object).length !== 0) | |
13 | throw "Error: bad value " + Object.getOwnPropertyNames(object).length; | |
14 | if (Object.getOwnPropertySymbols(object).length !== 1) | |
15 | throw "Error: bad value " + Object.getOwnPropertySymbols(object).length; | |
16 | if (Object.getOwnPropertySymbols(object)[0] !== symbol) | |
17 | throw "Error: bad value " + String(Object.getOwnPropertySymbols(object)[0]); | |
18 | ||
19 | function forIn(obj) { | |
20 | var array = []; | |
21 | // Symbol should not be enumerated. | |
22 | for (var key in obj) array.push(key); | |
23 | return array; | |
24 | } | |
25 | ||
26 | if (forIn(object).length !== 0) | |
27 | throw "Error: bad value " + forIn(object).length; | |
28 | if (Object.keys(object).length !== 0) | |
29 | throw "Error: bad value " + Object.keys(object).length; | |
30 | ||
31 | delete object[symbol]; | |
32 | if (Object.getOwnPropertyNames(object).length !== 0) | |
33 | throw "Error: bad value " + Object.getOwnPropertyNames(object).length; | |
34 | if (Object.getOwnPropertySymbols(object).length !== 0) | |
35 | throw "Error: bad value " + Object.getOwnPropertySymbols(object).length; |