summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhlaaftana <10591326+hlaaftana@users.noreply.github.com>2021-11-24 10:20:15 +0300
committerGitHub <noreply@github.com>2021-11-24 08:20:15 +0100
commitff39f6e26062651a56d6ac4c24fe5a799c177c50 (patch)
treeb3337627cfac7d2a39543f1a33de18ad4c51552f
parent2859069dbe1c943494cb6be299b200afa748cf52 (diff)
downloadNim-ff39f6e26062651a56d6ac4c24fe5a799c177c50.tar.gz
make JS trunc polyfill opt-in, closes #16144 (#19183)
-rw-r--r--changelog.md8
-rw-r--r--lib/system/jssys.nim6
2 files changed, 10 insertions, 4 deletions
diff --git a/changelog.md b/changelog.md
index b645bc5c7..f7f92ad3c 100644
--- a/changelog.md
+++ b/changelog.md
@@ -3,7 +3,13 @@
 
 ## Changes affecting backward compatibility
 
-
+- The `Math.trunc` polyfill for targeting Internet Explorer was
+  previously emitted for every JavaScript output file except if
+  the symbol `nodejs` was defined via `-d:nodejs`. Now, it is only
+  emitted if the symbol `nimJsMathTruncPolyfill` is defined. If you are
+  targeting Internet Explorer, you may choose to enable this option
+  or define your own `Math.trunc` polyfill using the [`emit` pragma](https://nim-lang.org/docs/manual.html#implementation-specific-pragmas-emit-pragma). Nim uses
+  `Math.trunc` for the division and modulo operators for integers.
 
 ## Standard library additions and changes
 
diff --git a/lib/system/jssys.nim b/lib/system/jssys.nim
index cd4f378be..250bd069d 100644
--- a/lib/system/jssys.nim
+++ b/lib/system/jssys.nim
@@ -763,7 +763,8 @@ proc nimParseBiggestFloat(s: string, number: var BiggestFloat, start: int): int
 
 # Workaround for IE, IE up to version 11 lacks 'Math.trunc'. We produce
 # 'Math.trunc' for Nim's ``div`` and ``mod`` operators:
-const jsMathTrunc = """
+when defined(nimJsMathTruncPolyfill):
+  {.emit: """
 if (!Math.trunc) {
   Math.trunc = function(v) {
     v = +v;
@@ -771,5 +772,4 @@ if (!Math.trunc) {
     return (v - v % 1) || (v < 0 ? -0 : v === 0 ? v : 0);
   };
 }
-"""
-when not defined(nodejs): {.emit: jsMathTrunc .}
+""".}
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228