Skip to main content

JsObject

Struct JsObject 

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

A JavaScript object.

The interior mutability is what makes const o = {}; o.x = 1 work: the handle is immutable, the object it points at is not.

Implementations§

Source§

impl JsObject

Source

pub fn array_buffer_storage(&self) -> Option<Rc<RefCell<BufferStorage>>>

The storage of this object, when it is an ArrayBuffer.

Source

pub fn set_array_buffer(&self, storage: Rc<RefCell<BufferStorage>>)

Make this object an ArrayBuffer owning storage.

Source

pub fn collection_entries(&self) -> Option<Vec<(Value, Value)>>

The entries of this object, when it is a Map or a Set.

Source

pub fn collection_is_set(&self) -> Option<bool>

Whether this object is a Set rather than a Map.

Source

pub fn set_collection(&self, entries: Vec<(Value, Value)>, is_set: bool)

Make this object a Map or Set holding entries.

Source

pub fn typed_array_parts( &self, ) -> Option<(Gc<JsObject>, ElementType, usize, usize)>

(buffer, element, offset, length), when this object is a typed-array view.

Source

pub fn set_typed_array( &self, buffer: Gc<JsObject>, element: ElementType, offset: usize, length: usize, )

Make this object a typed-array view.

Source

pub fn typed_array_element_type(&self) -> Option<ElementType>

The element type, when this object is a typed-array view.

Source

pub fn typed_array_length(&self) -> Option<usize>

How many elements the view exposes, or None when this is not a view.

A detached buffer reports 0: the storage is gone, so there is nothing to index.

Source

pub fn typed_array_element(&self, index: usize) -> Option<Value>

Read one view element.

Out-of-range and detached reads are undefined rather than an error, which is what makes a[999] and a detached a[0] behave the way the language says.

Source

pub fn typed_array_set(&self, index: usize, value: Value) -> Option<()>

Store one view element, applying the type’s wrap or clamp.

Source§

impl JsObject

Source

pub fn ordinary(heap: &Heap, proto: Option<Gc<JsObject>>) -> Gc<JsObject>

An ordinary object with the given prototype.

Source

pub fn array( heap: &Heap, proto: Option<Gc<JsObject>>, capacity: usize, ) -> Gc<JsObject>

An array with the given prototype and initial capacity.

Source

pub fn function( heap: &Heap, proto: Option<Gc<JsObject>>, callable: Callable, ) -> Gc<JsObject>

A callable object.

Source

pub fn with<R>(&self, f: impl FnOnce(&ObjectData) -> R) -> R

Run f with the object’s data borrowed.

Source

pub fn with_mut<R>(&self, f: impl FnOnce(&mut ObjectData) -> R) -> R

Run f with the object’s data mutably borrowed.

Source

pub fn is_callable(&self) -> bool

Whether this object can be called.

Covers every Callable variant, Bound included: typeof bound === "function" and bound() works, so from a script’s point of view a bound function is a function.

Source

pub fn is_constructor(&self) -> bool

Whether the target of this proxy can be constructed.

Source

pub fn proxy_state(&self) -> Option<ProxyRef>

This object’s proxy slots, when it is one (revoked or not).

Source

pub fn proxy(heap: &Heap, target: Gc<JsObject>, handler: Value) -> Gc<JsObject>

A proxy over target reading its traps from handler.

The prototype stays empty on purpose: [[GetPrototypeOf]] on a proxy forwards to the target through the getPrototypeOf trap, so copying the target’s prototype here would be a second, disagreeing source of truth.

Source

pub fn proto(&self) -> Option<Gc<JsObject>>

The prototype.

Source

pub fn set_proto(&self, proto: Option<Gc<JsObject>>)

Replace the prototype.

Source

pub fn home_object(&self) -> Option<Gc<JsObject>>

The object a method was defined on, for super to resolve against.

Source

pub fn set_home_object(&self, home: Option<Gc<JsObject>>)

Record the object a method was defined on.

Source

pub fn is_class_constructor(&self) -> bool

Whether this is a class constructor.

Source

pub fn set_class_constructor(&self, yes: bool)

Mark this function as a class constructor.

Source

pub fn array_elements(&self) -> Option<Vec<Value>>

The elements of an array object, if this is one.

Source

pub fn property_entries(&self) -> Vec<(PropertyKey, Property)>

Every own key with its descriptor, array indices included.

JsObject::own_property_keys answers the same question without the descriptors; a proxy invariant needs both at once, because it has to check the value of a key it is told about and the presence of a key it is not.

Source

pub fn is_array(&self) -> bool

Whether this object has array elements at all.

Source

pub fn regexp(&self) -> Option<RegExpData>

length for an array, reading it out of the element vector. The compiled pattern, when this object is a RegExp.

Source

pub fn disposable_stack(&self) -> Option<StackState>

