Trait boa_engine::class::Class
source · pub trait Class: NativeObject + Sized {
const NAME: &'static str;
const LENGTH: usize = 0usize;
const ATTRIBUTES: Attribute = _;
// Required methods
fn init(class: &mut ClassBuilder<'_>) -> JsResult<()>;
fn data_constructor(
new_target: &JsValue,
args: &[JsValue],
context: &mut Context
) -> JsResult<Self>;
// Provided methods
fn object_constructor(
instance: &JsObject,
args: &[JsValue],
context: &mut Context
) -> JsResult<()> { ... }
fn construct(
new_target: &JsValue,
args: &[JsValue],
context: &mut Context
) -> JsResult<JsObject> { ... }
fn from_data(data: Self, context: &mut Context) -> JsResult<JsObject> { ... }
}
Expand description
Native class.
See the module-level documentation for more details.
Required Associated Constants§
Provided Associated Constants§
sourceconst LENGTH: usize = 0usize
const LENGTH: usize = 0usize
The amount of arguments this class’ constructor takes. Default is 0
.
sourceconst ATTRIBUTES: Attribute = _
const ATTRIBUTES: Attribute = _
The property attributes of this class’ constructor in the global object.
Default is writable
, enumerable
, configurable
.
Required Methods§
sourcefn init(class: &mut ClassBuilder<'_>) -> JsResult<()>
fn init(class: &mut ClassBuilder<'_>) -> JsResult<()>
Initializes the properties and methods of this class.
Provided Methods§
sourcefn object_constructor(
instance: &JsObject,
args: &[JsValue],
context: &mut Context
) -> JsResult<()>
fn object_constructor( instance: &JsObject, args: &[JsValue], context: &mut Context ) -> JsResult<()>
Initializes the properties of the constructed object for an instance of this class.
Useful to initialize additional properties for the constructed object that aren’t stored inside the native data.
sourcefn construct(
new_target: &JsValue,
args: &[JsValue],
context: &mut Context
) -> JsResult<JsObject>
fn construct( new_target: &JsValue, args: &[JsValue], context: &mut Context ) -> JsResult<JsObject>
Creates a new JsObject
with its internal data set to the result of calling
Class::data_constructor
and Class::object_constructor
.
§Errors
- Throws an error if
new_target
is undefined. - Throws an error if this class is not registered in
new_target
’s realm. SeeContext::register_global_class
.
sourcefn from_data(data: Self, context: &mut Context) -> JsResult<JsObject>
fn from_data(data: Self, context: &mut Context) -> JsResult<JsObject>
Constructs an instance of this class from its inner native data.
Note that the default implementation won’t call Class::data_constructor
, but it will
call Class::object_constructor
with no arguments.
§Errors
- Throws an error if this class is not registered in the context’s realm. See
Context::register_global_class
.