quickjs (quickjs v0.2.0)

View Source

QuickJS JavaScript engine for Erlang (powered by quickjs-ng).

Summary

Types

bindings/0

-type bindings() :: #{atom() | binary() => term()}.

context/0

-opaque context()

context_opts/0

-type context_opts() :: #{handler => pid()}.

js_value/0

-type js_value() ::
          integer() |
          float() |
          binary() |
          true | false | null | undefined |
          [js_value()] |
          #{binary() | atom() => js_value()}.

memory_stats/0

-type memory_stats() ::
          #{heap_bytes := non_neg_integer(),
            heap_peak := non_neg_integer(),
            alloc_count := non_neg_integer(),
            realloc_count := non_neg_integer(),
            free_count := non_neg_integer(),
            gc_runs := non_neg_integer()}.

Functions

call(Ctx, FunctionName)

-spec call(context(), iodata() | atom()) -> {ok, js_value()} | {error, term()}.

call(Ctx, FunctionName, Timeout)

-spec call(context(), iodata() | atom(), [term()] | timeout()) -> {ok, js_value()} | {error, term()}.

call(Ctx, FunctionName, Args, Timeout)

-spec call(context(), iodata() | atom(), [term()], timeout()) -> {ok, js_value()} | {error, term()}.

cbor_decode(Ctx, Binary)

-spec cbor_decode(context(), binary()) -> {ok, js_value()} | {error, term()}.

cbor_encode(Ctx, Value)

-spec cbor_encode(context(), term()) -> {ok, binary()} | {error, term()}.

destroy_context(Ctx)

-spec destroy_context(context()) -> ok | {error, term()}.

eval(Ctx, Code)

-spec eval(context(), iodata()) -> {ok, js_value()} | {error, term()}.

eval(Ctx, Code, Timeout)

-spec eval(context(), iodata(), bindings() | timeout()) -> {ok, js_value()} | {error, term()}.

eval(Ctx, Code, Bindings, Timeout)

-spec eval(context(), iodata(), bindings(), timeout()) -> {ok, js_value()} | {error, term()}.

gc(Ctx)

-spec gc(context()) -> ok | {error, term()}.

get_memory_stats(Ctx)

-spec get_memory_stats(context()) -> {ok, memory_stats()} | {error, term()}.

info()

-spec info() -> {ok, string()}.

new_context()

-spec new_context() -> {ok, context()} | {error, term()}.

new_context(Opts)

-spec new_context(context_opts()) -> {ok, context()} | {error, term()}.

register_function(Ctx, Name, Fun)

-spec register_function(context(), atom() | binary(), Fun | {atom(), atom()}) -> ok | {error, term()}
                           when Fun :: fun(([term()]) -> term()).

register_module(Ctx, ModuleId, Source)

-spec register_module(context(), iodata() | atom(), iodata()) -> ok | {error, term()}.

require(Ctx, ModuleId)

-spec require(context(), iodata() | atom()) -> {ok, js_value()} | {error, term()}.

send(Ctx, Event, Data)

-spec send(context(), atom() | iodata(), term()) -> {ok, js_value()} | ok | {error, term()}.