From c8153fe288574098a0f1cf5337d7fa64d64bbd56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Thu, 9 Jan 2025 22:57:13 +0100 Subject: [PATCH] Build backtrace in JS_NewError Behave similarly to the constructor since it's expected that a backtrace be created. --- quickjs.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/quickjs.c b/quickjs.c index c9cb6b65..86eee698 100644 --- a/quickjs.c +++ b/quickjs.c @@ -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, @@ -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);