make JS trunc polyfill opt-in, closes #16144 (#19183)

This commit is contained in:
hlaaftana 2021-11-24 10:20:15 +03:00 • committed by GitHub
commit ff39f6e260
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 4 deletions

View file

@ -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 .}
""".}