@@ -97,8 +97,6 @@ Parser::Parser(Js::ScriptContext* scriptContext, BOOL strictMode, PageAllocator
97
97
m_funcInArray(0 ),
98
98
m_scopeCountNoAst(0 ),
99
99
100
- m_parsingSuperRestrictionState(ParsingSuperRestrictionState_SuperDisallowed),
101
-
102
100
m_funcParenExprDepth(0 ),
103
101
m_deferEllipsisError(false ),
104
102
m_deferEllipsisErrorLoc(), // calls default initializer
@@ -330,11 +328,6 @@ HRESULT Parser::ParseSourceInternal(
330
328
331
329
try
332
330
{
333
- if ((grfscr & fscrEvalCode) != 0 )
334
- {
335
- this ->m_parsingSuperRestrictionState = Parser::ParsingSuperRestrictionState_SuperPropertyAllowed;
336
- }
337
-
338
331
if ((grfscr & fscrIsModuleCode) != 0 )
339
332
{
340
333
// Module source flag should not be enabled unless module is enabled
@@ -963,6 +956,7 @@ ParseNodeProg * Parser::CreateProgNode(bool isModuleSource, ULONG lineNumber)
963
956
pnodeProg->cbStringMin = pnodeProg->cbMin ;
964
957
pnodeProg->lineNumber = lineNumber;
965
958
pnodeProg->homeObjLocation = Js::Constants::NoRegister;
959
+ pnodeProg->superRestrictionState = SuperRestrictionState::Disallowed;
966
960
return pnodeProg;
967
961
}
968
962
@@ -3052,7 +3046,7 @@ ParseNodePtr Parser::ParseTerm(BOOL fAllowCall,
3052
3046
{
3053
3047
Assert ((stub->fncFlags & kFunctionIsLambda ) == kFunctionIsLambda );
3054
3048
3055
- pnode = ParseFncDeclCheckScope<true >(fFncLambda , /* resetParsingSuperRestrictionState */ false );
3049
+ pnode = ParseFncDeclCheckScope<true >(fFncLambda );
3056
3050
break ;
3057
3051
}
3058
3052
}
@@ -3320,7 +3314,7 @@ ParseNodePtr Parser::ParseTerm(BOOL fAllowCall,
3320
3314
{
3321
3315
flags |= fFncAsync ;
3322
3316
}
3323
- pnode = ParseFncDeclNoCheckScope<buildAST>(flags, pNameHint, false , true , fUnaryOrParen );
3317
+ pnode = ParseFncDeclNoCheckScope<buildAST>(flags, SuperRestrictionState::Disallowed, pNameHint, false , true , fUnaryOrParen );
3324
3318
if (isAsyncExpr)
3325
3319
{
3326
3320
pnode->AsParseNodeFnc ()->cbStringMin = iecpMin;
@@ -4287,10 +4281,8 @@ ParseNodeBin * Parser::ParseMemberGetSet(OpCode nop, LPCOLESTR* ppNameHint, size
4287
4281
flags |= fFncOneArg ;
4288
4282
}
4289
4283
4290
- AutoParsingSuperRestrictionStateRestorer restorer (this );
4291
- this ->m_parsingSuperRestrictionState = ParsingSuperRestrictionState_SuperPropertyAllowed;
4292
- ParseNodeFnc * pnodeFnc = ParseFncDeclNoCheckScope<buildAST>(flags, *ppNameHint,
4293
- /* needsPIDOnRCurlyScan*/ false , /* resetParsingSuperRestrictionState*/ false );
4284
+ ParseNodeFnc * pnodeFnc = ParseFncDeclNoCheckScope<buildAST>(flags, SuperRestrictionState::PropertyAllowed, *ppNameHint,
4285
+ /* needsPIDOnRCurlyScan*/ false );
4294
4286
4295
4287
pnodeFnc->cbStringMin = iecpMin;
4296
4288
@@ -4630,10 +4622,8 @@ ParseNodePtr Parser::ParseMemberList(LPCOLESTR pNameHint, uint32* pNameHintLengt
4630
4622
// Rewind to the PID and parse a function expression.
4631
4623
this ->GetScanner ()->SeekTo (atPid);
4632
4624
4633
- AutoParsingSuperRestrictionStateRestorer restorer (this );
4634
- this ->m_parsingSuperRestrictionState = ParsingSuperRestrictionState_SuperPropertyAllowed;
4635
- ParseNodeFnc * pnodeFnc = ParseFncDeclNoCheckScope<buildAST>(fncDeclFlags | (isAsyncMethod ? fFncAsync : fFncNoFlgs ), pFullNameHint,
4636
- /* needsPIDOnRCurlyScan*/ false , /* resetParsingSuperRestrictionState*/ false );
4625
+ ParseNodeFnc * pnodeFnc = ParseFncDeclNoCheckScope<buildAST>(fncDeclFlags | (isAsyncMethod ? fFncAsync : fFncNoFlgs ), SuperRestrictionState::PropertyAllowed, pFullNameHint,
4626
+ /* needsPIDOnRCurlyScan*/ false );
4637
4627
4638
4628
if (isAsyncMethod || isGenerator)
4639
4629
{
@@ -4862,7 +4852,7 @@ BOOL Parser::IsDeferredFnc()
4862
4852
}
4863
4853
4864
4854
template <bool buildAST>
4865
- ParseNode * Parser::ParseFncDeclCheckScope (ushort flags, bool resetParsingSuperRestrictionState, bool fAllowIn )
4855
+ ParseNode * Parser::ParseFncDeclCheckScope (ushort flags, bool fAllowIn )
4866
4856
{
4867
4857
ParseNodeBlock * pnodeFncBlockScope = nullptr ;
4868
4858
ParseNodePtr *ppnodeScopeSave = nullptr ;
@@ -4890,7 +4880,7 @@ ParseNode * Parser::ParseFncDeclCheckScope(ushort flags, bool resetParsingSuperR
4890
4880
}
4891
4881
}
4892
4882
4893
- ParseNodeFnc * pnodeFnc = ParseFncDeclInternal<buildAST>(flags, nullptr , /* needsPIDOnRCurlyScan */ false , resetParsingSuperRestrictionState, /* fUnaryOrParen */ false , noStmtContext, fAllowIn );
4883
+ ParseNodeFnc * pnodeFnc = ParseFncDeclInternal<buildAST>(flags, nullptr , /* needsPIDOnRCurlyScan */ false , /* fUnaryOrParen */ false , noStmtContext, SuperRestrictionState::Disallowed , fAllowIn );
4894
4884
4895
4885
if (pnodeFncBlockScope)
4896
4886
{
@@ -4909,22 +4899,15 @@ ParseNode * Parser::ParseFncDeclCheckScope(ushort flags, bool resetParsingSuperR
4909
4899
}
4910
4900
4911
4901
template <bool buildAST>
4912
- ParseNodeFnc * Parser::ParseFncDeclNoCheckScope (ushort flags, LPCOLESTR pNameHint, const bool needsPIDOnRCurlyScan, bool resetParsingSuperRestrictionState , bool fUnaryOrParen , bool fAllowIn )
4902
+ ParseNodeFnc * Parser::ParseFncDeclNoCheckScope (ushort flags, SuperRestrictionState::State superRestrictionState, LPCOLESTR pNameHint, const bool needsPIDOnRCurlyScan, bool fUnaryOrParen , bool fAllowIn )
4913
4903
{
4914
4904
Assert ((flags & fFncDeclaration ) == 0 );
4915
- return ParseFncDeclInternal<buildAST>(flags, pNameHint, needsPIDOnRCurlyScan, resetParsingSuperRestrictionState, fUnaryOrParen , /* noStmtContext */ false , fAllowIn );
4905
+ return ParseFncDeclInternal<buildAST>(flags, pNameHint, needsPIDOnRCurlyScan, fUnaryOrParen , /* noStmtContext */ false , superRestrictionState , fAllowIn );
4916
4906
}
4917
4907
4918
4908
template <bool buildAST>
4919
- ParseNodeFnc * Parser::ParseFncDeclInternal (ushort flags, LPCOLESTR pNameHint, const bool needsPIDOnRCurlyScan, bool resetParsingSuperRestrictionState , bool fUnaryOrParen , bool noStmtContext , bool fAllowIn )
4909
+ ParseNodeFnc * Parser::ParseFncDeclInternal (ushort flags, LPCOLESTR pNameHint, const bool needsPIDOnRCurlyScan, bool fUnaryOrParen , bool noStmtContext, SuperRestrictionState::State superRestrictionState , bool fAllowIn )
4920
4910
{
4921
- AutoParsingSuperRestrictionStateRestorer restorer (this );
4922
- if (resetParsingSuperRestrictionState)
4923
- {
4924
- // ParseFncDecl will always reset m_parsingSuperRestrictionState to super disallowed unless explicitly disabled
4925
- this ->m_parsingSuperRestrictionState = ParsingSuperRestrictionState_SuperDisallowed;
4926
- }
4927
-
4928
4911
ParseNodeFnc * pnodeFnc = nullptr ;
4929
4912
ParseNodePtr *ppnodeVarSave = nullptr ;
4930
4913
@@ -4961,6 +4944,7 @@ ParseNodeFnc * Parser::ParseFncDeclInternal(ushort flags, LPCOLESTR pNameHint, c
4961
4944
pnodeFnc->cbMin = this ->GetScanner ()->IecpMinTok ();
4962
4945
pnodeFnc->cbStringMin = pnodeFnc->cbMin ;
4963
4946
pnodeFnc->functionId = (*m_nextFunctionId)++;
4947
+ pnodeFnc->superRestrictionState = superRestrictionState;
4964
4948
4965
4949
4966
4950
// Push new parser state with this new function node
@@ -6730,7 +6714,7 @@ void Parser::ParseFncFormals(ParseNodeFnc * pnodeFnc, ParseNodeFnc * pnodeParent
6730
6714
template <bool buildAST>
6731
6715
ParseNodePtr Parser::GenerateModuleFunctionWrapper ()
6732
6716
{
6733
- ParseNodePtr pnodeFnc = ParseFncDeclNoCheckScope<buildAST>(fFncModule , nullptr , false , true , true );
6717
+ ParseNodePtr pnodeFnc = ParseFncDeclNoCheckScope<buildAST>(fFncModule , SuperRestrictionState::Disallowed, nullptr , false , true , true );
6734
6718
ParseNodePtr callNode = CreateCallNode (knopCall, pnodeFnc, nullptr );
6735
6719
6736
6720
return callNode;
@@ -7420,24 +7404,6 @@ LPCOLESTR Parser::ConstructFinalHintNode(IdentPtr pClassName, IdentPtr pMemberNa
7420
7404
return pFinalName;
7421
7405
}
7422
7406
7423
- class AutoParsingSuperRestrictionStateRestorer
7424
- {
7425
- public:
7426
- AutoParsingSuperRestrictionStateRestorer (Parser* parser) : m_parser(parser)
7427
- {
7428
- AssertMsg (this ->m_parser != nullptr , " This just should not happen" );
7429
- this ->m_originalParsingSuperRestrictionState = this ->m_parser ->m_parsingSuperRestrictionState ;
7430
- }
7431
- ~AutoParsingSuperRestrictionStateRestorer ()
7432
- {
7433
- AssertMsg (this ->m_parser != nullptr , " This just should not happen" );
7434
- this ->m_parser ->m_parsingSuperRestrictionState = m_originalParsingSuperRestrictionState;
7435
- }
7436
- private:
7437
- Parser * m_parser;
7438
- int m_originalParsingSuperRestrictionState;
7439
- };
7440
-
7441
7407
template <bool buildAST>
7442
7408
ParseNodeClass * Parser::ParseClassDecl (BOOL isDeclaration, LPCOLESTR pNameHint, uint32 *pHintLength, uint32 *pShortNameOffset)
7443
7409
{
@@ -7646,12 +7612,11 @@ ParseNodeClass * Parser::ParseClassDecl(BOOL isDeclaration, LPCOLESTR pNameHint,
7646
7612
}
7647
7613
7648
7614
{
7649
- AutoParsingSuperRestrictionStateRestorer restorer (this );
7650
- this ->m_parsingSuperRestrictionState = hasExtends ? ParsingSuperRestrictionState_SuperCallAndPropertyAllowed : ParsingSuperRestrictionState_SuperPropertyAllowed;
7615
+ SuperRestrictionState::State state = hasExtends ? SuperRestrictionState::CallAndPropertyAllowed : SuperRestrictionState::PropertyAllowed;
7651
7616
7652
7617
// Add the class constructor flag and base class constructor flag if pnodeExtends is nullptr
7653
7618
fncDeclFlags |= fFncClassConstructor | (hasExtends ? kFunctionNone : fFncBaseClassConstructor );
7654
- pnodeConstructor = ParseFncDeclNoCheckScope<buildAST>(fncDeclFlags, pConstructorName, /* needsPIDOnRCurlyScan */ true , /* resetParsingSuperRestrictionState = */ false );
7619
+ pnodeConstructor = ParseFncDeclNoCheckScope<buildAST>(fncDeclFlags, state, pConstructorName, /* needsPIDOnRCurlyScan */ true );
7655
7620
}
7656
7621
7657
7622
if (pnodeConstructor->IsGenerator ())
@@ -7713,11 +7678,8 @@ ParseNodeClass * Parser::ParseClassDecl(BOOL isDeclaration, LPCOLESTR pNameHint,
7713
7678
7714
7679
ParseNodeFnc * pnodeFnc = nullptr ;
7715
7680
{
7716
- AutoParsingSuperRestrictionStateRestorer restorer (this );
7717
- this ->m_parsingSuperRestrictionState = ParsingSuperRestrictionState_SuperPropertyAllowed;
7718
7681
pnodeFnc = ParseFncDeclNoCheckScope<buildAST>(fncDeclFlags | (isGetter ? fFncNoArg : fFncOneArg ),
7719
- pidHint ? pidHint->Psz () : nullptr , /* needsPIDOnRCurlyScan */ true ,
7720
- /* resetParsingSuperRestrictionState */ false );
7682
+ SuperRestrictionState::PropertyAllowed, pidHint ? pidHint->Psz () : nullptr , /* needsPIDOnRCurlyScan */ true );
7721
7683
}
7722
7684
7723
7685
pnodeFnc->SetIsStaticMember (isStatic);
@@ -7745,14 +7707,11 @@ ParseNodeClass * Parser::ParseClassDecl(BOOL isDeclaration, LPCOLESTR pNameHint,
7745
7707
7746
7708
ParseNodeFnc * pnodeFnc = nullptr ;
7747
7709
{
7748
- AutoParsingSuperRestrictionStateRestorer restorer (this );
7749
- this ->m_parsingSuperRestrictionState = ParsingSuperRestrictionState_SuperPropertyAllowed;
7750
-
7751
7710
if (isAsyncMethod)
7752
7711
{
7753
7712
fncDeclFlags |= fFncAsync ;
7754
7713
}
7755
- pnodeFnc = ParseFncDeclNoCheckScope<buildAST>(fncDeclFlags, pidHint ? pidHint->Psz () : nullptr , /* needsPIDOnRCurlyScan */ true , /* resetParsingSuperRestrictionState */ false );
7714
+ pnodeFnc = ParseFncDeclNoCheckScope<buildAST>(fncDeclFlags, SuperRestrictionState::PropertyAllowed, pidHint ? pidHint->Psz () : nullptr , /* needsPIDOnRCurlyScan */ true );
7756
7715
if (isAsyncMethod)
7757
7716
{
7758
7717
pnodeFnc->cbMin = iecpMin;
@@ -8871,7 +8830,7 @@ ParseNodePtr Parser::ParseExpr(int oplMin,
8871
8830
this ->GetScanner ()->SeekTo (termStart);
8872
8831
}
8873
8832
}
8874
- pnode = ParseFncDeclNoCheckScope<buildAST>(flags, nullptr , /* needsPIDOnRCurlyScan = */ false , /* resetParsingSuperRestrictionState = */ false , /* fUnaryOrParen = */ false , fAllowIn );
8833
+ pnode = ParseFncDeclNoCheckScope<buildAST>(flags, SuperRestrictionState::Disallowed, nullptr , /* needsPIDOnRCurlyScan = */ false , /* fUnaryOrParen = */ false , fAllowIn );
8875
8834
if (isAsyncMethod)
8876
8835
{
8877
8836
pnode->AsParseNodeFnc ()->cbStringMin = iecpMin;
@@ -11507,7 +11466,7 @@ ParseNodeProg * Parser::Parse(LPCUTF8 pszSrc, size_t offset, size_t length, char
11507
11466
flags |= fFncLambda ;
11508
11467
}
11509
11468
11510
- ParseNode * pnodeFnc = ParseFncDeclCheckScope<true >(flags, /* resetParsingSuperRestrictionState */ false );
11469
+ ParseNode * pnodeFnc = ParseFncDeclCheckScope<true >(flags);
11511
11470
pnodeProg->pnodeBody = nullptr ;
11512
11471
AddToNodeList (&pnodeProg->pnodeBody , &lastNodeRef, pnodeFnc);
11513
11472
@@ -12314,6 +12273,7 @@ template <bool buildAST>
12314
12273
IdentPtr Parser::ParseSuper (bool fAllowCall )
12315
12274
{
12316
12275
ParseNodeFnc * currentNodeFunc = GetCurrentFunctionNode ();
12276
+ ParseNodeFnc * currentNonLambdaFunc = GetCurrentNonLambdaFunctionNode ();
12317
12277
IdentPtr superPid = nullptr ;
12318
12278
12319
12279
switch (m_token.tk )
@@ -12345,12 +12305,14 @@ IdentPtr Parser::ParseSuper(bool fAllowCall)
12345
12305
{
12346
12306
Error (ERRInvalidSuper); // new super() is not allowed
12347
12307
}
12348
- else if (this ->m_parsingSuperRestrictionState == ParsingSuperRestrictionState_SuperCallAndPropertyAllowed)
12308
+ else if ((currentNodeFunc->IsConstructor () && currentNodeFunc->superRestrictionState == SuperRestrictionState::CallAndPropertyAllowed)
12309
+ || (currentNonLambdaFunc != nullptr && currentNonLambdaFunc->superRestrictionState == SuperRestrictionState::CallAndPropertyAllowed))
12349
12310
{
12350
12311
// Any super access is good within a class constructor
12351
12312
}
12352
- else if (this ->m_parsingSuperRestrictionState == ParsingSuperRestrictionState_SuperPropertyAllowed )
12313
+ else if (( this ->m_grfscr & fscrEval) == fscrEval || currentNonLambdaFunc-> superRestrictionState == SuperRestrictionState::PropertyAllowed )
12353
12314
{
12315
+ // Currently for eval cases during compile time we use propertyallowed and throw during runtime for error cases
12354
12316
if (m_token.tk == tkLParen)
12355
12317
{
12356
12318
if ((this ->m_grfscr & fscrEval) == fscrNil)
0 commit comments