pub struct JsObject<T: NativeObject = ErasedObjectData> { /* private fields */ }Expand description
Garbage collected Object.
Implementations§
Source§impl JsObject
impl JsObject
Sourcepub fn default(intrinsics: &Intrinsics) -> Self
pub fn default(intrinsics: &Intrinsics) -> Self
Creates a new ordinary object with its prototype set to the Object prototype.
This is an alias for Self::with_object_proto.
Sourcepub fn with_object_proto(intrinsics: &Intrinsics) -> Self
pub fn with_object_proto(intrinsics: &Intrinsics) -> Self
Creates a new ordinary object with its prototype set to the Object prototype.
This is equivalent to calling the specification’s abstract operation
OrdinaryObjectCreate(%Object.prototype%).
Sourcepub fn with_null_proto() -> Self
pub fn with_null_proto() -> Self
Creates a new ordinary object, with its prototype set to null.
This is equivalent to calling the specification’s abstract operation
OrdinaryObjectCreate(null).
Sourcepub fn from_proto_and_data<O: Into<Option<Self>>, T: NativeObject>(
prototype: O,
data: T,
) -> Self
pub fn from_proto_and_data<O: Into<Option<Self>>, T: NativeObject>( prototype: O, data: T, ) -> Self
Creates a new object with the provided prototype and object data.
This is equivalent to calling the specification’s abstract operation OrdinaryObjectCreate,
with the difference that the additionalInternalSlotsList parameter is determined by
the provided data.
Sourcepub fn downcast<T: NativeObject>(self) -> Result<JsObject<T>, Self>
pub fn downcast<T: NativeObject>(self) -> Result<JsObject<T>, Self>
Downcasts the object’s inner data if the object is of type T.
§Panics
Panics if the object is currently mutably borrowed.
Sourcepub unsafe fn downcast_unchecked<T: NativeObject>(self) -> JsObject<T>
pub unsafe fn downcast_unchecked<T: NativeObject>(self) -> JsObject<T>
Downcasts the object’s inner data to T without verifying the inner type of T.
§Safety
For this cast to be sound, self must contain an instance of T inside its inner data.
Sourcepub fn downcast_ref<T: NativeObject>(&self) -> Option<Ref<'_, T>>
pub fn downcast_ref<T: NativeObject>(&self) -> Option<Ref<'_, T>>
Downcasts a reference to the object,
if the object is of type T.
§Panics
Panics if the object is currently mutably borrowed.
Sourcepub fn downcast_mut<T: NativeObject>(&self) -> Option<RefMut<'_, T>>
pub fn downcast_mut<T: NativeObject>(&self) -> Option<RefMut<'_, T>>
Downcasts a mutable reference to the object,
if the object is type native object type T.
§Panics
Panics if the object is currently borrowed.
Sourcepub fn is<T: NativeObject>(&self) -> bool
pub fn is<T: NativeObject>(&self) -> bool
Checks if this object is an instance of a certain NativeObject.
§Panics
Panics if the object is currently mutably borrowed.
Sourcepub fn is_ordinary(&self) -> bool
pub fn is_ordinary(&self) -> bool
Sourcepub fn deep_strict_equals(
lhs: &Self,
rhs: &Self,
context: &mut Context,
) -> JsResult<bool>
pub fn deep_strict_equals( lhs: &Self, rhs: &Self, context: &mut Context, ) -> JsResult<bool>
Checks that all own property keys and values are equal (recursively).
Sourcepub fn to_property_descriptor(
&self,
context: &mut Context,
) -> JsResult<PropertyDescriptor>
pub fn to_property_descriptor( &self, context: &mut Context, ) -> JsResult<PropertyDescriptor>
Sourcepub fn copy_data_properties<K>(
&self,
source: &JsValue,
excluded_keys: Vec<K>,
context: &mut Context,
) -> JsResult<()>where
K: Into<PropertyKey>,
pub fn copy_data_properties<K>(
&self,
source: &JsValue,
excluded_keys: Vec<K>,
context: &mut Context,
) -> JsResult<()>where
K: Into<PropertyKey>,
Source§impl<T: NativeObject> JsObject<T>
impl<T: NativeObject> JsObject<T>
Sourcepub fn borrow(&self) -> Ref<'_, Object<T>>
pub fn borrow(&self) -> Ref<'_, Object<T>>
Immutably borrows the Object.
The borrow lasts until the returned Ref exits scope.
Multiple immutable borrows can be taken out at the same time.
§Panics
Panics if the object is currently mutably borrowed.
Sourcepub fn borrow_mut(&self) -> RefMut<'_, Object<T>>
pub fn borrow_mut(&self) -> RefMut<'_, Object<T>>
Mutably borrows the Object.
The borrow lasts until the returned RefMut exits scope.
The object cannot be borrowed while this borrow is active.
§Panics
Panics if the object is currently borrowed.
Sourcepub fn try_borrow(&self) -> StdResult<Ref<'_, Object<T>>, BorrowError>
pub fn try_borrow(&self) -> StdResult<Ref<'_, Object<T>>, BorrowError>
Immutably borrows the Object, returning an error if the value is currently mutably borrowed.
The borrow lasts until the returned GcCellRef exits scope.
Multiple immutable borrows can be taken out at the same time.
This is the non-panicking variant of borrow.
Sourcepub fn try_borrow_mut(&self) -> StdResult<RefMut<'_, Object<T>>, BorrowMutError>
pub fn try_borrow_mut(&self) -> StdResult<RefMut<'_, Object<T>>, BorrowMutError>
Mutably borrows the object, returning an error if the value is currently borrowed.
The borrow lasts until the returned GcCellRefMut exits scope.
The object be borrowed while this borrow is active.
This is the non-panicking variant of borrow_mut.
Sourcepub fn equals(lhs: &Self, rhs: &Self) -> bool
pub fn equals(lhs: &Self, rhs: &Self) -> bool
Checks if the garbage collected memory is the same.
Sourcepub fn prototype(&self) -> JsPrototype
pub fn prototype(&self) -> JsPrototype
Sourcepub fn set_prototype(&self, prototype: JsPrototype) -> bool
pub fn set_prototype(&self, prototype: JsPrototype) -> bool
Sourcepub fn insert_property<K, P>(&self, key: K, property: P) -> bool
pub fn insert_property<K, P>(&self, key: K, property: P) -> bool
Inserts a field in the object properties without checking if it’s writable.
If a field was already in the object with the same name, than true is returned
with that field, otherwise false is returned.
Sourcepub fn is_callable(&self) -> bool
pub fn is_callable(&self) -> bool
It determines if Object is a callable function with a [[Call]] internal method.
More information:
Sourcepub fn is_constructor(&self) -> bool
pub fn is_constructor(&self) -> bool
It determines if Object is a function object with a [[Construct]] internal method.
More information:
Source§impl<T: NativeObject> JsObject<T>
impl<T: NativeObject> JsObject<T>
Sourcepub fn new<O: Into<Option<JsObject>>>(
root_shape: &RootShape,
prototype: O,
data: T,
) -> Self
pub fn new<O: Into<Option<JsObject>>>( root_shape: &RootShape, prototype: O, data: T, ) -> Self
Creates a new JsObject from its root shape, prototype, and data.
Note that the returned object will not be erased to be convertible to a
JsValue. To erase the pointer, call JsObject::upcast.
Sourcepub fn new_unique<O: Into<Option<JsObject>>>(prototype: O, data: T) -> Self
pub fn new_unique<O: Into<Option<JsObject>>>(prototype: O, data: T) -> Self
Creates a new JsObject from prototype, and data.
Note that the returned object will not be erased to be convertible to a
JsValue. To erase the pointer, call JsObject::upcast.
Source§impl JsObject
impl JsObject
Sourcepub fn is_extensible(&self, context: &mut Context) -> JsResult<bool>
pub fn is_extensible(&self, context: &mut Context) -> JsResult<bool>
Sourcepub fn get<K>(&self, key: K, context: &mut Context) -> JsResult<JsValue>where
K: Into<PropertyKey>,
pub fn get<K>(&self, key: K, context: &mut Context) -> JsResult<JsValue>where
K: Into<PropertyKey>,
Sourcepub fn set<K, V>(
&self,
key: K,
value: V,
throw: bool,
context: &mut Context,
) -> JsResult<bool>
pub fn set<K, V>( &self, key: K, value: V, throw: bool, context: &mut Context, ) -> JsResult<bool>
Sourcepub fn create_data_property<K, V>(
&self,
key: K,
value: V,
context: &mut Context,
) -> JsResult<bool>
pub fn create_data_property<K, V>( &self, key: K, value: V, context: &mut Context, ) -> JsResult<bool>
Sourcepub fn create_data_property_or_throw<K, V>(
&self,
key: K,
value: V,
context: &mut Context,
) -> JsResult<bool>
pub fn create_data_property_or_throw<K, V>( &self, key: K, value: V, context: &mut Context, ) -> JsResult<bool>
Sourcepub fn define_property_or_throw<K, P>(
&self,
key: K,
desc: P,
context: &mut Context,
) -> JsResult<bool>
pub fn define_property_or_throw<K, P>( &self, key: K, desc: P, context: &mut Context, ) -> JsResult<bool>
Sourcepub fn delete_property_or_throw<K>(
&self,
key: K,
context: &mut Context,
) -> JsResult<bool>where
K: Into<PropertyKey>,
pub fn delete_property_or_throw<K>(
&self,
key: K,
context: &mut Context,
) -> JsResult<bool>where
K: Into<PropertyKey>,
Defines the property or throws a TypeError if the operation fails.
More information:
Sourcepub fn has_property<K>(&self, key: K, context: &mut Context) -> JsResult<bool>where
K: Into<PropertyKey>,
pub fn has_property<K>(&self, key: K, context: &mut Context) -> JsResult<bool>where
K: Into<PropertyKey>,
Sourcepub fn has_own_property<K>(
&self,
key: K,
context: &mut Context,
) -> JsResult<bool>where
K: Into<PropertyKey>,
pub fn has_own_property<K>(
&self,
key: K,
context: &mut Context,
) -> JsResult<bool>where
K: Into<PropertyKey>,
Sourcepub fn own_property_keys(
&self,
context: &mut Context,
) -> JsResult<Vec<PropertyKey>>
pub fn own_property_keys( &self, context: &mut Context, ) -> JsResult<Vec<PropertyKey>>
Sourcepub fn call(
&self,
this: &JsValue,
args: &[JsValue],
context: &mut Context,
) -> JsResult<JsValue>
pub fn call( &self, this: &JsValue, args: &[JsValue], context: &mut Context, ) -> JsResult<JsValue>
Call ( F, V [ , argumentsList ] )
§Panics
Panics if the object is currently mutably borrowed.
More information:
Sourcepub fn construct(
&self,
args: &[JsValue],
new_target: Option<&Self>,
context: &mut Context,
) -> JsResult<Self>
pub fn construct( &self, args: &[JsValue], new_target: Option<&Self>, context: &mut Context, ) -> JsResult<Self>
Construct ( F [ , argumentsList [ , newTarget ] ] )
Construct an instance of this object with the specified arguments.
§Panics
Panics if the object is currently mutably borrowed.
More information:
Sourcepub fn set_integrity_level(
&self,
level: IntegrityLevel,
context: &mut Context,
) -> JsResult<bool>
pub fn set_integrity_level( &self, level: IntegrityLevel, context: &mut Context, ) -> JsResult<bool>
Sourcepub fn test_integrity_level(
&self,
level: IntegrityLevel,
context: &mut Context,
) -> JsResult<bool>
pub fn test_integrity_level( &self, level: IntegrityLevel, context: &mut Context, ) -> JsResult<bool>
Trait Implementations§
Source§impl<T: NativeObject> Clone for JsObject<T>
impl<T: NativeObject> Clone for JsObject<T>
Source§impl<T: NativeObject> Debug for JsObject<T>
impl<T: NativeObject> Debug for JsObject<T>
Source§impl<T: NativeObject> Finalize for JsObject<T>
impl<T: NativeObject> Finalize for JsObject<T>
Source§impl From<JsArrayBuffer> for JsObject
impl From<JsArrayBuffer> for JsObject
Source§fn from(o: JsArrayBuffer) -> Self
fn from(o: JsArrayBuffer) -> Self
Source§impl From<JsArrayBuffer> for JsObject<ArrayBuffer>
impl From<JsArrayBuffer> for JsObject<ArrayBuffer>
Source§fn from(value: JsArrayBuffer) -> Self
fn from(value: JsArrayBuffer) -> Self
Source§impl From<JsBigInt64Array> for JsObject
impl From<JsBigInt64Array> for JsObject
Source§fn from(o: JsBigInt64Array) -> Self
fn from(o: JsBigInt64Array) -> Self
Source§impl From<JsBigUint64Array> for JsObject
impl From<JsBigUint64Array> for JsObject
Source§fn from(o: JsBigUint64Array) -> Self
fn from(o: JsBigUint64Array) -> Self
Source§impl From<JsDataView> for JsObject
impl From<JsDataView> for JsObject
Source§fn from(o: JsDataView) -> Self
fn from(o: JsDataView) -> Self
Source§impl From<JsDataView> for JsObject<DataView>
impl From<JsDataView> for JsObject<DataView>
Source§fn from(value: JsDataView) -> Self
fn from(value: JsDataView) -> Self
Source§impl From<JsFloat16Array> for JsObject
impl From<JsFloat16Array> for JsObject
Source§fn from(o: JsFloat16Array) -> Self
fn from(o: JsFloat16Array) -> Self
Source§impl From<JsFloat32Array> for JsObject
impl From<JsFloat32Array> for JsObject
Source§fn from(o: JsFloat32Array) -> Self
fn from(o: JsFloat32Array) -> Self
Source§impl From<JsFloat64Array> for JsObject
impl From<JsFloat64Array> for JsObject
Source§fn from(o: JsFloat64Array) -> Self
fn from(o: JsFloat64Array) -> Self
Source§impl From<JsFunction> for JsObject
impl From<JsFunction> for JsObject
Source§fn from(o: JsFunction) -> Self
fn from(o: JsFunction) -> Self
Source§impl From<JsGenerator> for JsObject
impl From<JsGenerator> for JsObject
Source§fn from(o: JsGenerator) -> Self
fn from(o: JsGenerator) -> Self
Source§impl From<JsInt16Array> for JsObject
impl From<JsInt16Array> for JsObject
Source§fn from(o: JsInt16Array) -> Self
fn from(o: JsInt16Array) -> Self
Source§impl From<JsInt32Array> for JsObject
impl From<JsInt32Array> for JsObject
Source§fn from(o: JsInt32Array) -> Self
fn from(o: JsInt32Array) -> Self
Source§impl From<JsInt8Array> for JsObject
impl From<JsInt8Array> for JsObject
Source§fn from(o: JsInt8Array) -> Self
fn from(o: JsInt8Array) -> Self
Source§impl From<JsMapIterator> for JsObject
impl From<JsMapIterator> for JsObject
Source§fn from(o: JsMapIterator) -> Self
fn from(o: JsMapIterator) -> Self
Source§impl From<JsObject<ArrayBuffer>> for JsArrayBuffer
impl From<JsObject<ArrayBuffer>> for JsArrayBuffer
Source§fn from(value: JsObject<ArrayBuffer>) -> Self
fn from(value: JsObject<ArrayBuffer>) -> Self
Source§fn from(value: JsObject<SharedArrayBuffer>) -> Self
fn from(value: JsObject<SharedArrayBuffer>) -> Self
Source§impl From<JsSetIterator> for JsObject
impl From<JsSetIterator> for JsObject
Source§fn from(o: JsSetIterator) -> Self
fn from(o: JsSetIterator) -> Self
Source§fn from(o: JsSharedArrayBuffer) -> Self
fn from(o: JsSharedArrayBuffer) -> Self
Source§fn from(value: JsSharedArrayBuffer) -> Self
fn from(value: JsSharedArrayBuffer) -> Self
Source§impl From<JsTypedArray> for JsObject
impl From<JsTypedArray> for JsObject
Source§fn from(o: JsTypedArray) -> Self
fn from(o: JsTypedArray) -> Self
Source§impl From<JsUint16Array> for JsObject
impl From<JsUint16Array> for JsObject
Source§fn from(o: JsUint16Array) -> Self
fn from(o: JsUint16Array) -> Self
Source§impl From<JsUint32Array> for JsObject
impl From<JsUint32Array> for JsObject
Source§fn from(o: JsUint32Array) -> Self
fn from(o: JsUint32Array) -> Self
Source§impl From<JsUint8Array> for JsObject
impl From<JsUint8Array> for JsObject
Source§fn from(o: JsUint8Array) -> Self
fn from(o: JsUint8Array) -> Self
Source§impl From<JsUint8ClampedArray> for JsObject
impl From<JsUint8ClampedArray> for JsObject
Source§fn from(o: JsUint8ClampedArray) -> Self
fn from(o: JsUint8ClampedArray) -> Self
Source§impl<T: NativeObject> Hash for JsObject<T>
impl<T: NativeObject> Hash for JsObject<T>
Source§impl<T: NativeObject> PartialEq for JsObject<T>
impl<T: NativeObject> PartialEq for JsObject<T>
Source§impl<T: NativeObject> Trace for JsObject<T>
impl<T: NativeObject> Trace for JsObject<T>
Source§unsafe fn trace_non_roots(&self)
unsafe fn trace_non_roots(&self)
Source§fn run_finalizer(&self)
fn run_finalizer(&self)
Finalize::finalize on this object and all
contained subobjects.impl<T: NativeObject> Eq for JsObject<T>
Auto Trait Implementations§
impl<T> Freeze for JsObject<T>
impl<T = ErasedObjectData> !RefUnwindSafe for JsObject<T>
impl<T = ErasedObjectData> !Send for JsObject<T>
impl<T = ErasedObjectData> !Sync for JsObject<T>
impl<T> Unpin for JsObject<T>
impl<T = ErasedObjectData> !UnwindSafe for JsObject<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.