Module Quickjs
OCaml bindings to QuickJS.
type
type runtimeruntimerepresents a Javascript runtime corresponding to an object heap. Several runtimes can exist at the same time but they cannot exchange objects. Inside a given runtime, no multi-threading is supported.
type contextcontextrepresents a Javascript context (or Realm). Each context has its own global objects and system objects. There can be several contexts per runtime and they can share objects, similar to frames of the same origin sharing Javascript objects in a web browser.
type bytecodebytecoderepresents the bytecode which is generated bycompileand can be executed withexecute.
type js_exn= valueJS can throw any
value
type 'a or_js_exn= ('a, js_exn) Stdlib.result
raw represent
val get_raw_runtime : runtime -> Quickjs_raw.js_runtime_ptrval get_raw_context : context -> Quickjs_raw.js_context_ptrval get_raw_value : value -> Quickjs_raw.js_valueval get_raw_bytecode : bytecode -> Quickjs_raw.js_value
runtime
val new_runtime : unit -> runtimeval set_max_stack_size : runtime -> Unsigned.size_t -> unitval set_memory_limit : runtime -> Unsigned.size_t -> unitval set_gc_threshold : runtime -> Unsigned.size_t -> unitval run_gc : runtime -> unitval compute_memory_usage : runtime -> Quickjs_raw.MemoryUsage.tval memory_usage_to_string : Quickjs_raw.MemoryUsage.t -> string
type interrupt_handler= runtime -> boolinterrupt_handler runtime, return false will interrupt runtime
val set_interrupt_handler : runtime -> interrupt_handler -> unit
context
val new_context : runtime -> contextval get_runtime : context -> runtimeval enable_bignum_ext : context -> unitenable math mode support.
val disable_bignum_ext : context -> unit
value
module Value : sig ... endconvert
valueto ocaml data
val check_exception : value -> value or_js_exncheck_exception valueget exception obj from context. Cannot be called twice with the samevalue.let _ = let open Quickjs in let r = eval_unsafe script in match check_exception r with | Ok obj -> "it is safe to use " ^ (Value.to_string obj) | Error js_exn -> "eval_unsafe throw " ^ (Value.to_string js_exn)
eval
type eval_type=[|`GLOBALglobal code (default)
|`MODULEmodule code
]type eval_flag=[|`STRICTforce 'strict' mode
|`STRIPforce 'strip' mode
|`BACKTRACE_BARRIERdon't include the stack frames before this eval in the Error() backtraces
]
val eval : ?typ:eval_type -> ?flags:eval_flag list -> ?ctx:context -> string -> value or_js_exneval ~typ ~flags ~ctx script
val eval_unsafe : ?typ:eval_type -> ?flags:eval_flag list -> ?ctx:context -> string -> valueeval_unsafe ~typ ~flags ~ctx script, you must check exception by yourself.check_exception