@@ -120,8 +120,6 @@ Parser::Parser(Js::ScriptContext* scriptContext, BOOL strictMode, PageAllocator
120
120
m_funcInArray(0 ),
121
121
m_scopeCountNoAst(0 ),
122
122
123
- m_parsingSuperRestrictionState(ParsingSuperRestrictionState_SuperDisallowed),
124
-
125
123
m_funcParenExprDepth(0 ),
126
124
m_deferEllipsisError(false ),
127
125
m_deferEllipsisErrorLoc(), // calls default initializer
@@ -353,11 +351,6 @@ HRESULT Parser::ParseSourceInternal(
353
351
354
352
try
355
353
{
356
- if ((grfscr & fscrEvalCode) != 0 )
357
- {
358
- this ->m_parsingSuperRestrictionState = Parser::ParsingSuperRestrictionState_SuperPropertyAllowed;
359
- }
360
-
361
354
if ((grfscr & fscrIsModuleCode) != 0 )
362
355
{
363
356
// Module source flag should not be enabled unless module is enabled
@@ -985,6 +978,7 @@ ParseNodeProg * Parser::CreateProgNode(bool isModuleSource, ULONG lineNumber)
985
978
pnodeProg->cbMin = this ->GetScanner ()->IecpMinTok ();
986
979
pnodeProg->lineNumber = lineNumber;
987
980
pnodeProg->homeObjLocation = Js::Constants::NoRegister;
981
+ pnodeProg->superRestrictionState = SuperRestrictionState::Disallowed;
988
982
return pnodeProg;
989
983
}
990
984
@@ -3074,7 +3068,7 @@ ParseNodePtr Parser::ParseTerm(BOOL fAllowCall,
3074
3068
{
3075
3069
Assert ((stub->fncFlags & kFunctionIsLambda ) == kFunctionIsLambda );
3076
3070
3077
- pnode = ParseFncDeclCheckScope<true >(fFncLambda , /* resetParsingSuperRestrictionState */ false );
3071
+ pnode = ParseFncDeclCheckScope<true >(fFncLambda );
3078
3072
break ;
3079
3073
}
3080
3074
}
@@ -3342,7 +3336,7 @@ ParseNodePtr Parser::ParseTerm(BOOL fAllowCall,
3342
3336
{
3343
3337
flags |= fFncAsync ;
3344
3338
}
3345
- pnode = ParseFncDeclNoCheckScope<buildAST>(flags, pNameHint, false , true , fUnaryOrParen );
3339
+ pnode = ParseFncDeclNoCheckScope<buildAST>(flags, SuperRestrictionState::Disallowed, pNameHint, false , true , fUnaryOrParen );
3346
3340
if (isAsyncExpr)
3347
3341
{
3348
3342
pnode->AsParseNodeFnc ()->cbMin = iecpMin;
@@ -4310,10 +4304,8 @@ ParseNodeBin * Parser::ParseMemberGetSet(OpCode nop, LPCOLESTR* ppNameHint)
4310
4304
flags |= fFncOneArg ;
4311
4305
}
4312
4306
4313
- AutoParsingSuperRestrictionStateRestorer restorer (this );
4314
- this ->m_parsingSuperRestrictionState = ParsingSuperRestrictionState_SuperPropertyAllowed;
4315
- ParseNodeFnc * pnodeFnc = ParseFncDeclNoCheckScope<buildAST>(flags, *ppNameHint,
4316
- /* needsPIDOnRCurlyScan*/ false , /* resetParsingSuperRestrictionState*/ false );
4307
+ ParseNodeFnc * pnodeFnc = ParseFncDeclNoCheckScope<buildAST>(flags, SuperRestrictionState::PropertyAllowed, *ppNameHint,
4308
+ /* needsPIDOnRCurlyScan*/ false );
4317
4309
4318
4310
if (isComputedName)
4319
4311
{
@@ -4634,10 +4626,8 @@ ParseNodePtr Parser::ParseMemberList(LPCOLESTR pNameHint, uint32* pNameHintLengt
4634
4626
// Rewind to the PID and parse a function expression.
4635
4627
this ->GetScanner ()->SeekTo (atPid);
4636
4628
4637
- AutoParsingSuperRestrictionStateRestorer restorer (this );
4638
- this ->m_parsingSuperRestrictionState = ParsingSuperRestrictionState_SuperPropertyAllowed;
4639
- ParseNodeFnc * pnodeFnc = ParseFncDeclNoCheckScope<buildAST>(fncDeclFlags | (isAsyncMethod ? fFncAsync : fFncNoFlgs ), pFullNameHint,
4640
- /* needsPIDOnRCurlyScan*/ false , /* resetParsingSuperRestrictionState*/ false );
4629
+ ParseNodeFnc * pnodeFnc = ParseFncDeclNoCheckScope<buildAST>(fncDeclFlags | (isAsyncMethod ? fFncAsync : fFncNoFlgs ), SuperRestrictionState::PropertyAllowed, pFullNameHint,
4630
+ /* needsPIDOnRCurlyScan*/ false );
4641
4631
4642
4632
if (isAsyncMethod || isGenerator)
4643
4633
{
@@ -4849,7 +4839,7 @@ BOOL Parser::IsDeferredFnc()
4849
4839
}
4850
4840
4851
4841
template <bool buildAST>
4852
- ParseNode * Parser::ParseFncDeclCheckScope (ushort flags, bool resetParsingSuperRestrictionState, bool fAllowIn )
4842
+ ParseNode * Parser::ParseFncDeclCheckScope (ushort flags, bool fAllowIn )
4853
4843
{
4854
4844
ParseNodeBlock * pnodeFncBlockScope = nullptr ;
4855
4845
ParseNodePtr *ppnodeScopeSave = nullptr ;
@@ -4877,7 +4867,7 @@ ParseNode * Parser::ParseFncDeclCheckScope(ushort flags, bool resetParsingSuperR
4877
4867
}
4878
4868
}
4879
4869
4880
- ParseNodeFnc * pnodeFnc = ParseFncDeclInternal<buildAST>(flags, nullptr , /* needsPIDOnRCurlyScan */ false , resetParsingSuperRestrictionState, /* fUnaryOrParen */ false , noStmtContext, fAllowIn );
4870
+ ParseNodeFnc * pnodeFnc = ParseFncDeclInternal<buildAST>(flags, nullptr , /* needsPIDOnRCurlyScan */ false , /* fUnaryOrParen */ false , noStmtContext, SuperRestrictionState::Disallowed , fAllowIn );
4881
4871
4882
4872
if (pnodeFncBlockScope)
4883
4873
{
@@ -4896,22 +4886,15 @@ ParseNode * Parser::ParseFncDeclCheckScope(ushort flags, bool resetParsingSuperR
4896
4886
}
4897
4887
4898
4888
template <bool buildAST>
4899
- ParseNodeFnc * Parser::ParseFncDeclNoCheckScope (ushort flags, LPCOLESTR pNameHint, const bool needsPIDOnRCurlyScan, bool resetParsingSuperRestrictionState , bool fUnaryOrParen , bool fAllowIn )
4889
+ ParseNodeFnc * Parser::ParseFncDeclNoCheckScope (ushort flags, SuperRestrictionState::State superRestrictionState, LPCOLESTR pNameHint, const bool needsPIDOnRCurlyScan, bool fUnaryOrParen , bool fAllowIn )
4900
4890
{
4901
4891
Assert ((flags & fFncDeclaration ) == 0 );
4902
- return ParseFncDeclInternal<buildAST>(flags, pNameHint, needsPIDOnRCurlyScan, resetParsingSuperRestrictionState, fUnaryOrParen , /* noStmtContext */ false , fAllowIn );
4892
+ return ParseFncDeclInternal<buildAST>(flags, pNameHint, needsPIDOnRCurlyScan, fUnaryOrParen , /* noStmtContext */ false , superRestrictionState , fAllowIn );
4903
4893
}
4904
4894
4905
4895
template <bool buildAST>
4906
- ParseNodeFnc * Parser::ParseFncDeclInternal (ushort flags, LPCOLESTR pNameHint, const bool needsPIDOnRCurlyScan, bool resetParsingSuperRestrictionState , bool fUnaryOrParen , bool noStmtContext , bool fAllowIn )
4896
+ ParseNodeFnc * Parser::ParseFncDeclInternal (ushort flags, LPCOLESTR pNameHint, const bool needsPIDOnRCurlyScan, bool fUnaryOrParen , bool noStmtContext, SuperRestrictionState::State superRestrictionState , bool fAllowIn )
4907
4897
{
4908
- AutoParsingSuperRestrictionStateRestorer restorer (this );
4909
- if (resetParsingSuperRestrictionState)
4910
- {
4911
- // ParseFncDecl will always reset m_parsingSuperRestrictionState to super disallowed unless explicitly disabled
4912
- this ->m_parsingSuperRestrictionState = ParsingSuperRestrictionState_SuperDisallowed;
4913
- }
4914
-
4915
4898
ParseNodeFnc * pnodeFnc = nullptr ;
4916
4899
ParseNodePtr *ppnodeVarSave = nullptr ;
4917
4900
@@ -4947,6 +4930,7 @@ ParseNodeFnc * Parser::ParseFncDeclInternal(ushort flags, LPCOLESTR pNameHint, c
4947
4930
pnodeFnc->nestedFuncEscapes = false ;
4948
4931
pnodeFnc->cbMin = this ->GetScanner ()->IecpMinTok ();
4949
4932
pnodeFnc->functionId = (*m_nextFunctionId)++;
4933
+ pnodeFnc->superRestrictionState = superRestrictionState;
4950
4934
4951
4935
4952
4936
// Push new parser state with this new function node
@@ -6713,7 +6697,7 @@ void Parser::ParseFncFormals(ParseNodeFnc * pnodeFnc, ParseNodeFnc * pnodeParent
6713
6697
template <bool buildAST>
6714
6698
ParseNodePtr Parser::GenerateModuleFunctionWrapper ()
6715
6699
{
6716
- ParseNodePtr pnodeFnc = ParseFncDeclNoCheckScope<buildAST>(fFncModule , nullptr , false , true , true );
6700
+ ParseNodePtr pnodeFnc = ParseFncDeclNoCheckScope<buildAST>(fFncModule , SuperRestrictionState::Disallowed, nullptr , false , true , true );
6717
6701
ParseNodePtr callNode = CreateCallNode (knopCall, pnodeFnc, nullptr );
6718
6702
6719
6703
return callNode;
@@ -7402,24 +7386,6 @@ LPCOLESTR Parser::ConstructFinalHintNode(IdentPtr pClassName, IdentPtr pMemberNa
7402
7386
return pFinalName;
7403
7387
}
7404
7388
7405
- class AutoParsingSuperRestrictionStateRestorer
7406
- {
7407
- public:
7408
- AutoParsingSuperRestrictionStateRestorer (Parser* parser) : m_parser(parser)
7409
- {
7410
- AssertMsg (this ->m_parser != nullptr , " This just should not happen" );
7411
- this ->m_originalParsingSuperRestrictionState = this ->m_parser ->m_parsingSuperRestrictionState ;
7412
- }
7413
- ~AutoParsingSuperRestrictionStateRestorer ()
7414
- {
7415
- AssertMsg (this ->m_parser != nullptr , " This just should not happen" );
7416
- this ->m_parser ->m_parsingSuperRestrictionState = m_originalParsingSuperRestrictionState;
7417
- }
7418
- private:
7419
- Parser * m_parser;
7420
- int m_originalParsingSuperRestrictionState;
7421
- };
7422
-
7423
7389
template <bool buildAST>
7424
7390
ParseNodeClass * Parser::ParseClassDecl (BOOL isDeclaration, LPCOLESTR pNameHint, uint32 *pHintLength, uint32 *pShortNameOffset)
7425
7391
{
@@ -7628,12 +7594,11 @@ ParseNodeClass * Parser::ParseClassDecl(BOOL isDeclaration, LPCOLESTR pNameHint,
7628
7594
}
7629
7595
7630
7596
{
7631
- AutoParsingSuperRestrictionStateRestorer restorer (this );
7632
- this ->m_parsingSuperRestrictionState = hasExtends ? ParsingSuperRestrictionState_SuperCallAndPropertyAllowed : ParsingSuperRestrictionState_SuperPropertyAllowed;
7597
+ SuperRestrictionState::State state = hasExtends ? SuperRestrictionState::CallAndPropertyAllowed : SuperRestrictionState::PropertyAllowed;
7633
7598
7634
7599
// Add the class constructor flag and base class constructor flag if pnodeExtends is nullptr
7635
7600
fncDeclFlags |= fFncClassConstructor | (hasExtends ? kFunctionNone : fFncBaseClassConstructor );
7636
- pnodeConstructor = ParseFncDeclNoCheckScope<buildAST>(fncDeclFlags, pConstructorName, /* needsPIDOnRCurlyScan */ true , /* resetParsingSuperRestrictionState = */ false );
7601
+ pnodeConstructor = ParseFncDeclNoCheckScope<buildAST>(fncDeclFlags, state, pConstructorName, /* needsPIDOnRCurlyScan */ true );
7637
7602
}
7638
7603
7639
7604
if (pnodeConstructor->IsGenerator ())
@@ -7695,11 +7660,8 @@ ParseNodeClass * Parser::ParseClassDecl(BOOL isDeclaration, LPCOLESTR pNameHint,
7695
7660
7696
7661
ParseNodeFnc * pnodeFnc = nullptr ;
7697
7662
{
7698
- AutoParsingSuperRestrictionStateRestorer restorer (this );
7699
- this ->m_parsingSuperRestrictionState = ParsingSuperRestrictionState_SuperPropertyAllowed;
7700
7663
pnodeFnc = ParseFncDeclNoCheckScope<buildAST>(fncDeclFlags | (isGetter ? fFncNoArg : fFncOneArg ),
7701
- pidHint ? pidHint->Psz () : nullptr , /* needsPIDOnRCurlyScan */ true ,
7702
- /* resetParsingSuperRestrictionState */ false );
7664
+ SuperRestrictionState::PropertyAllowed, pidHint ? pidHint->Psz () : nullptr , /* needsPIDOnRCurlyScan */ true );
7703
7665
}
7704
7666
7705
7667
pnodeFnc->SetIsStaticMember (isStatic);
@@ -7727,14 +7689,11 @@ ParseNodeClass * Parser::ParseClassDecl(BOOL isDeclaration, LPCOLESTR pNameHint,
7727
7689
7728
7690
ParseNodeFnc * pnodeFnc = nullptr ;
7729
7691
{
7730
- AutoParsingSuperRestrictionStateRestorer restorer (this );
7731
- this ->m_parsingSuperRestrictionState = ParsingSuperRestrictionState_SuperPropertyAllowed;
7732
-
7733
7692
if (isAsyncMethod)
7734
7693
{
7735
7694
fncDeclFlags |= fFncAsync ;
7736
7695
}
7737
- pnodeFnc = ParseFncDeclNoCheckScope<buildAST>(fncDeclFlags, pidHint ? pidHint->Psz () : nullptr , /* needsPIDOnRCurlyScan */ true , /* resetParsingSuperRestrictionState */ false );
7696
+ pnodeFnc = ParseFncDeclNoCheckScope<buildAST>(fncDeclFlags, SuperRestrictionState::PropertyAllowed, pidHint ? pidHint->Psz () : nullptr , /* needsPIDOnRCurlyScan */ true );
7738
7697
if (isAsyncMethod)
7739
7698
{
7740
7699
pnodeFnc->cbMin = iecpMin;
@@ -8847,7 +8806,7 @@ ParseNodePtr Parser::ParseExpr(int oplMin,
8847
8806
this ->GetScanner ()->SeekTo (termStart);
8848
8807
}
8849
8808
}
8850
- pnode = ParseFncDeclNoCheckScope<buildAST>(flags, nullptr , /* needsPIDOnRCurlyScan = */ false , /* resetParsingSuperRestrictionState = */ false , /* fUnaryOrParen = */ false , fAllowIn );
8809
+ pnode = ParseFncDeclNoCheckScope<buildAST>(flags, SuperRestrictionState::Disallowed, nullptr , /* needsPIDOnRCurlyScan = */ false , /* fUnaryOrParen = */ false , fAllowIn );
8851
8810
if (isAsyncMethod)
8852
8811
{
8853
8812
pnode->AsParseNodeFnc ()->cbMin = iecpMin;
@@ -11490,7 +11449,7 @@ ParseNodeProg * Parser::Parse(LPCUTF8 pszSrc, size_t offset, size_t length, char
11490
11449
flags |= fFncLambda ;
11491
11450
}
11492
11451
11493
- ParseNode * pnodeFnc = ParseFncDeclCheckScope<true >(flags, /* resetParsingSuperRestrictionState */ false );
11452
+ ParseNode * pnodeFnc = ParseFncDeclCheckScope<true >(flags);
11494
11453
pnodeProg->pnodeBody = nullptr ;
11495
11454
AddToNodeList (&pnodeProg->pnodeBody , &lastNodeRef, pnodeFnc);
11496
11455
@@ -12302,6 +12261,7 @@ template <bool buildAST>
12302
12261
IdentPtr Parser::ParseSuper (bool fAllowCall )
12303
12262
{
12304
12263
ParseNodeFnc * currentNodeFunc = GetCurrentFunctionNode ();
12264
+ ParseNodeFnc * currentNonLambdaFunc = GetCurrentNonLambdaFunctionNode ();
12305
12265
IdentPtr superPid = nullptr ;
12306
12266
12307
12267
switch (m_token.tk )
@@ -12333,12 +12293,14 @@ IdentPtr Parser::ParseSuper(bool fAllowCall)
12333
12293
{
12334
12294
Error (ERRInvalidSuper); // new super() is not allowed
12335
12295
}
12336
- else if (this ->m_parsingSuperRestrictionState == ParsingSuperRestrictionState_SuperCallAndPropertyAllowed)
12296
+ else if ((currentNodeFunc->IsConstructor () && currentNodeFunc->superRestrictionState == SuperRestrictionState::CallAndPropertyAllowed)
12297
+ || (currentNonLambdaFunc != nullptr && currentNonLambdaFunc->superRestrictionState == SuperRestrictionState::CallAndPropertyAllowed))
12337
12298
{
12338
12299
// Any super access is good within a class constructor
12339
12300
}
12340
- else if (this ->m_parsingSuperRestrictionState == ParsingSuperRestrictionState_SuperPropertyAllowed )
12301
+ else if (( this ->m_grfscr & fscrEval) == fscrEval || currentNonLambdaFunc-> superRestrictionState == SuperRestrictionState::PropertyAllowed )
12341
12302
{
12303
+ // Currently for eval cases during compile time we use propertyallowed and throw during runtime for error cases
12342
12304
if (m_token.tk == tkLParen)
12343
12305
{
12344
12306
if ((this ->m_grfscr & fscrEval) == fscrNil)
0 commit comments