]> git.kaiwu.me - quickjs.git/commitdiff
Add `JS_HasException()` (#265)
authorKasper Isager Dalsgarð <kasperisager@hey.com>
Wed, 8 May 2024 21:19:15 +0000 (23:19 +0200)
committerGitHub <noreply@github.com>
Wed, 8 May 2024 21:19:15 +0000 (23:19 +0200)
quickjs.c
quickjs.h

index 61cfb3d3da66fb5e482945e74eb7c82e3fd597e1..bbba0050ff1b4687b47a345d177c1324fde05844 100644 (file)
--- a/quickjs.c
+++ b/quickjs.c
@@ -6402,6 +6402,11 @@ JSValue JS_GetException(JSContext *ctx)
     return val;
 }
 
+JS_BOOL JS_HasException(JSContext *ctx)
+{
+    return !JS_IsNull(ctx->rt->current_exception);
+}
+
 static void dbuf_put_leb128(DynBuf *s, uint32_t v)
 {
     uint32_t a;
index f0bab382d1dfc73d16dbc5f6953407a32e97541d..8e938873503d01748056c035add3ea18705c84d9 100644 (file)
--- a/quickjs.h
+++ b/quickjs.h
@@ -633,6 +633,7 @@ static inline JS_BOOL JS_IsObject(JSValueConst v)
 
 JSValue JS_Throw(JSContext *ctx, JSValue obj);
 JSValue JS_GetException(JSContext *ctx);
+JS_BOOL JS_HasException(JSContext *ctx);
 JS_BOOL JS_IsError(JSContext *ctx, JSValueConst val);
 void JS_ResetUncatchableError(JSContext *ctx);
 JSValue JS_NewError(JSContext *ctx);