testDirectProxyOwnKeysSymbol.js (1158B)
1 // Make sure that we can find own, enumerable symbols. 2 var symbol = Symbol("bad"); 3 var symbol2 = Symbol("good"); 4 var proxy = new Proxy({}, { 5 ownKeys() { 6 return [symbol, symbol2]; 7 }, 8 getOwnPropertyDescriptor(target, name) { 9 if (name == symbol) 10 return {configurable: true, enumerable: false, value: {}}; 11 // Only this enumerable symbol should be defined. 12 if (name == symbol2) 13 return {configurable: true, enumerable: true, value: {}}; 14 assertEq(true, false); 15 }, 16 get(target, name) { 17 // Slightly confusing, but these are the descriptors that defineProperties 18 // is going to define on the object. 19 if (name == symbol) 20 return {configurable: true, value: "bad"}; 21 if (name == symbol2) 22 return {configurable: true, value: "good"}; 23 assertEq(true, false); 24 } 25 }); 26 assertEq(Object.getOwnPropertySymbols(proxy).length, 2); 27 28 var obj = {}; 29 Object.defineProperties(obj, proxy); 30 assertEq(Object.getOwnPropertySymbols(obj).length, 1); 31 assertEq(symbol in obj, false); 32 assertEq(symbol2 in obj, true); 33 assertEq(obj[symbol2], "good");