File tree Expand file tree Collapse file tree 3 files changed +13
-1
lines changed Expand file tree Collapse file tree 3 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -94,10 +94,15 @@ let rec write b v =
94
94
then
95
95
match custom_identifier v with
96
96
| "_i" -> Printf. bprintf b " %ld" (Obj. obj v : int32 )
97
+ | "_n" -> Printf. bprintf b " %nd" (Obj. obj v : nativeint )
97
98
| "_j" ->
98
99
let i : int64 = Obj. obj v in
99
100
write_int64 b i
100
101
| id -> failwith (Printf. sprintf " Json.output: unsupported custom value %s " id)
102
+ else if t = Obj. abstract_tag
103
+ then
104
+ (* Presumably a JavaScript value *)
105
+ Buffer. add_string b (Js. to_string (Unsafe. global##._JSON##stringify v))
101
106
else failwith (Printf. sprintf " Json.output: unsupported tag %d " t)
102
107
103
108
let to_json v =
Original file line number Diff line number Diff line change @@ -55,7 +55,7 @@ type enabled_if =
55
55
let enabled_if = function
56
56
| "test_sys" -> GE5
57
57
| "test_fun_call" -> No_effects_not_wasm
58
- | "test_json" | " test_poly_compare" -> Not_wasm
58
+ | "test_poly_compare" -> Not_wasm
59
59
| _ -> Any
60
60
61
61
let () =
Original file line number Diff line number Diff line change @@ -61,3 +61,10 @@ let%expect_test _ =
61
61
[% expect {| [254 ,1 ,2 ,3 ] | }];
62
62
round_trip 2n ;
63
63
[% expect {| 2 | }]
64
+
65
+ let % expect_test " JavaScript object" =
66
+ let x = object % js val x = 1 val y = Js. string " abcd" end in
67
+ let s = Json. output x in
68
+ let s1 = Js. to_string s in
69
+ Printf. printf " %s\n " s1;
70
+ [% expect {| {" x" :1 ," y" :" abcd" } | }]
You can’t perform that action at this time.
0 commit comments