Skip to content

Commit 5417ab0

Browse files
authored
Fix JS_HasException() when null is thrown (bellard#313)
Use `JS_UNINITIALIZED` instead of `JS_NULL` when no exception is pending, so `null` can be thrown and distinguished from no exception pending.
1 parent b3715f7 commit 5417ab0

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

quickjs.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,7 +1681,7 @@ JSRuntime *JS_NewRuntime2(const JSMallocFunctions *mf, void *opaque)
16811681
rt->stack_size = JS_DEFAULT_STACK_SIZE;
16821682
JS_UpdateStackTop(rt);
16831683

1684-
rt->current_exception = JS_NULL;
1684+
rt->current_exception = JS_UNINITIALIZED;
16851685

16861686
return rt;
16871687
fail:
@@ -6398,13 +6398,13 @@ JSValue JS_GetException(JSContext *ctx)
63986398
JSValue val;
63996399
JSRuntime *rt = ctx->rt;
64006400
val = rt->current_exception;
6401-
rt->current_exception = JS_NULL;
6401+
rt->current_exception = JS_UNINITIALIZED;
64026402
return val;
64036403
}
64046404

64056405
JS_BOOL JS_HasException(JSContext *ctx)
64066406
{
6407-
return !JS_IsNull(ctx->rt->current_exception);
6407+
return !JS_IsUninitialized(ctx->rt->current_exception);
64086408
}
64096409

64106410
static void dbuf_put_leb128(DynBuf *s, uint32_t v)
@@ -15321,7 +15321,7 @@ static int JS_IteratorClose(JSContext *ctx, JSValueConst enum_obj,
1532115321

1532215322
if (is_exception_pending) {
1532315323
ex_obj = ctx->rt->current_exception;
15324-
ctx->rt->current_exception = JS_NULL;
15324+
ctx->rt->current_exception = JS_UNINITIALIZED;
1532515325
res = -1;
1532615326
} else {
1532715327
ex_obj = JS_UNDEFINED;
@@ -18674,7 +18674,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj,
1867418674
JS_IteratorClose(ctx, sp[-1], TRUE);
1867518675
} else {
1867618676
*sp++ = rt->current_exception;
18677-
rt->current_exception = JS_NULL;
18677+
rt->current_exception = JS_UNINITIALIZED;
1867818678
pc = b->byte_code_buf + pos;
1867918679
goto restart;
1868018680
}

0 commit comments

Comments
 (0)