Skip to main content

JsClass

Trait JsClass 

Source
pub trait JsClass<'js>:
    Sized
    + Trace<'js>
    + JsLifetime<'js> {
    type Mutable: Mutability;

    const NAME: &'static str;
    const KIND: ClassKind = ClassKind::Plain;

    // Required method
    fn constructor(ctx: &Ctx<'js>) -> Result<Option<Constructor<'js>>, Error>;

    // Provided methods
    fn prototype(ctx: &Ctx<'js>) -> Result<Option<Object<'js>>, Error> { ... }
    fn call<'a>(
        this: &JsCell<'js, Self>,
        params: Params<'a, 'js>,
    ) -> Result<Value<'js>, Error> { ... }
    fn exotic_get_property(
        this: &JsCell<'js, Self>,
        ctx: &Ctx<'js>,
        _atom: Atom<'js>,
        _receiver: Value<'js>,
    ) -> Result<Value<'js>, Error> { ... }
    fn exotic_set_property(
        this: &JsCell<'js, Self>,
        _ctx: &Ctx<'js>,
        _atom: Atom<'js>,
        _receiver: Value<'js>,
        _value: Value<'js>,
    ) -> Result<bool, Error> { ... }
    fn exotic_delete_property(
        this: &JsCell<'js, Self>,
        _ctx: &Ctx<'js>,
        _atom: Atom<'js>,
    ) -> Result<bool, Error> { ... }
    fn exotic_has_property(
        this: &JsCell<'js, Self>,
        _ctx: &Ctx<'js>,
        _atom: Atom<'js>,
    ) -> Result<bool, Error> { ... }
    fn exotic_get_own_property(
        this: &JsCell<'js, Self>,
        _ctx: &Ctx<'js>,
        _atom: Atom<'js>,
    ) -> Result<Option<PropertyDescriptor<'js>>, Error> { ... }
    fn exotic_get_own_property_names(
        this: &JsCell<'js, Self>,
        _ctx: &Ctx<'js>,
    ) -> Result<Vec<PropertyName<'js>>, Error> { ... }
}
Expand description

The trait which allows Rust types to be used from JavaScript.

Required Associated Constants§

Source

const NAME: &'static str

The name the constructor has in JavaScript

Provided Associated Constants§

Source

const KIND: ClassKind = ClassKind::Plain

The kind of this class (plain, callable, or exotic).

Required Associated Types§

Source

type Mutable: Mutability

Can the type be mutated while a JavaScript value.

This should either be Readable or Writable.

Required Methods§

Source

fn constructor(ctx: &Ctx<'js>) -> Result<Option<Constructor<'js>>, Error>

Returns a predefined constructor for this specific class type if there is one.

Provided Methods§

Source

fn prototype(ctx: &Ctx<'js>) -> Result<Option<Object<'js>>, Error>

Returns the class prototype,

Source

fn call<'a>( this: &JsCell<'js, Self>, params: Params<'a, 'js>, ) -> Result<Value<'js>, Error>

The function which will be called if Self::KIND is ClassKind::Callable and an object with this class is called as if it is a function.

Source

fn exotic_get_property( this: &JsCell<'js, Self>, ctx: &Ctx<'js>, _atom: Atom<'js>, _receiver: Value<'js>, ) -> Result<Value<'js>, Error>

The function which will be called if a get property is performed on an object with this class

Source

fn exotic_set_property( this: &JsCell<'js, Self>, _ctx: &Ctx<'js>, _atom: Atom<'js>, _receiver: Value<'js>, _value: Value<'js>, ) -> Result<bool, Error>

The function which will be called if a set property is performed on an object with this class

Source

fn exotic_delete_property( this: &JsCell<'js, Self>, _ctx: &Ctx<'js>, _atom: Atom<'js>, ) -> Result<bool, Error>

The function which will be called if a delete property is performed on an object with this class

Source

fn exotic_has_property( this: &JsCell<'js, Self>, _ctx: &Ctx<'js>, _atom: Atom<'js>, ) -> Result<bool, Error>

The function which will be called if has property or similar is called on an object with this class

Source

fn exotic_get_own_property( this: &JsCell<'js, Self>, _ctx: &Ctx<'js>, _atom: Atom<'js>, ) -> Result<Option<PropertyDescriptor<'js>>, Error>

Called to get the own property descriptor for a given property name.

Return Ok(Some(descriptor)) if the property exists, Ok(None) if it doesn’t.

Source

fn exotic_get_own_property_names( this: &JsCell<'js, Self>, _ctx: &Ctx<'js>, ) -> Result<Vec<PropertyName<'js>>, Error>

Called to enumerate the own property names of this object.

Return a list of property names.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§

Source§

impl<'js> JsClass<'js> for RustFunction<'js>

Source§

const NAME: &'static str = "RustFunction"

Source§

const KIND: ClassKind = ClassKind::Callable

Source§

type Mutable = Readable