-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathojs.mli
155 lines (106 loc) · 4.33 KB
/
ojs.mli
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
(* The gen_js_api is released under the terms of an MIT-like license. *)
(* See the attached LICENSE file. *)
(* Copyright 2015 by LexiFi. *)
(** Binding with JS values. *)
type t
(** The universal type representing arbitrary JS values. *)
(** {2 Mapper for built-in types} *)
external t_of_js: t -> t = "%identity"
external t_to_js: t -> t = "%identity"
external string_of_js: t -> string = "caml_js_to_string"
external string_to_js: string -> t = "caml_js_from_string"
external int_of_js: t -> int = "%identity"
external int_to_js: int -> t = "%identity"
external bool_of_js: t -> bool = "caml_js_to_bool"
external bool_to_js: bool -> t = "caml_js_from_bool"
external float_of_js: t -> float = "%identity"
external float_to_js: float -> t = "%identity"
val array_of_js: (t -> 'a) -> t -> 'a array
val array_to_js: ('a -> t) -> 'a array -> t
val list_of_js: (t -> 'a) -> t -> 'a list
val list_to_js: ('a -> t) -> 'a list -> t
val array_of_js_from: (t -> 'a) -> t -> int -> 'a array
val list_of_js_from: (t -> 'a) -> t -> int -> 'a list
val option_of_js: (t -> 'a) -> t -> 'a option
(** Both [null] and [undefined] are mapped to [None]. *)
val option_to_js: ('a -> t) -> 'a option -> t
(** [None] is mapped to [null]. *)
val unit_of_js: t -> unit
val unit_to_js: unit -> t
(** {2 Wrap OCaml functions as JS functions} *)
external fun_to_js: int -> (t -> 'a) -> t = "caml_js_wrap_callback_strict"
(** Wrap an OCaml function of known arity (>=1) into a JS function.
Extra arguments are discarded and missing argument are filled with
'undefined'.
*)
external fun_to_js_args: (t -> 'a) -> t = "caml_ojs_wrap_fun_arguments"
(** Wrap an OCaml function taking JS arguments as a JS array. *)
(** {2 JS objects} *)
external get: t -> string -> t = "caml_js_get"
[@@ocaml.deprecated "Use Ojs.get_prop_ascii instead."]
external set: t -> string -> t -> unit = "caml_js_set"
[@@ocaml.deprecated "Use Ojs.set_prop_ascii instead."]
external delete: t -> string -> unit = "caml_js_delete"
[@@ocaml.deprecated "Use Ojs.delete_prop_ascii instead."]
external get_prop_ascii: t -> string -> t = "caml_js_get"
(** Get the property from an object (only works if the property key is a plain ascii string). *)
external set_prop_ascii: t -> string -> t -> unit = "caml_js_set"
(** Set an object property (only works if the property key is a plain ascii string). *)
external delete_prop_ascii: t -> string -> unit = "caml_js_delete"
(** Delete an object property (only works if the property key is a plain ascii string). *)
external get_prop: t -> t -> t = "caml_js_get"
(** Get the property from an object. *)
external set_prop: t -> t -> t -> unit = "caml_js_set"
(** Set an object property. *)
external delete_prop: t -> t -> unit = "caml_js_delete"
(** Delete an object property. *)
external obj: (string * t) array -> t = "caml_js_object"
val empty_obj: unit -> t
val has_property: t -> string -> bool
external iter_properties: t -> (string -> unit) -> unit = "caml_ojs_iterate_properties"
(** {2 Calling JS functions} *)
external call: t -> string -> t array -> t = "caml_js_meth_call"
(** Call a method on an object (binding 'this' to the object). *)
external apply: t -> t array -> t = "caml_js_fun_call"
(** Call a function. *)
external new_obj: t -> t array -> t = "caml_js_new"
(** Call a constructor *)
val call_arr: t -> string -> t -> t
(** Variant of [Ojs.call] where the arguments are passed as an already
built JS array. *)
val apply_arr: t -> t -> t
(** Variant of [Ojs.apply] where the arguments are passed as an already
built JS array. *)
external new_obj_arr: t -> t -> t = "caml_ojs_new_arr"
(** Variant of [Ojs.new_obj] where the arguments are passed as an already
built JS array. *)
(** {2 Arrays} *)
val array_make: int -> t
val array_get: t -> int -> t
val array_set: t -> int -> t -> unit
(** {2 Misc} *)
val global: t
val null: t
external variable: string -> t = "caml_js_var"
val type_of: t -> string
class obj: t ->
object
method to_js: t
end
val is_null: t -> bool
val obj_type: t -> string
(** Returns:
"[object Array]"
"[object Object]"
"[object Number]"
"[object String]"
"[object Null]"
"[object Boolean]"
*)
module type T =
sig
type js := t
type t
val t_to_js : t -> js
val t_of_js : js -> t
end