Bug 1035973 - Add DebuggerObject.getOwnPropertySymbols; r=fitzgen

--HG--
extra : rebase_source : 366d863b827cd82f75edbc4992f7f040f2e9c835
This commit is contained in:
Manish Goregaokar 2015-06-16 09:30:00 +02:00
parent 5e589d88a4
commit be8b70fa10
5 changed files with 72 additions and 7 deletions

View File

@ -248,6 +248,12 @@ code), the call throws a [`Debugger.DebuggeeWouldRun`][wouldrun] exception.
called in the debuggee, and the result copied in the scope of the
debugger's global object.
`getOwnPropertySymbols()`
: Return an array of strings naming all the referent's own symbols, as
if <code>Object.getOwnPropertySymbols(<i>referent</i>)</code> had been
called in the debuggee, and the result copied in the scope of the
debugger's global object.
<code>defineProperty(<i>name</i>, <i>attributes</i>)</code>
: Define a property on the referent named <i>name</i>, as described by
the property descriptor <i>descriptor</i>. Any `value`, `get`, and

View File

@ -9,4 +9,3 @@ var wp = gobj.getOwnPropertyDescriptor("p").value;
var names = wp.getOwnPropertyNames();
assertEq(names.length, 1);
assertEq(names[0], "xyzzy");

View File

@ -0,0 +1,33 @@
// Basic getOwnPropertSymbols tests.
var g = newGlobal();
var dbg = Debugger();
var gobj = dbg.addDebuggee(g);
function test(code) {
code = "(" + code + ");";
var expected = Object.getOwnPropertySymbols(eval(code));
g.eval("obj = " + code);
var actual = gobj.getOwnPropertyDescriptor("obj").value.getOwnPropertySymbols();
assertEq(JSON.stringify(actual.map((x) => x.toString()).sort()),
JSON.stringify(expected.map((x) => x.toString()).sort()));
}
test("{}");
test("Array.prototype"); // Symbol.iterator
test("Object.create(null)");
test("(function() {let x = Symbol(); let o = {}; o[x] = 1; return o;})()");
test("(function() {let x = Symbol('foo'); let o = {}; o[x] = 1; return o;})()");
test("(function() {let x = Symbol('foo'); let y = Symbol('bar'); \
let o = {}; o[x] = 1; o[y] = 2; return o;})()");
test("(function() {let x = Symbol('foo with spaces'); \
let o = {}; o[x] = 1; return o;})()");
test("(function() {let x = Symbol('foo'); \
let o = function(){}; o[x] = 1; return o;})()");
test("(function() {let x = Symbol('foo'); \
let o = Object.create(null); o[x] = 1; return o;})()");
test("(function() {let x = Symbol('foo'); \
let o = new Array(); o[x] = 1; return o;})()");
test("(function() {let x = Symbol('foo'); \
let o = {}; o[x] = 1; delete o[x]; return o;})()");

View File

@ -0,0 +1,12 @@
// obj.getOwnPropertySymbols() works when obj's referent is itself a cross-compartment wrapper.
var g = newGlobal();
var dbg = Debugger();
var gobj = dbg.addDebuggee(g);
g.p = {xyzzy: 8}; // makes a cross-compartment wrapper
var sym = Symbol("plugh");
g.p[sym] = 9;
var wp = gobj.getOwnPropertyDescriptor("p").value;
var names = wp.getOwnPropertySymbols();
assertEq(names.length, 1);
assertEq(names[0], sym);

View File

@ -6937,17 +6937,17 @@ DebuggerObject_getOwnPropertyDescriptor(JSContext* cx, unsigned argc, Value* vp)
return FromPropertyDescriptor(cx, desc, args.rval());
}
static bool
DebuggerObject_getOwnPropertyNames(JSContext* cx, unsigned argc, Value* vp)
{
THIS_DEBUGOBJECT_REFERENT(cx, argc, vp, "getOwnPropertyNames", args, obj);
static bool
getOwnPropertyKeys(JSContext* cx, unsigned argc, unsigned flags, Value* vp)
{
THIS_DEBUGOBJECT_REFERENT(cx, argc, vp, "getOwnPropertyKeys", args, obj);
AutoIdVector keys(cx);
{
Maybe<AutoCompartment> ac;
ac.emplace(cx, obj);
ErrorCopier ec(ac);
if (!GetPropertyKeys(cx, obj, JSITER_OWNONLY | JSITER_HIDDEN, &keys))
if (!GetPropertyKeys(cx, obj, flags, &keys))
return false;
}
@ -6964,8 +6964,10 @@ DebuggerObject_getOwnPropertyNames(JSContext* cx, unsigned argc, Value* vp)
vals[i].setString(str);
} else if (JSID_IS_ATOM(id)) {
vals[i].setString(JSID_TO_STRING(id));
} else if (JSID_IS_SYMBOL(id)) {
vals[i].setSymbol(JSID_TO_SYMBOL(id));
} else {
MOZ_ASSERT_UNREACHABLE("GetPropertyKeys must return only string and int jsids");
MOZ_ASSERT_UNREACHABLE("GetPropertyKeys must return only string, int, and Symbol jsids");
}
}
@ -6976,6 +6978,18 @@ DebuggerObject_getOwnPropertyNames(JSContext* cx, unsigned argc, Value* vp)
return true;
}
static bool
DebuggerObject_getOwnPropertyNames(JSContext* cx, unsigned argc, Value* vp) {
return getOwnPropertyKeys(cx, argc, JSITER_OWNONLY | JSITER_HIDDEN, vp);
}
static bool
DebuggerObject_getOwnPropertySymbols(JSContext* cx, unsigned argc, Value* vp) {
return getOwnPropertyKeys(cx, argc,
JSITER_OWNONLY | JSITER_HIDDEN | JSITER_SYMBOLS | JSITER_SYMBOLSONLY,
vp);
}
static bool
DebuggerObject_defineProperty(JSContext* cx, unsigned argc, Value* vp)
{
@ -7408,6 +7422,7 @@ static const JSPropertySpec DebuggerObject_properties[] = {
static const JSFunctionSpec DebuggerObject_methods[] = {
JS_FN("getOwnPropertyDescriptor", DebuggerObject_getOwnPropertyDescriptor, 1, 0),
JS_FN("getOwnPropertyNames", DebuggerObject_getOwnPropertyNames, 0, 0),
JS_FN("getOwnPropertySymbols", DebuggerObject_getOwnPropertySymbols, 0, 0),
JS_FN("defineProperty", DebuggerObject_defineProperty, 2, 0),
JS_FN("defineProperties", DebuggerObject_defineProperties, 1, 0),
JS_FN("deleteProperty", DebuggerObject_deleteProperty, 1, 0),