Object-getOwnPropertySymbols-01.js (1390B)
1 // Basic getOwnPropertSymbols tests. 2 3 var g = newGlobal({newCompartment: true}); 4 var dbg = Debugger(); 5 var gobj = dbg.addDebuggee(g); 6 7 function test(code) { 8 code = "(" + code + ");"; 9 var expected = Object.getOwnPropertySymbols(eval(code)); 10 g.eval("obj = " + code); 11 var actual = gobj.getOwnPropertyDescriptor("obj").value.getOwnPropertySymbols(); 12 13 assertEq(JSON.stringify(actual.map((x) => x.toString()).sort()), 14 JSON.stringify(expected.map((x) => x.toString()).sort())); 15 } 16 17 test("{}"); 18 test("Array.prototype"); // Symbol.iterator 19 test("Object.create(null)"); 20 test("(function() {let x = Symbol(); let o = {}; o[x] = 1; return o;})()"); 21 test("(function() {let x = Symbol('foo'); let o = {}; o[x] = 1; return o;})()"); 22 test("(function() {let x = Symbol('foo'); let y = Symbol('bar'); \ 23 let o = {}; o[x] = 1; o[y] = 2; return o;})()"); 24 test("(function() {let x = Symbol('foo with spaces'); \ 25 let o = {}; o[x] = 1; return o;})()"); 26 test("(function() {let x = Symbol('foo'); \ 27 let o = function(){}; o[x] = 1; return o;})()"); 28 test("(function() {let x = Symbol('foo'); \ 29 let o = Object.create(null); o[x] = 1; return o;})()"); 30 test("(function() {let x = Symbol('foo'); \ 31 let o = new Array(); o[x] = 1; return o;})()"); 32 test("(function() {let x = Symbol('foo'); \ 33 let o = {}; o[x] = 1; delete o[x]; return o;})()");