Last active
November 21, 2019 06:18
-
-
Save koush/938bf8926d816aae7866969aca337d67 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function foo1() { | |
throw new Error(); | |
} | |
function foo2() { | |
try { | |
foo1(); | |
} | |
catch (e) { | |
throw e; | |
} | |
} | |
function foo3() { | |
try { | |
foo2(); | |
} | |
finally { | |
} | |
} | |
function foo4() { | |
try { | |
foo3(); | |
} | |
finally { | |
} | |
} | |
foo4(); |
backtrace is rebuilt every time it is rethrown:
diff --git a/quickjs.c b/quickjs.c
index 4392020..00b19cb 100644
--- a/quickjs.c
+++ b/quickjs.c
@@ -5923,7 +5923,14 @@ JSValue JS_Throw(JSContext *ctx, JSValue obj)
{
JS_FreeValue(ctx, ctx->current_exception);
ctx->current_exception = obj;
- ctx->exception_needs_backtrace = JS_IsError(ctx, obj);
+ if (JS_IsError(ctx, obj)) {
+ JSValue stack = JS_GetProperty(ctx, obj, JS_ATOM_stack);
+ ctx->exception_needs_backtrace = JS_IsUndefined(stack);
+ JS_FreeValue(ctx, stack);
+ }
+ else {
+ ctx->exception_needs_backtrace = FALSE;
+ }
js_debugger_exception(ctx);
return JS_EXCEPTION;
}
This is correct.
Mac-3:quickjs-2019-10-27$ ./qjs test.js
Error
at foo1 (test.js:2)
at foo2 (test.js:7)
at foo3 (test.js:15)
at foo4 (test.js:22)
at <eval> (test.js:28)
@koush
Thanks man, this fix helps a lot <3
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Where's the rest of the stack? This is wrong!