@@ -712,11 +712,6 @@ bool ByteCodeGenerator::IsFalse(ParseNode* node)
712712 return (node->nop == knopInt && node->sxInt .lw == 0 ) || node->nop == knopFalse;
713713}
714714
715- bool ByteCodeGenerator::UseParserBindings () const
716- {
717- return !PHASE_OFF1 (Js::ParserBindPhase);
718- }
719-
720715bool ByteCodeGenerator::IsES6DestructuringEnabled () const
721716{
722717 return scriptContext->GetConfig ()->IsES6DestructuringEnabled ();
@@ -972,11 +967,7 @@ void ByteCodeGenerator::RestoreScopeInfo(Js::FunctionBody* functionBody)
972967 if (paramScopeInfo != nullptr )
973968 {
974969 paramScope = paramScopeInfo->GetScope ();
975- Assert (paramScope || !UseParserBindings ());
976- if (paramScope == nullptr || !UseParserBindings ())
977- {
978- paramScope = Anew (alloc, Scope, alloc, ScopeType_Parameter, true );
979- }
970+ Assert (paramScope);
980971 if (!paramScopeInfo->GetCanMergeWithBodyScope ())
981972 {
982973 paramScope->SetCannotMergeWithBodyScope ();
@@ -986,18 +977,7 @@ void ByteCodeGenerator::RestoreScopeInfo(Js::FunctionBody* functionBody)
986977
987978 Scope* bodyScope = scopeInfo->GetScope ();
988979
989- Assert (bodyScope || !UseParserBindings ());
990- if (bodyScope == nullptr || !UseParserBindings ())
991- {
992- if (scopeInfo->IsGlobalEval ())
993- {
994- bodyScope = Anew (alloc, Scope, alloc, ScopeType_GlobalEvalBlock, true );
995- }
996- else
997- {
998- bodyScope = Anew (alloc, Scope, alloc, ScopeType_FunctionBody, true );
999- }
1000- }
980+ Assert (bodyScope);
1001981 bodyScope->SetHasOwnLocalInClosure (scopeInfo->GetHasOwnLocalInClosure ());
1002982
1003983 FuncInfo* func = Anew (alloc, FuncInfo, functionBody->GetDisplayName (), alloc, paramScope, bodyScope, nullptr , functionBody);
@@ -1017,11 +997,7 @@ void ByteCodeGenerator::RestoreScopeInfo(Js::FunctionBody* functionBody)
1017997 if (funcExprScopeInfo)
1018998 {
1019999 Scope* funcExprScope = funcExprScopeInfo->GetScope ();
1020- Assert (funcExprScope || !UseParserBindings ());
1021- if (funcExprScope == nullptr || !UseParserBindings ())
1022- {
1023- funcExprScope = Anew (alloc, Scope, alloc, ScopeType_FuncExpr, true );
1024- }
1000+ Assert (funcExprScope);
10251001 funcExprScope->SetFunc (func);
10261002 func->SetFuncExprScope (funcExprScope);
10271003 funcExprScopeInfo->GetScopeInfo (nullptr , this , func, funcExprScope);
@@ -1039,7 +1015,7 @@ void ByteCodeGenerator::RestoreScopeInfo(Js::FunctionBody* functionBody)
10391015 {
10401016 Assert (this ->TopFuncInfo () == nullptr );
10411017 // funcBody is glo
1042- currentScope = Anew (alloc, Scope, alloc, ScopeType_Global, ! UseParserBindings () );
1018+ currentScope = Anew (alloc, Scope, alloc, ScopeType_Global);
10431019 globalScope = currentScope;
10441020
10451021 FuncInfo *func = Anew (alloc, FuncInfo, Js::Constants::GlobalFunction,
@@ -1063,11 +1039,6 @@ FuncInfo * ByteCodeGenerator::StartBindGlobalStatements(ParseNode *pnode)
10631039 {
10641040 currentScope = pnode->sxProg .scope ;
10651041 Assert (currentScope);
1066- if (!currentScope || !UseParserBindings ())
1067- {
1068- currentScope = Anew (alloc, Scope, alloc, ScopeType_Global, true );
1069- pnode->sxProg .scope = currentScope;
1070- }
10711042 globalScope = currentScope;
10721043 }
10731044
@@ -1324,16 +1295,8 @@ FuncInfo * ByteCodeGenerator::StartBindFunction(const char16 *name, uint nameLen
13241295 Scope *funcExprScope = nullptr ;
13251296 if (funcExprWithName)
13261297 {
1327- if (!UseParserBindings ())
1328- {
1329- funcExprScope = Anew (alloc, Scope, alloc, ScopeType_FuncExpr, true );
1330- pnode->sxFnc .scope = funcExprScope;
1331- }
1332- else
1333- {
1334- funcExprScope = pnode->sxFnc .scope ;
1335- Assert (funcExprScope);
1336- }
1298+ funcExprScope = pnode->sxFnc .scope ;
1299+ Assert (funcExprScope);
13371300 PushScope (funcExprScope);
13381301 Symbol *sym = AddSymbolToScope (funcExprScope, name, nameLength, pnode->sxFnc .pnodeName , STFunction);
13391302
@@ -1346,16 +1309,16 @@ FuncInfo * ByteCodeGenerator::StartBindFunction(const char16 *name, uint nameLen
13461309
13471310 Scope *paramScope = pnode->sxFnc .pnodeScopes ? pnode->sxFnc .pnodeScopes ->sxBlock .scope : nullptr ;
13481311 Scope *bodyScope = pnode->sxFnc .pnodeBodyScope ? pnode->sxFnc .pnodeBodyScope ->sxBlock .scope : nullptr ;
1349- Assert (paramScope != nullptr || !pnode->sxFnc .pnodeScopes || ! UseParserBindings () );
1350- if (paramScope == nullptr || ! UseParserBindings () )
1312+ Assert (paramScope != nullptr || !pnode->sxFnc .pnodeScopes );
1313+ if (paramScope == nullptr )
13511314 {
13521315 paramScope = Anew (alloc, Scope, alloc, ScopeType_Parameter, true );
13531316 if (pnode->sxFnc .pnodeScopes )
13541317 {
13551318 pnode->sxFnc .pnodeScopes ->sxBlock .scope = paramScope;
13561319 }
13571320 }
1358- if (bodyScope == nullptr || ! UseParserBindings () )
1321+ if (bodyScope == nullptr )
13591322 {
13601323 bodyScope = Anew (alloc, Scope, alloc, ScopeType_FunctionBody, true );
13611324 if (pnode->sxFnc .pnodeBodyScope )
@@ -1465,11 +1428,6 @@ void ByteCodeGenerator::StartBindCatch(ParseNode *pnode)
14651428{
14661429 Scope *scope = pnode->sxCatch .scope ;
14671430 Assert (scope);
1468- if (scope == nullptr || !UseParserBindings ())
1469- {
1470- scope = Anew (alloc, Scope, alloc, (pnode->sxCatch .pnodeParam ->nop == knopParamPattern) ? ScopeType_CatchParamPattern : ScopeType_Catch, true );
1471- pnode->sxCatch .scope = scope;
1472- }
14731431 Assert (currentScope);
14741432 scope->SetFunc (currentScope->GetFunc ());
14751433 PushScope (scope);
@@ -1573,33 +1531,19 @@ void ByteCodeGenerator::PopFuncInfo(char16 const * location)
15731531Symbol * ByteCodeGenerator::FindSymbol (Symbol **symRef, IdentPtr pid, bool forReference)
15741532{
15751533 const char16 *key = nullptr ;
1576- int keyLength;
15771534
15781535 Symbol *sym = nullptr ;
1579- if (!UseParserBindings ())
1536+ Assert (symRef);
1537+ if (*symRef)
15801538 {
1581- key = reinterpret_cast <const char16*>(pid->Psz ());
1582- keyLength = pid->Cch ();
1583- sym = currentScope->FindSymbol (SymbolName (key, keyLength), STUnknown);
1584- if (symRef)
1585- {
1586- *symRef = sym;
1587- }
1539+ sym = *symRef;
15881540 }
15891541 else
15901542 {
1591- Assert (symRef);
1592- if (*symRef)
1593- {
1594- sym = *symRef;
1595- }
1596- else
1597- {
1598- this ->AssignPropertyId (pid);
1599- return nullptr ;
1600- }
1601- key = reinterpret_cast <const char16*>(sym->GetPid ()->Psz ());
1543+ this ->AssignPropertyId (pid);
1544+ return nullptr ;
16021545 }
1546+ key = reinterpret_cast <const char16*>(sym->GetPid ()->Psz ());
16031547
16041548 Scope *symScope = sym->GetScope ();
16051549 Assert (symScope);
@@ -1686,63 +1630,33 @@ Symbol * ByteCodeGenerator::AddSymbolToScope(Scope *scope, const char16 *key, in
16861630{
16871631 Symbol *sym = nullptr ;
16881632
1689- if (! UseParserBindings () )
1633+ switch (varDecl-> nop )
16901634 {
1691- SymbolName const symName (key, keyLength);
1692-
1693- if (scope->GetScopeType () == ScopeType_FunctionBody)
1694- {
1695- sym = scope->GetFunc ()->GetParamScope ()->FindLocalSymbol (symName);
1696- }
1697-
1698- if (sym == nullptr )
1699- {
1700- sym = scope->FindLocalSymbol (symName);
1701- }
1702-
1703- if (sym == nullptr )
1704- {
1705- sym = Anew (alloc, Symbol, symName, varDecl, symbolType);
1706-
1707- scope->AddNewSymbol (sym);
1708- #if DBG_DUMP
1709- if (this ->Trace ())
1710- {
1711- Output::Print (_u (" added symbol %s of type %s to scope %x\n " ), key, sym->GetSymbolTypeName (), scope);
1712- }
1713- #endif
1714- }
1635+ case knopConstDecl:
1636+ case knopLetDecl:
1637+ case knopVarDecl:
1638+ sym = varDecl->sxVar .sym ;
1639+ break ;
1640+ case knopName:
1641+ AnalysisAssert (varDecl->sxPid .symRef );
1642+ sym = *varDecl->sxPid .symRef ;
1643+ break ;
1644+ default :
1645+ AnalysisAssert (0 );
1646+ sym = nullptr ;
1647+ break ;
17151648 }
1716- else
1717- {
1718- switch (varDecl->nop )
1719- {
1720- case knopConstDecl:
1721- case knopLetDecl:
1722- case knopVarDecl:
1723- sym = varDecl->sxVar .sym /* New*/ ;
1724- break ;
1725- case knopName:
1726- AnalysisAssert (varDecl->sxPid .symRef );
1727- sym = *varDecl->sxPid .symRef ;
1728- break ;
1729- default :
1730- AnalysisAssert (0 );
1731- sym = nullptr ;
1732- break ;
1733- }
17341649
1735- if (sym->GetScope () != scope && sym->GetScope ()->GetScopeType () != ScopeType_Parameter)
1736- {
1737- // This can happen when we have a function declared at global eval scope, and it has
1738- // references in deferred function bodies inside the eval. The BCG creates a new global scope
1739- // on such compiles, so we essentially have to migrate the symbol to the new scope.
1740- // We check fscrEvalCode, not fscrEval, because the same thing can happen in indirect eval,
1741- // when fscrEval is not set.
1742- Assert (((this ->flags & fscrEvalCode) && sym->GetIsGlobal () && sym->GetSymbolType () == STFunction) || this ->IsConsoleScopeEval ());
1743- Assert (scope->GetScopeType () == ScopeType_Global);
1744- scope->AddNewSymbol (sym);
1745- }
1650+ if (sym->GetScope () != scope && sym->GetScope ()->GetScopeType () != ScopeType_Parameter)
1651+ {
1652+ // This can happen when we have a function declared at global eval scope, and it has
1653+ // references in deferred function bodies inside the eval. The BCG creates a new global scope
1654+ // on such compiles, so we essentially have to migrate the symbol to the new scope.
1655+ // We check fscrEvalCode, not fscrEval, because the same thing can happen in indirect eval,
1656+ // when fscrEval is not set.
1657+ Assert (((this ->flags & fscrEvalCode) && sym->GetIsGlobal () && sym->GetSymbolType () == STFunction) || this ->IsConsoleScopeEval ());
1658+ Assert (scope->GetScopeType () == ScopeType_Global);
1659+ scope->AddNewSymbol (sym);
17461660 }
17471661
17481662 Assert (sym && sym->GetScope () && (sym->GetScope () == scope || sym->GetScope ()->GetScopeType () == ScopeType_Parameter));
@@ -2264,28 +2178,7 @@ void AddVarsToScope(ParseNode *vars, ByteCodeGenerator *byteCodeGenerator)
22642178{
22652179 while (vars != nullptr )
22662180 {
2267- Symbol *sym = nullptr ;
2268-
2269- if (!byteCodeGenerator->UseParserBindings ()
2270- && byteCodeGenerator->GetCurrentScope ()->GetFunc ()->GetParamScope () != nullptr )
2271- {
2272- SymbolName const symName (reinterpret_cast <const char16*>(vars->sxVar .pid ->Psz ()), vars->sxVar .pid ->Cch ());
2273- // If we are not using parser bindings, we need to check that the sym is not in the parameter scope before adding it.
2274- // Fetch the sym we just added from the param scope.
2275- sym = byteCodeGenerator->GetCurrentScope ()->GetFunc ()->GetParamScope ()->FindLocalSymbol (symName);
2276-
2277- // Arguments needs to be created at parameter scope.
2278- if (sym == nullptr && vars->grfpn & PNodeFlags::fpnArguments)
2279- {
2280- Scope* scope = byteCodeGenerator->GetCurrentScope ()->GetFunc ()->GetParamScope ();
2281- sym = byteCodeGenerator->AddSymbolToScope (scope, reinterpret_cast <const char16*>(vars->sxVar .pid ->Psz ()), vars->sxVar .pid ->Cch (), vars, STVariable);
2282- }
2283- }
2284-
2285- if (sym == nullptr )
2286- {
2287- sym = byteCodeGenerator->AddSymbolToFunctionScope (reinterpret_cast <const char16*>(vars->sxVar .pid ->Psz ()), vars->sxVar .pid ->Cch (), vars, STVariable);
2288- }
2181+ Symbol *sym = byteCodeGenerator->AddSymbolToFunctionScope (reinterpret_cast <const char16*>(vars->sxVar .pid ->Psz ()), vars->sxVar .pid ->Cch (), vars, STVariable);
22892182
22902183#if DBG_DUMP
22912184 if (sym->GetSymbolType () == STVariable && byteCodeGenerator->Trace ())
@@ -2413,17 +2306,10 @@ FuncInfo* PreVisitFunction(ParseNode* pnode, ByteCodeGenerator* byteCodeGenerato
24132306 {
24142307 // This is a deferred byte code gen, so we're done.
24152308 // Process the formal arguments, even if there's no AST for the body, to support Function.length.
2416- if (byteCodeGenerator->UseParserBindings ())
2417- {
2418- Js::ArgSlot pos = 1 ;
2419- // We skip the rest parameter here because it is not counted towards the in arg count.
2420- MapFormalsWithoutRest (pnode, [&](ParseNode *pnode) { UInt16Math::Inc (pos); });
2421- byteCodeGenerator->SetNumberOfInArgs (pos);
2422- }
2423- else
2424- {
2425- AddArgsToScope (pnode, byteCodeGenerator, false );
2426- }
2309+ Js::ArgSlot pos = 1 ;
2310+ // We skip the rest parameter here because it is not counted towards the in arg count.
2311+ MapFormalsWithoutRest (pnode, [&](ParseNode *pnode) { UInt16Math::Inc (pos); });
2312+ byteCodeGenerator->SetNumberOfInArgs (pos);
24272313 return funcInfo;
24282314 }
24292315
@@ -3292,8 +3178,7 @@ void PreVisitBlock(ParseNode *pnodeBlock, ByteCodeGenerator *byteCodeGenerator)
32923178 {
32933179 isGlobalEvalBlockScope = true ;
32943180 }
3295- Assert (!byteCodeGenerator->UseParserBindings () ||
3296- !pnodeBlock->sxBlock .scope ||
3181+ Assert (!pnodeBlock->sxBlock .scope ||
32973182 isGlobalEvalBlockScope == (pnodeBlock->sxBlock .scope ->GetScopeType () == ScopeType_GlobalEvalBlock));
32983183
32993184 ArenaAllocator *alloc = byteCodeGenerator->GetAllocator ();
@@ -3318,7 +3203,7 @@ void PreVisitBlock(ParseNode *pnodeBlock, ByteCodeGenerator *byteCodeGenerator)
33183203 else if (!(pnodeBlock->grfpn & fpnSyntheticNode) || isGlobalEvalBlockScope)
33193204 {
33203205 scope = pnodeBlock->sxBlock .scope ;
3321- if (!scope || !byteCodeGenerator-> UseParserBindings () )
3206+ if (!scope)
33223207 {
33233208 scope = Anew (alloc, Scope, alloc,
33243209 isGlobalEvalBlockScope? ScopeType_GlobalEvalBlock : ScopeType_Block, true );
@@ -3419,11 +3304,6 @@ void PreVisitCatch(ParseNode *pnode, ByteCodeGenerator *byteCodeGenerator)
34193304 Parser::MapBindIdentifier (pnode->sxCatch .pnodeParam ->sxParamPattern .pnode1 , [&](ParseNodePtr item)
34203305 {
34213306 Symbol *sym = item->sxVar .sym ;
3422- if (!byteCodeGenerator->UseParserBindings ())
3423- {
3424- sym = byteCodeGenerator->AddSymbolToScope (pnode->sxCatch .scope , reinterpret_cast <const char16*>(item->sxVar .pid ->Psz ()), item->sxVar .pid ->Cch (), item, STVariable);
3425- item->sxVar .sym = sym;
3426- }
34273307#if DBG_DUMP
34283308 if (byteCodeGenerator->Trace ())
34293309 {
@@ -3435,15 +3315,7 @@ void PreVisitCatch(ParseNode *pnode, ByteCodeGenerator *byteCodeGenerator)
34353315 }
34363316 else
34373317 {
3438- Symbol *sym;
3439- if (!byteCodeGenerator->UseParserBindings ())
3440- {
3441- sym = byteCodeGenerator->AddSymbolToScope (pnode->sxCatch .scope , reinterpret_cast <const char16*>(pnode->sxCatch .pnodeParam ->sxPid .pid ->Psz ()), pnode->sxCatch .pnodeParam ->sxPid .pid ->Cch (), pnode->sxCatch .pnodeParam , STVariable);
3442- }
3443- else
3444- {
3445- sym = *pnode->sxCatch .pnodeParam ->sxPid .symRef ;
3446- }
3318+ Symbol *sym = *pnode->sxCatch .pnodeParam ->sxPid .symRef ;
34473319 Assert (sym->GetScope () == pnode->sxCatch .scope );
34483320#if DBG_DUMP
34493321 if (byteCodeGenerator->Trace ())
0 commit comments