Bug 958646: Implement Debugger.Script.prototype.global accessor. r=sfink

This commit is contained in:
Jim Blandy 2014-01-22 16:55:12 -08:00
parent 1966bd11ff
commit 075e271ed0
5 changed files with 123 additions and 0 deletions

View File

@ -0,0 +1,20 @@
// Debugger.Script.prototype.script returns the global the script runs in.
var g = newGlobal();
var dbg = new Debugger;
var gw = dbg.addDebuggee(g);
var log = '';
dbg.onDebuggerStatement = function (frame) {
log += 'd';
assertEq(frame.script.global, gw);
}
g.eval('debugger;');
assertEq(log, 'd');
g.eval('function f() { debugger; }');
g.f();
assertEq(log, 'dd');
assertEq(gw.getOwnPropertyDescriptor('f').value.global, gw);

View File

@ -0,0 +1,40 @@
// Debugger.Script.prototype.script returns the global the script runs in.
// Multi-global version.
var dbg = new Debugger;
var g1 = newGlobal();
var g1w = dbg.addDebuggee(g1);
var g2 = newGlobal();
var g2w = dbg.addDebuggee(g2);
var g3 = newGlobal();
var g3w = dbg.addDebuggee(g3);
var log = '';
dbg.onDebuggerStatement = function (frame) {
log += 'd';
assertEq(frame.script.global, g1w);
assertEq(frame.older.script.global, g2w);
assertEq(frame.older.older.script.global, g3w);
assertEq(frame.older.older.older.script.global, g1w);
}
g1.eval('function f() { debugger; }');
g2.g1 = g1;
g2.eval('function g() { g1.f(); }');
g3.g2 = g2;
g3.eval('function h() { g2.g(); }');
g1.g3 = g3;
g1.eval('function i() { g3.h(); }');
g1.i();
assertEq(log, 'd');
assertEq(g1w.getOwnPropertyDescriptor('f').value.global, g1w);
assertEq(g2w.getOwnPropertyDescriptor('g').value.global, g2w);
assertEq(g3w.getOwnPropertyDescriptor('h').value.global, g3w);

View File

@ -3003,6 +3003,19 @@ DebuggerScript_getSourceMapUrl(JSContext *cx, unsigned argc, Value *vp)
return true;
}
static bool
DebuggerScript_getGlobal(JSContext *cx, unsigned argc, Value *vp)
{
THIS_DEBUGSCRIPT_SCRIPT(cx, argc, vp, "(get global)", args, obj, script);
Debugger *dbg = Debugger::fromChildJSObject(obj);
RootedValue v(cx, ObjectValue(script->global()));
if (!dbg->wrapDebuggeeValue(cx, &v))
return false;
args.rval().set(v);
return true;
}
static bool
DebuggerScript_getChildScripts(JSContext *cx, unsigned argc, Value *vp)
{
@ -3666,6 +3679,7 @@ static const JSPropertySpec DebuggerScript_properties[] = {
JS_PSG("sourceLength", DebuggerScript_getSourceLength, 0),
JS_PSG("staticLevel", DebuggerScript_getStaticLevel, 0),
JS_PSG("sourceMapURL", DebuggerScript_getSourceMapUrl, 0),
JS_PSG("global", DebuggerScript_getGlobal, 0),
JS_PS_END
};

View File

@ -9,6 +9,7 @@ support-files =
large-image.jpg
small-image.gif
[test_Debugger.Script.prototype.global.html]
[test_connection-manager.html]
[test_device.html]
[test_inspector-changeattrs.html]

View File

@ -0,0 +1,48 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=958646
Debugger.Script.prototype.global should return innerize globals, not WindowProxies.
-->
<head>
<meta charset="utf-8">
<title>Debugger.Script.prototype.global should return inner windows</title>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
</head>
<body>
<pre id="test">
<script>
Components.utils.import("resource://gre/modules/jsdebugger.jsm");
addDebuggerToGlobal(this);
window.onload = function () {
SimpleTest.waitForExplicitFinish();
var iframe = document.createElement("iframe");
iframe.src = "data:text/html,<script>function glorp() { }<\/script>";
iframe.onload = firstOnLoadHandler;
document.body.appendChild(iframe);
function firstOnLoadHandler() {
var dbg = new Debugger;
var iframeDO = dbg.addDebuggee(iframe.contentWindow);
// For sanity: check that the debuggee global is the inner window,
// and that the outer window gets a distinct D.O.
var iframeWindowProxyDO = iframeDO.makeDebuggeeValue(iframe.contentWindow);
ok(iframeDO !== iframeWindowProxyDO);
// The real test: Debugger.Script.prototype.global returns inner windows.
ok(iframeDO.getOwnPropertyDescriptor('glorp').value.script.global === iframeDO);
SimpleTest.finish();
}
}
</script>
</pre>
</body>
</html>