Bug 799272: Implement Debugger.Object.prototype.global. r=luke

This commit is contained in:
Jim Blandy 2012-10-13 16:04:16 -07:00
parent 4e37e1c2f8
commit 520b89592a
3 changed files with 64 additions and 0 deletions

View File

@ -0,0 +1,26 @@
// Debugger.Object.prototype.global accessor surfaces.
load(libdir + 'asserts.js');
var dbg = new Debugger;
var g = newGlobal();
var gw = dbg.addDebuggee(g);
assertEq(Object.getOwnPropertyDescriptor(gw, 'global'), undefined);
var d = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(gw), 'global');
assertEq(d.enumerable, false);
assertEq(d.configurable, true);
assertEq(typeof d.get, "function");
assertEq(d.get.length, 0);
assertEq(d.set, undefined);
// This should not throw.
gw.global = '';
// This should throw.
assertThrowsInstanceOf(function () { "use strict"; gw.global = {}; }, TypeError);
assertEq(gw.global, gw);
// You shouldn't be able to apply the accessor to the prototype.
assertThrowsInstanceOf(function () { return Debugger.Object.prototype.global; },
TypeError);

View File

@ -0,0 +1,25 @@
// Debugger.Object.prototype.global retrieves the correct global.
var dbg = new Debugger;
var g1 = newGlobal();
var g1w = dbg.addDebuggee(g1);
var g2 = newGlobal();
var g2w = dbg.addDebuggee(g2);
assertEq(g1w === g2w, false);
assertEq(g1w.global, g1w);
assertEq(g2w.global, g2w);
var g1ow = g1w.makeDebuggeeValue(g1.Object());
var g2ow = g2w.makeDebuggeeValue(g2.Object());
assertEq(g1ow.global, g1w);
assertEq(g2ow.global, g2w);
// mild paranoia
assertEq(g1ow.global === g1ow, false);
assertEq(g2ow.global === g2ow, false);
// The .global accessor doesn't unwrap.
assertEq(g1w.makeDebuggeeValue(g2.Object()).global, g1w);
assertEq(g2w.makeDebuggeeValue(g1.Object()).global, g2w);

View File

@ -3827,6 +3827,18 @@ DebuggerObject_getEnvironment(JSContext *cx, unsigned argc, Value *vp)
return dbg->wrapEnvironment(cx, env, args.rval().address());
}
static JSBool
DebuggerObject_getGlobal(JSContext *cx, unsigned argc, Value *vp)
{
THIS_DEBUGOBJECT_OWNER_REFERENT(cx, argc, vp, "get global", args, dbg, obj);
Value v = ObjectValue(obj->global());
if (!dbg->wrapDebuggeeValue(cx, &v))
return false;
args.rval().set(v);
return true;
}
static JSBool
DebuggerObject_getOwnPropertyDescriptor(JSContext *cx, unsigned argc, Value *vp)
{
@ -4275,6 +4287,7 @@ static JSPropertySpec DebuggerObject_properties[] = {
JS_PSG("parameterNames", DebuggerObject_getParameterNames, 0),
JS_PSG("script", DebuggerObject_getScript, 0),
JS_PSG("environment", DebuggerObject_getEnvironment, 0),
JS_PSG("global", DebuggerObject_getGlobal, 0),
JS_PS_END
};