Bug 1527671 - Assign the correct start position to arrow functions. r=arai,jorendorff

This position ends up being used for source notes in some cases now, meaning that this can
cause breakpoints to be given the wrong position when assigned to a variable. This fixes
that by using the correct token for the position value.

This fix also ensures that `cur->pos.end` is updated when skipping functions because
expression statements set their end based on the end position of the expression, and
if the expression statements end token is the end of a skipped function, we would
otherwise read the wrong position triggering assertion failures.

Differential Revision: https://phabricator.services.mozilla.com/D19714

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Logan Smyth 2019-02-20 19:52:10 +00:00
parent 918805dafb
commit 9117266d4b
3 changed files with 20 additions and 3 deletions

View File

@ -8024,7 +8024,8 @@ typename ParseHandler::Node GeneralParser<ParseHandler, Unit>::assignExpr(
if (!tokenStream.getToken(&next, TokenStream::Operand)) {
return null();
}
uint32_t toStringStart = pos().begin;
TokenPos startPos = pos();
uint32_t toStringStart = startPos.begin;
anyChars.ungetToken();
FunctionAsyncKind asyncKind = FunctionAsyncKind::SyncFunction;
@ -8049,7 +8050,7 @@ typename ParseHandler::Node GeneralParser<ParseHandler, Unit>::assignExpr(
}
FunctionSyntaxKind syntaxKind = FunctionSyntaxKind::Arrow;
FunctionNodeType funNode = handler.newFunction(syntaxKind, pos());
FunctionNodeType funNode = handler.newFunction(syntaxKind, startPos);
if (!funNode) {
return null();
}

View File

@ -1275,6 +1275,7 @@ bool TokenStreamSpecific<Unit, AnyCharsAccess>::advance(size_t position) {
TokenStreamAnyChars& anyChars = anyCharsAccess();
Token* cur = const_cast<Token*>(&anyChars.currentToken());
cur->pos.begin = this->sourceUnits.offset();
cur->pos.end = cur->pos.begin;
MOZ_MAKE_MEM_UNDEFINED(&cur->type, sizeof(cur->type));
anyChars.lookahead = 0;
return true;

View File

@ -259,7 +259,7 @@ assertBreakpoints(`
}
`);
assertBreakpoints(`
var fn /*S*/= () => {
var fn = /*S*/() => {
/*S*/console./*B*/log("fn");
/*S*/return /*B*/new Proxy({ prop: 42 }, {
deleteProperty() {
@ -268,6 +268,21 @@ assertBreakpoints(`
});
/*B*/};
`);
assertBreakpoints(`
var fn = /*S*/async (arg) => {
/*S*/console./*B*/log("fn");
/*B*/};
`);
assertBreakpoints(`
var fn = /*S*/arg => {
/*S*/console./*B*/log("fn");
/*B*/};
`);
assertBreakpoints(`
var fn = /*S*/async arg => {
/*S*/console./*B*/log("fn");
/*B*/};
`);
assertBreakpoints(`
if ((/*S*/delete /*B*/fn().prop) + /*B*/b()) {
/*S*/console./*B*/log("foo");