Bug 1024786 - Watch for inferred file/line information on errors when printing error contexts, r=jandem.
authorBrian Hackett <bhackett1024@gmail.com>
Fri, 11 Jul 2014 14:59:20 -0800
changeset 215621 de4ce465c58c5b53030a33fe956851f2bb8d3503
parent 215620 91a2a519a72507fe9aff6d7b99905e29b32aa836
child 215622 67c13008762f79f95e6f8d51f5b74386e075822b
push id515
push userraliiev@mozilla.com
push dateMon, 06 Oct 2014 12:51:51 +0000
treeherdermozilla-release@267c7a481bef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1024786
milestone33.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1024786 - Watch for inferred file/line information on errors when printing error contexts, r=jandem.
js/src/frontend/TokenStream.cpp
js/src/jit-test/tests/basic/bug1024786.js
--- a/js/src/frontend/TokenStream.cpp
+++ b/js/src/frontend/TokenStream.cpp
@@ -649,21 +649,23 @@ TokenStream::reportCompileErrorNumberVA(
         err.report.lineno = 0;
         err.report.column = 0;
     } else {
         err.report.lineno = srcCoords.lineNum(offset);
         err.report.column = srcCoords.columnIndex(offset);
     }
 
     // If we have no location information, try to get one from the caller.
+    bool callerFilename = false;
     if (offset != NoOffset && !err.report.filename && cx->isJSContext()) {
         NonBuiltinFrameIter iter(cx->asJSContext(),
                                  FrameIter::ALL_CONTEXTS, FrameIter::GO_THROUGH_SAVED,
                                  cx->compartment()->principals);
         if (!iter.done() && iter.scriptFilename()) {
+            callerFilename = true;
             err.report.filename = iter.scriptFilename();
             err.report.lineno = iter.computeLine(&err.report.column);
         }
     }
 
     err.argumentsType = (flags & JSREPORT_UC) ? ArgumentsAreUnicode : ArgumentsAreASCII;
 
     if (!js_ExpandErrorArguments(cx, js_GetErrorMessage, nullptr, errorNumber, &err.message,
@@ -675,17 +677,17 @@ TokenStream::reportCompileErrorNumberVA(
     // Given a token, T, that we want to complain about: if T's (starting)
     // lineno doesn't match TokenStream's lineno, that means we've scanned past
     // the line that T starts on, which makes it hard to print some or all of
     // T's (starting) line for context.
     //
     // So we don't even try, leaving report.linebuf and friends zeroed.  This
     // means that any error involving a multi-line token (e.g. an unterminated
     // multi-line string literal) won't have a context printed.
-    if (offset != NoOffset && err.report.lineno == lineno) {
+    if (offset != NoOffset && err.report.lineno == lineno && !callerFilename) {
         const jschar *tokenStart = userbuf.base() + offset;
 
         // We show only a portion (a "window") of the line around the erroneous
         // token -- the first char in the token, plus |windowRadius| chars
         // before it and |windowRadius - 1| chars after it.  This is because
         // lines can be very long and printing the whole line is (a) not that
         // helpful, and (b) can waste a lot of memory.  See bug 634444.
         static const size_t windowRadius = 60;
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/basic/bug1024786.js
@@ -0,0 +1,65 @@
+//|jit-test| error: SyntaxError
+
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+(function(){});
+evaluate("function f(){\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n",({
+    fileName: null,
+    lineNumber: 42,
+    compileAndGo: 9
+}))