Skip to content

Commit 8edb18b

Browse files
committed
Make ParseNodeParamPattern a real ParseNodeUni and thus the down cast is valid.
Fix walking the ast with ParamPattern in pnodewalk Do a dummy walk of the ast in ByteCode Generator to do some basic validation of our walker Give up on knopList being a fnopBin as it has side-effects in ByteCodeEmitter::MayHaveSideEffectOnNode and ByteCodeGenerator::AssignRegisters
1 parent 127f153 commit 8edb18b

File tree

7 files changed

+35
-12
lines changed

7 files changed

+35
-12
lines changed

lib/Parser/Parse.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,6 @@ ParseNodeSuperCall * Parser::CreateSuperCallNode(ParseNodeSpecialName * pnode1,
10431043
Assert(!this->m_deferringAST);
10441044
Assert(pnode1 && pnode1->isSuper);
10451045

1046-
DebugOnly(VerifyNodeSize(knopSuperCall, sizeof(ParseNodeSuperCall)));
10471046
ParseNodeSuperCall* pnode = Anew(&m_nodeAllocator, ParseNodeSuperCall, knopCall, pnode1->ichMin, pnode2 == nullptr ? pnode1->ichLim : pnode2->ichLim, pnode1, pnode2);
10481047
AddAstSize(sizeof(ParseNodeSuperCall));
10491048
return pnode;
@@ -13266,7 +13265,7 @@ void PrintPnodeWIndent(ParseNode *pnode, int indentAmt) {
1326613265
//PTNODE(knopMod , "%" ,Mod ,Bin ,fnopBin)
1326713266
case knopMod:
1326813267
Indent(indentAmt);
13269-
Output::Print(_u("%\n"));
13268+
Output::Print(_u("%%\n"));
1327013269
PrintPnodeWIndent(pnode->AsParseNodeBin()->pnode1, indentAmt + INDENT_SIZE);
1327113270
PrintPnodeWIndent(pnode->AsParseNodeBin()->pnode2, indentAmt + INDENT_SIZE);
1327213271
break;

lib/Parser/pnodewalk.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,19 @@ class ParseNodeWalker : public WalkerPolicy
173173
{
174174
ResultType result;
175175
// For ordering, arguments are considered prior to the function and the body after.
176-
for (ParseNodePtr* argNode = &(pnode->pnodeParams); *argNode != nullptr; argNode = &((*argNode)->AsParseNodeVar()->pnodeNext))
176+
ParseNodePtr argNode = pnode->pnodeParams;
177+
while (argNode)
177178
{
178-
result = *argNode == pnode->pnodeParams ? WalkFirstChild(*argNode, context) : WalkNthChild(pnode, *argNode, context);
179+
result = argNode == pnode->pnodeParams ? WalkFirstChild(argNode, context) : WalkNthChild(pnode, argNode, context);
179180
if (!ContinueWalk(result)) return result;
181+
if (argNode->nop == knopParamPattern)
182+
{
183+
argNode = argNode->AsParseNodeParamPattern()->pnodeNext;
184+
}
185+
else
186+
{
187+
argNode = argNode->AsParseNodeVar()->pnodeNext;
188+
}
180189
}
181190

182191
if (pnode->pnodeRest != nullptr)

lib/Parser/ptlist.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ PTNODE(knopGetMember , "get" , Nop , Bin , fnopBin
117117
/***************************************************************************
118118
General nodes.
119119
***************************************************************************/
120-
PTNODE(knopList , "<list>" , Nop , Bin , fnopBin|fnopNotExprStmt, "" )
120+
PTNODE(knopList , "<list>" , Nop , Bin , fnopBinList|fnopNotExprStmt, "" )
121121
PTNODE(knopVarDecl , "varDcl" , Nop , Var , fnopNotExprStmt|fnopAllowDefer, "VarDecl" )
122122
PTNODE(knopConstDecl , "constDcl" , Nop , Var , fnopNotExprStmt|fnopAllowDefer, "ConstDecl" )
123123
PTNODE(knopLetDecl , "letDcl" , Nop , Var , fnopNotExprStmt|fnopAllowDefer, "LetDecl" )
@@ -151,7 +151,7 @@ PTNODE(knopTryFinally , "try-finally" , Nop , TryFinally , fnopNotExp
151151
PTNODE(knopObjectPattern, "{} = " , Nop , Uni , fnopUni , "ObjectAssignmentPattern" )
152152
PTNODE(knopObjectPatternMember, "{:} = " , Nop , Bin , fnopBin , "ObjectAssignmentPatternMember" )
153153
PTNODE(knopArrayPattern, "[] = " , Nop , ArrLit , fnopUni , "ArrayAssignmentPattern" )
154-
PTNODE(knopParamPattern, "({[]})" , Nop , ParamPattern, fnopNone , "DestructurePattern" )
154+
PTNODE(knopParamPattern, "({[]})" , Nop , ParamPattern, fnopUni , "DestructurePattern" )
155155
PTNODE(knopExportDefault, "export default" , Nop , ExportDefault,fnopNone , "ExportDefault" )
156156

157157

lib/Parser/ptree.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ ParseNode::ParseNode(OpCode nop, charcount_t ichMin, charcount_t ichLim)
1919

2020
ParseNodeUni * ParseNode::AsParseNodeUni()
2121
{
22-
Assert(((this->Grfnop() & fnopUni) && this->nop != knopParamPattern) || this->nop == knopThrow);
22+
Assert((this->Grfnop() & fnopUni) || this->nop == knopThrow);
2323
return reinterpret_cast<ParseNodeUni *>(this);
2424
}
2525

2626
ParseNodeBin * ParseNode::AsParseNodeBin()
2727
{
28-
Assert(this->Grfnop() & fnopBin);
28+
Assert((this->Grfnop() & fnopBin) || this->nop == knopList);
2929
return reinterpret_cast<ParseNodeBin *>(this);
3030
}
3131

@@ -485,7 +485,7 @@ ParseNodeWith::ParseNodeWith(OpCode nop, charcount_t ichMin, charcount_t ichLim)
485485
}
486486

487487
ParseNodeParamPattern::ParseNodeParamPattern(OpCode nop, charcount_t ichMin, charcount_t ichLim)
488-
: ParseNode(nop, ichMin, ichLim)
488+
: ParseNodeUni(nop, ichMin, ichLim, nullptr)
489489
{
490490
}
491491

lib/Parser/ptree.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ const uint fnopContinue = 0x0080; // continue can be used within this statement
2424
const uint fnopCleanup = 0x0100; // requires cleanup (eg, with or for-in).
2525
const uint fnopJump = 0x0200;
2626
const uint fnopNotExprStmt = 0x0400;
27+
const uint fnopBinList = 0x0800;
2728
const uint fnopExprMask = (fnopLeaf|fnopUni|fnopBin);
28-
const uint fnopAllowDefer = 0x0800; // allow to be created during defer parse
29+
const uint fnopAllowDefer = 0x1000; // allow to be created during defer parse
2930

3031
/***************************************************************************
3132
Flags for classifying parse nodes.
@@ -826,13 +827,12 @@ class ParseNodeWith : public ParseNodeStmt
826827
};
827828

828829
// Destructure pattern for function/catch parameter
829-
class ParseNodeParamPattern : public ParseNode
830+
class ParseNodeParamPattern : public ParseNodeUni
830831
{
831832
public:
832833
ParseNodeParamPattern(OpCode nop, charcount_t ichMin, charcount_t ichLim);
833834

834835
ParseNodePtr pnodeNext;
835-
ParseNodePtr pnode1;
836836
Js::RegSlot location;
837837
DISABLE_SELF_CAST(ParseNodeParamPattern);
838838
};

lib/Runtime/ByteCode/ByteCodeGenerator.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
#include "FormalsUtil.h"
77
#include "Library/StackScriptFunction.h"
88

9+
#if DBG
10+
#include "pnodewalk.h"
11+
#endif
12+
913
void PreVisitBlock(ParseNodeBlock *pnodeBlock, ByteCodeGenerator *byteCodeGenerator);
1014
void PostVisitBlock(ParseNodeBlock *pnodeBlock, ByteCodeGenerator *byteCodeGenerator);
1115

@@ -1941,6 +1945,16 @@ void ByteCodeGenerator::Generate(__in ParseNode *pnode, uint32 grfscr, __in Byte
19411945
__inout Js::ParseableFunctionInfo ** ppRootFunc, __in uint sourceIndex,
19421946
__in bool forceNoNative, __in Parser* parser, Js::ScriptFunction **functionRef)
19431947
{
1948+
#if DBG
1949+
struct WalkerPolicyTest : public WalkerPolicyBase<bool, ParseNodeWalker<WalkerPolicyTest>*>
1950+
{
1951+
inline bool ContinueWalk(ResultType) { return ThreadContext::IsCurrentStackAvailable(Js::Constants::MinStackByteCodeVisitor); }
1952+
virtual ResultType WalkChild(ParseNode *pnode, ParseNodeWalker<WalkerPolicyTest>* walker) { return ContinueWalk(true) && walker->Walk(pnode, walker); }
1953+
};
1954+
ParseNodeWalker<WalkerPolicyTest> walker;
1955+
// Just walk the ast to see if our walker encounters any problems
1956+
walker.Walk(pnode, &walker);
1957+
#endif
19441958
Js::ScriptContext * scriptContext = byteCodeGenerator->scriptContext;
19451959

19461960
#ifdef PROFILE_EXEC

test/Error/RuntimeCompileStackOverflow.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)