author | Jeff Walden <jwalden@mit.edu> |
Thu, 11 Oct 2018 13:54:42 -0700 | |
changeset 502407 | 2052c58dfe9835eb4451a1cc02ff9b566419e2e2 |
parent 502406 | e6b6326c593d9a8c1095b2c872056df7f8ff088f |
child 502408 | d9e71df3d1d7a6dbf8effeb426273cd901d7700b |
push id | 10290 |
push user | ffxbld-merge |
push date | Mon, 03 Dec 2018 16:23:23 +0000 |
treeherder | mozilla-beta@700bed2445e6 [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | tcampbell |
bugs | 1498320 |
milestone | 65.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
|
--- a/js/src/frontend/BytecodeCompiler.cpp +++ b/js/src/frontend/BytecodeCompiler.cpp @@ -46,24 +46,38 @@ class MOZ_STACK_CLASS BytecodeCompiler // Construct an object passing mandatory arguments. BytecodeCompiler(JSContext* cx, const ReadOnlyCompileOptions& options, SourceBufferHolder& sourceBuffer, HandleScope enclosingScope); JSScript* compileGlobalScript(ScopeKind scopeKind); JSScript* compileEvalScript(HandleObject environment, HandleScope enclosingScope); + + // Call this before calling compileModule. + MOZ_MUST_USE bool prepareModuleParse() { + return createSourceAndParser(ParseGoal::Module); + } + ModuleObject* compileModule(); + bool compileStandaloneFunction(MutableHandleFunction fun, GeneratorKind generatorKind, FunctionAsyncKind asyncKind, const Maybe<uint32_t>& parameterListEnd); ScriptSourceObject* sourceObjectPtr() const; private: + void assertSourceAndParserCreated() const { + MOZ_ASSERT(sourceObject != nullptr); + MOZ_ASSERT(scriptSource != nullptr); + MOZ_ASSERT(usedNames.isSome()); + MOZ_ASSERT(parser.isSome()); + } + JSScript* compileScript(HandleObject environment, SharedContext* sc); bool checkLength(); bool createScriptSource(const Maybe<uint32_t>& parameterListEnd); bool canLazilyParse(); bool createParser(ParseGoal goal); bool createSourceAndParser(ParseGoal goal, const Maybe<uint32_t>& parameterListEnd = Nothing()); @@ -224,19 +238,20 @@ BytecodeCompiler::canLazilyParse() } bool BytecodeCompiler::createParser(ParseGoal goal) { usedNames.emplace(cx); if (canLazilyParse()) { - syntaxParser.emplace(cx, cx->tempLifoAlloc(), options, sourceBuffer.get(), - sourceBuffer.length(), /* foldConstants = */ false, - *usedNames, nullptr, nullptr, sourceObject, goal); + syntaxParser.emplace(cx, cx->tempLifoAlloc(), options, + sourceBuffer.get(), sourceBuffer.length(), + /* foldConstants = */ false, *usedNames, nullptr, nullptr, + sourceObject, goal); if (!syntaxParser->checkOptions()) { return false; } } parser.emplace(cx, cx->tempLifoAlloc(), options, sourceBuffer.get(), sourceBuffer.length(), /* foldConstants = */ true, *usedNames, syntaxParser.ptrOr(nullptr), nullptr, sourceObject, goal); @@ -405,19 +420,17 @@ BytecodeCompiler::compileEvalScript(Hand EvalSharedContext evalsc(cx, environment, enclosingScope, directives, options.extraWarningsOption); return compileScript(environment, &evalsc); } ModuleObject* BytecodeCompiler::compileModule() { - if (!createSourceAndParser(ParseGoal::Module)) { - return nullptr; - } + assertSourceAndParserCreated(); if (!createScript()) { return nullptr; } Rooted<ModuleObject*> module(cx, ModuleObject::create(cx)); if (!module) { return nullptr; @@ -751,16 +764,21 @@ frontend::CompileModule(JSContext* cx, c CompileOptions options(cx, optionsInput); options.maybeMakeStrictMode(true); // ES6 10.2.1 Module code is always strict mode code. options.setIsRunOnce(true); options.allowHTMLComments = false; RootedScope emptyGlobalScope(cx, &cx->global()->emptyGlobalScope()); BytecodeCompiler compiler(cx, options, srcBuf, emptyGlobalScope); AutoInitializeSourceObject autoSSO(compiler, sourceObjectOut); + + if (!compiler.prepareModuleParse()) { + return nullptr; + } + ModuleObject* module = compiler.compileModule(); if (!module) { return nullptr; } assertException.reset(); return module; }