#[boa_class]Expand description
boa_class proc macro attribute that applies to an impl XYZ block and
add a [boa_engine::JsClass] implementation for it.
It will transform functions in the impl ... block as follow (by default, see
below):
fn some_method(&self, ...) -> ... {}will be added as class methods with the namesome_method, borrowing the object for the ref. This is dangerous if the function execute/eval JavaScript back (potentially leading to aBorrowError).fn some_method(&mut self, ...) -> ... {}will be added as class methods, similar to the above but borrowing as mutable at runtime.fn some_method(...) -> ... {}(no self mention) will be added as a static method.#[boa(constructor)] fn ...(...) -> Self {}(or returningJsResult<Self>) will be used as the constructor of the class. If no constructor is declared,Default::default()will be used instead. If theDefaulttrait is not defined for the type, an error will happen.#[boa(getter)]
To change this behaviour, you can use the following attributes on the function declarations:
#[boa(rename = "...")]renames the function in JavaScript with the string.#[boa(getter)]will declare a getter accessor.#[boa(setter)]will declare a setter accessor.#[boa(static)]will declare a static method.#[boa(method)]will declare a method.#[boa(constructor)]will declare a constructor.#[boa(length = 123)]sets the length of the function in JavaScript (ie. its number of arguments accepted).
Multiple of those attributes can be added to a single method.
The top level boa_class supports the following:
#[boa_class(rename = "...")]sets the name of the class in JavaScript.#[boa(rename_all = "camelCase")]will change the naming scheme of verbatim to using “camelCase” or “none”.
§Warning
This should not be used directly as is, and instead should be used through
the embed_module! macro in boa_engine for convenience.