Bug 1338914 - Optimize hidden/internal script detection for devtools. r?shu draft
authorYury Delendik <ydelendik@mozilla.com>
Wed, 22 Feb 2017 12:25:36 -0600
changeset 492201 a4c1bf8954456eaae17141bd6dd537851bb3deb1
parent 492009 d29f84406483c721a13cf9a52936ecced0c5c98a
child 547677 9295f7c0dd0e0f8dcb7782c920e8bc1e9bf36f40
push id47557
push userydelendik@mozilla.com
push dateThu, 02 Mar 2017 22:24:24 +0000
reviewersshu
bugs1338914
milestone54.0a1
Bug 1338914 - Optimize hidden/internal script detection for devtools. r?shu MozReview-Commit-ID: JT1TJtJUGrq
devtools/server/actors/utils/TabSources.js
js/src/doc/Debugger/Debugger.Source.md
js/src/jit-test/tests/debug/bug1338914.js
js/src/jsfun.cpp
--- 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,