mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-12 22:33:49 +00:00
js -r defines nodejs & program result undeclared if unavailable (#21849)
* js -r defines nodejs & program result undefined if unavailable fixes #16985, fixes #16074 * fix * add changelog too * minor word change
This commit is contained in:
@@ -519,6 +519,12 @@ proc exceptionTypeName(e: ref Exception): string {.inline.} =
|
||||
if e == nil: "<foreign exception>"
|
||||
else: $e.name
|
||||
|
||||
when not declared(setProgramResult):
|
||||
{.warning: "setProgramResult not available on platform, unittest will not" &
|
||||
" give failing exit code on test failure".}
|
||||
template setProgramResult(a: int) =
|
||||
discard
|
||||
|
||||
template test*(name, body) {.dirty.} =
|
||||
## Define a single test case identified by `name`.
|
||||
##
|
||||
|
||||
@@ -69,23 +69,19 @@ proc addExitProc*(cl: proc() {.noconv.}) =
|
||||
fun()
|
||||
gFuns.add Fun(kind: kNoconv, fun2: cl)
|
||||
|
||||
when not defined(nimscript):
|
||||
when not defined(nimscript) and (not defined(js) or defined(nodejs)):
|
||||
proc getProgramResult*(): int =
|
||||
when defined(js) and defined(nodejs):
|
||||
asm """
|
||||
`result` = process.exitCode;
|
||||
"""
|
||||
elif not defined(js):
|
||||
result = programResult
|
||||
else:
|
||||
doAssert false
|
||||
result = programResult
|
||||
|
||||
proc setProgramResult*(a: int) =
|
||||
when defined(js) and defined(nodejs):
|
||||
asm """
|
||||
process.exitCode = `a`;
|
||||
"""
|
||||
elif not defined(js):
|
||||
programResult = a
|
||||
else:
|
||||
doAssert false
|
||||
programResult = a
|
||||
|
||||
Reference in New Issue
Block a user