[gjs: 1/2] context: Job queue should not swallow pending exceptions



commit 562cadcec55d50097ee42aeecc6fa7ef3870002a
Author: Philip Chimento <philip chimento gmail com>
Date:   Sun Mar 18 22:45:31 2018 -0700

    context: Job queue should not swallow pending exceptions
    
    Previously, the promise job queue would try to execute promise jobs
    regardless of whether there was an exception pending. In debug mode, this
    would abort due to calling into JS code while an exception was already
    pending. In non-debug mode, this would likely just swallow the exception.
    
    Now, we save and restore the exception state before handling the promise
    job queue.
    
    Closes #18.

 gjs/context.cpp                            | 5 ++++-
 installed-tests/scripts/testCommandLine.sh | 3 +++
 2 files changed, 7 insertions(+), 1 deletion(-)
---
diff --git a/gjs/context.cpp b/gjs/context.cpp
index a9cdbec..70041f1 100644
--- a/gjs/context.cpp
+++ b/gjs/context.cpp
@@ -807,7 +807,10 @@ gjs_context_eval(GjsContext   *js_context,
     /* The promise job queue should be drained even on error, to finish
      * outstanding async tasks before the context is torn down. Drain after
      * uncaught exceptions have been reported since draining runs callbacks. */
-    ok = _gjs_context_run_jobs(js_context) && ok;
+    {
+        JS::AutoSaveExceptionState saved_exc(js_context->context);
+        ok = _gjs_context_run_jobs(js_context) && ok;
+    }
 
     if (auto_profile)
         gjs_profiler_stop(js_context->profiler);
diff --git a/installed-tests/scripts/testCommandLine.sh b/installed-tests/scripts/testCommandLine.sh
index 30834c8..0a56f47 100755
--- a/installed-tests/scripts/testCommandLine.sh
+++ b/installed-tests/scripts/testCommandLine.sh
@@ -203,6 +203,9 @@ $gjs -c "Promise.resolve().then(() => { throw new Error(); });" 2>&1 | grep -q '
 report "unhandled promise rejection should be reported"
 test -z "$($gjs awaitcatch.js)"
 report "catching an await expression should not cause unhandled rejection"
+# https://gitlab.gnome.org/GNOME/gjs/issues/18
+$gjs -c "(async () => await true)(); void foobar;" 2>&1 | grep -q 'Script .* threw an exception'
+report "main program exceptions are not swallowed by queued promise jobs"
 
 # https://gitlab.gnome.org/GNOME/gjs/issues/26
 $gjs -c 'new imports.gi.Gio.Subprocess({argv: ["true"]}).init(null);'


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]