Macros and helpers for defining JS builtins.
Summary
Functions
Emits fallback clauses for modules that define prototype or static properties.
Uniform macros for defining JS builtins in all contexts.
Returns a positional argument with a JavaScript :undefined default.
Builds a raw map of builtin method/property entries.
Builds a heap-wrapped object from builtin method/property entries.
Wraps a two-arity callback in the VM builtin tuple representation.
Wraps a receiver-only callback in the VM builtin tuple representation.
Dispatches a VM callable value to its underlying Elixir callback.
Returns whether a VM value can be called as a JavaScript function.
Registers a JavaScript constructor and optional prototype definition.
Defines a named builtin object exported by object/0.
Defines a prototype property as a JavaScript builtin function.
Defines a constructor/static property as a JavaScript builtin function.
Defines a constructor/static property as a fixed value.
Functions
Emits fallback clauses for modules that define prototype or static properties.
Uniform macros for defining JS builtins in all contexts.
All builtins use 2-arity fn args, this -> convention.
Module-level dispatch (generates def clauses)
proto "push" do ... end # → def proto_property("push")
static "isArray" do ... end # → def static_property("isArray")
static_val "PI", :math.pi() # → def static_property("PI"), do: valueNamed object (generates def object/0)
js_object "Math" do
method "floor" do ... end
val "PI", :math.pi()
endInline maps and objects
build_methods do # returns %{"name" => {:builtin, ...}, ...}
method "add" do ... end
args_method "from", &from_args/1
receiver_method "slice", &slice/2
this_method "toJSON", &to_json/1
symbol_method "Symbol.iterator" do ... end
accessor "size" do
get do ... end
end
prop "size", 0
end
object do # returns Heap.wrap(%{"name" => {:builtin, ...}, ...})
prop "type", type
method "preventDefault" do ... end
end
object heap: false do # returns the raw map for post-processing
prop "searchParams", search_params
end
constructor "DOMException", &build_dom_exception/2 do
proto do
extends build_error_proto()
end
endargs and this are injected in all proto/static/method bodies.
arg/3, argv/2, builtin_*, and iterator_from/1 cover the repeated
argument-defaulting, function-wrapping, and iterator boilerplate used by Web APIs.
Catch-all fallbacks are auto-generated by @before_compile.
Returns a positional argument with a JavaScript :undefined default.
Builds a raw map of builtin method/property entries.
Builds a heap-wrapped object from builtin method/property entries.
Wraps a two-arity callback in the VM builtin tuple representation.
Wraps a receiver-only callback in the VM builtin tuple representation.
Dispatches a VM callable value to its underlying Elixir callback.
Returns whether a VM value can be called as a JavaScript function.
Registers a JavaScript constructor and optional prototype definition.
Defines a named builtin object exported by object/0.
Defines a prototype property as a JavaScript builtin function.
Defines a constructor/static property as a JavaScript builtin function.
Defines a constructor/static property as a fixed value.