Skip to content

Commit

Permalink
Rework FFI module expose raw
Browse files Browse the repository at this point in the history
  • Loading branch information
rizo committed Jul 16, 2024
1 parent f239099 commit 18b000f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 35 deletions.
1 change: 1 addition & 0 deletions vendor/jx/src/jx/Jx.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ let is_number js = String.equal (Jx_ffi.type_of js) "number"
let is_boolean js = String.equal (Jx_ffi.type_of js) "boolean"
let is_string js = String.equal (Jx_ffi.type_of js) "string"
let is_object js = String.equal (Jx_ffi.type_of js) "object"
let raw = Jx_ffi.raw

let is_int js =
if is_number js then
Expand Down
3 changes: 3 additions & 0 deletions vendor/jx/src/jx/Jx.mli
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ val log : 'a -> unit

val debug : string list -> unit

val raw : string -> js
(** An unsafe JavaScript expression. *)

val is_null : js -> bool
(** [is_null js] is [js == null]. *)

Expand Down
52 changes: 27 additions & 25 deletions vendor/jx/src/jx/Jx_ffi.mli
Original file line number Diff line number Diff line change
Expand Up @@ -9,46 +9,48 @@ val undefined : t
val global_this : t
(** JavaScript [globalThis] value. *)

external raw : string -> 'a = "caml_pure_js_expr"

(* {2 Equality} *)

val equal : t -> t -> bool
val strict_equal : t -> t -> bool
external equal : t -> t -> bool = "caml_js_equals"
external strict_equal : t -> t -> bool = "caml_js_strict_equals"

(** {2 Converters} *)

val of_string : string -> t
val to_string : t -> string
val of_bool : bool -> t
val to_bool : t -> bool
val of_float : float -> t
val to_float : t -> float
val of_int : int -> t
val to_int : t -> int
val of_array : t array -> t
val to_array : t -> t array
val of_list : t list -> t
val to_list : t -> t list
external of_int : int -> t = "%identity"
external to_int : t -> int = "%identity"
external of_string : string -> t = "caml_jsstring_of_string"
external to_string : t -> string = "caml_string_of_jsstring"
external of_bool : bool -> t = "caml_js_from_bool"
external to_bool : t -> bool = "caml_js_to_bool"
external of_float : float -> t = "caml_js_from_float"
external to_float : t -> float = "caml_js_to_float"
external of_array : 'a array -> t = "caml_js_from_array"
external to_array : t -> 'a array = "caml_js_to_array"
external of_list : t list -> t = "caml_list_to_js_array"
external to_list : t -> t list = "caml_list_of_js_array"

(** {2 Objects and properties} *)

val obj : (string * t) array -> t
val obj_new : t -> t array -> t
val get : t -> t -> t
val set : t -> t -> t -> unit
val del : t -> t -> unit
external obj : (string * t) array -> t = "caml_js_object"
external obj_new : t -> t array -> t = "caml_js_new"
external get : t -> t -> t = "caml_js_get"
external set : t -> t -> t -> unit = "caml_js_set"
external del : t -> t -> unit = "caml_js_delete"

(** {2 Function and method helpers} *)

val obj_call : t -> string -> t array -> t
val call : t -> t array -> t
val of_fun : int -> (_ -> _) -> t
external obj_call : t -> string -> t array -> t = "caml_js_meth_call"
external call : t -> t array -> t = "caml_js_fun_call"
external of_fun : int -> (_ -> _) -> t = "caml_js_wrap_callback_strict"

(** {2 Type helpers} *)

val type_of : t -> string
val instance_of : t -> constr:t -> bool
external type_of : t -> string = "caml_js_typeof"
external instance_of : t -> constr:t -> bool = "caml_js_instanceof"

(** {2 Debugger} *)

val debugger : unit -> unit
external debugger : unit -> unit = "debugger"
(** JavaScript [debugger] primitive. *)
16 changes: 6 additions & 10 deletions vendor/jx/src/jx_jsoo/Jx_ffi.ml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
type t

external _pure_js_expr : string -> 'a = "caml_pure_js_expr"
external raw : string -> 'a = "caml_pure_js_expr"

let global_this = _pure_js_expr "globalThis"
let null = _pure_js_expr "null"
let undefined = _pure_js_expr "undefined"
let global_this = raw "globalThis"
let null = raw "null"
let undefined = raw "undefined"

external debugger : unit -> unit = "debugger"
external equal : t -> t -> bool = "caml_js_equals"
Expand Down Expand Up @@ -42,12 +42,8 @@ external of_fun : int -> (_ -> _) -> t = "caml_js_wrap_callback_strict"

(* type_of *)

external _type_of : t -> t = "caml_js_typeof"

let type_of js = to_string (_type_of js)
external type_of : t -> string = "caml_js_typeof"

(* instance_of *)

external _instance_of : t -> t -> bool = "caml_js_instanceof"

let instance_of t ~constr = _instance_of t constr
external instance_of : t -> constr:t -> bool = "caml_js_instanceof"

0 comments on commit 18b000f

Please sign in to comment.