package ojs

  1. Overview
  2. Docs

Module OjsSource

Binding with JS values.

Sourcetype t

The universal type representing arbitrary JS values.

Mapper for built-in types

Sourceval t_of_js : t -> t
Sourceval t_to_js : t -> t
Sourceval string_of_js : t -> string
Sourceval string_to_js : string -> t
Sourceval int_of_js : t -> int
Sourceval int_to_js : int -> t
Sourceval bool_of_js : t -> bool
Sourceval bool_to_js : bool -> t
Sourceval float_of_js : t -> float
Sourceval float_to_js : float -> t
Sourceval array_of_js : (t -> 'a) -> t -> 'a array
Sourceval array_to_js : ('a -> t) -> 'a array -> t
Sourceval list_of_js : (t -> 'a) -> t -> 'a list
Sourceval list_to_js : ('a -> t) -> 'a list -> t
Sourceval array_of_js_from : (t -> 'a) -> t -> int -> 'a array
Sourceval list_of_js_from : (t -> 'a) -> t -> int -> 'a list
Sourceval option_of_js : (t -> 'a) -> t -> 'a option

Both null and undefined are mapped to None.

Sourceval option_to_js : ('a -> t) -> 'a option -> t

None is mapped to null.

Sourceval unit_of_js : t -> unit
Sourceval unit_to_js : unit -> t

Wrap OCaml functions as JS functions

Sourceval 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'.

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

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

JS objects

Sourceval get : t -> string -> t
  • deprecated Use Ojs.get_prop_ascii instead.
Sourceval set : t -> string -> t -> unit
  • deprecated Use Ojs.set_prop_ascii instead.
Sourceval delete : t -> string -> unit
  • deprecated Use Ojs.delete_prop_ascii instead.
Sourceval get_prop_ascii : t -> string -> t

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

Sourceval set_prop_ascii : t -> string -> t -> unit

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

Sourceval delete_prop_ascii : t -> string -> unit

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

Sourceval get_prop : t -> t -> t

Get the property from an object.

Sourceval set_prop : t -> t -> t -> unit

Set an object property.

Sourceval delete_prop : t -> t -> unit

Delete an object property.

Sourceval obj : (string * t) array -> t
Sourceval empty_obj : unit -> t
Sourceval has_property : t -> string -> bool
Sourceval iter_properties : t -> (string -> unit) -> unit

Calling JS functions

Sourceval call : t -> string -> t array -> t

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

Sourceval apply : t -> t array -> t

Call a function.

Sourceval new_obj : t -> t array -> t

Call a constructor

Sourceval call_arr : t -> string -> t -> t

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

Sourceval apply_arr : t -> t -> t

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

Sourceval new_obj_arr : t -> t -> t

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

Arrays

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

Misc

Sourceval global : t
Sourceval null : t
Sourceval variable : string -> t
Sourceval type_of : t -> string
Sourceclass obj : t -> object ... end
Sourceval is_null : t -> bool
Sourceval obj_type : t -> string

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

Sourcemodule type T = sig ... end
OCaml

Innovation. Community. Security.