Bug 1250842 - Fix initialization of script source object when modules are compiled off main thread r=shu
authorJon Coppeard <jcoppeard@mozilla.com>
Thu, 25 Feb 2016 09:43:07 +0000
changeset 321892 5a5874ed903337de47dff5c76ed7cf541e3f3788
parent 321891 17bfd6a2a52944f0f0e544dcc5e9d8118dd46d02
child 321893 3b913f81cb98b75061bb8c90f7780f88ac4b7dbb
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersshu
bugs1250842
milestone47.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 1250842 - Fix initialization of script source object when modules are compiled off main thread r=shu
js/src/frontend/BytecodeCompiler.cpp
js/src/frontend/BytecodeCompiler.h
js/src/vm/HelperThreads.cpp
--- a/js/src/frontend/BytecodeCompiler.cpp
+++ b/js/src/frontend/BytecodeCompiler.cpp
@@ -755,23 +755,25 @@ frontend::CompileScript(ExclusiveContext
     if (sourceObjectOut)
         *sourceObjectOut = compiler.sourceObjectPtr();
 
     return script;
 }
 
 ModuleObject*
 frontend::CompileModule(ExclusiveContext* cx, const ReadOnlyCompileOptions& optionsInput,
-                        SourceBufferHolder& srcBuf, LifoAlloc* alloc)
+                        SourceBufferHolder& srcBuf, LifoAlloc* alloc,
+                        ScriptSourceObject** sourceObjectOut /* = nullptr */)
 {
     MOZ_ASSERT(srcBuf.get());
     MOZ_ASSERT(cx->isJSContext() == (alloc == nullptr));
 
     if (!alloc)
         alloc = &cx->asJSContext()->tempLifoAlloc();
+    MOZ_ASSERT_IF(sourceObjectOut, *sourceObjectOut == nullptr);
 
     CompileOptions options(cx, optionsInput);
     options.maybeMakeStrictMode(true); // ES6 10.2.1 Module code is always strict mode code.
     options.setIsRunOnce(true);
 
     Rooted<StaticScope*> staticScope(cx, &cx->global()->lexicalScope().staticBlock());
     BytecodeCompiler compiler(cx, alloc, options, srcBuf, staticScope,
                               TraceLogger_ParserCompileModule);
@@ -779,16 +781,20 @@ frontend::CompileModule(ExclusiveContext
     if (!module)
         return nullptr;
 
     // This happens in GlobalHelperThreadState::finishModuleParseTask() when a
     // module is compiled off main thread.
     if (cx->isJSContext() && !ModuleObject::FreezeArrayProperties(cx->asJSContext(), module))
         return nullptr;
 
+    // See the comment about sourceObjectOut above.
+    if (sourceObjectOut)
+        *sourceObjectOut = compiler.sourceObjectPtr();
+
     return module;
 }
 
 bool
 frontend::CompileLazyFunction(JSContext* cx, Handle<LazyScript*> lazy, const char16_t* chars, size_t length)
 {
     MOZ_ASSERT(cx->compartment() == lazy->functionNonDelazifying()->compartment());
 
--- a/js/src/frontend/BytecodeCompiler.h
+++ b/js/src/frontend/BytecodeCompiler.h
@@ -29,17 +29,18 @@ CompileScript(ExclusiveContext* cx, Lifo
               HandleObject scopeChain, Handle<StaticScope*> enclosingStaticScope,
               HandleScript evalCaller, const ReadOnlyCompileOptions& options,
               SourceBufferHolder& srcBuf, JSString* source_ = nullptr,
               SourceCompressionTask* extraSct = nullptr,
               ScriptSourceObject** sourceObjectOut = nullptr);
 
 ModuleObject*
 CompileModule(ExclusiveContext *cx, const ReadOnlyCompileOptions &options,
-              SourceBufferHolder &srcBuf, LifoAlloc* alloc = nullptr);
+              SourceBufferHolder &srcBuf, LifoAlloc* alloc = nullptr,
+              ScriptSourceObject** sourceObjectOut = nullptr);
 
 bool
 CompileLazyFunction(JSContext* cx, Handle<LazyScript*> lazy, const char16_t* chars, size_t length);
 
 /*
  * enclosingStaticScope is a static enclosing scope (e.g. a StaticWithScope).
  * Must be null if the enclosing scope is a global.
  */
--- a/js/src/vm/HelperThreads.cpp
+++ b/js/src/vm/HelperThreads.cpp
@@ -280,17 +280,18 @@ ModuleParseTask::ModuleParseTask(Exclusi
               callbackData)
 {
 }
 
 void
 ModuleParseTask::parse()
 {
     SourceBufferHolder srcBuf(chars, length, SourceBufferHolder::NoOwnership);
-    ModuleObject* module = frontend::CompileModule(cx, options, srcBuf, &alloc);
+    ModuleObject* module = frontend::CompileModule(cx, options, srcBuf, &alloc,
+                                                   sourceObject.address());
     if (module)
         script = module->script();
 }
 
 void
 js::CancelOffThreadParses(JSRuntime* rt)
 {
     AutoLockHelperThreadState lock;