Skip to main content

HostClasses

Struct HostClasses 

Source
pub struct HostClasses { /* private fields */ }
Expand description

The host’s class registry: the JS_NewClass / JS_SetClassProto half of the class API.

One per realm, because a class id is only meaningful within the runtime that handed it out — the reference keeps one array per JSRuntime for the same reason, so a Date and a host class cannot collide.

Implementations§

Source§

impl HostClasses

Source

pub fn register(&mut self, def: ClassDef) -> ClassId

Allocate an id and register def under it (JS_NewClassID + JS_NewClass).

Source

pub fn define(&mut self, id: ClassId, def: ClassDef) -> bool

Register def under an id the caller already has (JS_NewClass).

The C API splits “get an id” from “register a class” because a module may be initialised lazily; registering twice under one id replaces the definition, and an object created under the old one keeps the old behaviour, since it carries its own reference.

Source

pub fn def(&self, id: ClassId) -> Option<Rc<ClassDef>>

What id was registered with.

Source

pub fn set_proto(&mut self, id: ClassId, proto: Gc<JsObject>)

Install the prototype instances of id inherit (JS_SetClassProto).

Source

pub fn proto(&self, id: ClassId) -> Option<Gc<JsObject>>

The prototype installed for id, if the host installed one.

Source

pub fn len(&self) -> usize

How many classes the host registered.

Source

pub fn is_empty(&self) -> bool

Whether no class has been registered.

Trait Implementations§

Source§

impl Default for HostClasses

Source§

fn default() -> HostClasses

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.