Bug 758428: complain when the compiler returns false without an error, r=jorendorff
authorBenjamin Peterson <benjamin@python.org>
Thu, 31 May 2012 16:13:10 -0500
changeset 95392 2c7a1e5ac5bd28a9fae9c05c4f36f6cdcb826b3c
parent 95391 784dd8bb1ce38e1afbe75ad51db97a91a32c164d
child 95393 ee0193bef630b7270ebc62a18ce5b0a7728c405b
push id10102
push userjorendorff@mozilla.com
push dateThu, 31 May 2012 21:42:17 +0000
treeherdermozilla-inbound@af60f15c49e1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorendorff
bugs758428
milestone15.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 758428: complain when the compiler returns false without an error, r=jorendorff
js/src/shell/js.cpp
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -159,16 +159,17 @@ static PRCondVar *gSleepWakeup = NULL;
 #else
 
 static JSRuntime *gRuntime = NULL;
 
 #endif
 
 int gExitCode = 0;
 JSBool gQuitting = JS_FALSE;
+bool gGotError = false;
 FILE *gErrFile = NULL;
 FILE *gOutFile = NULL;
 #ifdef JS_THREADSAFE
 JSObject *gWorkers = NULL;
 js::workers::ThreadPool *gWorkerThreadPool = NULL;
 #endif
 
 static JSBool reportWarnings = JS_TRUE;
@@ -433,19 +434,21 @@ Process(JSContext *cx, JSObject *obj_, c
                 if (ch == '\n' || ch == '\r')
                     break;
             }
         }
         ungetc(ch, file);
 
         int64_t t1 = PRMJ_Now();
         oldopts = JS_GetOptions(cx);
+        gGotError = false;
         JS_SetOptions(cx, oldopts | JSOPTION_COMPILE_N_GO | JSOPTION_NO_SCRIPT_RVAL);
         script = JS_CompileUTF8FileHandle(cx, obj, filename, file);
         JS_SetOptions(cx, oldopts);
+        JS_ASSERT_IF(!script, gGotError);
         if (script && !compileOnly) {
             if (!JS_ExecuteScript(cx, obj, script, NULL)) {
                 if (!gQuitting && !gCanceled)
                     gExitCode = EXITCODE_RUNTIME_ERROR;
             }
             int64_t t2 = PRMJ_Now() - t1;
             if (printTiming)
                 printf("runtime = %.3f ms\n", double(t2) / PRMJ_USEC_PER_MSEC);
@@ -533,22 +536,25 @@ Process(JSContext *cx, JSObject *obj_, c
         uc_buffer = (jschar*)malloc(uc_len * sizeof(jschar));
         JS_DecodeUTF8(cx, buffer, len, uc_buffer, &uc_len);
 
         /* Clear any pending exception from previous failed compiles. */
         JS_ClearPendingException(cx);
 
         /* Even though we're interactive, we have a compile-n-go opportunity. */
         oldopts = JS_GetOptions(cx);
+        gGotError = false;
         if (!compileOnly)
             JS_SetOptions(cx, oldopts | JSOPTION_COMPILE_N_GO);
         script = JS_CompileUCScript(cx, obj, uc_buffer, uc_len, "typein", startline);
         if (!compileOnly)
             JS_SetOptions(cx, oldopts);
 
+        JS_ASSERT_IF(!script, gGotError);
+
         if (script && !compileOnly) {
             ok = JS_ExecuteScript(cx, obj, script, &result);
             if (ok && !JSVAL_IS_VOID(result)) {
                 str = JS_ValueToSource(cx, result);
                 ok = !!str;
                 if (ok) {
                     JSAutoByteString bytes(cx, str);
                     ok = !!bytes;
@@ -4212,16 +4218,18 @@ my_ErrorReporter(JSContext *cx, const ch
         fflush(gErrFile);
         return;
     }
 
     /* Conditionally ignore reported warnings. */
     if (JSREPORT_IS_WARNING(report->flags) && !reportWarnings)
         return;
 
+    gGotError = true;
+
     prefix = NULL;
     if (report->filename)
         prefix = JS_smprintf("%s:", report->filename);
     if (report->lineno) {
         tmp = prefix;
         prefix = JS_smprintf("%s%u: ", tmp ? tmp : "", report->lineno);
         JS_free(cx, tmp);
     }