package gen_js_api

  1. Overview
  2. Docs

Binding with JS values.

type t

The universal type representing arbitrary JS values.

Mapper for built-in types

val t_of_js : t -> t
val t_to_js : t -> t
val string_of_js : t -> string
val string_to_js : string -> t
val int_of_js : t -> int
val int_to_js : int -> t
val bool_of_js : t -> bool
val bool_to_js : bool -> t
val float_of_js : t -> float
val float_to_js : float -> t
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.

Wrap OCaml functions as JS functions

val fun_to_js : int -> (t -> 'a) -> t

Wrap an OCaml function of known arity (>=1) into a JS function. Extra arguments are discarded and missing argument are filled with 'undefined'.

val fun_to_js_args : (t -> 'a) -> t

Wrap an OCaml function taking JS arguments as a JS array.

JS objects

val get : t -> string -> t
val set : t -> string -> t -> unit
val obj : (string * t) array -> t
val empty_obj : unit -> t
val has_property : t -> string -> bool
val iter_properties : t -> (string -> unit) -> unit

Calling JS functions

val call : t -> string -> t array -> t

Call a method on an object (binding 'this' to the object).

val apply : t -> t array -> t

Call a function.

val new_obj : t -> t array -> t

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.

val new_obj_arr : t -> t -> t

Variant of Ojs.new_obj where the arguments are passed as an already built JS array.

Arrays

val array_make : int -> t
val array_get : t -> int -> t
val array_set : t -> int -> t -> unit

Misc

val global : t
val null : t
val variable : string -> t
val type_of : t -> string
class obj : t -> object ... end
val delete : t -> string -> unit
val is_null : t -> bool
val obj_type : t -> string

Returns: "object Array" "object Object" "object Number" "object String" "object Null" "object Boolean"

OCaml

Innovation. Community. Security.