Skip to content

Commit

Permalink
fix system for nimscript config files on js backend (#24135)
Browse files Browse the repository at this point in the history
fixes #21441

When compiling for JS, nimscript config files have both `defined(js)`
and `defined(nimscript)` be true at the same time. This is required so
that the nimscript config file knows the current compilation is for the
JS backend. However the system module doesn't account for this in some
cases, defining JS-specific code or not defining nimscript-specific code
when compiling such nimscript files. To fix this, have the `nimscript`
define take priority over the `js` one.
  • Loading branch information
metagn authored Sep 18, 2024
1 parent 58cf624 commit 6cc50ec
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/system.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2085,7 +2085,8 @@ when notJSnotNims:
proc cmpMem(a, b: pointer, size: Natural): int =
nimCmpMem(a, b, size).int

when not defined(js):
when not defined(js) or defined(nimscript):
# nimscript can be defined if config file for js compilation
proc cmp(x, y: string): int =
when nimvm:
if x < y: result = -1
Expand Down Expand Up @@ -2365,7 +2366,8 @@ proc finished*[T: iterator {.closure.}](x: T): bool {.noSideEffect, inline, magi
from std/private/digitsutils import addInt
export addInt

when defined(js):
when defined(js) and not defined(nimscript):
# nimscript can be defined if config file for js compilation
include "system/jssys"
include "system/reprjs"

Expand Down
1 change: 1 addition & 0 deletions tests/js/tjsnimscombined.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import std/jsffi
1 change: 1 addition & 0 deletions tests/js/tjsnimscombined.nims
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# test the condition where both `js` and `nimscript` are defined (nimscript receives priority)

0 comments on commit 6cc50ec

Please sign in to comment.