mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-19 16:25:38 +00:00
Bug 1658971 - Part 1: Store self-hosting global scope in CompilationInput.enclosingScope. r=tcampbell
Differential Revision: https://phabricator.services.mozilla.com/D88601
This commit is contained in:
parent
cdda495ffc
commit
fbd7e031b2
@ -287,8 +287,14 @@ static JSScript* CompileGlobalScriptImpl(
|
||||
JSContext* cx, const JS::ReadOnlyCompileOptions& options,
|
||||
JS::SourceText<Unit>& srcBuf, ScopeKind scopeKind) {
|
||||
Rooted<CompilationInfo> compilationInfo(cx, CompilationInfo(cx, options));
|
||||
if (!compilationInfo.get().input.initForGlobal(cx)) {
|
||||
return nullptr;
|
||||
if (options.selfHostingMode) {
|
||||
if (!compilationInfo.get().input.initForSelfHostingGlobal(cx)) {
|
||||
return nullptr;
|
||||
}
|
||||
} else {
|
||||
if (!compilationInfo.get().input.initForGlobal(cx)) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
if (!CompileGlobalScriptToStencil(compilationInfo.get(), srcBuf, scopeKind)) {
|
||||
|
@ -34,8 +34,8 @@ bool GCThingList::append(FunctionBox* funbox, GCThingIndex* index) {
|
||||
AbstractScopePtr GCThingList::getScope(size_t index) const {
|
||||
const ScriptThingVariant& elem = vector[index];
|
||||
if (elem.is<EmptyGlobalScopeType>()) {
|
||||
MOZ_ASSERT(compilationInfo.input.enclosingScope == nullptr);
|
||||
return AbstractScopePtr(&compilationInfo.cx->global()->emptyGlobalScope());
|
||||
MOZ_ASSERT(compilationInfo.input.enclosingScope == &cx->global()->emptyGlobalScope());
|
||||
return AbstractScopePtr(compilationInfo.input.enclosingScope);
|
||||
}
|
||||
return AbstractScopePtr(compilationInfo, elem.as<ScopeIndex>());
|
||||
}
|
||||
|
@ -110,6 +110,10 @@ struct CompilationInput {
|
||||
// * If we're compiling eval, the non-null enclosing scope of the `eval`.
|
||||
// * If we're compiling module, null that means empty global scope
|
||||
// (See EmitterScope::checkEnvironmentChainLength)
|
||||
// * If we're compiling self-hosted JS, an empty global scope.
|
||||
// This scope is also used for EmptyGlobalScopeType in
|
||||
// CompilationStencil.gcThings.
|
||||
// See the comment in initForSelfHostingGlobal.
|
||||
// * Null otherwise
|
||||
Scope* enclosingScope = nullptr;
|
||||
|
||||
@ -122,6 +126,21 @@ struct CompilationInput {
|
||||
public:
|
||||
bool initForGlobal(JSContext* cx) { return initScriptSource(cx); }
|
||||
|
||||
bool initForSelfHostingGlobal(JSContext* cx) {
|
||||
if (!initScriptSource(cx)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// This enclosing scope is also recorded as EmptyGlobalScopeType in
|
||||
// CompilationStencil.gcThings even though corresponding ScopeStencil
|
||||
// isn't generated.
|
||||
//
|
||||
// Store the enclosing scope here in order to access it from
|
||||
// inner scopes' ScopeStencil::enclosing.
|
||||
enclosingScope = &cx->global()->emptyGlobalScope();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool initForStandaloneFunction(JSContext* cx,
|
||||
HandleScope functionEnclosingScope) {
|
||||
if (!initScriptSource(cx)) {
|
||||
|
@ -40,14 +40,6 @@ AbstractScopePtr ScopeStencil::enclosing(CompilationInfo& compilationInfo) {
|
||||
return AbstractScopePtr(compilationInfo, *enclosing_);
|
||||
}
|
||||
|
||||
// HACK: The self-hosting script uses the EmptyGlobalScopeType placeholder
|
||||
// which does not correspond to a ScopeStencil. This means that the inner
|
||||
// scopes may store Nothing as an enclosing ScopeIndex.
|
||||
if (compilationInfo.input.options.selfHostingMode) {
|
||||
MOZ_ASSERT(compilationInfo.input.enclosingScope == nullptr);
|
||||
return AbstractScopePtr(&compilationInfo.cx->global()->emptyGlobalScope());
|
||||
}
|
||||
|
||||
return AbstractScopePtr(compilationInfo.input.enclosingScope);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user