pub struct JSObject { /* private fields */ }
Expand description
Javascript objects.
A JSObject
always has a proto
.
It can have an optional ObjectValue
(a primitive or array/function/closure).
It has a dictionary of properties
.
Implementations
sourceimpl JSObject
impl JSObject
pub fn new() -> JSObject
sourcepub fn from_closure(closure: Closure) -> JSObject
pub fn from_closure(closure: Closure) -> JSObject
Wrap the given closure
into a Function.
sourcepub fn from_array(values: Vec<JSValue>) -> JSObject
pub fn from_array(values: Vec<JSValue>) -> JSObject
Wrap the given vector into an Array.
pub fn get_proto(&self) -> JSRef
pub fn set_proto(&mut self, proto: JSRef)
sourcepub fn to_primitive(&self) -> Option<JSValue>
pub fn to_primitive(&self) -> Option<JSValue>
It’s roughly Object.valueOf(self)
sourcepub fn as_array_mut(&mut self) -> Option<&mut JSArray>
pub fn as_array_mut(&mut self) -> Option<&mut JSArray>
If self
is an Array, give its underlying storage mutably.
pub fn is_callable(&self) -> bool
pub fn as_hostfn(&self) -> Option<HostFunc>
pub fn as_closure(&self) -> Option<Closure>
pub fn get_own_property(&self, name: &str) -> Option<Property>
sourcepub fn get_own_value(&self, name: &str) -> Option<JSValue>
pub fn get_own_value(&self, name: &str) -> Option<JSValue>
Tries to get JSValue of the own property name
.
This might call getters of the property.
sourcepub fn lookup_value(&self, name: &str, heap: &Heap) -> Option<JSValue>
pub fn lookup_value(&self, name: &str, heap: &Heap) -> Option<JSValue>
Check own and all inherited properties for name
and returns the first found value.
ES5: [[Get]], None corresponds to undefined
pub fn protochain<'a>(&self, heap: &'a Heap) -> ProtoChainIter<'a>ⓘNotable traits for ProtoChainIter<'a>impl<'a> Iterator for ProtoChainIter<'a> type Item = JSRef;
pub fn get_own_keys(&self) -> Vec<JSString>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
pub fn get_own_enumerable_keys(&self) -> Vec<JSString>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
pub fn define_own_property(
&mut self,
name: JSString,
access: Access
) -> JSResult<()>
pub fn delete_property(&mut self, name: JSString) -> JSResult<()>
sourcepub fn set_property<V>(&mut self, name: JSString, value: V) -> JSResult<()> where
Content: From<V>,
pub fn set_property<V>(&mut self, name: JSString, value: V) -> JSResult<()> where
Content: From<V>,
If name
is a number and self
is an Array, just set the array elemnt to value
.
Otherwise: if the own property name
does not exist, create it with Access::all()
and
set to Content::from(value)
.
If the own property exists already, call .set()
with its current access. This will fail
to update non-writable properties.
ES5: [[Put]] with strict error handing
sourcepub fn set_even_nonwritable<V>(
&mut self,
name: JSString,
value: V
) -> JSResult<()> where
Content: From<V>,
pub fn set_even_nonwritable<V>(
&mut self,
name: JSString,
value: V
) -> JSResult<()> where
Content: From<V>,
Just like .set_property()
, but updates even non-writable properties.
sourcepub fn set_system<V>(&mut self, name: JSString, value: V) -> JSResult<()> where
Content: From<V>,
pub fn set_system<V>(&mut self, name: JSString, value: V) -> JSResult<()> where
Content: From<V>,
A shortcut for define_own_property(Access::NONE)
and assigning the value.
A shortcut for defining a non-enumerable property and setting its value.
sourcepub fn set_nonconf<V>(&mut self, name: JSString, value: V) -> JSResult<()> where
Content: From<V>,
pub fn set_nonconf<V>(&mut self, name: JSString, value: V) -> JSResult<()> where
Content: From<V>,
A shortcut for defining a non-configurable property and setting its value.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for JSObject
impl !Send for JSObject
impl !Sync for JSObject
impl Unpin for JSObject
impl UnwindSafe for JSObject
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more