Skip to content

Commit

Permalink
Bug 1378808 - Add a new ParseNodeKind::Arguments node type for call a…
Browse files Browse the repository at this point in the history
…rgument lists. r=jorendorff

MozReview-Commit-ID: 7L4nNHjVoZo

--HG--
extra : rebase_source : 8ccc04cb335a227c45a332ded88408d6a2ec7c09
  • Loading branch information
loganfsmyth committed Jul 12, 2018
1 parent 12450ae commit fa55860
Show file tree
Hide file tree
Showing 13 changed files with 305 additions and 236 deletions.
15 changes: 8 additions & 7 deletions js/src/builtin/ReflectParse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2702,24 +2702,25 @@ ASTSerializer::expression(ParseNode* pn, MutableHandleValue dst)
case ParseNodeKind::Call:
case ParseNodeKind::SuperCall:
{
ParseNode* next = pn->pn_head;
MOZ_ASSERT(pn->pn_pos.encloses(next->pn_pos));
ParseNode* pn_callee = pn->pn_left;
ParseNode* pn_args = pn->pn_right;
MOZ_ASSERT(pn->pn_pos.encloses(pn_callee->pn_pos));

RootedValue callee(cx);
if (pn->isKind(ParseNodeKind::SuperCall)) {
MOZ_ASSERT(next->isKind(ParseNodeKind::SuperBase));
if (!builder.super(&next->pn_pos, &callee))
MOZ_ASSERT(pn_callee->isKind(ParseNodeKind::SuperBase));
if (!builder.super(&pn_callee->pn_pos, &callee))
return false;
} else {
if (!expression(next, &callee))
if (!expression(pn_callee, &callee))
return false;
}

NodeVector args(cx);
if (!args.reserve(pn->pn_count - 1))
if (!args.reserve(pn_args->pn_count))
return false;

for (next = next->pn_next; next; next = next->pn_next) {
for (ParseNode* next = pn_args->pn_head; next; next = next->pn_next) {
MOZ_ASSERT(pn->pn_pos.encloses(next->pn_pos));

RootedValue arg(cx);
Expand Down
20 changes: 8 additions & 12 deletions js/src/frontend/BinSource-auto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3462,9 +3462,8 @@ BinASTParser<Tok>::parseInterfaceCallExpression(const size_t start, const BinKin
op = parseContext_->sc()->strict() ? JSOP_STRICTEVAL : JSOP_EVAL;
}
}
auto result = arguments;
result->setKind(ParseNodeKind::Call);
result->prepend(callee);

BINJS_TRY_DECL(result, factory_.newCall(callee, arguments));
result->setOp(op);
return result;
}
Expand Down Expand Up @@ -3742,7 +3741,7 @@ BinASTParser<Tok>::parseInterfaceComputedMemberAssignmentTarget(const size_t sta

BINJS_MOZ_TRY_DECL(expression, parseExpression());

BINJS_TRY_DECL(result, factory_.newPropertyByValue(object, expression, start));
BINJS_TRY_DECL(result, factory_.newPropertyByValue(object, expression, tokenizer_->offset()));
return result;
}

Expand Down Expand Up @@ -3786,7 +3785,7 @@ BinASTParser<Tok>::parseInterfaceComputedMemberExpression(const size_t start, co

BINJS_MOZ_TRY_DECL(expression, parseExpression());

BINJS_TRY_DECL(result, factory_.newPropertyByValue(object, expression, start));
BINJS_TRY_DECL(result, factory_.newPropertyByValue(object, expression, tokenizer_->offset()));
return result;
}

Expand Down Expand Up @@ -5677,10 +5676,7 @@ BinASTParser<Tok>::parseInterfaceNewExpression(const size_t start, const BinKind

BINJS_MOZ_TRY_DECL(arguments, parseArguments());

auto result = arguments;
result->setKind(ParseNodeKind::New);
result->prepend(callee);
result->setOp(JSOP_NEW);
BINJS_TRY_DECL(result, factory_.newNewExpression(tokenizer_->pos(start).begin, callee, arguments));
return result;
}

Expand Down Expand Up @@ -6203,7 +6199,7 @@ BinASTParser<Tok>::parseInterfaceStaticMemberAssignmentTarget(const size_t start
RootedAtom property(cx_);
MOZ_TRY_VAR(property, tokenizer_->readAtom());

BINJS_TRY_DECL(result, factory_.newPropertyAccess(object, property->asPropertyName(), start));
BINJS_TRY_DECL(result, factory_.newPropertyAccess(object, property->asPropertyName(), tokenizer_->offset()));
return result;
}

Expand Down Expand Up @@ -6248,7 +6244,7 @@ BinASTParser<Tok>::parseInterfaceStaticMemberExpression(const size_t start, cons
RootedAtom property(cx_);
MOZ_TRY_VAR(property, tokenizer_->readAtom());

BINJS_TRY_DECL(result, factory_.newPropertyAccess(object, property->asPropertyName(), start));
BINJS_TRY_DECL(result, factory_.newPropertyAccess(object, property->asPropertyName(), tokenizer_->offset()));
return result;
}

Expand Down Expand Up @@ -7381,7 +7377,7 @@ BinASTParser<Tok>::parseArguments()

const auto start = tokenizer_->offset();
MOZ_TRY(tokenizer_->enterList(length, guard));
BINJS_TRY_DECL(result, factory_.newList(ParseNodeKind::ParamsBody, tokenizer_->pos(start)));
BINJS_TRY_DECL(result, factory_.newList(ParseNodeKind::Arguments, tokenizer_->pos(start)));

for (uint32_t i = 0; i < length; ++i) {
BINJS_MOZ_TRY_DECL(item, parseSpreadElementOrExpression());
Expand Down
20 changes: 8 additions & 12 deletions js/src/frontend/BinSource.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ hpp:
Arguments:
init:
BINJS_TRY_DECL(result, factory_.newList(ParseNodeKind::ParamsBody, tokenizer_->pos(start)));
BINJS_TRY_DECL(result, factory_.newList(ParseNodeKind::Arguments, tokenizer_->pos(start)));
append:
factory_.addList(/* list = */ result, /* kid = */ item);

Expand Down Expand Up @@ -428,9 +428,8 @@ CallExpression:
op = parseContext_->sc()->strict() ? JSOP_STRICTEVAL : JSOP_EVAL;
}
}
auto result = arguments;
result->setKind(ParseNodeKind::Call);
result->prepend(callee);
BINJS_TRY_DECL(result, factory_.newCall(callee, arguments));
result->setOp(op);
Expand Down Expand Up @@ -489,11 +488,11 @@ CompoundAssignmentExpression:
ComputedMemberAssignmentTarget:
build: |
BINJS_TRY_DECL(result, factory_.newPropertyByValue(object, expression, start));
BINJS_TRY_DECL(result, factory_.newPropertyByValue(object, expression, tokenizer_->offset()));
ComputedMemberExpression:
build: |
BINJS_TRY_DECL(result, factory_.newPropertyByValue(object, expression, start));
BINJS_TRY_DECL(result, factory_.newPropertyByValue(object, expression, tokenizer_->offset()));
ConditionalExpression:
build: |
Expand Down Expand Up @@ -831,10 +830,7 @@ LiteralStringExpression:

NewExpression:
build: |
auto result = arguments;
result->setKind(ParseNodeKind::New);
result->prepend(callee);
result->setOp(JSOP_NEW);
BINJS_TRY_DECL(result, factory_.newNewExpression(tokenizer_->pos(start).begin, callee, arguments));
ObjectExpression:
build:
Expand Down Expand Up @@ -923,11 +919,11 @@ SwitchStatementWithDefault:
StaticMemberAssignmentTarget:
build: |
BINJS_TRY_DECL(result, factory_.newPropertyAccess(object, property->asPropertyName(), start));
BINJS_TRY_DECL(result, factory_.newPropertyAccess(object, property->asPropertyName(), tokenizer_->offset()));
StaticMemberExpression:
build: |
BINJS_TRY_DECL(result, factory_.newPropertyAccess(object, property->asPropertyName(), start));
BINJS_TRY_DECL(result, factory_.newPropertyAccess(object, property->asPropertyName(), tokenizer_->offset()));
ThisExpression:
build: |
Expand Down
Loading

0 comments on commit fa55860

Please sign in to comment.