Bug 933460 - part 0: add 'displayURL' filtering to Debugger.prototype.findScripts; r=ejpbruel

This commit is contained in:
Nick Fitzgerald 2014-01-07 10:17:39 -08:00
parent 466ccf73ee
commit c5c169f211
3 changed files with 81 additions and 5 deletions

View File

@ -0,0 +1,39 @@
// In a debuggee with multiple scripts with varying displayURLs (aka //#
// sourceURL), findScripts can filter by displayURL.
var g = newGlobal();
g.eval("function f(){} //# sourceURL=f.js");
g.eval("function g(){} //# sourceURL=g.js");
g.eval("function h(){}");
var dbg = new Debugger();
var gw = dbg.addDebuggee(g);
var fw = gw.makeDebuggeeValue(g.f);
var ggw = gw.makeDebuggeeValue(g.g);
var hw = gw.makeDebuggeeValue(g.h);
var fScripts = dbg.findScripts({ displayURL: "f.js" });
assertEq(fScripts.indexOf(fw.script) != -1, true);
assertEq(fScripts.indexOf(ggw.script), -1);
assertEq(fScripts.indexOf(hw.script), -1);
var gScripts = dbg.findScripts({ displayURL: "g.js" });
assertEq(gScripts.indexOf(ggw.script) != -1, true);
assertEq(gScripts.indexOf(fw.script), -1);
assertEq(gScripts.indexOf(hw.script), -1);
var allScripts = dbg.findScripts();
assertEq(allScripts.indexOf(fw.script) != -1, true);
assertEq(allScripts.indexOf(ggw.script) != -1, true);
assertEq(allScripts.indexOf(hw.script) != -1, true);
try {
dbg.findScripts({ displayURL: 3 });
// Should never get here because the above line should throw
// JSMSG_UNEXPECTED_TYPE.
assertEq(true, false);
} catch(e) {
assertEq(e.name, "TypeError");
assertEq(e.message.contains("displayURL"), true);
}

View File

@ -52,6 +52,7 @@
macro(defineSetter, defineSetter, "__defineSetter__") \
macro(delete, delete_, "delete") \
macro(deleteProperty, deleteProperty, "deleteProperty") \
macro(displayURL, displayURL, "displayURL") \
macro(done, done, "done") \
macro(each, each, "each") \
macro(elementType, elementType, "elementType") \

View File

@ -2321,8 +2321,8 @@ class Debugger::ScriptQuery {
public:
/* Construct a ScriptQuery to use matching scripts for |dbg|. */
ScriptQuery(JSContext *cx, Debugger *dbg):
cx(cx), debugger(dbg), compartments(cx->runtime()), url(cx),
innermostForCompartment(cx->runtime())
cx(cx), debugger(dbg), compartments(cx->runtime()), url(cx), sourceURL(cx),
sourceURLChars(nullptr), innermostForCompartment(cx->runtime())
{}
/*
@ -2419,6 +2419,16 @@ class Debugger::ScriptQuery {
}
}
/* Check for a 'displayURL' property. */
if (!JSObject::getProperty(cx, query, query, cx->names().displayURL, &sourceURL))
return false;
if (!sourceURL.isUndefined() && !sourceURL.isString()) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, nullptr, JSMSG_UNEXPECTED_TYPE,
"query object's 'displayURL' property",
"neither undefined nor a string");
return false;
}
return true;
}
@ -2427,6 +2437,7 @@ class Debugger::ScriptQuery {
url.setUndefined();
hasLine = false;
innermost = false;
sourceURLChars = nullptr;
return matchAllDebuggeeGlobals();
}
@ -2490,6 +2501,14 @@ class Debugger::ScriptQuery {
/* url as a C string. */
JSAutoByteString urlCString;
/* If this is a string, matching scripts' sources have sourceURLs equal to
* it. */
RootedValue sourceURL;
/* sourceURL as a jschar* */
const jschar *sourceURLChars;
size_t sourceURLLength;
/* True if the query contained a 'line' property. */
bool hasLine;
@ -2553,15 +2572,23 @@ class Debugger::ScriptQuery {
}
/*
* Given that parseQuery or omittedQuery has been called, prepare to
* match scripts. Set urlCString as appropriate.
* Given that parseQuery or omittedQuery has been called, prepare to match
* scripts. Set urlCString and sourceURLChars as appropriate.
*/
bool prepareQuery() {
/* Compute urlCString, if a url was given. */
/* Compute urlCString and sourceURLChars, if a url or sourceURL was
* given respectively. */
if (url.isString()) {
if (!urlCString.encodeLatin1(cx, url.toString()))
return false;
}
if (sourceURL.isString()) {
JSString *s = sourceURL.toString();
sourceURLChars = s->getChars(cx);
sourceURLLength = s->length();
if (!sourceURLChars)
return false;
}
return true;
}
@ -2590,6 +2617,15 @@ class Debugger::ScriptQuery {
if (line < script->lineno() || script->lineno() + js_GetScriptLineExtent(script) < line)
return;
}
if (sourceURLChars) {
if (!script->scriptSource() || !script->scriptSource()->hasSourceURL())
return;
const jschar *s = script->scriptSource()->sourceURL();
if (CompareChars(s, js_strlen(s), sourceURLChars, sourceURLLength) != 0) {
return;
}
}
if (innermost) {
/*
* For 'innermost' queries, we don't place scripts in |vector| right