Add JS_HasException

Ref: db9dbd0a2b
Ref: 5417ab0159
This commit is contained in:
Saúl Ibarra Corretgé 2024-09-13 23:45:18 +02:00
parent 8557bd0a0a
commit 56da486312
2 changed files with 10 additions and 4 deletions

View file

@ -1700,7 +1700,7 @@ JSRuntime *JS_NewRuntime2(const JSMallocFunctions *mf, void *opaque)
#endif #endif
JS_UpdateStackTop(rt); JS_UpdateStackTop(rt);
rt->current_exception = JS_NULL; rt->current_exception = JS_UNINITIALIZED;
return rt; return rt;
fail: fail:
@ -6353,10 +6353,15 @@ JSValue JS_GetException(JSContext *ctx)
JSValue val; JSValue val;
JSRuntime *rt = ctx->rt; JSRuntime *rt = ctx->rt;
val = rt->current_exception; val = rt->current_exception;
rt->current_exception = JS_NULL; rt->current_exception = JS_UNINITIALIZED;
return val; return val;
} }
JS_BOOL JS_HasException(JSContext *ctx)
{
return !JS_IsUninitialized(ctx->rt->current_exception);
}
static void dbuf_put_leb128(DynBuf *s, uint32_t v) static void dbuf_put_leb128(DynBuf *s, uint32_t v)
{ {
uint32_t a; uint32_t a;
@ -13803,7 +13808,7 @@ static int JS_IteratorClose(JSContext *ctx, JSValue enum_obj,
if (is_exception_pending) { if (is_exception_pending) {
ex_obj = ctx->rt->current_exception; ex_obj = ctx->rt->current_exception;
ctx->rt->current_exception = JS_NULL; ctx->rt->current_exception = JS_UNINITIALIZED;
res = -1; res = -1;
} else { } else {
ex_obj = JS_UNDEFINED; ex_obj = JS_UNDEFINED;
@ -17174,7 +17179,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValue func_obj,
JS_IteratorClose(ctx, sp[-1], TRUE); JS_IteratorClose(ctx, sp[-1], TRUE);
} else { } else {
*sp++ = rt->current_exception; *sp++ = rt->current_exception;
rt->current_exception = JS_NULL; rt->current_exception = JS_UNINITIALIZED;
pc = b->byte_code_buf + pos; pc = b->byte_code_buf + pos;
goto restart; goto restart;
} }

View file

@ -585,6 +585,7 @@ static inline JS_BOOL JS_IsObject(JSValue v)
JS_EXTERN JSValue JS_Throw(JSContext *ctx, JSValue obj); JS_EXTERN JSValue JS_Throw(JSContext *ctx, JSValue obj);
JS_EXTERN JSValue JS_GetException(JSContext *ctx); JS_EXTERN JSValue JS_GetException(JSContext *ctx);
JS_BOOL JS_HasException(JSContext *ctx);
JS_EXTERN JS_BOOL JS_IsError(JSContext *ctx, JSValue val); JS_EXTERN JS_BOOL JS_IsError(JSContext *ctx, JSValue val);
JS_EXTERN void JS_ResetUncatchableError(JSContext *ctx); JS_EXTERN void JS_ResetUncatchableError(JSContext *ctx);
JS_EXTERN JSValue JS_NewError(JSContext *ctx); JS_EXTERN JSValue JS_NewError(JSContext *ctx);