Object-getOwnPropertyNamesLength.js (1350B)
1 // Basic getOwnPropertyNamesLength tests. 2 3 var g = newGlobal({ newCompartment: true }); 4 var dbg = Debugger(); 5 var gobj = dbg.addDebuggee(g); 6 7 function testGetOwnPropertyLength(code) { 8 code = `(${code});`; 9 const expected = Object.getOwnPropertyNames(eval(code)).length; 10 g.eval(`obj = ${code}`); 11 const length = gobj 12 .getOwnPropertyDescriptor("obj") 13 .value.getOwnPropertyNamesLength(); 14 assertEq(length, expected, `Expected result for: ${code}`); 15 } 16 17 testGetOwnPropertyLength("{}"); 18 testGetOwnPropertyLength("{a: 0, b: 1}"); 19 testGetOwnPropertyLength("{'name with space': 0}"); 20 testGetOwnPropertyLength("{get x() {}, set y(v) {}}"); 21 testGetOwnPropertyLength("{get x() { throw 'fit'; }}"); 22 testGetOwnPropertyLength("Object.create({a: 1})"); 23 testGetOwnPropertyLength("Object.create({get a() {}, set a(v) {}})"); 24 testGetOwnPropertyLength( 25 "(function () { var x = {a: 0, b: 1}; delete a; return x; })()" 26 ); 27 testGetOwnPropertyLength("Object.create(null, {x: {value: 0}})"); 28 testGetOwnPropertyLength("[]"); 29 testGetOwnPropertyLength("[0, 1, 2]"); 30 testGetOwnPropertyLength("[,,,,,]"); 31 testGetOwnPropertyLength("/a*a/"); 32 testGetOwnPropertyLength("function () {}"); 33 testGetOwnPropertyLength( 34 `(function () { 35 var x = {}; 36 x[Symbol()] = 1; 37 x[Symbol.for('moon')] = 2; 38 x[Symbol.iterator] = 3; 39 return x; 40 })()` 41 );