@@ -76,6 +76,7 @@ struct Context {
76
76
bool allowLexicalDeclaration : 1 ;
77
77
bool allowSuperCall : 1 ;
78
78
bool allowSuperProperty : 1 ;
79
+ bool allowNewTarget : 1 ;
79
80
bool isAssignmentTarget : 1 ;
80
81
bool isBindingElement : 1 ;
81
82
bool inFunctionBody : 1 ;
@@ -221,6 +222,7 @@ class Parser {
221
222
this ->context ->allowLexicalDeclaration = false ;
222
223
this ->context ->allowSuperCall = false ;
223
224
this ->context ->allowSuperProperty = false ;
225
+ this ->context ->allowNewTarget = false ;
224
226
this ->context ->isAssignmentTarget = true ;
225
227
this ->context ->isBindingElement = true ;
226
228
this ->context ->inFunctionBody = false ;
@@ -1398,11 +1400,13 @@ class Parser {
1398
1400
const bool previousAllowYield = this ->context ->allowYield ;
1399
1401
const bool previousAllowSuperCall = this ->context ->allowSuperCall ;
1400
1402
const bool previousAllowSuperProperty = this ->context ->allowSuperProperty ;
1403
+ const bool previousAllowNewTarget = this ->context ->allowNewTarget ;
1401
1404
const bool previousInArrowFunction = this ->context ->inArrowFunction ;
1402
1405
1403
1406
this ->context ->allowYield = true ;
1404
1407
this ->context ->inArrowFunction = false ;
1405
1408
this ->context ->allowSuperProperty = true ;
1409
+ this ->context ->allowNewTarget = true ;
1406
1410
1407
1411
if (allowSuperCall) {
1408
1412
this ->context ->allowSuperCall = true ;
@@ -1419,6 +1423,7 @@ class Parser {
1419
1423
this ->context ->allowYield = previousAllowYield;
1420
1424
this ->context ->inArrowFunction = previousInArrowFunction;
1421
1425
this ->context ->allowSuperProperty = previousAllowSuperProperty;
1426
+ this ->context ->allowNewTarget = previousAllowNewTarget;
1422
1427
this ->context ->allowSuperCall = previousAllowSuperCall;
1423
1428
1424
1429
this ->currentScopeContext ->m_paramsStartLOC .index = node.index ;
@@ -1886,7 +1891,7 @@ class Parser {
1886
1891
1887
1892
if (this ->match (Period)) {
1888
1893
this ->nextToken ();
1889
- if (this ->lookahead .type == Token::IdentifierToken && this ->context ->inFunctionBody && this ->lookahead .relatedSource (this ->scanner ->source ) == " target" ) {
1894
+ if (this ->lookahead .type == Token::IdentifierToken && this ->context ->allowNewTarget && this ->lookahead .relatedSource (this ->scanner ->source ) == " target" ) {
1890
1895
this ->nextToken ();
1891
1896
this ->currentScopeContext ->m_hasSuperOrNewTarget = true ;
1892
1897
MetaNode node = this ->createNode ();
@@ -4157,8 +4162,11 @@ class Parser {
4157
4162
4158
4163
bool previousAllowYield = this ->context ->allowYield ;
4159
4164
bool previousInArrowFunction = this ->context ->inArrowFunction ;
4165
+ bool previousAllowNewTarget = this ->context ->allowNewTarget ;
4166
+
4160
4167
this ->context ->allowYield = !isGenerator;
4161
4168
this ->context ->inArrowFunction = false ;
4169
+ this ->context ->allowNewTarget = true ;
4162
4170
4163
4171
ParseFormalParametersResult formalParameters;
4164
4172
this ->parseFormalParameters (newBuilder, formalParameters, &firstRestricted);
@@ -4180,6 +4188,7 @@ class Parser {
4180
4188
this ->context ->strict = previousStrict;
4181
4189
this ->context ->allowYield = previousAllowYield;
4182
4190
this ->context ->inArrowFunction = previousInArrowFunction;
4191
+ this ->context ->allowNewTarget = previousAllowNewTarget;
4183
4192
4184
4193
this ->currentScopeContext ->m_nodeType = ASTNodeType::FunctionDeclaration;
4185
4194
this ->currentScopeContext ->m_isGenerator = isGenerator;
@@ -4205,8 +4214,11 @@ class Parser {
4205
4214
4206
4215
bool previousAllowYield = this ->context ->allowYield ;
4207
4216
bool previousInArrowFunction = this ->context ->inArrowFunction ;
4217
+ bool previousAllowNewTarget = this ->context ->allowNewTarget ;
4218
+
4208
4219
this ->context ->allowYield = !isGenerator;
4209
4220
this ->context ->inArrowFunction = false ;
4221
+ this ->context ->allowNewTarget = true ;
4210
4222
4211
4223
if (!this ->match (LeftParenthesis)) {
4212
4224
ALLOC_TOKEN (token);
@@ -4269,6 +4281,7 @@ class Parser {
4269
4281
this ->context ->strict = previousStrict;
4270
4282
this ->context ->allowYield = previousAllowYield;
4271
4283
this ->context ->inArrowFunction = previousInArrowFunction;
4284
+ this ->context ->allowNewTarget = previousAllowNewTarget;
4272
4285
4273
4286
this ->currentScopeContext ->m_nodeType = ASTNodeType::FunctionExpression;
4274
4287
this ->currentScopeContext ->m_isGenerator = isGenerator;
@@ -4354,10 +4367,12 @@ class Parser {
4354
4367
const bool previousAllowYield = this ->context ->allowYield ;
4355
4368
const bool previousInArrowFunction = this ->context ->inArrowFunction ;
4356
4369
const bool previousAllowSuperProperty = this ->context ->allowSuperProperty ;
4370
+ const bool previousAllowNewTarget = this ->context ->allowNewTarget ;
4357
4371
4358
4372
this ->context ->allowYield = true ;
4359
4373
this ->context ->inArrowFunction = false ;
4360
4374
this ->context ->allowSuperProperty = true ;
4375
+ this ->context ->allowNewTarget = true ;
4361
4376
4362
4377
this ->expect (LeftParenthesis);
4363
4378
this ->expect (RightParenthesis);
@@ -4371,6 +4386,7 @@ class Parser {
4371
4386
this ->context ->allowYield = previousAllowYield;
4372
4387
this ->context ->inArrowFunction = previousInArrowFunction;
4373
4388
this ->context ->allowSuperProperty = previousAllowSuperProperty;
4389
+ this ->context ->allowNewTarget = previousAllowNewTarget;
4374
4390
4375
4391
this ->currentScopeContext ->m_paramsStartLOC .index = node.index ;
4376
4392
this ->currentScopeContext ->m_paramsStartLOC .column = node.column ;
@@ -4398,10 +4414,12 @@ class Parser {
4398
4414
const bool previousAllowYield = this ->context ->allowYield ;
4399
4415
const bool previousInArrowFunction = this ->context ->inArrowFunction ;
4400
4416
const bool previousAllowSuperProperty = this ->context ->allowSuperProperty ;
4417
+ const bool previousAllowNewTarget = this ->context ->allowNewTarget ;
4401
4418
4402
4419
this ->context ->allowYield = true ;
4403
4420
this ->context ->allowSuperProperty = true ;
4404
4421
this ->context ->inArrowFunction = false ;
4422
+ this ->context ->allowNewTarget = true ;
4405
4423
4406
4424
this ->expect (LeftParenthesis);
4407
4425
@@ -4420,6 +4438,7 @@ class Parser {
4420
4438
this ->context ->allowYield = previousAllowYield;
4421
4439
this ->context ->allowSuperProperty = previousAllowSuperProperty;
4422
4440
this ->context ->inArrowFunction = previousInArrowFunction;
4441
+ this ->context ->allowNewTarget = previousAllowNewTarget;
4423
4442
4424
4443
this ->currentScopeContext ->m_paramsStartLOC .index = node.index ;
4425
4444
this ->currentScopeContext ->m_paramsStartLOC .column = node.column ;
@@ -4447,10 +4466,12 @@ class Parser {
4447
4466
const bool previousAllowYield = this ->context ->allowYield ;
4448
4467
const bool previousInArrowFunction = this ->context ->inArrowFunction ;
4449
4468
const bool previousAllowSuperProperty = this ->context ->allowSuperProperty ;
4469
+ const bool previousAllowNewTarget = this ->context ->allowNewTarget ;
4450
4470
4451
4471
this ->context ->allowYield = false ;
4452
4472
this ->context ->allowSuperProperty = true ;
4453
4473
this ->context ->inArrowFunction = false ;
4474
+ this ->context ->allowNewTarget = true ;
4454
4475
4455
4476
this ->expect (LeftParenthesis);
4456
4477
@@ -4464,6 +4485,7 @@ class Parser {
4464
4485
this ->context ->allowYield = previousAllowYield;
4465
4486
this ->context ->allowSuperProperty = previousAllowSuperProperty;
4466
4487
this ->context ->inArrowFunction = previousInArrowFunction;
4488
+ this ->context ->allowNewTarget = previousAllowNewTarget;
4467
4489
4468
4490
this ->currentScopeContext ->m_paramsStartLOC .index = node.index ;
4469
4491
this ->currentScopeContext ->m_paramsStartLOC .column = node.column ;
@@ -5198,10 +5220,15 @@ class Parser {
5198
5220
{
5199
5221
ASSERT (this ->isParsingSingleFunction );
5200
5222
5223
+ const bool previousAllowNewTarget = context->allowNewTarget ;
5224
+
5225
+ context->allowNewTarget = true ;
5201
5226
MetaNode node = this ->createNode ();
5202
5227
StatementContainer* params = this ->parseFunctionParameters (builder);
5203
5228
BlockStatementNode* body = this ->parseFunctionBody (builder);
5204
5229
5230
+ context->allowNewTarget = previousAllowNewTarget;
5231
+
5205
5232
return this ->finalize (node, builder.createFunctionNode (params, body, std::move (this ->numeralLiteralVector )));
5206
5233
}
5207
5234
@@ -5276,7 +5303,7 @@ class Parser {
5276
5303
}
5277
5304
};
5278
5305
5279
- ProgramNode* parseProgram (::Escargot::Context* ctx, StringView source, bool isModule, bool strictFromOutside, bool inWith, size_t stackRemain, bool allowSuperCallOutside , bool allowSuperPropertyOutside )
5306
+ ProgramNode* parseProgram (::Escargot::Context* ctx, StringView source, bool isModule, bool strictFromOutside, bool inWith, size_t stackRemain, bool allowSuperCallFromOutside , bool allowSuperPropertyFromOutside, bool allowNewTargetFromOutside )
5280
5307
{
5281
5308
// GC should be disabled during the parsing process
5282
5309
ASSERT (GC_is_disabled ());
@@ -5287,8 +5314,9 @@ ProgramNode* parseProgram(::Escargot::Context* ctx, StringView source, bool isMo
5287
5314
5288
5315
parser.context ->strict = strictFromOutside;
5289
5316
parser.context ->inWith = inWith;
5290
- parser.context ->allowSuperCall = allowSuperCallOutside;
5291
- parser.context ->allowSuperProperty = allowSuperPropertyOutside;
5317
+ parser.context ->allowSuperCall = allowSuperCallFromOutside;
5318
+ parser.context ->allowSuperProperty = allowSuperPropertyFromOutside;
5319
+ parser.context ->allowNewTarget = allowNewTargetFromOutside;
5292
5320
5293
5321
ProgramNode* nd = parser.parseProgram (builder);
5294
5322
return nd;
@@ -5307,8 +5335,8 @@ FunctionNode* parseSingleFunction(::Escargot::Context* ctx, InterpretedCodeBlock
5307
5335
parser.context ->allowLexicalDeclaration = true ;
5308
5336
parser.context ->allowSuperCall = true ;
5309
5337
parser.context ->allowSuperProperty = true ;
5338
+ parser.context ->allowNewTarget = true ;
5310
5339
parser.isParsingSingleFunction = true ;
5311
-
5312
5340
parser.codeBlock = codeBlock;
5313
5341
5314
5342
scopeContext = new (ctx->astAllocator ()) ASTFunctionScopeContext (ctx->astAllocator (), codeBlock->isStrict ());
0 commit comments