[gjs/ewlsh/fix-callback-exit] Ensure exit when a closure fails after marshal.




commit 091c25b47d3f42578a01bddcb7e39fda165c272f
Author: Evan Welsh <contact evanwelsh com>
Date:   Thu Feb 11 17:41:09 2021 -0800

    Ensure exit when a closure fails after marshal.
    
    We didn't correctly check for an exit condition after marshaling,
    this caused a discrepancy with our other callback code and segfaults
    if System.exit was used in signal callbacks.
    
    Fixes #19

 gi/value.cpp | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
---
diff --git a/gi/value.cpp b/gi/value.cpp
index c9bb7f25..86054265 100644
--- a/gi/value.cpp
+++ b/gi/value.cpp
@@ -5,7 +5,7 @@
 #include <config.h>
 
 #include <stdint.h>
-#include <string.h>  // for memset
+#include <stdlib.h>  // for exit
 
 #include <girepository.h>
 #include <glib-object.h>
@@ -20,7 +20,6 @@
 #include <js/Value.h>
 #include <js/ValueArray.h>
 #include <jsapi.h>  // for InformalValueTypeName, JS_ClearPendingException
-#include <mozilla/Unused.h>
 
 #include "gi/arg-inl.h"
 #include "gi/arg.h"
@@ -259,7 +258,15 @@ closure_marshal(GClosure        *closure,
     }
 
     JS::RootedValue rval(context);
-    mozilla::Unused << gjs_closure_invoke(closure, nullptr, argv, &rval, false);
+
+    if (!gjs_closure_invoke(closure, nullptr, argv, &rval, false)) {
+        // "Uncatchable" exception thrown, we have to exit. This
+        // matches the closure exit handling in function.cpp
+        uint8_t code;
+        if (gjs->should_exit(&code))
+            exit(code);
+    }
+
     // Any exception now pending, is handled when returning control to JS
 
     if (return_value != NULL) {


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