Skip to main content

BuiltInObject

Struct BuiltInObject 

Source
pub struct BuiltInObject {
    pub name: String,
    pub prototype: Option<String>,
    pub methods: HashMap<String, BuiltInFn>,
    pub properties: HashMap<String, JsValue>,
    pub constructor: Option<BuiltInFn>,
}
Expand description

Built-in object definition. Represents a JavaScript built-in object like Array, Object, String, etc.

Fields§

§name: String

Name of the object (e.g., “Array”, “Object”, “Math”).

§prototype: Option<String>

Parent prototype name, if any (e.g., “Object” for most built-ins).

§methods: HashMap<String, BuiltInFn>

Methods defined on this object or its prototype.

§properties: HashMap<String, JsValue>

Static properties.

§constructor: Option<BuiltInFn>

Constructor function, if this object is constructable.

Implementations§

Source§

impl BuiltInObject

Source

pub fn new(name: impl Into<String>) -> Self

Create a new built-in object with the given name.

Source

pub fn with_prototype(self, prototype: impl Into<String>) -> Self

Set the prototype chain parent.

Source

pub fn with_no_prototype(self) -> Self

Set no prototype (for objects like Object.prototype itself).

Source

pub fn add_method(self, name: impl Into<String>, func: NativeFn) -> Self

Add a native method.

Source

pub fn add_property(self, name: impl Into<String>, value: JsValue) -> Self

Add a property.

Source

pub fn with_constructor(self, constructor: NativeFn) -> Self

Set the constructor function.

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.