Skip to content

Commit

Permalink
Build backtrace in JS_NewError
Browse files Browse the repository at this point in the history
Behave similarly to the constructor since it's expected that a backtrace
be created.
  • Loading branch information
saghul committed Jan 10, 2025
1 parent f22dee0 commit c8153fe
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -6821,7 +6821,11 @@ static BOOL is_backtrace_needed(JSContext *ctx, JSValue obj)

JSValue JS_NewError(JSContext *ctx)
{
return JS_NewObjectClass(ctx, JS_CLASS_ERROR);
JSValue obj = JS_NewObjectClass(ctx, JS_CLASS_ERROR);
if (JS_IsException(obj))
return JS_EXCEPTION;
build_backtrace(ctx, obj, JS_UNDEFINED, NULL, 0, 0, 0);
return obj;
}

static JSValue JS_MakeError(JSContext *ctx, JSErrorEnum error_num,
Expand All @@ -6830,7 +6834,7 @@ static JSValue JS_MakeError(JSContext *ctx, JSErrorEnum error_num,
JSValue obj, msg;

if (error_num == JS_PLAIN_ERROR) {
obj = JS_NewError(ctx);
obj = JS_NewObjectClass(ctx, JS_CLASS_ERROR);
} else {
obj = JS_NewObjectProtoClass(ctx, ctx->native_error_proto[error_num],
JS_CLASS_ERROR);
Expand Down

0 comments on commit c8153fe

Please sign in to comment.