[gjs/mozjs91: 21/25] closure: Warn about unhandled promise rejections right away




commit c8996a7b8fa54daea44388d49c4619a6269a9854
Author: Philip Chimento <philip chimento gmail com>
Date:   Mon Oct 11 15:04:41 2021 -0700

    closure: Warn about unhandled promise rejections right away
    
    In the new SpiderMonkey, the weirdness has been fixed where unregistering
    a promise rejection when it is handled, actually works and does not
    trigger the unhandled rejection warning. This means that a try-await-catch
    construction is no longer treated as an unhandled promise rejection, so we
    can warn earlier without causing false positives.
    
    Closes: #417

 gi/closure.cpp  | 6 ++++--
 gjs/context.cpp | 5 ++++-
 2 files changed, 8 insertions(+), 3 deletions(-)
---
diff --git a/gi/closure.cpp b/gi/closure.cpp
index 1981d1da..15b6a5fe 100644
--- a/gi/closure.cpp
+++ b/gi/closure.cpp
@@ -181,7 +181,10 @@ bool Closure::invoke(JS::HandleObject this_obj,
     }
 
     JS::RootedFunction func(m_cx, m_func);
-    if (!JS::Call(m_cx, this_obj, func, args, retval)) {
+    bool ok = JS::Call(m_cx, this_obj, func, args, retval);
+    GjsContextPrivate* gjs = GjsContextPrivate::from_cx(m_cx);
+    gjs->warn_about_unhandled_promise_rejections();
+    if (!ok) {
         /* Exception thrown... */
         gjs_debug_closure(
             "Closure invocation failed (exception should have been thrown) "
@@ -197,7 +200,6 @@ bool Closure::invoke(JS::HandleObject this_obj,
             m_cx);
     }
 
-    GjsContextPrivate* gjs = GjsContextPrivate::from_cx(m_cx);
     gjs->schedule_gc_if_needed();
     return true;
 }
diff --git a/gjs/context.cpp b/gjs/context.cpp
index 97205cb8..e68be628 100644
--- a/gjs/context.cpp
+++ b/gjs/context.cpp
@@ -1011,7 +1011,10 @@ bool GjsContextPrivate::run_jobs_fallible(GCancellable* cancellable) {
             JSAutoRealm ar(m_cx, job);
             gjs_debug(GJS_DEBUG_CONTEXT, "handling job %s",
                       gjs_debug_object(job).c_str());
-            if (!JS::Call(m_cx, JS::UndefinedHandleValue, job, args, &rval)) {
+            bool ok =
+                JS::Call(m_cx, JS::UndefinedHandleValue, job, args, &rval);
+            warn_about_unhandled_promise_rejections();
+            if (!ok) {
                 /* Uncatchable exception - return false so that
                  * System.exit() works in the interactive shell and when
                  * exiting the interpreter. */


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