diff options
-rw-r--r-- | changelog.md | 2 | ||||
-rw-r--r-- | lib/system/jssys.nim | 3 | ||||
-rw-r--r-- | tests/exception/tsetexceptions.nim | 8 |
3 files changed, 12 insertions, 1 deletions
diff --git a/changelog.md b/changelog.md index 9806a6011..900b23ad8 100644 --- a/changelog.md +++ b/changelog.md @@ -329,7 +329,7 @@ - Fixed premature garbage collection in asyncdispatch, when a stack trace override is in place. - +- Added setCurrentException for JS backend. ## Language changes diff --git a/lib/system/jssys.nim b/lib/system/jssys.nim index ef06437e5..371cb7962 100644 --- a/lib/system/jssys.nim +++ b/lib/system/jssys.nim @@ -69,6 +69,9 @@ proc getCurrentExceptionMsg*(): string = return $msg return "" +proc setCurrentException*(exc: ref Exception) = + lastJSError = cast[PJSError](exc) + proc auxWriteStackTrace(f: PCallFrame): string = type TempFrame = tuple[procname: cstring, line: int, filename: cstring] diff --git a/tests/exception/tsetexceptions.nim b/tests/exception/tsetexceptions.nim new file mode 100644 index 000000000..557fc1898 --- /dev/null +++ b/tests/exception/tsetexceptions.nim @@ -0,0 +1,8 @@ +discard """ + targets: "c cpp js" +""" + +let ex = newException(CatchableError, "test") +setCurrentException(ex) +doAssert getCurrentException().msg == ex.msg +doAssert getCurrentExceptionMsg() == ex.msg |