Skip to content

Commit 7d4af38

Browse files
committed
Reorder code
1 parent 9d3d91b commit 7d4af38

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

lib/js_of_ocaml/json.ml

+17-15
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,22 @@ open! Import
2222

2323
(****)
2424

25+
class type json = object
26+
method parse : 'a. js_string t -> 'a meth
27+
28+
method parse_ :
29+
'a 'b 'c 'd. js_string t -> ('b t, js_string t -> 'c -> 'd) meth_callback -> 'a meth
30+
31+
method stringify : 'a. 'a -> js_string t meth
32+
33+
method stringify_ :
34+
'a 'b 'c 'd. 'a -> ('b, js_string t -> 'c -> 'd) meth_callback -> js_string t meth
35+
end
36+
37+
let json : json Js.t = Unsafe.global##._JSON
38+
39+
(****)
40+
2541
(* The writing logic for basic types is copied from [lib/deriving_json]. *)
2642

2743
let write_string buffer s =
@@ -102,7 +118,7 @@ let rec write b v =
102118
else if t = Obj.abstract_tag
103119
then
104120
(* Presumably a JavaScript value *)
105-
Buffer.add_string b (Js.to_string (Unsafe.global##._JSON##stringify v))
121+
Buffer.add_string b (Js.to_string (json##stringify v))
106122
else failwith (Printf.sprintf "Json.output: unsupported tag %d " t)
107123

108124
let to_json v =
@@ -112,20 +128,6 @@ let to_json v =
112128

113129
(****)
114130

115-
class type json = object
116-
method parse : 'a. js_string t -> 'a meth
117-
118-
method parse_ :
119-
'a 'b 'c 'd. js_string t -> ('b t, js_string t -> 'c -> 'd) meth_callback -> 'a meth
120-
121-
method stringify : 'a. 'a -> js_string t meth
122-
123-
method stringify_ :
124-
'a 'b 'c 'd. 'a -> ('b, js_string t -> 'c -> 'd) meth_callback -> js_string t meth
125-
end
126-
127-
let json : json Js.t = Unsafe.global##._JSON
128-
129131
let input_reviver =
130132
let reviver _this _key (value : Unsafe.any) : Obj.t =
131133
if Js.equals (typeof value) (string "string")

0 commit comments

Comments
 (0)