Bug 1338914 - Optimize hidden/internal script detection for devtools. r?shu
MozReview-Commit-ID: JT1TJtJUGrq
--- a/devtools/server/actors/utils/TabSources.js
+++ b/devtools/server/actors/utils/TabSources.js
@@ -796,18 +796,17 @@ TabSources.prototype = {
}
};
/*
* Checks if a source should never be displayed to the user because
* it's either internal or we don't support in the UI yet.
*/
function isHiddenSource(source) {
- // Ignore the internal Function.prototype script
- return source.text === "() {\n}";
+ return source.introductionType === "Function.prototype";
}
/**
* Returns true if its argument is not null.
*/
function isNotNull(thing) {
return thing !== null;
}
--- a/js/src/doc/Debugger/Debugger.Source.md
+++ b/js/src/doc/Debugger/Debugger.Source.md
@@ -151,16 +151,18 @@ from its prototype:
: **If the instance refers to JavaScript source**, a string indicating how
this source code was introduced into the system. This accessor returns
one of the following values:
* `"eval"`, for code passed to `eval`.
* `"Function"`, for code passed to the `Function` constructor.
+ * `"Function.prototype"`, for `Function.prototype` internally generated code.
+
* `"Worker"`, for code loaded by calling the Web worker constructor—the
worker's main script.
* `"importScripts"`, for code by calling `importScripts` in a web worker.
* `"eventHandler"`, for code assigned to DOM elements' event handler IDL
attributes as a string.
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/debug/bug1338914.js
@@ -0,0 +1,11 @@
+// In a debuggee, the Function.prototype script source has the introductionType
+// property set to "Function.prototype".
+
+var g = newGlobal();
+var dbg = new Debugger(g);
+var scripts = dbg.findScripts();
+assertEq(scripts.length > 0, true);
+var fpScripts = scripts.filter(s => s.source.introductionType == "Function.prototype");
+assertEq(fpScripts.length, 1);
+var source = fpScripts[0].source;
+assertEq(source.text, "() {\n}");
--- a/js/src/jsfun.cpp
+++ b/js/src/jsfun.cpp
@@ -849,18 +849,21 @@ CreateFunctionPrototype(JSContext* cx, J
ScriptSource* ss = cx->new_<ScriptSource>();
if (!ss)
return nullptr;
ScriptSourceHolder ssHolder(ss);
if (!ss->setSource(cx, mozilla::Move(source), sourceLen))
return nullptr;
CompileOptions options(cx);
- options.setNoScriptRval(true)
+ options.setIntroductionType("Function.prototype")
+ .setNoScriptRval(true)
.setVersion(JSVERSION_DEFAULT);
+ if (!ss->initFromOptions(cx, options))
+ return nullptr;
RootedScriptSource sourceObject(cx, ScriptSourceObject::create(cx, ss));
if (!sourceObject || !ScriptSourceObject::initFromOptions(cx, sourceObject, options))
return nullptr;
RootedScript script(cx, JSScript::Create(cx,
options,
sourceObject,
0,