Skip to content

Commit c8153fe

Browse files
committed
Build backtrace in JS_NewError
Behave similarly to the constructor since it's expected that a backtrace be created.
1 parent f22dee0 commit c8153fe

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

quickjs.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6821,7 +6821,11 @@ static BOOL is_backtrace_needed(JSContext *ctx, JSValue obj)
68216821

68226822
JSValue JS_NewError(JSContext *ctx)
68236823
{
6824-
return JS_NewObjectClass(ctx, JS_CLASS_ERROR);
6824+
JSValue obj = JS_NewObjectClass(ctx, JS_CLASS_ERROR);
6825+
if (JS_IsException(obj))
6826+
return JS_EXCEPTION;
6827+
build_backtrace(ctx, obj, JS_UNDEFINED, NULL, 0, 0, 0);
6828+
return obj;
68256829
}
68266830

68276831
static JSValue JS_MakeError(JSContext *ctx, JSErrorEnum error_num,
@@ -6830,7 +6834,7 @@ static JSValue JS_MakeError(JSContext *ctx, JSErrorEnum error_num,
68306834
JSValue obj, msg;
68316835

68326836
if (error_num == JS_PLAIN_ERROR) {
6833-
obj = JS_NewError(ctx);
6837+
obj = JS_NewObjectClass(ctx, JS_CLASS_ERROR);
68346838
} else {
68356839
obj = JS_NewObjectProtoClass(ctx, ctx->native_error_proto[error_num],
68366840
JS_CLASS_ERROR);

0 commit comments

Comments
 (0)