зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1635976 - Use traceList for publishing deferred functions. r=mgaudet
The FunctionBoxes are added to head of the trace-list as they are created in source order. This means the final list is the reverse of that and inner functions are seen before their parent. This is exactly what we need for the publishDeferredFunctions method. Differential Revision: https://phabricator.services.mozilla.com/D74313
This commit is contained in:
Родитель
7d91374595
Коммит
6effa4082a
|
@ -3759,7 +3759,7 @@ static bool reflect_parse(JSContext* cx, uint32_t argc, Value* vp) {
|
|||
pn = pn->as<ModuleNode>().body();
|
||||
}
|
||||
|
||||
if (!parser.publishDeferredFunctions()) {
|
||||
if (!compilationInfo.publishDeferredFunctions()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -486,7 +486,7 @@ JSScript* frontend::ScriptCompiler<Unit>::compileScript(
|
|||
JS::ProfilingCategoryPair::JS_Parsing);
|
||||
|
||||
// Publish deferred items
|
||||
if (!parser->publishDeferredFunctions()) {
|
||||
if (!compilationInfo.publishDeferredFunctions()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -544,7 +544,7 @@ ModuleObject* frontend::ModuleCompiler<Unit>::compile(
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
if (!parser->publishDeferredFunctions()) {
|
||||
if (!compilationInfo.publishDeferredFunctions()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -643,7 +643,7 @@ bool frontend::StandaloneFunctionCompiler<Unit>::compile(
|
|||
compilationInfo.options.column};
|
||||
funbox->scriptExtent.emplace(extent);
|
||||
|
||||
if (!parser->publishDeferredFunctions()) {
|
||||
if (!compilationInfo.publishDeferredFunctions()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -932,7 +932,7 @@ static bool CompileLazyFunctionImpl(JSContext* cx, Handle<BaseScript*> lazy,
|
|||
if (!pn) {
|
||||
return false;
|
||||
}
|
||||
if (!parser.publishDeferredFunctions()) {
|
||||
if (!compilationInfo.publishDeferredFunctions()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -102,6 +102,8 @@ struct MOZ_RAII CompilationInfo : public JS::CustomAutoRooter {
|
|||
return sourceObject->source()->assignSource(cx, options, sourceBuffer);
|
||||
}
|
||||
|
||||
MOZ_MUST_USE bool publishDeferredFunctions();
|
||||
|
||||
void trace(JSTracer* trc) final;
|
||||
|
||||
// To avoid any misuses, make sure this is neither copyable,
|
||||
|
|
|
@ -282,6 +282,7 @@ FunctionBox* PerHandlerParser<ParseHandler>::newFunctionBox(
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
// Note: The order we insert into traceListHead is important. See consumers.
|
||||
compilationInfo_.traceListHead = funbox;
|
||||
handler_.setFunctionBox(funNode, funbox);
|
||||
|
||||
|
@ -324,6 +325,7 @@ FunctionBox* PerHandlerParser<ParseHandler>::newFunctionBox(
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
// Note: The order we insert into traceListHead is important. See consumers.
|
||||
compilationInfo.traceListHead = funbox;
|
||||
handler_.setFunctionBox(funNode, funbox);
|
||||
|
||||
|
@ -1878,18 +1880,19 @@ static bool MaybePublishFunction(JSContext* cx,
|
|||
return CreateLazyScript(cx, compilationInfo, stencil, fun, funbox);
|
||||
}
|
||||
|
||||
bool ParserBase::publishDeferredFunctions(FunctionTree* root) {
|
||||
if (root) {
|
||||
auto visitor = [](ParserBase* parser, FunctionTree* tree) {
|
||||
FunctionBox* funbox = tree->funbox();
|
||||
if (!funbox) {
|
||||
return true;
|
||||
}
|
||||
return MaybePublishFunction(parser->cx_, parser->compilationInfo_,
|
||||
funbox);
|
||||
};
|
||||
return root->visitRecursively(this->cx_, this, visitor);
|
||||
bool CompilationInfo::publishDeferredFunctions() {
|
||||
// Use the trace list to visit funboxes. We must visit inner functions before
|
||||
// their parents. The trace list inserts functions to the head of list as they
|
||||
// are encountered. These leaves each list in a reverse-pre-order which is
|
||||
// what we want.
|
||||
|
||||
for (FunctionBox* funbox = traceListHead; funbox;
|
||||
funbox = funbox->traceLink()) {
|
||||
if (!MaybePublishFunction(cx, *this, funbox)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -296,15 +296,9 @@ class MOZ_STACK_CLASS ParserBase : public ParserSharedBase,
|
|||
|
||||
FunctionTreeHolder& treeHolder_;
|
||||
|
||||
MOZ_MUST_USE bool publishDeferredFunctions(FunctionTree* root);
|
||||
|
||||
public:
|
||||
FunctionTreeHolder& getTreeHolder() { return treeHolder_; }
|
||||
|
||||
MOZ_MUST_USE bool publishDeferredFunctions() {
|
||||
return publishDeferredFunctions(getTreeHolder().getFunctionTree());
|
||||
}
|
||||
|
||||
bool awaitIsKeyword() const { return awaitHandling_ != AwaitIsName; }
|
||||
|
||||
bool inParametersOfAsyncFunction() const {
|
||||
|
|
|
@ -595,6 +595,8 @@ class FunctionBox : public SharedContext {
|
|||
void trace(JSTracer* trc);
|
||||
|
||||
static void TraceList(JSTracer* trc, FunctionBox* listHead);
|
||||
|
||||
FunctionBox* traceLink() { return traceLink_; }
|
||||
};
|
||||
|
||||
#undef FLAG_GETTER_SETTER
|
||||
|
|
Загрузка…
Ссылка в новой задаче