package ojs

  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.

val unit_of_js : t -> unit
val unit_to_js : unit -> t

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
  • deprecated Use Ojs.get_prop_ascii instead.
val set : t -> string -> t -> unit
  • deprecated Use Ojs.set_prop_ascii instead.
val delete : t -> string -> unit
  • deprecated Use Ojs.delete_prop_ascii instead.
val get_prop_ascii : t -> string -> t

Get the property from an object (only works if the property key is a plain ascii string).

val set_prop_ascii : t -> string -> t -> unit

Set an object property (only works if the property key is a plain ascii string).

val delete_prop_ascii : t -> string -> unit

Delete an object property (only works if the property key is a plain ascii string).

val get_prop : t -> t -> t

Get the property from an object.

val set_prop : t -> t -> t -> unit

Set an object property.

val delete_prop : t -> t -> unit

Delete an object property.

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
val instance_of : t -> constr:t -> bool
class obj : t -> object ... 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 ... end
OCaml

Innovation. Community. Security.