This commit is contained in:
flywind
2021-03-09 19:22:26 +08:00
committed by GitHub
parent 9c5223a5f5
commit cc37fee0ab
3 changed files with 11 additions and 7 deletions

View File

@@ -909,7 +909,7 @@ proc parseJson*(s: Stream, filename: string = ""; rawIntegers = false, rawFloats
when defined(js):
from std/math import `mod`
from std/jsffi import JSObject, `[]`, to
from std/private/jsutils import getProtoName
from std/private/jsutils import getProtoName, isInteger, isSafeInteger
proc parseNativeJson(x: cstring): JSObject {.importjs: "JSON.parse(#)".}
@@ -919,8 +919,11 @@ when defined(js):
of "[object Array]": return JArray
of "[object Object]": return JObject
of "[object Number]":
if cast[float](x) mod 1.0 == 0:
return JInt
if isInteger(x):
if isSafeInteger(x):
return JInt
else:
return JString
else:
return JFloat
of "[object Boolean]": return JBool

View File

@@ -37,3 +37,7 @@ when defined(js):
asm """`result` = typeof BigUint64Array != 'undefined'"""
proc getProtoName*[T](a: T): cstring {.importjs: "Object.prototype.toString.call(#)".}
proc isInteger*[T](x: T): bool {.importjs: "Number.isInteger(#)".}
proc isSafeInteger*[T](x: T): bool {.importjs: "Number.isSafeInteger(#)".}

View File

@@ -240,10 +240,7 @@ doAssert isRefSkipDistinct(MyOtherDistinct)
let x = parseJson("9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999")
when defined(js): # xxx fixme
doAssert x.kind == JInt
else:
doAssert x.kind == JString
doAssert x.kind == JString
block: # bug #15835
type