mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-01 19:02:18 +00:00
@@ -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
|
||||
|
||||
@@ -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(#)".}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user