void FuncInfo::OnStartVisitScope(Scope *scope, bool *pisMergedScope) { *pisMergedScope = false; if (scope == nullptr) { return; } Scope* childScope = this->GetCurrentChildScope(); if (childScope) { if (scope->GetScopeType() == ScopeType_Parameter) { Assert(childScope->GetEnclosingScope() == scope); } else if (childScope->GetScopeType() == ScopeType_Parameter && childScope->GetCanMergeWithBodyScope() && scope->GetScopeType() == ScopeType_Block) { // If param and body are merged then the class declaration in param scope will have body as the parent *pisMergedScope = true; Assert(childScope == scope->GetEnclosingScope()->GetEnclosingScope()); } else { Assert(childScope == scope->GetEnclosingScope()); } } this->SetCurrentChildScope(scope); return; }
// // Save scope info for an outer func which has deferred child. // void ScopeInfo::SaveScopeInfo(ByteCodeGenerator* byteCodeGenerator, FuncInfo* parentFunc, FuncInfo* func) { ParseableFunctionInfo* funcBody = func->byteCodeFunction; Assert((!func->IsGlobalFunction() || byteCodeGenerator->GetFlags() & fscrEvalCode) && (func->HasDeferredChild() || (funcBody->IsReparsed()))); // If we are reparsing a deferred function, we already have correct "parent" info in // funcBody->scopeInfo. parentFunc is the knopProg shell and should not be used in this // case. We should use existing parent if available. FunctionBody * parent = funcBody->GetScopeInfo() ? funcBody->GetScopeInfo()->GetParent() : parentFunc ? parentFunc->byteCodeFunction->GetFunctionBody() : nullptr; ScopeInfo* funcExprScopeInfo = nullptr; Scope* funcExprScope = func->GetFuncExprScope(); if (funcExprScope && funcExprScope->GetMustInstantiate()) { funcExprScopeInfo = FromScope(byteCodeGenerator, parent, funcExprScope, funcBody->GetScriptContext()); } Scope* bodyScope = func->IsGlobalFunction() ? func->GetGlobalEvalBlockScope() : func->GetBodyScope(); ScopeInfo* paramScopeInfo = nullptr; Scope* paramScope = func->GetParamScope(); if (paramScope && !paramScope->GetCanMergeWithBodyScope()) { paramScopeInfo = FromScope(byteCodeGenerator, parent, paramScope, funcBody->GetScriptContext()); } ScopeInfo* scopeInfo = FromScope(byteCodeGenerator, parent, bodyScope, funcBody->GetScriptContext()); scopeInfo->SetFuncExprScopeInfo(funcExprScopeInfo); scopeInfo->SetParamScopeInfo(paramScopeInfo); funcBody->SetScopeInfo(scopeInfo); }