@@ -96,8 +96,6 @@ Parser::Parser(Js::ScriptContext* scriptContext, BOOL strictMode, PageAllocator
96
96
m_funcInArray(0 ),
97
97
m_scopeCountNoAst(0 ),
98
98
99
- m_parsingSuperRestrictionState(ParsingSuperRestrictionState_SuperDisallowed),
100
-
101
99
m_funcParenExprDepth(0 ),
102
100
m_deferEllipsisError(false ),
103
101
m_deferEllipsisErrorLoc(), // calls default initializer
@@ -329,11 +327,6 @@ HRESULT Parser::ParseSourceInternal(
329
327
330
328
try
331
329
{
332
- if ((grfscr & fscrEvalCode) != 0 )
333
- {
334
- this ->m_parsingSuperRestrictionState = Parser::ParsingSuperRestrictionState_SuperPropertyAllowed;
335
- }
336
-
337
330
if ((grfscr & fscrIsModuleCode) != 0 )
338
331
{
339
332
// Module source flag should not be enabled unless module is enabled
@@ -961,6 +954,7 @@ ParseNodeProg * Parser::CreateProgNode(bool isModuleSource, ULONG lineNumber)
961
954
pnodeProg->cbMin = this ->GetScanner ()->IecpMinTok ();
962
955
pnodeProg->lineNumber = lineNumber;
963
956
pnodeProg->homeObjLocation = Js::Constants::NoRegister;
957
+ pnodeProg->superRestrictionState = SuperRestrictionState::Disallowed;
964
958
return pnodeProg;
965
959
}
966
960
@@ -3050,7 +3044,7 @@ ParseNodePtr Parser::ParseTerm(BOOL fAllowCall,
3050
3044
{
3051
3045
Assert ((stub->fncFlags & kFunctionIsLambda ) == kFunctionIsLambda );
3052
3046
3053
- pnode = ParseFncDeclCheckScope<true >(fFncLambda , /* resetParsingSuperRestrictionState */ false );
3047
+ pnode = ParseFncDeclCheckScope<true >(fFncLambda );
3054
3048
break ;
3055
3049
}
3056
3050
}
@@ -3318,7 +3312,7 @@ ParseNodePtr Parser::ParseTerm(BOOL fAllowCall,
3318
3312
{
3319
3313
flags |= fFncAsync ;
3320
3314
}
3321
- pnode = ParseFncDeclNoCheckScope<buildAST>(flags, pNameHint, false , true , fUnaryOrParen );
3315
+ pnode = ParseFncDeclNoCheckScope<buildAST>(flags, SuperRestrictionState::Disallowed, pNameHint, false , true , fUnaryOrParen );
3322
3316
if (isAsyncExpr)
3323
3317
{
3324
3318
pnode->AsParseNodeFnc ()->cbMin = iecpMin;
@@ -4286,10 +4280,8 @@ ParseNodeBin * Parser::ParseMemberGetSet(OpCode nop, LPCOLESTR* ppNameHint)
4286
4280
flags |= fFncOneArg ;
4287
4281
}
4288
4282
4289
- AutoParsingSuperRestrictionStateRestorer restorer (this );
4290
- this ->m_parsingSuperRestrictionState = ParsingSuperRestrictionState_SuperPropertyAllowed;
4291
- ParseNodeFnc * pnodeFnc = ParseFncDeclNoCheckScope<buildAST>(flags, *ppNameHint,
4292
- /* needsPIDOnRCurlyScan*/ false , /* resetParsingSuperRestrictionState*/ false );
4283
+ ParseNodeFnc * pnodeFnc = ParseFncDeclNoCheckScope<buildAST>(flags, SuperRestrictionState::PropertyAllowed, *ppNameHint,
4284
+ /* needsPIDOnRCurlyScan*/ false );
4293
4285
4294
4286
if (isComputedName)
4295
4287
{
@@ -4610,10 +4602,8 @@ ParseNodePtr Parser::ParseMemberList(LPCOLESTR pNameHint, uint32* pNameHintLengt
4610
4602
// Rewind to the PID and parse a function expression.
4611
4603
this ->GetScanner ()->SeekTo (atPid);
4612
4604
4613
- AutoParsingSuperRestrictionStateRestorer restorer (this );
4614
- this ->m_parsingSuperRestrictionState = ParsingSuperRestrictionState_SuperPropertyAllowed;
4615
- ParseNodeFnc * pnodeFnc = ParseFncDeclNoCheckScope<buildAST>(fncDeclFlags | (isAsyncMethod ? fFncAsync : fFncNoFlgs ), pFullNameHint,
4616
- /* needsPIDOnRCurlyScan*/ false , /* resetParsingSuperRestrictionState*/ false );
4605
+ ParseNodeFnc * pnodeFnc = ParseFncDeclNoCheckScope<buildAST>(fncDeclFlags | (isAsyncMethod ? fFncAsync : fFncNoFlgs ), SuperRestrictionState::PropertyAllowed, pFullNameHint,
4606
+ /* needsPIDOnRCurlyScan*/ false );
4617
4607
4618
4608
if (isAsyncMethod || isGenerator)
4619
4609
{
@@ -4825,7 +4815,7 @@ BOOL Parser::IsDeferredFnc()
4825
4815
}
4826
4816
4827
4817
template <bool buildAST>
4828
- ParseNode * Parser::ParseFncDeclCheckScope (ushort flags, bool resetParsingSuperRestrictionState, bool fAllowIn )
4818
+ ParseNode * Parser::ParseFncDeclCheckScope (ushort flags, bool fAllowIn )
4829
4819
{
4830
4820
ParseNodeBlock * pnodeFncBlockScope = nullptr ;
4831
4821
ParseNodePtr *ppnodeScopeSave = nullptr ;
@@ -4853,7 +4843,7 @@ ParseNode * Parser::ParseFncDeclCheckScope(ushort flags, bool resetParsingSuperR
4853
4843
}
4854
4844
}
4855
4845
4856
- ParseNodeFnc * pnodeFnc = ParseFncDeclInternal<buildAST>(flags, nullptr , /* needsPIDOnRCurlyScan */ false , resetParsingSuperRestrictionState, /* fUnaryOrParen */ false , noStmtContext, fAllowIn );
4846
+ ParseNodeFnc * pnodeFnc = ParseFncDeclInternal<buildAST>(flags, nullptr , /* needsPIDOnRCurlyScan */ false , /* fUnaryOrParen */ false , noStmtContext, SuperRestrictionState::Disallowed , fAllowIn );
4857
4847
4858
4848
if (pnodeFncBlockScope)
4859
4849
{
@@ -4872,22 +4862,15 @@ ParseNode * Parser::ParseFncDeclCheckScope(ushort flags, bool resetParsingSuperR
4872
4862
}
4873
4863
4874
4864
template <bool buildAST>
4875
- ParseNodeFnc * Parser::ParseFncDeclNoCheckScope (ushort flags, LPCOLESTR pNameHint, const bool needsPIDOnRCurlyScan, bool resetParsingSuperRestrictionState , bool fUnaryOrParen , bool fAllowIn )
4865
+ ParseNodeFnc * Parser::ParseFncDeclNoCheckScope (ushort flags, SuperRestrictionState::State superRestrictionState, LPCOLESTR pNameHint, const bool needsPIDOnRCurlyScan, bool fUnaryOrParen , bool fAllowIn )
4876
4866
{
4877
4867
Assert ((flags & fFncDeclaration ) == 0 );
4878
- return ParseFncDeclInternal<buildAST>(flags, pNameHint, needsPIDOnRCurlyScan, resetParsingSuperRestrictionState, fUnaryOrParen , /* noStmtContext */ false , fAllowIn );
4868
+ return ParseFncDeclInternal<buildAST>(flags, pNameHint, needsPIDOnRCurlyScan, fUnaryOrParen , /* noStmtContext */ false , superRestrictionState , fAllowIn );
4879
4869
}
4880
4870
4881
4871
template <bool buildAST>
4882
- ParseNodeFnc * Parser::ParseFncDeclInternal (ushort flags, LPCOLESTR pNameHint, const bool needsPIDOnRCurlyScan, bool resetParsingSuperRestrictionState , bool fUnaryOrParen , bool noStmtContext , bool fAllowIn )
4872
+ ParseNodeFnc * Parser::ParseFncDeclInternal (ushort flags, LPCOLESTR pNameHint, const bool needsPIDOnRCurlyScan, bool fUnaryOrParen , bool noStmtContext, SuperRestrictionState::State superRestrictionState , bool fAllowIn )
4883
4873
{
4884
- AutoParsingSuperRestrictionStateRestorer restorer (this );
4885
- if (resetParsingSuperRestrictionState)
4886
- {
4887
- // ParseFncDecl will always reset m_parsingSuperRestrictionState to super disallowed unless explicitly disabled
4888
- this ->m_parsingSuperRestrictionState = ParsingSuperRestrictionState_SuperDisallowed;
4889
- }
4890
-
4891
4874
ParseNodeFnc * pnodeFnc = nullptr ;
4892
4875
ParseNodePtr *ppnodeVarSave = nullptr ;
4893
4876
@@ -4923,6 +4906,7 @@ ParseNodeFnc * Parser::ParseFncDeclInternal(ushort flags, LPCOLESTR pNameHint, c
4923
4906
pnodeFnc->nestedFuncEscapes = false ;
4924
4907
pnodeFnc->cbMin = this ->GetScanner ()->IecpMinTok ();
4925
4908
pnodeFnc->functionId = (*m_nextFunctionId)++;
4909
+ pnodeFnc->superRestrictionState = superRestrictionState;
4926
4910
4927
4911
4928
4912
// Push new parser state with this new function node
@@ -6689,7 +6673,7 @@ void Parser::ParseFncFormals(ParseNodeFnc * pnodeFnc, ParseNodeFnc * pnodeParent
6689
6673
template <bool buildAST>
6690
6674
ParseNodePtr Parser::GenerateModuleFunctionWrapper ()
6691
6675
{
6692
- ParseNodePtr pnodeFnc = ParseFncDeclNoCheckScope<buildAST>(fFncModule , nullptr , false , true , true );
6676
+ ParseNodePtr pnodeFnc = ParseFncDeclNoCheckScope<buildAST>(fFncModule , SuperRestrictionState::Disallowed, nullptr , false , true , true );
6693
6677
ParseNodePtr callNode = CreateCallNode (knopCall, pnodeFnc, nullptr );
6694
6678
6695
6679
return callNode;
@@ -7378,24 +7362,6 @@ LPCOLESTR Parser::ConstructFinalHintNode(IdentPtr pClassName, IdentPtr pMemberNa
7378
7362
return pFinalName;
7379
7363
}
7380
7364
7381
- class AutoParsingSuperRestrictionStateRestorer
7382
- {
7383
- public:
7384
- AutoParsingSuperRestrictionStateRestorer (Parser* parser) : m_parser(parser)
7385
- {
7386
- AssertMsg (this ->m_parser != nullptr , " This just should not happen" );
7387
- this ->m_originalParsingSuperRestrictionState = this ->m_parser ->m_parsingSuperRestrictionState ;
7388
- }
7389
- ~AutoParsingSuperRestrictionStateRestorer ()
7390
- {
7391
- AssertMsg (this ->m_parser != nullptr , " This just should not happen" );
7392
- this ->m_parser ->m_parsingSuperRestrictionState = m_originalParsingSuperRestrictionState;
7393
- }
7394
- private:
7395
- Parser * m_parser;
7396
- int m_originalParsingSuperRestrictionState;
7397
- };
7398
-
7399
7365
template <bool buildAST>
7400
7366
ParseNodeClass * Parser::ParseClassDecl (BOOL isDeclaration, LPCOLESTR pNameHint, uint32 *pHintLength, uint32 *pShortNameOffset)
7401
7367
{
@@ -7604,12 +7570,11 @@ ParseNodeClass * Parser::ParseClassDecl(BOOL isDeclaration, LPCOLESTR pNameHint,
7604
7570
}
7605
7571
7606
7572
{
7607
- AutoParsingSuperRestrictionStateRestorer restorer (this );
7608
- this ->m_parsingSuperRestrictionState = hasExtends ? ParsingSuperRestrictionState_SuperCallAndPropertyAllowed : ParsingSuperRestrictionState_SuperPropertyAllowed;
7573
+ SuperRestrictionState::State state = hasExtends ? SuperRestrictionState::CallAndPropertyAllowed : SuperRestrictionState::PropertyAllowed;
7609
7574
7610
7575
// Add the class constructor flag and base class constructor flag if pnodeExtends is nullptr
7611
7576
fncDeclFlags |= fFncClassConstructor | (hasExtends ? kFunctionNone : fFncBaseClassConstructor );
7612
- pnodeConstructor = ParseFncDeclNoCheckScope<buildAST>(fncDeclFlags, pConstructorName, /* needsPIDOnRCurlyScan */ true , /* resetParsingSuperRestrictionState = */ false );
7577
+ pnodeConstructor = ParseFncDeclNoCheckScope<buildAST>(fncDeclFlags, state, pConstructorName, /* needsPIDOnRCurlyScan */ true );
7613
7578
}
7614
7579
7615
7580
if (pnodeConstructor->IsGenerator ())
@@ -7671,11 +7636,8 @@ ParseNodeClass * Parser::ParseClassDecl(BOOL isDeclaration, LPCOLESTR pNameHint,
7671
7636
7672
7637
ParseNodeFnc * pnodeFnc = nullptr ;
7673
7638
{
7674
- AutoParsingSuperRestrictionStateRestorer restorer (this );
7675
- this ->m_parsingSuperRestrictionState = ParsingSuperRestrictionState_SuperPropertyAllowed;
7676
7639
pnodeFnc = ParseFncDeclNoCheckScope<buildAST>(fncDeclFlags | (isGetter ? fFncNoArg : fFncOneArg ),
7677
- pidHint ? pidHint->Psz () : nullptr , /* needsPIDOnRCurlyScan */ true ,
7678
- /* resetParsingSuperRestrictionState */ false );
7640
+ SuperRestrictionState::PropertyAllowed, pidHint ? pidHint->Psz () : nullptr , /* needsPIDOnRCurlyScan */ true );
7679
7641
}
7680
7642
7681
7643
pnodeFnc->SetIsStaticMember (isStatic);
@@ -7703,14 +7665,11 @@ ParseNodeClass * Parser::ParseClassDecl(BOOL isDeclaration, LPCOLESTR pNameHint,
7703
7665
7704
7666
ParseNodeFnc * pnodeFnc = nullptr ;
7705
7667
{
7706
- AutoParsingSuperRestrictionStateRestorer restorer (this );
7707
- this ->m_parsingSuperRestrictionState = ParsingSuperRestrictionState_SuperPropertyAllowed;
7708
-
7709
7668
if (isAsyncMethod)
7710
7669
{
7711
7670
fncDeclFlags |= fFncAsync ;
7712
7671
}
7713
- pnodeFnc = ParseFncDeclNoCheckScope<buildAST>(fncDeclFlags, pidHint ? pidHint->Psz () : nullptr , /* needsPIDOnRCurlyScan */ true , /* resetParsingSuperRestrictionState */ false );
7672
+ pnodeFnc = ParseFncDeclNoCheckScope<buildAST>(fncDeclFlags, SuperRestrictionState::PropertyAllowed, pidHint ? pidHint->Psz () : nullptr , /* needsPIDOnRCurlyScan */ true );
7714
7673
if (isAsyncMethod)
7715
7674
{
7716
7675
pnodeFnc->cbMin = iecpMin;
@@ -8823,7 +8782,7 @@ ParseNodePtr Parser::ParseExpr(int oplMin,
8823
8782
this ->GetScanner ()->SeekTo (termStart);
8824
8783
}
8825
8784
}
8826
- pnode = ParseFncDeclNoCheckScope<buildAST>(flags, nullptr , /* needsPIDOnRCurlyScan = */ false , /* resetParsingSuperRestrictionState = */ false , /* fUnaryOrParen = */ false , fAllowIn );
8785
+ pnode = ParseFncDeclNoCheckScope<buildAST>(flags, SuperRestrictionState::Disallowed, nullptr , /* needsPIDOnRCurlyScan = */ false , /* fUnaryOrParen = */ false , fAllowIn );
8827
8786
if (isAsyncMethod)
8828
8787
{
8829
8788
pnode->AsParseNodeFnc ()->cbMin = iecpMin;
@@ -11466,7 +11425,7 @@ ParseNodeProg * Parser::Parse(LPCUTF8 pszSrc, size_t offset, size_t length, char
11466
11425
flags |= fFncLambda ;
11467
11426
}
11468
11427
11469
- ParseNode * pnodeFnc = ParseFncDeclCheckScope<true >(flags, /* resetParsingSuperRestrictionState */ false );
11428
+ ParseNode * pnodeFnc = ParseFncDeclCheckScope<true >(flags);
11470
11429
pnodeProg->pnodeBody = nullptr ;
11471
11430
AddToNodeList (&pnodeProg->pnodeBody , &lastNodeRef, pnodeFnc);
11472
11431
@@ -12278,6 +12237,7 @@ template <bool buildAST>
12278
12237
IdentPtr Parser::ParseSuper (bool fAllowCall )
12279
12238
{
12280
12239
ParseNodeFnc * currentNodeFunc = GetCurrentFunctionNode ();
12240
+ ParseNodeFnc * currentNonLambdaFunc = GetCurrentNonLambdaFunctionNode ();
12281
12241
IdentPtr superPid = nullptr ;
12282
12242
12283
12243
switch (m_token.tk )
@@ -12309,12 +12269,14 @@ IdentPtr Parser::ParseSuper(bool fAllowCall)
12309
12269
{
12310
12270
Error (ERRInvalidSuper); // new super() is not allowed
12311
12271
}
12312
- else if (this ->m_parsingSuperRestrictionState == ParsingSuperRestrictionState_SuperCallAndPropertyAllowed)
12272
+ else if ((currentNodeFunc->IsConstructor () && currentNodeFunc->superRestrictionState == SuperRestrictionState::CallAndPropertyAllowed)
12273
+ || (currentNonLambdaFunc != nullptr && currentNonLambdaFunc->superRestrictionState == SuperRestrictionState::CallAndPropertyAllowed))
12313
12274
{
12314
12275
// Any super access is good within a class constructor
12315
12276
}
12316
- else if (this ->m_parsingSuperRestrictionState == ParsingSuperRestrictionState_SuperPropertyAllowed )
12277
+ else if (( this ->m_grfscr & fscrEval) == fscrEval || currentNonLambdaFunc-> superRestrictionState == SuperRestrictionState::PropertyAllowed )
12317
12278
{
12279
+ // Currently for eval cases during compile time we use propertyallowed and throw during runtime for error cases
12318
12280
if (m_token.tk == tkLParen)
12319
12281
{
12320
12282
if ((this ->m_grfscr & fscrEval) == fscrNil)
0 commit comments