Bug 1338914 - Optimize hidden/internal script detection for devtools. r=shu
authorYury Delendik <ydelendik@mozilla.com>
Wed, 22 Feb 2017 12:25:36 -0600
changeset 345684 8a2b1bdb15491e41508b8959e3fe2bc24a26d790
parent 345683 b0b40ce3dfe576bd23aba0e0de79c221564b8f13
child 345685 1a9f4c3c782d969e64394573c8030aaf9ef42167
push id38253
push userydelendik@mozilla.com
push dateFri, 03 Mar 2017 00:44:53 +0000
treeherderautoland@8a2b1bdb1549 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersshu
bugs1338914
milestone54.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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,