diff --git a/changelog.md b/changelog.md index d28edd34cded..c5d65b50e6e2 100644 --- a/changelog.md +++ b/changelog.md @@ -19,6 +19,8 @@ - Added std/enumutils module containing `genEnumCaseStmt` macro that generates case statement to parse string to enum. +- `writeStackTrace` is available in JS backend now. + ## Language changes diff --git a/lib/system.nim b/lib/system.nim index e41dfe1ca9f3..ab9140c13768 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -1762,7 +1762,7 @@ when notJSnotNims and defined(nimSeqsV2): {.pop.} -when notJSnotNims: +when not defined(nimscript): proc writeStackTrace*() {.tags: [], gcsafe, raises: [].} ## Writes the current stack trace to ``stderr``. This is only works ## for debug builds. Since it's usually used for debugging, this diff --git a/lib/system/jssys.nim b/lib/system/jssys.nim index df05a9a62830..d0be35dd097a 100644 --- a/lib/system/jssys.nim +++ b/lib/system/jssys.nim @@ -105,6 +105,11 @@ proc rawWriteStackTrace(): string = else: result = "No stack traceback available\n" +proc writeStackTrace() = + var trace = rawWriteStackTrace() + trace.setLen(trace.len - 1) + echo trace + proc getStackTrace*(): string = rawWriteStackTrace() proc getStackTrace*(e: ref Exception): string = e.trace diff --git a/tests/js/twritestacktrace.nim b/tests/js/twritestacktrace.nim new file mode 100644 index 000000000000..2fe2b1987a7e --- /dev/null +++ b/tests/js/twritestacktrace.nim @@ -0,0 +1,12 @@ +discard """ + cmd: "nim js --panics:on $file" + output: '''Traceback (most recent call last) +twritestacktrace.nim(12) at module twritestacktrace +twritestacktrace.nim(10) at twritestacktrace.hello +''' +""" + +proc hello() = + writeStackTrace() + +hello()