Bug 1250842 - Fix initialization of script source object when modules are compiled off main thread r=shu

This commit is contained in:
Jon Coppeard 2016-02-25 09:43:07 +00:00
parent 0a7da07627
commit 19cf2e0cbd
3 changed files with 11 additions and 3 deletions

View File

@ -760,13 +760,15 @@ frontend::CompileScript(ExclusiveContext* cx, LifoAlloc* alloc, HandleObject sco
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.
@ -784,6 +786,10 @@ frontend::CompileModule(ExclusiveContext* cx, const ReadOnlyCompileOptions& opti
if (cx->isJSContext() && !ModuleObject::FreezeArrayProperties(cx->asJSContext(), module))
return nullptr;
// See the comment about sourceObjectOut above.
if (sourceObjectOut)
*sourceObjectOut = compiler.sourceObjectPtr();
return module;
}

View File

@ -34,7 +34,8 @@ CompileScript(ExclusiveContext* cx, LifoAlloc* alloc,
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);

View File

@ -285,7 +285,8 @@ 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();
}