]> git.saurik.com Git - apple/javascriptcore.git/blame - tests/stress/symbol-define-property.js
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / tests / stress / symbol-define-property.js
CommitLineData
ed1e77d3
A
1// This tests Object.create, Object.defineProperty, Object.defineProperties work with Symbol.
2
3function 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
16var object = Object.create(Object.prototype, {
17 [Symbol.iterator]: {
18 value: 42
19 }
20});
21testSymbol(object);
22
23var object = Object.defineProperties({}, {
24 [Symbol.iterator]: {
25 value: 42
26 }
27});
28testSymbol(object);
29
30var object = Object.defineProperty({}, Symbol.iterator, {
31 value: 42
32});
33testSymbol(object);