Skip to main content

JsClassOps

Trait JsClassOps 

Source
pub trait JsClassOps: HostObject {
    // Required method
    unsafe fn construct(
        cx: *mut JSContext,
        args: &CallArgs,
    ) -> Result<JsValue, JsError>;
}
Expand description

Trait for JS class construction operations.

Implemented by types annotated with #[bao_engine_macros::JsClass]. The macro generates HostObject impl automatically; users must implement JsClassOps to provide the constructor logic.

Required Methods§

Source

unsafe fn construct( cx: *mut JSContext, args: &CallArgs, ) -> Result<JsValue, JsError>

Construct a new instance of this class from JS call arguments.

The implementor should:

  1. Create the Rust instance
  2. Create a JS object with the class prototype
  3. Store the Rust pointer in the JS object’s reserved slot via HostObject::to_private
  4. Return the JS object as a JsValue

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§