From 9117266d4b7ca6dfaf088ede86e83d6b3ee8aa0b Mon Sep 17 00:00:00 2001 From: Logan Smyth Date: Wed, 20 Feb 2019 19:52:10 +0000 Subject: [PATCH] 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 --- js/src/frontend/Parser.cpp | 5 +++-- js/src/frontend/TokenStream.cpp | 1 + .../debug/Script-getPossibleBreakpoints.js | 17 ++++++++++++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/js/src/frontend/Parser.cpp b/js/src/frontend/Parser.cpp index 5bd02f91e025..1a01ca108c7b 100644 --- a/js/src/frontend/Parser.cpp +++ b/js/src/frontend/Parser.cpp @@ -8024,7 +8024,8 @@ typename ParseHandler::Node GeneralParser::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::assignExpr( } FunctionSyntaxKind syntaxKind = FunctionSyntaxKind::Arrow; - FunctionNodeType funNode = handler.newFunction(syntaxKind, pos()); + FunctionNodeType funNode = handler.newFunction(syntaxKind, startPos); if (!funNode) { return null(); } diff --git a/js/src/frontend/TokenStream.cpp b/js/src/frontend/TokenStream.cpp index 46960f34d75e..c0a57c1105ae 100644 --- a/js/src/frontend/TokenStream.cpp +++ b/js/src/frontend/TokenStream.cpp @@ -1275,6 +1275,7 @@ bool TokenStreamSpecific::advance(size_t position) { TokenStreamAnyChars& anyChars = anyCharsAccess(); Token* cur = const_cast(&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; diff --git a/js/src/jit-test/tests/debug/Script-getPossibleBreakpoints.js b/js/src/jit-test/tests/debug/Script-getPossibleBreakpoints.js index e374fea241d7..9717bf268211 100644 --- a/js/src/jit-test/tests/debug/Script-getPossibleBreakpoints.js +++ b/js/src/jit-test/tests/debug/Script-getPossibleBreakpoints.js @@ -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");