pub struct JsObject(/* private fields */);
Expand description
The type of JavaScript objects, i.e., the root of all object types.
§Example
// Extract the console.log function:
let console: Handle<JsObject> = cx.global("console")?;
let log: Handle<JsFunction> = console.get(&mut cx, "log")?;
// Create an object:
let obj = cx.empty_object();
let name = cx.string("Neon");
obj.set(&mut cx, "name", name)?;
let url = cx.string("https://neon-bindings.com");
obj.set(&mut cx, "url", url)?;
// Call console.log(obj):
log.call_with(&cx).arg(obj).exec(&mut cx)?;
Implementations§
Trait Implementations§
source§impl Object for JsObject
impl Object for JsObject
source§fn get_opt<'a, V: Value, C: Context<'a>, K: PropertyKey>(
&self,
cx: &mut C,
key: K
) -> NeonResult<Option<Handle<'a, V>>>
fn get_opt<'a, V: Value, C: Context<'a>, K: PropertyKey>( &self, cx: &mut C, key: K ) -> NeonResult<Option<Handle<'a, V>>>
Gets a property from a JavaScript object that may be
undefined
and
attempts to downcast the value if it existed.source§fn get_value<'a, C: Context<'a>, K: PropertyKey>(
&self,
cx: &mut C,
key: K
) -> NeonResult<Handle<'a, JsValue>>
fn get_value<'a, C: Context<'a>, K: PropertyKey>( &self, cx: &mut C, key: K ) -> NeonResult<Handle<'a, JsValue>>
source§fn get<'a, V: Value, C: Context<'a>, K: PropertyKey>(
&self,
cx: &mut C,
key: K
) -> NeonResult<Handle<'a, V>>
fn get<'a, V: Value, C: Context<'a>, K: PropertyKey>( &self, cx: &mut C, key: K ) -> NeonResult<Handle<'a, V>>
Gets a property from a JavaScript object and attempts to downcast as a specific type.
Equivalent to calling
obj.get_value(&mut cx)?.downcast_or_throw(&mut cx)
. Read moresource§fn get_own_property_names<'a, C: Context<'a>>(
&self,
cx: &mut C
) -> JsResult<'a, JsArray>
fn get_own_property_names<'a, C: Context<'a>>( &self, cx: &mut C ) -> JsResult<'a, JsArray>
Available on crate feature
napi-6
only.fn freeze<'a, C: Context<'a>>(&self, cx: &mut C) -> NeonResult<&Self>
fn seal<'a, C: Context<'a>>(&self, cx: &mut C) -> NeonResult<&Self>
fn set<'a, C: Context<'a>, K: PropertyKey, W: Value>( &self, cx: &mut C, key: K, val: Handle<'_, W> ) -> NeonResult<bool>
fn root<'a, C: Context<'a>>(&self, cx: &mut C) -> Root<Self>
fn call_method_with<'a, C, K>(
&self,
cx: &mut C,
method: K
) -> NeonResult<CallOptions<'a>>where
C: Context<'a>,
K: PropertyKey,
source§impl Value for JsObject
impl Value for JsObject
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§
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
Mutably borrows from an owned value. Read more