Bug 895395 - Support NameFunctions when compiling scripts off the main thread Bug 895395 - Support NameFunctions when compiling scripts off the main thread (r=bhackett)
authorBill McCloskey <wmccloskey@mozilla.com>
Tue, 19 Nov 2013 13:20:33 -0800
changeset 171500 ac44e599259349e5bfb5c92c840ba8948dfd36e1
parent 171499 bad7c90bb6308f5f8b0295efa4cbe222cd1cfc1f
child 171501 e5dd91e7d90fa5680b32600839f5c35d795b277f
push id3224
push userlsblakk@mozilla.com
push dateTue, 04 Feb 2014 01:06:49 +0000
treeherdermozilla-beta@60c04d0987f1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbhackett
bugs895395
milestone28.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 895395 - Support NameFunctions when compiling scripts off the main thread Bug 895395 - Support NameFunctions when compiling scripts off the main thread (r=bhackett)
js/src/frontend/BytecodeCompiler.cpp
js/src/frontend/NameFunctions.cpp
js/src/frontend/NameFunctions.h
--- a/js/src/frontend/BytecodeCompiler.cpp
+++ b/js/src/frontend/BytecodeCompiler.cpp
@@ -350,19 +350,17 @@ frontend::CompileScript(ExclusiveContext
         if (canHaveDirectives) {
             if (!parser.maybeParseDirective(/* stmtList = */ nullptr, pn, &canHaveDirectives))
                 return nullptr;
         }
 
         if (!FoldConstants(cx, &pn, &parser))
             return nullptr;
 
-        // Inferring names for functions in compiled scripts is currently only
-        // supported while on the main thread. See bug 895395.
-        if (cx->isJSContext() && !NameFunctions(cx->asJSContext(), pn))
+        if (!NameFunctions(cx, pn))
             return nullptr;
 
         if (!EmitTree(cx, &bce, pn))
             return nullptr;
 
         parser.handler.freeTree(pn);
     }
 
--- a/js/src/frontend/NameFunctions.cpp
+++ b/js/src/frontend/NameFunctions.cpp
@@ -18,17 +18,17 @@ using namespace js;
 using namespace js::frontend;
 
 namespace {
 
 class NameResolver
 {
     static const size_t MaxParents = 100;
 
-    JSContext *cx;
+    ExclusiveContext *cx;
     size_t nparents;                /* number of parents in the parents array */
     ParseNode *parents[MaxParents]; /* history of ParseNodes we've been looking at */
     StringBuffer *buf;              /* when resolving, buffer to append to */
 
     /* Test whether a ParseNode represents a function invocation */
     bool call(ParseNode *pn) {
         return pn && pn->isKind(PNK_CALL);
     }
@@ -257,17 +257,17 @@ class NameResolver
      * This is the case for functions which do things like simply create a scope
      * for new variables and then return an anonymous function using this scope.
      */
     bool isDirectCall(int pos, ParseNode *cur) {
         return pos >= 0 && call(parents[pos]) && parents[pos]->pn_head == cur;
     }
 
   public:
-    explicit NameResolver(JSContext *cx) : cx(cx), nparents(0), buf(nullptr) {}
+    explicit NameResolver(ExclusiveContext *cx) : cx(cx), nparents(0), buf(nullptr) {}
 
     /*
      * Resolve all names for anonymous functions recursively within the
      * ParseNode instance given. The prefix is for each subsequent name, and
      * should initially be nullptr.
      */
     void resolve(ParseNode *cur, HandleAtom prefixArg = NullPtr()) {
         RootedAtom prefix(cx, prefixArg);
@@ -326,14 +326,14 @@ class NameResolver
         }
         nparents--;
     }
 };
 
 } /* anonymous namespace */
 
 bool
-frontend::NameFunctions(JSContext *cx, ParseNode *pn)
+frontend::NameFunctions(ExclusiveContext *cx, ParseNode *pn)
 {
     NameResolver nr(cx);
     nr.resolve(pn);
     return true;
 }
--- a/js/src/frontend/NameFunctions.h
+++ b/js/src/frontend/NameFunctions.h
@@ -5,19 +5,22 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef frontend_NameFunctions_h
 #define frontend_NameFunctions_h
 
 #include "js/TypeDecls.h"
 
 namespace js {
+
+class ExclusiveContext;
+
 namespace frontend {
 
 class ParseNode;
 
 bool
-NameFunctions(JSContext *cx, ParseNode *pn);
+NameFunctions(ExclusiveContext *cx, ParseNode *pn);
 
 } /* namespace frontend */
 } /* namespace js */
 
 #endif /* frontend_NameFunctions_h */