[gjs/mozjs91] closure: Warn about unhandled promise rejections right away
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/mozjs91] closure: Warn about unhandled promise rejections right away
- Date: Mon, 11 Oct 2021 22:07:09 +0000 (UTC)
commit 46d0d8c71b7fbdb2c79a11c5791a5d19d9352228
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 6e1d6340..b1633fc5 100644
--- a/gjs/context.cpp
+++ b/gjs/context.cpp
@@ -1021,7 +1021,10 @@ bool GjsContextPrivate::run_jobs_fallible(void) {
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]