Skip to content

Commit

Permalink
[JSC] Tweak parseMemberExpression() to get rid of baseIsNewTarget
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=268575
<rdar://problem/122131541>

Reviewed by Justin Michaud and Yusuke Suzuki.

Only one of `match(DOT)`, `baseIsSuper`, and `baseIsImport` can be true since they all call match()
in the same location. Given that, we can leverage `else if` to get rid of `baseIsNewTarget`.

This change is non-observable code tweak.

* Source/JavaScriptCore/parser/Parser.cpp:
(JSC::Parser<LexerType>::parseMemberExpression):

Canonical link: https://commits.webkit.org/273967@main
  • Loading branch information
Alexey Shvayka committed Feb 2, 2024
1 parent e15eaf5 commit ebaf43b
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions Source/JavaScriptCore/parser/Parser.cpp
Expand Up @@ -5271,16 +5271,15 @@ template <class TreeBuilder> TreeExpression Parser<LexerType>::parseMemberExpres
bool baseIsSuper = match(SUPER);
bool previousBaseWasSuper = false;
bool baseIsImport = match(IMPORT);
bool baseIsAsyncKeyword = false;

bool baseIsNewTarget = false;
if (newCount && match(DOT)) {
next();
if (matchContextualKeyword(m_vm.propertyNames->target)) {
ScopeRef closestOrdinaryFunctionScope = closestParentOrdinaryFunctionNonLexicalScope();
bool isClassFieldInitializer = m_parserState.isParsingClassFieldInitializer;
bool isFunctionEvalContextType = m_isInsideOrdinaryFunction && (closestOrdinaryFunctionScope->evalContextType() == EvalContextType::FunctionEvalContext || closestOrdinaryFunctionScope->evalContextType() == EvalContextType::InstanceFieldEvalContext);
semanticFailIfFalse(currentScope()->isFunction() || currentScope()->isStaticBlock() || isFunctionEvalContextType || isClassFieldInitializer, "new.target is only valid inside functions or static blocks");
baseIsNewTarget = true;
if (currentScope()->isArrowFunction()) {
semanticFailIfFalse(!closestOrdinaryFunctionScope->isGlobalCode() || isFunctionEvalContextType || isClassFieldInitializer, "new.target is not valid inside arrow functions in global code");
currentScope()->setInnerArrowFunctionUsesNewTarget();
Expand All @@ -5292,11 +5291,7 @@ template <class TreeBuilder> TreeExpression Parser<LexerType>::parseMemberExpres
failIfTrue(match(IDENT), "\"new.\" can only be followed with target");
failDueToUnexpectedToken();
}
}

bool baseIsAsyncKeyword = false;

if (baseIsSuper) {
} else if (baseIsSuper) {
ScopeRef closestOrdinaryFunctionScope = closestParentOrdinaryFunctionNonLexicalScope();
ScopeRef classScope = closestClassScopeOrTopLevelScope();
bool isClassFieldInitializer = classScope.index() > closestOrdinaryFunctionScope.index();
Expand Down Expand Up @@ -5345,7 +5340,7 @@ template <class TreeBuilder> TreeExpression Parser<LexerType>::parseMemberExpres
consumeOrFail(CLOSEPAREN, "import call expects one or two arguments");
base = context.createImportExpr(location, expr, optionExpression, expressionStart, expressionEnd, lastTokenEndPosition());
}
} else if (!baseIsNewTarget) {
} else {
const bool isAsync = matchContextualKeyword(m_vm.propertyNames->async);

if (TreeExpression argumentsDotLengthExpression = tryParseArgumentsDotLengthForFastPath(context))
Expand Down

0 comments on commit ebaf43b

Please sign in to comment.