diff options
-rw-r--r-- | lib/pure/json.nim | 27 | ||||
-rw-r--r-- | tests/stdlib/t15835.nim | 7 | ||||
-rw-r--r-- | tests/stdlib/talgorithm.nim | 3 | ||||
-rw-r--r-- | tests/stdlib/tjson_unmarshall.nim | 3 |
4 files changed, 17 insertions, 23 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() diff --git a/tests/stdlib/t15835.nim b/tests/stdlib/t15835.nim index bddfa87aa..ba3405780 100644 --- a/tests/stdlib/t15835.nim +++ b/tests/stdlib/t15835.nim @@ -1,4 +1,9 @@ -import json +discard """ + targets: "c js" +""" + + +import std/json type Foo = object diff --git a/tests/stdlib/talgorithm.nim b/tests/stdlib/talgorithm.nim index 47a8d327b..fecd85820 100644 --- a/tests/stdlib/talgorithm.nim +++ b/tests/stdlib/talgorithm.nim @@ -1,9 +1,10 @@ discard """ + targets: "c js" output:'''@["3", "2", "1"] ''' """ #12928,10456 -import sequtils, algorithm, json +import std/[sequtils, algorithm, json] proc test() = try: diff --git a/tests/stdlib/tjson_unmarshall.nim b/tests/stdlib/tjson_unmarshall.nim index 69bed3ac9..4353d1ee2 100644 --- a/tests/stdlib/tjson_unmarshall.nim +++ b/tests/stdlib/tjson_unmarshall.nim @@ -1,4 +1,5 @@ discard """ + targets: "c js" output: ''' Original: (kind: P, pChildren: @[(kind: Text, textStr: "mychild"), (kind: Br)]) jsonNode: {"kind":"P","pChildren":[{"kind":"Text","textStr":"mychild"},{"kind":"Br"}]} @@ -6,7 +7,7 @@ Reversed: (kind: P, pChildren: @[(kind: Text, textStr: "mychild"), (kind: Br)]) ''' """ -import json +import std/json type ContentNodeKind* = enum |