forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjs.ml
286 lines (224 loc) · 12.7 KB
/
js.ml
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* In addition to the permissions granted to you by the LGPL, you may combine
* or link a "work that uses the Library" with a publicly distributed version
* of this file to produce a combined library or application, then distribute
* that combined work under the terms of your choosing, with no requirement
* to comply with the obligations normally placed on you by section 4 of the
* LGPL version 3 (or the corresponding section of a later version of the LGPL
* should you choose to use a later version).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
(* DESIGN:
- It does not have any code, all its code will be inlined so that
there will never be
{[ require('js')]}
- Its interface should be minimal
*)
(** This library provides bindings and necessary support for JS FFI.
It contains all bindings into [Js] namespace.
@example {[
[| 1;2;3;4|]
|. Js.Array2.map (fun x -> x + 1 )
|. Js.Array2.reduce (+) 0
|. Js.log
]}
*)
(** Types for JS objects *)
type +'a t
(** Js object type.
@example {[
let x : < x : int ; y : int > Js.t =
[%obj{ x = 1 ; y = 2}]
]}
*)
(* internal types for FFI, these types are not used by normal users *)
(**/**)
module MapperRt = Js_mapperRt
module Internal = struct
(* Generated by scripts/js_unsafe_gen.ml *)
type (-'obj, +'a) meth_callback
type (-'arg, + 'result) meth
type (-'arg, + 'result) fn
(** Js uncurried function *)
external (!) : 'a t -> 'a = "#unsafe_downgrade"
external debugger : unit -> unit = "#debugger"
external raw_expr : string -> 'a = "#raw_expr"
external raw_stmt : string -> 'a = "#raw_stmt"
external raw_function: string -> 'a = "#raw_function"
external unsafe_downgrade : 'a t -> 'a = "#unsafe_downgrade"
external fn_mk0 : (unit -> 'a0) -> (([`Arity_0], 'a0) fn) = "#fn_mk" "0"
external fn_mk1 : ('a0 -> 'a1) -> (([`Arity_1 of ( 'a0 )], 'a1) fn) = "#fn_mk" "1"
external fn_mk2 : ('a0 -> 'a1 -> 'a2) -> (([`Arity_2 of ( 'a0 * 'a1 )], 'a2) fn) = "#fn_mk" "2"
external fn_mk3 : ('a0 -> 'a1 -> 'a2 -> 'a3) -> (([`Arity_3 of ( 'a0 * 'a1 * 'a2 )], 'a3) fn) = "#fn_mk" "3"
external fn_mk4 : ('a0 -> 'a1 -> 'a2 -> 'a3 -> 'a4) -> (([`Arity_4 of ( 'a0 * 'a1 * 'a2 * 'a3 )], 'a4) fn) = "#fn_mk" "4"
external fn_mk5 : ('a0 -> 'a1 -> 'a2 -> 'a3 -> 'a4 -> 'a5) -> (([`Arity_5 of ( 'a0 * 'a1 * 'a2 * 'a3 * 'a4 )], 'a5) fn) = "#fn_mk" "5"
external fn_mk6 : ('a0 -> 'a1 -> 'a2 -> 'a3 -> 'a4 -> 'a5 -> 'a6) -> (([`Arity_6 of ( 'a0 * 'a1 * 'a2 * 'a3 * 'a4 * 'a5 )], 'a6) fn) = "#fn_mk" "6"
external fn_mk7 : ('a0 -> 'a1 -> 'a2 -> 'a3 -> 'a4 -> 'a5 -> 'a6 -> 'a7) -> (([`Arity_7 of ( 'a0 * 'a1 * 'a2 * 'a3 * 'a4 * 'a5 * 'a6 )], 'a7) fn) = "#fn_mk" "7"
external fn_mk8 : ('a0 -> 'a1 -> 'a2 -> 'a3 -> 'a4 -> 'a5 -> 'a6 -> 'a7 -> 'a8) -> (([`Arity_8 of ( 'a0 * 'a1 * 'a2 * 'a3 * 'a4 * 'a5 * 'a6 * 'a7 )], 'a8) fn) = "#fn_mk" "8"
external fn_mk9 : ('a0 -> 'a1 -> 'a2 -> 'a3 -> 'a4 -> 'a5 -> 'a6 -> 'a7 -> 'a8 -> 'a9) -> (([`Arity_9 of ( 'a0 * 'a1 * 'a2 * 'a3 * 'a4 * 'a5 * 'a6 * 'a7 * 'a8 )], 'a9) fn) = "#fn_mk" "9"
external fn_method1 : ('a0 -> 'a1) -> (([`Arity_1 of ( 'a0 )], 'a1 ) meth_callback) = "#fn_method" "1"
external fn_method2 : ('a0 -> 'a1 -> 'a2) -> (([`Arity_2 of ( 'a0 * 'a1 )], 'a2 ) meth_callback) = "#fn_method" "2"
external fn_method3 : ('a0 -> 'a1 -> 'a2 -> 'a3) -> (([`Arity_3 of ( 'a0 * 'a1 * 'a2 )], 'a3 ) meth_callback) = "#fn_method" "3"
external fn_method4 : ('a0 -> 'a1 -> 'a2 -> 'a3 -> 'a4) -> (([`Arity_4 of ( 'a0 * 'a1 * 'a2 * 'a3 )], 'a4 ) meth_callback) = "#fn_method" "4"
external fn_method5 : ('a0 -> 'a1 -> 'a2 -> 'a3 -> 'a4 -> 'a5) -> (([`Arity_5 of ( 'a0 * 'a1 * 'a2 * 'a3 * 'a4 )], 'a5 ) meth_callback) = "#fn_method" "5"
external fn_method6 : ('a0 -> 'a1 -> 'a2 -> 'a3 -> 'a4 -> 'a5 -> 'a6) -> (([`Arity_6 of ( 'a0 * 'a1 * 'a2 * 'a3 * 'a4 * 'a5 )], 'a6 ) meth_callback) = "#fn_method" "6"
external fn_method7 : ('a0 -> 'a1 -> 'a2 -> 'a3 -> 'a4 -> 'a5 -> 'a6 -> 'a7) -> (([`Arity_7 of ( 'a0 * 'a1 * 'a2 * 'a3 * 'a4 * 'a5 * 'a6 )], 'a7 ) meth_callback) = "#fn_method" "7"
external fn_method8 : ('a0 -> 'a1 -> 'a2 -> 'a3 -> 'a4 -> 'a5 -> 'a6 -> 'a7 -> 'a8) -> (([`Arity_8 of ( 'a0 * 'a1 * 'a2 * 'a3 * 'a4 * 'a5 * 'a6 * 'a7 )], 'a8 ) meth_callback) = "#fn_method" "8"
external fn_method9 : ('a0 -> 'a1 -> 'a2 -> 'a3 -> 'a4 -> 'a5 -> 'a6 -> 'a7 -> 'a8 -> 'a9) -> (([`Arity_9 of ( 'a0 * 'a1 * 'a2 * 'a3 * 'a4 * 'a5 * 'a6 * 'a7 * 'a8 )], 'a9 ) meth_callback) = "#fn_method" "9"
external fn_method10 : ('a0 -> 'a1 -> 'a2 -> 'a3 -> 'a4 -> 'a5 -> 'a6 -> 'a7 -> 'a8 -> 'a9 -> 'a10) -> (([`Arity_10 of ( 'a0 * 'a1 * 'a2 * 'a3 * 'a4 * 'a5 * 'a6 * 'a7 * 'a8 * 'a9 )], 'a10 ) meth_callback) = "#fn_method" "10"
external fn_run0 : (([`Arity_0], 'a0) fn) -> 'a0 = "#fn_run" "0"
external fn_run1 : (([`Arity_1 of ( 'a0 )], 'a1) fn) -> ('a0 -> 'a1 ) = "#fn_run" "1"
external fn_run2 : (([`Arity_2 of ( 'a0 * 'a1 )], 'a2) fn) -> ('a0 -> 'a1 -> 'a2 ) = "#fn_run" "2"
external fn_run3 : (([`Arity_3 of ( 'a0 * 'a1 * 'a2 )], 'a3) fn) -> ('a0 -> 'a1 -> 'a2 -> 'a3 ) = "#fn_run" "3"
external fn_run4 : (([`Arity_4 of ( 'a0 * 'a1 * 'a2 * 'a3 )], 'a4) fn) -> ('a0 -> 'a1 -> 'a2 -> 'a3 -> 'a4 ) = "#fn_run" "4"
external fn_run5 : (([`Arity_5 of ( 'a0 * 'a1 * 'a2 * 'a3 * 'a4 )], 'a5) fn) -> ('a0 -> 'a1 -> 'a2 -> 'a3 -> 'a4 -> 'a5 ) = "#fn_run" "5"
external fn_run6 : (([`Arity_6 of ( 'a0 * 'a1 * 'a2 * 'a3 * 'a4 * 'a5 )], 'a6) fn) -> ('a0 -> 'a1 -> 'a2 -> 'a3 -> 'a4 -> 'a5 -> 'a6 ) = "#fn_run" "6"
external fn_run7 : (([`Arity_7 of ( 'a0 * 'a1 * 'a2 * 'a3 * 'a4 * 'a5 * 'a6 )], 'a7) fn) -> ('a0 -> 'a1 -> 'a2 -> 'a3 -> 'a4 -> 'a5 -> 'a6 -> 'a7 ) = "#fn_run" "7"
external fn_run8 : (([`Arity_8 of ( 'a0 * 'a1 * 'a2 * 'a3 * 'a4 * 'a5 * 'a6 * 'a7 )], 'a8) fn) -> ('a0 -> 'a1 -> 'a2 -> 'a3 -> 'a4 -> 'a5 -> 'a6 -> 'a7 -> 'a8 ) = "#fn_run" "8"
external fn_run9 : (([`Arity_9 of ( 'a0 * 'a1 * 'a2 * 'a3 * 'a4 * 'a5 * 'a6 * 'a7 * 'a8 )], 'a9) fn) -> ('a0 -> 'a1 -> 'a2 -> 'a3 -> 'a4 -> 'a5 -> 'a6 -> 'a7 -> 'a8 -> 'a9 ) = "#fn_run" "9"
external method_run0 : (([`Arity_0], 'a0) meth) -> 'a0 = "#method_run" "0"
external method_run1 : (([`Arity_1 of ( 'a0 )], 'a1) meth) -> ('a0 -> 'a1 ) = "#method_run" "1"
external method_run2 : (([`Arity_2 of ( 'a0 * 'a1 )], 'a2) meth) -> ('a0 -> 'a1 -> 'a2 ) = "#method_run" "2"
external method_run3 : (([`Arity_3 of ( 'a0 * 'a1 * 'a2 )], 'a3) meth) -> ('a0 -> 'a1 -> 'a2 -> 'a3 ) = "#method_run" "3"
external method_run4 : (([`Arity_4 of ( 'a0 * 'a1 * 'a2 * 'a3 )], 'a4) meth) -> ('a0 -> 'a1 -> 'a2 -> 'a3 -> 'a4 ) = "#method_run" "4"
external method_run5 : (([`Arity_5 of ( 'a0 * 'a1 * 'a2 * 'a3 * 'a4 )], 'a5) meth) -> ('a0 -> 'a1 -> 'a2 -> 'a3 -> 'a4 -> 'a5 ) = "#method_run" "5"
external method_run6 : (([`Arity_6 of ( 'a0 * 'a1 * 'a2 * 'a3 * 'a4 * 'a5 )], 'a6) meth) -> ('a0 -> 'a1 -> 'a2 -> 'a3 -> 'a4 -> 'a5 -> 'a6 ) = "#method_run" "6"
external method_run7 : (([`Arity_7 of ( 'a0 * 'a1 * 'a2 * 'a3 * 'a4 * 'a5 * 'a6 )], 'a7) meth) -> ('a0 -> 'a1 -> 'a2 -> 'a3 -> 'a4 -> 'a5 -> 'a6 -> 'a7 ) = "#method_run" "7"
external method_run8 : (([`Arity_8 of ( 'a0 * 'a1 * 'a2 * 'a3 * 'a4 * 'a5 * 'a6 * 'a7 )], 'a8) meth) -> ('a0 -> 'a1 -> 'a2 -> 'a3 -> 'a4 -> 'a5 -> 'a6 -> 'a7 -> 'a8 ) = "#method_run" "8"
external method_run9 : (([`Arity_9 of ( 'a0 * 'a1 * 'a2 * 'a3 * 'a4 * 'a5 * 'a6 * 'a7 * 'a8 )], 'a9) meth) -> ('a0 -> 'a1 -> 'a2 -> 'a3 -> 'a4 -> 'a5 -> 'a6 -> 'a7 -> 'a8 -> 'a9 ) = "#method_run" "9"
end
(**/**)
type + 'a null
(** nullable, value of this type can be either [null] or ['a]
this type is the same as type [t] in {!Null}
*)
type + 'a undefined
(** value of this type can be either [undefined] or ['a]
this type is the same as type [t] in {!Undefined} *)
type + 'a nullable
(** value of this type can be [undefined], [null] or ['a]
this type is the same as type [t] n {!Null_undefined} *)
type + 'a null_undefined = 'a nullable
external toOption : 'a nullable -> 'a option = "#nullable_to_opt"
external undefinedToOption : 'a undefined -> 'a option = "#undefined_to_opt"
external nullToOption : 'a null -> 'a option = "#null_to_opt"
external test : 'a nullable -> bool = "#is_nullable"
[@@ocaml.deprecated "Use Js.isNullable instead"]
external isNullable : 'a nullable -> bool = "#is_nullable"
(** The same as {!test} except that it is more permissive on the types of input *)
external testAny : 'a -> bool = "#is_nullable"
type (+'a, +'e) promise
(** The promise type, defined here for interoperation across packages
@deprecated please use {!Js.Promise}
*)
external null : 'a null = "#null"
(** The same as [empty] in {!Js.Null} will be compiled as [null]*)
external undefined : 'a undefined = "#undefined"
(** The same as [empty] {!Js.Undefined} will be compiled as [undefined]*)
external typeof : 'a -> string = "#typeof"
(** [typeof x] will be compiled as [typeof x] in JS
Please consider functions in {!Types} for a type safe way of reflection
*)
external log : 'a -> unit = "log"
[@@bs.val] [@@bs.scope "console"]
external log2 : 'a -> 'b -> unit = "log"
[@@bs.val] [@@bs.scope "console"]
external log3 : 'a -> 'b -> 'c -> unit = "log"
[@@bs.val] [@@bs.scope "console"]
external log4 : 'a -> 'b -> 'c -> 'd -> unit = "log"
[@@bs.val] [@@bs.scope "console"]
(** A convenience function to log everything *)
external logMany : 'a array -> unit = "log"
[@@bs.val] [@@bs.scope "console"] [@@bs.splice]
(** A convenience function to log more than 4 arguments *)
external eqNull : 'a -> 'a null -> bool = "%bs_equal_null"
external eqUndefined : 'a -> 'a undefined -> bool = "%bs_equal_undefined"
external eqNullable : 'a -> 'a nullable -> bool = "%bs_equal_nullable"
(** {4 operators }*)
external unsafe_lt : 'a -> 'a -> bool = "#unsafe_lt"
(** [unsafe_lt a b] will be compiled as [a < b].
It is marked as unsafe, since it is impossible
to give a proper semantics for comparision which applies to any type
*)
external unsafe_le : 'a -> 'a -> bool = "#unsafe_le"
(** [unsafe_le a b] will be compiled as [a <= b].
See also {!unsafe_lt}
*)
external unsafe_gt : 'a -> 'a -> bool = "#unsafe_gt"
(** [unsafe_gt a b] will be compiled as [a > b].
See also {!unsafe_lt}
*)
external unsafe_ge : 'a -> 'a -> bool = "#unsafe_ge"
(** [unsafe_ge a b] will be compiled as [a >= b].
See also {!unsafe_lt}
*)
(** {12 nested modules}*)
module Null = Js_null
(** Provide utilities around ['a null] *)
module Undefined = Js_undefined
(** Provide utilities around {!undefined} *)
module Nullable = Js_null_undefined
(** Provide utilities around {!null_undefined} *)
module Null_undefined = Js_null_undefined
(** @deprecated please use {!Js.Nullable} *)
module Exn = Js_exn
(** Provide utilities for dealing with Js exceptions *)
module Array = Js_array
(** Provide bindings to Js array*)
module Array2 = Js_array2
(** Provide bindings to Js array*)
module String = Js_string
(** Provide bindings to JS string *)
module String2 = Js_string2
(** Provide bindings to JS string *)
module Re = Js_re
(** Provide bindings to Js regex expression *)
module Re2 = Js_re2
(** Provide bindings to Js regex expression *)
module Promise = Js_promise
(** Provide bindings to JS promise *)
module Promise2 = Js_promise2
(** Provide bindings to JS promise *)
module Date = Js_date
(** Provide bindings for JS Date *)
module Dict = Js_dict
(** Provide utilities for JS dictionary object *)
module Global = Js_global
(** Provide bindings to JS global functions in global namespace*)
module Json = Js_json
(** Provide utilities for json *)
module Math = Js_math
(** Provide bindings for JS [Math] object *)
module Obj = Js_obj
(** Provide utilities for {!Js.t} *)
module Typed_array = Js_typed_array
(** Provide bindings for JS typed array *)
module TypedArray2 = Js_typed_array2
(** Provide bindings for JS typed array *)
module Types = Js_types
(** Provide utilities for manipulating JS types *)
module Float = Js_float
(** Provide utilities for JS float *)
module Int = Js_int
(** Provide utilities for int *)
module Option = Js_option
(** Provide utilities for option *)
module Result = Js_result
(** Define the interface for result *)
module List = Js_list
(** Provide utilities for list *)
module Vector = Js_vector
module Console = Js_console