Skip to content

Commit ea29437

Browse files
author
Ian Halliday
committed
[MERGE chakra-core#936] Fix numerous issues with Use Before Declaration
Merge pull request chakra-core#936 from ianwjhalliday:fix505 Fixes chakra-core#505 and VSO 5425942 Emit() needs to visit all AST nodes so that various algorithms can collect data and set info on symbols and such, assign locations etc. In our implementation of the let/const lexical variable Use Before Declaration error, we had a call to EmitUseBeforeDeclaration() at the beginning of Emit() and would exit early if it decided to emit the error into the bytecode. This would prevent visitation of subtrees in certain cases, like e.g. issue chakra-core#505. It would do this for assignments, i.e. stores. Detection for Use Before Declaration for loads (and typeof) are done in EmitPropLoad and EmitPropTypeof. This fix pushes Use Before Declaration detection for stores down into EmitPropStore and fixes up where we clear the `needsDeclaration` flag on symbols that we weren't doing exactly right for EmitPropStore to work this way. Summary of changes - Tweak parse tree tracing to note deferred funcs - Change EmitPropStore to emit static UseBeforeDecl - Consolidate Emit() of knop[Var|Let|Const]Decl - Reduce code duplication in TrackMemberNodesInObjectForIntConstants - Add missing EmitUseBeforeDeclaration in EmitReference for knopCall - Remove EmitUseBeforeDeclaration for knopVarDecl case in Emit() - Remove redundant parameter fLoadUndef from EmitUseBeforeDeclarationRuntimeError(). Use the presence of the location parameter to indicate that a LdUndef is needed instead. - Remove fAcquire param from EmitUseBeforeDeclaration - Remove pnodeNeedUndef parameter from EmitUseBeforeDeclaration - Remove always true fAssignRegs parameter from EmitApplyCall. - Removed call to EmitUseBeforeDeclaration in EmitCallTargetNoEvalComponents. This was the only remaining call that used pnodeNeedUndef, hence ability to remove that parameter from EmitUseBeforeDeclaration. - Added three test cases to unittests
2 parents e477b13 + 008cc68 commit ea29437

3 files changed

Lines changed: 161 additions & 162 deletions

File tree

lib/Parser/Parse.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12915,6 +12915,12 @@ void PrintPnodeWIndent(ParseNode *pnode,int indentAmt) {
1291512915
PrintFormalsWIndent(pnode->sxFnc.pnodeParams, indentAmt + INDENT_SIZE);
1291612916
PrintPnodeWIndent(pnode->sxFnc.pnodeRest, indentAmt + INDENT_SIZE);
1291712917
PrintPnodeWIndent(pnode->sxFnc.pnodeBody, indentAmt + INDENT_SIZE);
12918+
if (pnode->sxFnc.pnodeBody == nullptr)
12919+
{
12920+
Output::Print(_u("[%4d, %4d): "), pnode->ichMin, pnode->ichLim);
12921+
Indent(indentAmt + INDENT_SIZE);
12922+
Output::Print(_u("<parse deferred body>\n"));
12923+
}
1291812924
break;
1291912925
//PTNODE(knopProg , "program" ,None ,Fnc ,fnopNone)
1292012926
case knopProg:

0 commit comments

Comments
 (0)