Skip to content

Commit

Permalink
Bug 1066331 - Fix for multi-line template strings reflecting incorrec…
Browse files Browse the repository at this point in the history
…t debugger line numbers r=jorendorff
  • Loading branch information
Guptha Rajagopal committed Oct 8, 2014
1 parent 1e0fdf9 commit f4a871f
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
2 changes: 2 additions & 0 deletions js/src/frontend/TokenStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1737,6 +1737,8 @@ bool TokenStream::getStringOrTemplateToken(int qc, Token **tp)
if (userbuf.peekRawChar() == '\n')
skipChars(1);
}
updateLineInfoForEOL();
updateFlagsForEOL();
} else if (qc == '`' && c == '$') {
if ((nc = getCharIgnoreEOL()) == '{')
break;
Expand Down
50 changes: 50 additions & 0 deletions js/src/tests/ecma_6/TemplateStrings/debugLineNumber.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

// TEST BEGIN

// verify debugger line numbers are accurate
try {
`
a
b
c
`;
throw Error("error");
} catch (e) {
assertEq(e.lineNumber, 14);
}

try {
function tagThatThrows(...args) { throw new Error(); }

tagThatThrows`
multi-line
template
string`;
} catch (e) {
var stackLines = e.stack.split('\n');
var firstLine = stackLines[0].split(':');
var secondLine = stackLines[1].split(':');
var firstLineSize = firstLine.length;
var secondLineSize = secondLine.length;
assertEq(firstLine[firstLineSize - 2], "20");
assertEq(firstLine[firstLineSize - 1], "45");
assertEq(secondLine[secondLineSize - 2], "22");
assertEq(secondLine[secondLineSize - 1], "5");
}

try {
` multi-line
template
with
${substitutionThatThrows()}`

} catch (e) {
assertEq(e.lineNumber, 42);
}



reportCompare(0, 0, "ok");
11 changes: 11 additions & 0 deletions js/src/tests/js1_8_5/extensions/reflect-parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,17 @@ assertExpr("func`hey${4}``${5}there``mine`",
template(["", "there"], ["", "there"], lit(5))),
template(["mine"], ["mine"])));

// multi-line template string - line numbers
var node = Reflect.parse("`\n\n ${2}\n\n\n`");
Pattern({loc:{start:{line:1, column:0}, end:{line:6, column:1}, source:null}, type:"Program",
body:[{loc:{start:{line:1, column:0}, end:{line:6, column:1}, source:null},
type:"ExpressionStatement", expression:{loc:{start:{line:1, column:0}, end:{line:6, column:1},
source:null}, type:"TemplateLiteral", elements:[{loc:{start:{line:1, column:0}, end:{line:3,
column:5}, source:null}, type:"Literal", value:"\n\n "}, {loc:{start:{line:3, column:5},
end:{line:3, column:6}, source:null}, type:"Literal", value:2}, {loc:{start:{line:3, column:6},
end:{line:6, column:1}, source:null}, type:"Literal", value:"\n\n\n"}]}}]}).match(node);


assertStringExpr("\"hey there\"", literal("hey there"));

assertStmt("foo: for(;;) break foo;", labStmt(ident("foo"), forStmt(null, null, null, breakStmt(ident("foo")))));
Expand Down

0 comments on commit f4a871f

Please sign in to comment.