]>
Commit | Line | Data |
---|---|---|
ed1e77d3 A |
1 | // This tests Object.create, Object.defineProperty, Object.defineProperties work with Symbol. |
2 | ||
3 | function testSymbol(object) { | |
4 | if (!object.hasOwnProperty(Symbol.iterator)) | |
5 | throw "Error: object doesn't have Symbol.iterator"; | |
6 | if (object.propertyIsEnumerable(Symbol.iterator)) | |
7 | throw "Error: Symbol.iterator is defined as enumerable"; | |
8 | if (JSON.stringify(Object.getOwnPropertyDescriptor(object, Symbol.iterator)) !== '{"value":42,"writable":false,"enumerable":false,"configurable":false}') | |
9 | throw "Error: bad property descriptor " + JSON.stringify(Object.getOwnPropertyDescriptor(object, Symbol.iterator)); | |
10 | if (Object.getOwnPropertySymbols(object).length !== 1) | |
11 | throw "Error: bad value " + Object.getOwnPropertySymbols(object).length; | |
12 | if (Object.getOwnPropertySymbols(object)[0] !== Symbol.iterator) | |
13 | throw "Error: bad value " + String(Object.getOwnPropertySymbols(object)[0]); | |
14 | } | |
15 | ||
16 | var object = Object.create(Object.prototype, { | |
17 | [Symbol.iterator]: { | |
18 | value: 42 | |
19 | } | |
20 | }); | |
21 | testSymbol(object); | |
22 | ||
23 | var object = Object.defineProperties({}, { | |
24 | [Symbol.iterator]: { | |
25 | value: 42 | |
26 | } | |
27 | }); | |
28 | testSymbol(object); | |
29 | ||
30 | var object = Object.defineProperty({}, Symbol.iterator, { | |
31 | value: 42 | |
32 | }); | |
33 | testSymbol(object); |