Skip to content

Commit 8bcc070

Browse files
authored
Rework JS_SetUncatchableError (#827)
Remove the (cryptic!) `flag` argument and add JS_ClearUncatchableError. Fixes: #826
1 parent d02a4ba commit 8bcc070

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

quickjs.c

+14-3
Original file line numberDiff line numberDiff line change
@@ -1320,6 +1320,7 @@ static JSValue js_module_ns_autoinit(JSContext *ctx, JSObject *p, JSAtom atom,
13201320
void *opaque);
13211321
static JSValue JS_InstantiateFunctionListItem2(JSContext *ctx, JSObject *p,
13221322
JSAtom atom, void *opaque);
1323+
static void js_set_uncatchable_error(JSContext *ctx, JSValue val, BOOL flag);
13231324

13241325
static JSValue js_new_callsite(JSContext *ctx, JSCallSiteData *csd);
13251326
static void js_new_callsite_data(JSContext *ctx, JSCallSiteData *csd, JSStackFrame *sf);
@@ -7065,7 +7066,7 @@ static no_inline __exception int __js_poll_interrupts(JSContext *ctx)
70657066
if (rt->interrupt_handler(rt, rt->interrupt_opaque)) {
70667067
/* XXX: should set a specific flag to avoid catching */
70677068
JS_ThrowInternalError(ctx, "interrupted");
7068-
JS_SetUncatchableError(ctx, ctx->rt->current_exception, TRUE);
7069+
js_set_uncatchable_error(ctx, ctx->rt->current_exception, TRUE);
70697070
return -1;
70707071
}
70717072
}
@@ -10134,7 +10135,7 @@ BOOL JS_IsUncatchableError(JSContext *ctx, JSValue val)
1013410135
return p->class_id == JS_CLASS_ERROR && p->is_uncatchable_error;
1013510136
}
1013610137

10137-
void JS_SetUncatchableError(JSContext *ctx, JSValue val, BOOL flag)
10138+
static void js_set_uncatchable_error(JSContext *ctx, JSValue val, BOOL flag)
1013810139
{
1013910140
JSObject *p;
1014010141
if (JS_VALUE_GET_TAG(val) != JS_TAG_OBJECT)
@@ -10144,9 +10145,19 @@ void JS_SetUncatchableError(JSContext *ctx, JSValue val, BOOL flag)
1014410145
p->is_uncatchable_error = flag;
1014510146
}
1014610147

10148+
void JS_SetUncatchableError(JSContext *ctx, JSValue val)
10149+
{
10150+
js_set_uncatchable_error(ctx, val, TRUE);
10151+
}
10152+
10153+
void JS_ClearUncatchableError(JSContext *ctx, JSValue val)
10154+
{
10155+
js_set_uncatchable_error(ctx, val, FALSE);
10156+
}
10157+
1014710158
void JS_ResetUncatchableError(JSContext *ctx)
1014810159
{
10149-
JS_SetUncatchableError(ctx, ctx->rt->current_exception, FALSE);
10160+
js_set_uncatchable_error(ctx, ctx->rt->current_exception, FALSE);
1015010161
}
1015110162

1015210163
int JS_SetOpaque(JSValue obj, void *opaque)

quickjs.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -616,8 +616,13 @@ JS_EXTERN JSValue JS_Throw(JSContext *ctx, JSValue obj);
616616
JS_EXTERN JSValue JS_GetException(JSContext *ctx);
617617
JS_EXTERN JS_BOOL JS_HasException(JSContext *ctx);
618618
JS_EXTERN JS_BOOL JS_IsError(JSContext *ctx, JSValue val);
619-
JS_EXTERN void JS_SetUncatchableError(JSContext *ctx, JSValue val, JS_BOOL flag);
620619
JS_EXTERN JS_BOOL JS_IsUncatchableError(JSContext* ctx, JSValue val);
620+
JS_EXTERN void JS_SetUncatchableError(JSContext *ctx, JSValue val);
621+
JS_EXTERN void JS_ClearUncatchableError(JSContext *ctx, JSValue val);
622+
// Shorthand for:
623+
// JSValue exc = JS_GetException(ctx);
624+
// JS_ClearUncatchableError(ctx, exc);
625+
// JS_Throw(ctx, exc);
621626
JS_EXTERN void JS_ResetUncatchableError(JSContext *ctx);
622627
JS_EXTERN JSValue JS_NewError(JSContext *ctx);
623628
JS_EXTERN JSValue __js_printf_like(2, 3) JS_ThrowPlainError(JSContext *ctx, const char *fmt, ...);

0 commit comments

Comments
 (0)