diff options
author | flywind <xzsflywind@gmail.com> | 2021-03-05 02:37:12 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-04 19:37:12 +0100 |
commit | 81889fb84ce9fb185bdbf4d4f657c80cf94b23fc (patch) | |
tree | 8e1e886ede34fdb127055900310193136a435773 /lib | |
parent | e1cc3b83fba0bc66790959d3cd84d70464c31e4f (diff) | |
download | Nim-81889fb84ce9fb185bdbf4d4f657c80cf94b23fc.tar.gz |
reuse jsffi in json module (#17165)
* remove unnecessary when statement * remove outdated codes * reuse jsffi * move js json coverage
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pure/json.nim | 27 |
1 files changed, 7 insertions, 20 deletions
diff --git a/lib/pure/json.nim b/lib/pure/json.nim index 7706901b4..1d2b20176 100644 --- a/lib/pure/json.nim +++ b/lib/pure/json.nim @@ -908,15 +908,14 @@ proc parseJson*(s: Stream, filename: string = ""; rawIntegers = false, rawFloats when defined(js): from std/math import `mod` - type - JSObject = object + import std/jsffi - proc parseNativeJson(x: cstring): JSObject {.importc: "JSON.parse".} + proc parseNativeJson(x: cstring): JSObject {.importjs: "JSON.parse(#)".} proc getVarType(x: JSObject): JsonNodeKind = result = JNull proc getProtoName(y: JSObject): cstring - {.importc: "Object.prototype.toString.call".} + {.importjs: "Object.prototype.toString.call(#)".} case $getProtoName(x) # TODO: Implicit returns fail here. of "[object Array]": return JArray of "[object Object]": return JObject @@ -936,18 +935,6 @@ when defined(js): `result` = `x`.length; """ - proc `[]`(x: JSObject, y: string): JSObject = - assert x.getVarType == JObject - asm """ - `result` = `x`[`y`]; - """ - - proc `[]`(x: JSObject, y: int): JSObject = - assert x.getVarType == JArray - asm """ - `result` = `x`[`y`]; - """ - proc convertObject(x: JSObject): JsonNode = case getVarType(x) of JArray: @@ -965,14 +952,14 @@ when defined(js): result[$nimProperty] = nimValue.convertObject() asm "}}" of JInt: - result = newJInt(cast[int](x)) + result = newJInt(x.to(int)) of JFloat: - result = newJFloat(cast[float](x)) + result = newJFloat(x.to(float)) of JString: # Dunno what to do with isUnquoted here - result = newJString($cast[cstring](x)) + result = newJString($x.to(cstring)) of JBool: - result = newJBool(cast[bool](x)) + result = newJBool(x.to(bool)) of JNull: result = newJNull() |