The held resources, when this object is a DisposableStack.

Source

pub fn set_disposable_stack(&self, state: StackState)

Make this object a DisposableStack holding state.

Source

pub fn set_regexp(&self, data: RegExpData)

Make this object a RegExp carrying data.

Source

pub fn is_regexp(&self) -> bool

Whether this object is a RegExp.

Source

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

An array’s element count, when this object is an array.

Source

pub fn array_get(&self, index: usize) -> Option<Value>

Read one array element.

Source

pub fn array_push(&self, value: Value) -> usize

Append to an array and return the new length.

Source

pub fn array_set(&self, index: usize, value: Value) -> bool

Store into an array, and return whether the write happened.

The gap an out-of-range store leaves behind is filled with Value::Hole, not undefined: a = [1]; a[3] = 4 has holes at 1 and 2, which forEach skips and the debug printer reports. A store of undefined is a real element.

Source

pub fn array_store(&self, index: usize, value: Value) -> bool

Store an element, honouring its attributes, reporting whether it happened.

Array methods that write back (sort, reverse, splice, …) use this rather than Self::array_set: the spec has them go through [[Set]], so a frozen element makes them throw instead of being quietly overwritten.

Source

pub fn array_push_hole(&self) -> bool

Store value as a plain element without creating holes, used by push.

Source

pub fn array_set_length(&self, length: usize) -> bool

Set the length of an array, truncating or extending with holes.

a.length = 5 on a two-element array leaves three holes, so the fill value is Value::Hole rather than undefined.

Source

pub fn array_truncate(&self, length: usize) -> bool

Truncate an array to length elements without extending it.

This is what arr.length = n does for n smaller than the current length; it is separate from Self::array_set_length because growing an array by assignment produces holes, which are indistinguishable from undefined here.

Source

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

The own data property key, if there is one.

Source

pub fn own_property(&self, name: &str) -> Option<Property>

The own data property name, if there is one.

Source

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

Whether the object has an own property key.

Source

pub fn has_own(&self, name: &str) -> bool

Whether the object has an own property name.

Source

pub fn define_key(&self, key: &PropertyKey, property: Property)

Define or replace an own property, keeping the original position when the key already exists.

Source

pub fn define(&self, name: &str, property: Property)

Define or replace an own property under a string key.

Source

pub fn define_data(&self, name: &str, value: Value)

Define an own data property, with the default attributes.

This creates: on an existing property it overwrites the attributes too, so it is the wrong call for a plain assignment. Use Self::write_value for that.

Source

pub fn define_data_key(&self, key: &PropertyKey, value: Value)

Define an own data property under key.

Source

pub fn write_value(&self, name: &str, value: Value) -> bool

Store a value into an existing own data property, keeping its attributes.

Returns false when the property is absent, is an accessor, or is not writable. An assignment has to go through this rather than Self::define_data, because redefining is how a non-configurable global silently became configurable again and started answering delete with true.

Source

pub fn write_value_key(&self, key: &PropertyKey, value: Value) -> bool

Store a value into an existing own data property under key.

Source

pub fn delete(&self, name: &str) -> bool

Delete an own property, reporting whether it was there and removable.

Source

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

Delete an own property under key.

Source

pub fn is_extensible(&self) -> bool

Whether new properties may be added.

Source

pub fn set_extensible(&self, extensible: bool)

Make the object non-extensible.

Source

pub fn elements_writable(&self) -> bool

Whether array elements may be replaced.

Source

pub fn set_elements_writable(&self, writable: bool)

Make array elements read-only, as Object.freeze does.

Source

pub fn element_attributes(&self, index: u32) -> Option<Property>

The attributes recorded for an array index, if defineProperty set any.

Source

pub fn element_is_locked(&self, index: u32) -> bool

Whether a store at index would be rejected.

An element is locked either by Object.freeze on the whole object or by a non-configurable, non-writable descriptor recorded for that one index.

Source

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

The own property names, in definition order. Symbol keys are excluded: Object.keys and for…in cannot see them.

Source

pub fn own_enumerable_keys(&self) -> Vec<Wtf8>

The own enumerable property names, in definition order.

Source

pub fn own_symbol_keys(&self) -> Vec<Gc<JsSymbol>>

The own symbol keys, in definition order, for Object.getOwnPropertySymbols.

Source

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

Every own key, strings first then symbols — the order Reflect.ownKeys and Object.getOwnPropertyDescriptors report, and the order JSON.stringify walks before it skips the symbols.

Source

pub fn chain(&self) -> Vec<Gc<JsObject>>

The prototype chain, starting with the prototypes of this object.

Trait Implementations§

Source§

impl Trace for JsObject

Source§

fn trace(&self, tracer: &mut Tracer<'_>)

Report every Gc owned by self to tracer.

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.