From f3bf7afb626c5efb357c03bd673b53ec58e3c1bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Isager=20Dalsgar=C3=B0?= Date: Wed, 8 May 2024 23:19:15 +0200 Subject: [PATCH] Add `JS_HasException()` (#265) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Author: Kasper Isager Dalsgarð Date: Wed May 8 23:19:15 2024 +0200 --- quickjs.c | 5 +++++ quickjs.h | 1 + 2 files changed, 6 insertions(+) diff --git a/quickjs.c b/quickjs.c index b71d88e..4947b8e 100644 --- a/quickjs.c +++ b/quickjs.c @@ -6305,6 +6305,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; diff --git a/quickjs.h b/quickjs.h index 73f12b0..c3ef419 100644 --- a/quickjs.h +++ b/quickjs.h @@ -570,6 +570,7 @@ static inline JS_BOOL JS_IsObject(JSValue v) JS_EXTERN JSValue JS_Throw(JSContext *ctx, JSValue obj); JS_EXTERN JSValue JS_GetException(JSContext *ctx); +JS_EXTERN JS_BOOL JS_HasException(JSContext *ctx); JS_EXTERN JS_BOOL JS_IsError(JSContext *ctx, JSValue val); JS_EXTERN void JS_ResetUncatchableError(JSContext *ctx); JS_EXTERN JSValue JS_NewError(JSContext *ctx);