Skip to main content

host_fn

Attribute Macro host_fn 

Source
#[host_fn]
Expand description

#[host_fn] proc-macro for SpiderMonkey host function shims.

Generates a unsafe extern "C" fn(cx, argc, vp) -> bool that extracts arguments from SM CallArgs, invokes the wrapped Rust function, and handles exceptions.

Usage:

#[host_fn]
fn my_function(global: &JsGlobal, argc: u32, args: &[JsValue]) -> Result<JsValue, JsError> { ... }

#[host_fn(method)]
fn my_method(this: &MyType, global: &JsGlobal, argc: u32, args: &[JsValue]) -> Result<JsValue, JsError> { ... }

#[host_fn(getter)]
fn my_getter(this: &MyType) -> Result<JsValue, JsError> { ... }

#[host_fn(setter)]
fn my_setter(this: &mut MyType, value: JsValue) -> Result<(), JsError> { ... }

#[host_fn(export = "customName")]
fn some_fn(global: &JsGlobal, argc: u32, args: &[JsValue]) -> Result<JsValue, JsError> { ... }