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§
Sourceunsafe fn construct(
cx: *mut JSContext,
args: &CallArgs,
) -> Result<JsValue, JsError>
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:
- Create the Rust instance
- Create a JS object with the class prototype
- Store the Rust pointer in the JS object’s reserved slot via
HostObject::to_private - 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".