From c4942592adf9b86e0b97ab0eeb40e5677b5ad67e Mon Sep 17 00:00:00 2001 From: Bill McCloskey Date: Tue, 19 Nov 2013 13:20:33 -0800 Subject: [PATCH] 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 | 4 +--- js/src/frontend/NameFunctions.cpp | 6 +++--- js/src/frontend/NameFunctions.h | 5 ++++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/js/src/frontend/BytecodeCompiler.cpp b/js/src/frontend/BytecodeCompiler.cpp index c0fc473f71b5..cfcf1735ed97 100644 --- a/js/src/frontend/BytecodeCompiler.cpp +++ b/js/src/frontend/BytecodeCompiler.cpp @@ -355,9 +355,7 @@ frontend::CompileScript(ExclusiveContext *cx, LifoAlloc *alloc, HandleObject sco 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)) diff --git a/js/src/frontend/NameFunctions.cpp b/js/src/frontend/NameFunctions.cpp index ab26b3fddd55..23805cace95e 100644 --- a/js/src/frontend/NameFunctions.cpp +++ b/js/src/frontend/NameFunctions.cpp @@ -23,7 +23,7 @@ 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 */ @@ -262,7 +262,7 @@ class NameResolver } 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 @@ -331,7 +331,7 @@ class NameResolver } /* anonymous namespace */ bool -frontend::NameFunctions(JSContext *cx, ParseNode *pn) +frontend::NameFunctions(ExclusiveContext *cx, ParseNode *pn) { NameResolver nr(cx); nr.resolve(pn); diff --git a/js/src/frontend/NameFunctions.h b/js/src/frontend/NameFunctions.h index c6845c4cbfad..0f8717e74433 100644 --- a/js/src/frontend/NameFunctions.h +++ b/js/src/frontend/NameFunctions.h @@ -10,12 +10,15 @@ #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 */