@@ -317,38 +317,50 @@ class Parser {
317317 }
318318 }
319319
320- ASTScopeContext* popScopeContext (ASTScopeContext* lastPushedScopeContext)
321- {
322- auto ret = this ->currentScopeContext ;
323- this ->lastUsingName = AtomicString ();
324- this ->lastPoppedScopeContext = ret;
325- this ->currentScopeContext = lastPushedScopeContext;
326320#ifndef ESCARGOT_DEBUGGER
327- ASTScopeContext* scopeCtx = ret;
328- while (scopeCtx) {
329- if (!scopeCtx->m_parameters .size ()) {
330- scopeCtx->m_parameterUsed = 0xFFFF ;
331- }
321+ void checkUsedParameters (ASTScopeContext* scopeCtx)
322+ {
323+ AtomicStringTightVector& parameters = this ->currentScopeContext ->m_parameters ;
332324
333- if (scopeCtx->m_parameterUsed == 0xFFFF ) {
334- scopeCtx = scopeCtx->m_parentScope ;
335- continue ;
325+ for (size_t i = 0 ; i < parameters.size (); i++) {
326+ AtomicString& name = parameters[i];
327+ for (size_t j = 0 ; j < scopeCtx->m_childBlockScopes .size (); j++) {
328+ ASTBlockContext& blockCtx = *scopeCtx->m_childBlockScopes [j];
329+ if (VectorUtil::findInVector (blockCtx.m_usingNames , name) != VectorUtil::invalidIndex) {
330+ this ->currentScopeContext ->m_parameterUsed |= (1 << i);
331+ break ;
332+ } else if (UNLIKELY (scopeCtx->m_parameterUsed == DISABLE_PARAM_CHECK)) {
333+ this ->currentScopeContext ->m_parameterUsed = DISABLE_PARAM_CHECK;
334+ return ;
335+ }
336336 }
337+ }
337338
338- for (size_t i = 0 ; i < scopeCtx->m_parameters .size (); i++) {
339- AtomicString paramName = scopeCtx->m_parameters [i];
340- for (size_t j = 0 ; j < ret->m_childBlockScopes .size (); j++) {
341- ASTBlockContext* block = ret->m_childBlockScopes [j];
342- if (VectorUtil::findInVector (block->m_usingNames , paramName) != VectorUtil::invalidIndex) {
343- scopeCtx->m_parameterUsed |= (1 << i);
344- break ;
345- }
346- }
339+ // check nested functions
340+ size_t childCount = scopeCtx->childCount ();
341+ if (childCount > 0 ) {
342+ ASTScopeContext* child = scopeCtx->firstChild ();
343+ for (size_t i = 0 ; i < childCount; i++) {
344+ checkUsedParameters (child);
345+ child = child->nextSibling ();
347346 }
347+ }
348+ }
349+ #endif
348350
349- scopeCtx = scopeCtx->m_parentScope ;
351+ ASTScopeContext* popScopeContext (ASTScopeContext* lastPushedScopeContext)
352+ {
353+ #ifndef ESCARGOT_DEBUGGER
354+ if (UNLIKELY (this ->currentScopeContext ->m_hasEval || this ->currentScopeContext ->m_hasStringArguments || this ->currentScopeContext ->m_parameters .size () > 16 )) {
355+ this ->currentScopeContext ->m_parameterUsed = DISABLE_PARAM_CHECK;
356+ } else {
357+ checkUsedParameters (this ->currentScopeContext );
350358 }
351359#endif
360+ auto ret = this ->currentScopeContext ;
361+ this ->lastUsingName = AtomicString ();
362+ this ->lastPoppedScopeContext = ret;
363+ this ->currentScopeContext = lastPushedScopeContext;
352364 return ret;
353365 }
354366
@@ -381,10 +393,6 @@ class Parser {
381393 parentContext->appendChild (this ->currentScopeContext );
382394 }
383395
384- #ifndef ESCARGOT_DEBUGGER
385- this ->currentScopeContext ->m_parentScope = parentContext;
386- #endif
387-
388396 return parentContext;
389397 }
390398
@@ -511,11 +519,6 @@ class Parser {
511519 ASSERT (this ->currentScopeContext ->m_functionLength == paramNames.size ());
512520 ASSERT (this ->currentScopeContext ->m_functionLength == this ->currentScopeContext ->m_parameterCount );
513521 }
514- #endif
515- #ifndef ESCARGOT_DEBUGGER
516- if (UNLIKELY (paramNames.size () > 16 )) {
517- this ->currentScopeContext ->m_parameterUsed = 0xFFFF ;
518- }
519522#endif
520523 this ->currentScopeContext ->m_parameters .resizeWithUninitializedValues (paramNames.size ());
521524 LexicalBlockIndex functionBodyBlockIndex = this ->currentScopeContext ->m_functionBodyBlockIndex ;
@@ -1077,11 +1080,7 @@ class Parser {
10771080
10781081#ifndef ESCARGOT_DEBUGGER
10791082 if (UNLIKELY (ret->asIdentifier ()->name () == this ->stringArguments )) {
1080- ASTScopeContext* scopeCtx = this ->currentScopeContext ;
1081- while (scopeCtx) {
1082- scopeCtx->m_parameterUsed = 0xFFFF ;
1083- scopeCtx = scopeCtx->m_parentScope ;
1084- }
1083+ this ->currentScopeContext ->m_hasStringArguments = true ;
10851084 }
10861085#endif
10871086
@@ -1755,9 +1754,6 @@ class Parser {
17551754 this ->currentScopeContext ->m_parameterCount = 1 ;
17561755 this ->currentScopeContext ->m_parameters .resizeWithUninitializedValues (1 );
17571756 this ->currentScopeContext ->m_parameters [0 ] = className;
1758- #ifndef ESCARGOT_DEBUGGER
1759- this ->currentScopeContext ->m_parameterUsed |= 1 ;
1760- #endif
17611757 this ->currentScopeContext ->insertVarName (className, 0 , true , true , true );
17621758 }
17631759
@@ -2610,9 +2606,6 @@ class Parser {
26102606 // check callee of CallExpressionNode
26112607 if (exprNode->isIdentifier () && exprNode->asIdentifier ()->name () == escargotContext->staticStrings ().eval ) {
26122608 this ->currentScopeContext ->m_hasEval = true ;
2613- #ifndef ESCARGOT_DEBUGGER
2614- this ->currentScopeContext ->m_parameterUsed = 0xFFFF ;
2615- #endif
26162609 }
26172610 exprNode = this ->finalize (this ->startNode (startToken), builder.createCallExpressionNode (exprNode, args, optional));
26182611 if (asyncArrow && this ->match (Arrow)) {
@@ -3584,9 +3577,6 @@ class Parser {
35843577 this ->currentScopeContext ->m_parameterCount = 1 ;
35853578 this ->currentScopeContext ->m_parameters .resizeWithUninitializedValues (1 );
35863579 this ->currentScopeContext ->m_parameters [0 ] = paramName;
3587- #ifndef ESCARGOT_DEBUGGER
3588- this ->currentScopeContext ->m_parameterUsed |= 1 ;
3589- #endif
35903580 this ->currentScopeContext ->insertVarName (paramName, 0 , true , true , true );
35913581 }
35923582
@@ -5088,7 +5078,7 @@ class Parser {
50885078 switch (param->type ()) {
50895079 case Identifier: {
50905080#ifndef ESCARGOT_DEBUGGER
5091- if (this ->codeBlock ->parameterUsed () & (1 << paramIndex) || this ->codeBlock ->parameterUsed () == 0xFFFF ) {
5081+ if (this ->codeBlock ->parameterUsed () & (1 << paramIndex) || this ->codeBlock ->parameterUsed () == DISABLE_PARAM_CHECK ) {
50925082#endif
50935083 Node* init = this ->finalize (node, builder.createInitializeParameterExpressionNode (param, paramIndex));
50945084 Node* statement = this ->finalize (node, builder.createExpressionStatementNode (init));
@@ -5108,7 +5098,7 @@ class Parser {
51085098 }
51095099 case RestElement: {
51105100#ifndef ESCARGOT_DEBUGGER
5111- if (this ->codeBlock ->parameterUsed () & (1 << paramIndex) || param-> asRestElement ()-> argument ()-> type () != Identifier || this -> codeBlock -> parameterUsed () == 0xFFFF ) {
5101+ if (this ->codeBlock ->parameterUsed () & (1 << paramIndex) || this -> codeBlock -> parameterUsed () == DISABLE_PARAM_CHECK || param-> asRestElement ()-> argument ()-> type () != Identifier ) {
51125102#endif
51135103 Node* statement = this ->finalize (node, builder.createExpressionStatementNode (param));
51145104 container->appendChild (statement);
0 commit comments