Skip to main content

JsObject

Struct JsObject 

Source
pub struct JsObject {
    pub prototype: Option<JsObjectRef>,
    pub extensible: bool,
    pub frozen: bool,
    pub sealed: bool,
    pub null_prototype: bool,
    pub properties: PropertyStorage,
    pub exotic: ExoticObject,
    pub private_fields: Option<FxHashMap<PrivateFieldKey, JsValue>>,
}
Expand description

A JavaScript object

Fields§

§prototype: Option<JsObjectRef>

Prototype link

§extensible: bool

Whether the object can have properties added

§frozen: bool

Whether the object is frozen (no modifications allowed)

§sealed: bool

Whether the object is sealed (no new properties, but existing can be modified)

§null_prototype: bool

Whether this object was explicitly created with null prototype (Object.create(null))

§properties: PropertyStorage

Object properties (optimized for small objects)

§exotic: ExoticObject

Exotic object behavior

§private_fields: Option<FxHashMap<PrivateFieldKey, JsValue>>

Private fields storage (only used by instances of classes with private members) Key is (ClassBrandId, field_name), value is the private field/method value

Implementations§

Source§

impl JsObject

Source

pub fn new() -> Self

Create a new ordinary object

Source

pub fn with_capacity(capacity: usize) -> Self

Create a new ordinary object with pre-allocated property capacity

Source

pub fn with_prototype(prototype: JsObjectRef) -> Self

Create a new ordinary object with a prototype

Source

pub fn get_private_field(&self, key: &PrivateFieldKey) -> Option<&JsValue>

Get a private field value

Source

pub fn set_private_field(&mut self, key: PrivateFieldKey, value: JsValue)

Set a private field value

Source

pub fn has_private_field(&self, key: &PrivateFieldKey) -> bool

Check if an object has a specific private field

Source

pub fn is_callable(&self) -> bool

Check if this object is callable

Source

pub fn get_own_property(&self, key: &PropertyKey) -> Option<&Property>

Get an own property

Source

pub fn get_property(&self, key: &PropertyKey) -> Option<JsValue>

Get a property, searching the prototype chain

Source

pub fn get_property_descriptor( &self, key: &PropertyKey, ) -> Option<(Property, bool)>

Get a property descriptor, searching the prototype chain Returns (property, found_in_prototype)

Source

pub fn set_property(&mut self, key: PropertyKey, value: JsValue)

Set a property

Source

pub fn define_property(&mut self, key: PropertyKey, prop: Property)

Define a property with attributes

Source

pub fn has_own_property(&self, key: &PropertyKey) -> bool

Check if object has own property

Source

pub fn own_keys(&self) -> Vec<PropertyKey>

Get own property keys

Source

pub fn array_length(&self) -> Option<u32>

Get array length if this is an array, None otherwise

Source

pub fn array_elements(&self) -> Option<&[JsValue]>

Get array elements slice if this is an array

Source

pub fn array_elements_mut(&mut self) -> Option<&mut Vec<JsValue>>

Get mutable array elements if this is an array

Source

pub fn is_array(&self) -> bool

Check if this is an array

Source§

impl JsObject

Source

pub fn as_environment(&self) -> Option<&EnvironmentData>

Get environment data if this is an environment object

Source

pub fn as_environment_mut(&mut self) -> Option<&mut EnvironmentData>

Get mutable environment data if this is an environment object

Source

pub fn is_environment(&self) -> bool

Check if this object is an environment

Trait Implementations§

Source§

impl Debug for JsObject

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for JsObject

Source§

fn default() -> Self

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

impl Reset for JsObject

Reset implementation for JsObject - used by new GC for object pooling.

When an object is collected, it can be reset and reused instead of being dropped. This is more efficient than allocating new objects.

Source§

fn reset(&mut self)

Reset object to clean state (equivalent to Default but in-place)
Source§

impl Traceable for JsObject

Source§

fn trace<F: FnMut(GcPtr<Self>)>(&self, visitor: F)

Visit all Gc<Self> references held by this object. 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 = 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.