pub trait JsObjectValue<'env>: JsValue<'env> {
Show 38 methods
// Provided methods
fn set_property<'k, 'v, K, V>(&mut self, key: K, value: V) -> Result<()>
where K: JsValue<'k>,
V: JsValue<'v> { ... }
fn get_property<'k, K, T>(&self, key: K) -> Result<T>
where K: JsValue<'k>,
T: FromNapiValue + ValidateNapiValue { ... }
fn get_property_unchecked<'k, K, T>(&self, key: K) -> Result<T>
where K: JsValue<'k>,
T: FromNapiValue { ... }
fn set_named_property<T>(&mut self, name: &str, value: T) -> Result<()>
where T: ToNapiValue { ... }
fn set_c_named_property<T>(&mut self, name: &CStr, value: T) -> Result<()>
where T: ToNapiValue { ... }
fn create_named_method<K>(
&mut self,
name: K,
function: Callback,
) -> Result<()>
where K: AsRef<str> { ... }
fn create_c_named_method(
&mut self,
name: &CStr,
function: Callback,
) -> Result<()> { ... }
fn get_named_property<T>(&self, name: &str) -> Result<T>
where T: FromNapiValue + ValidateNapiValue { ... }
fn get_c_named_property<T>(&self, name: &CStr) -> Result<T>
where T: FromNapiValue + ValidateNapiValue { ... }
fn get_named_property_unchecked<T>(&self, name: &str) -> Result<T>
where T: FromNapiValue { ... }
fn get_c_named_property_unchecked<T>(&self, name: &CStr) -> Result<T>
where T: FromNapiValue { ... }
fn has_named_property<N: AsRef<str>>(&self, name: N) -> Result<bool> { ... }
fn has_c_named_property(&self, name: &CStr) -> Result<bool> { ... }
fn delete_property<'s, S>(&mut self, name: S) -> Result<bool>
where S: JsValue<'s> { ... }
fn delete_named_property<K: AsRef<str>>(&mut self, name: K) -> Result<bool> { ... }
fn delete_c_named_property(&mut self, name: &CStr) -> Result<bool> { ... }
fn has_own_property(&self, key: &str) -> Result<bool> { ... }
fn has_c_own_property(&self, key: &CStr) -> Result<bool> { ... }
fn has_own_property_js<'k, K>(&self, key: K) -> Result<bool>
where K: JsValue<'k> { ... }
fn has_property(&self, name: &str) -> Result<bool> { ... }
fn has_property_js<'k, K>(&self, name: K) -> Result<bool>
where K: JsValue<'k> { ... }
fn get_property_names(&self) -> Result<Object<'env>> { ... }
fn get_all_property_names(
&self,
mode: KeyCollectionMode,
filter: KeyFilter,
conversion: KeyConversion,
) -> Result<Object<'env>> { ... }
fn get_prototype(&self) -> Result<Unknown<'env>> { ... }
fn get_prototype_unchecked<T>(&self) -> Result<T>
where T: FromNapiValue { ... }
fn set_element<'t, T>(&mut self, index: u32, value: T) -> Result<()>
where T: JsValue<'t> { ... }
fn has_element(&self, index: u32) -> Result<bool> { ... }
fn delete_element(&mut self, index: u32) -> Result<bool> { ... }
fn get_element<T>(&self, index: u32) -> Result<T>
where T: FromNapiValue { ... }
fn define_properties(&mut self, properties: &[Property]) -> Result<()> { ... }
fn get_array_length(&self) -> Result<u32> { ... }
fn get_array_length_unchecked(&self) -> Result<u32> { ... }
fn wrap<T: 'static>(
&mut self,
native_object: T,
size_hint: Option<usize>,
) -> Result<()> { ... }
fn unwrap<T: 'static>(&self) -> Result<&mut T> { ... }
fn remove_wrapped<T: 'static>(&mut self) -> Result<()> { ... }
fn add_finalizer<T, Hint, F>(
&mut self,
native: T,
finalize_hint: Hint,
finalize_cb: F,
) -> Result<()>
where T: 'static,
Hint: 'static,
F: FnOnce(FinalizeContext<T, Hint>) + 'static { ... }
fn freeze(&mut self) -> Result<()> { ... }
fn seal(&mut self) -> Result<()> { ... }
}Provided Methods§
Sourcefn set_property<'k, 'v, K, V>(&mut self, key: K, value: V) -> Result<()>
fn set_property<'k, 'v, K, V>(&mut self, key: K, value: V) -> Result<()>
Set the property value to the Object
Sourcefn get_property<'k, K, T>(&self, key: K) -> Result<T>
fn get_property<'k, K, T>(&self, key: K) -> Result<T>
Get the property value from the Object
Return the InvalidArg error if the property is not T
Sourcefn get_property_unchecked<'k, K, T>(&self, key: K) -> Result<T>where
K: JsValue<'k>,
T: FromNapiValue,
fn get_property_unchecked<'k, K, T>(&self, key: K) -> Result<T>where
K: JsValue<'k>,
T: FromNapiValue,
Get the property value from the Object without validation
Sourcefn set_named_property<T>(&mut self, name: &str, value: T) -> Result<()>where
T: ToNapiValue,
fn set_named_property<T>(&mut self, name: &str, value: T) -> Result<()>where
T: ToNapiValue,
Set the property value to the Object
Sourcefn set_c_named_property<T>(&mut self, name: &CStr, value: T) -> Result<()>where
T: ToNapiValue,
fn set_c_named_property<T>(&mut self, name: &CStr, value: T) -> Result<()>where
T: ToNapiValue,
Set the property value to the Object, the property name is a CStr
This is useful when the property name comes from a C library
Sourcefn create_named_method<K>(&mut self, name: K, function: Callback) -> Result<()>
fn create_named_method<K>(&mut self, name: K, function: Callback) -> Result<()>
Create a named method on the Object
Sourcefn create_c_named_method(
&mut self,
name: &CStr,
function: Callback,
) -> Result<()>
fn create_c_named_method( &mut self, name: &CStr, function: Callback, ) -> Result<()>
Create a named method on the Object, the name is a CStr
This is useful when the method name comes from a C library
Sourcefn get_named_property<T>(&self, name: &str) -> Result<T>where
T: FromNapiValue + ValidateNapiValue,
fn get_named_property<T>(&self, name: &str) -> Result<T>where
T: FromNapiValue + ValidateNapiValue,
Get the property value from the Object
Return the InvalidArg error if the property is not T
Sourcefn get_c_named_property<T>(&self, name: &CStr) -> Result<T>where
T: FromNapiValue + ValidateNapiValue,
fn get_c_named_property<T>(&self, name: &CStr) -> Result<T>where
T: FromNapiValue + ValidateNapiValue,
Get the property value from the Object
Return the InvalidArg error if the property is not T
This is useful when the property name comes from a C library
Sourcefn get_named_property_unchecked<T>(&self, name: &str) -> Result<T>where
T: FromNapiValue,
fn get_named_property_unchecked<T>(&self, name: &str) -> Result<T>where
T: FromNapiValue,
Get the property value from the Object without validation
Sourcefn get_c_named_property_unchecked<T>(&self, name: &CStr) -> Result<T>where
T: FromNapiValue,
fn get_c_named_property_unchecked<T>(&self, name: &CStr) -> Result<T>where
T: FromNapiValue,
Get the property value from the Object without validation
This is useful when the property name comes from a C library
Sourcefn has_named_property<N: AsRef<str>>(&self, name: N) -> Result<bool>
fn has_named_property<N: AsRef<str>>(&self, name: N) -> Result<bool>
Check if the Object has the named property
Sourcefn has_c_named_property(&self, name: &CStr) -> Result<bool>
fn has_c_named_property(&self, name: &CStr) -> Result<bool>
Check if the Object has the named property
This is useful when the property name comes from a C library
Sourcefn delete_property<'s, S>(&mut self, name: S) -> Result<bool>where
S: JsValue<'s>,
fn delete_property<'s, S>(&mut self, name: S) -> Result<bool>where
S: JsValue<'s>,
Delete the property from the Object, the property name can be a JsValue
Sourcefn delete_named_property<K: AsRef<str>>(&mut self, name: K) -> Result<bool>
fn delete_named_property<K: AsRef<str>>(&mut self, name: K) -> Result<bool>
Delete the property from the Object
Sourcefn delete_c_named_property(&mut self, name: &CStr) -> Result<bool>
fn delete_c_named_property(&mut self, name: &CStr) -> Result<bool>
Delete the property from the Object
This is useful when the property name comes from a C library
Sourcefn has_own_property(&self, key: &str) -> Result<bool>
fn has_own_property(&self, key: &str) -> Result<bool>
Check if the Object has the own property
Sourcefn has_c_own_property(&self, key: &CStr) -> Result<bool>
fn has_c_own_property(&self, key: &CStr) -> Result<bool>
Check if the Object has the own property
This is useful when the property name comes from a C library
Sourcefn has_own_property_js<'k, K>(&self, key: K) -> Result<bool>where
K: JsValue<'k>,
fn has_own_property_js<'k, K>(&self, key: K) -> Result<bool>where
K: JsValue<'k>,
The same as has_own_property, but accepts a JsValue as the property name.
Sourcefn has_property(&self, name: &str) -> Result<bool>
fn has_property(&self, name: &str) -> Result<bool>
This API checks if the Object passed in has the named property.
Sourcefn has_property_js<'k, K>(&self, name: K) -> Result<bool>where
K: JsValue<'k>,
fn has_property_js<'k, K>(&self, name: K) -> Result<bool>where
K: JsValue<'k>,
This API is the same as has_property, but accepts a JsValue as the property name.
So you can pass the JsNumber or JsSymbol as the property name.
Sourcefn get_property_names(&self) -> Result<Object<'env>>
fn get_property_names(&self) -> Result<Object<'env>>
This API returns the names of the enumerable properties of object as an array of strings. The properties of object whose key is a symbol will not be included.
Sourcefn get_all_property_names(
&self,
mode: KeyCollectionMode,
filter: KeyFilter,
conversion: KeyConversion,
) -> Result<Object<'env>>
fn get_all_property_names( &self, mode: KeyCollectionMode, filter: KeyFilter, conversion: KeyConversion, ) -> Result<Object<'env>>
https://nodejs.org/api/n-api.html#n_api_napi_get_all_property_names This API returns an array containing the names of the available properties of this object.
Sourcefn get_prototype(&self) -> Result<Unknown<'env>>
fn get_prototype(&self) -> Result<Unknown<'env>>
This returns the equivalent of Object.getPrototypeOf (which is not the same as the function’s prototype property).
Sourcefn get_prototype_unchecked<T>(&self) -> Result<T>where
T: FromNapiValue,
fn get_prototype_unchecked<T>(&self) -> Result<T>where
T: FromNapiValue,
Get the prototype of the Object
Sourcefn set_element<'t, T>(&mut self, index: u32, value: T) -> Result<()>where
T: JsValue<'t>,
fn set_element<'t, T>(&mut self, index: u32, value: T) -> Result<()>where
T: JsValue<'t>,
Set the element at the given index
Sourcefn has_element(&self, index: u32) -> Result<bool>
fn has_element(&self, index: u32) -> Result<bool>
Check if the Array has the element at the given index
Sourcefn delete_element(&mut self, index: u32) -> Result<bool>
fn delete_element(&mut self, index: u32) -> Result<bool>
Delete the element at the given index
Sourcefn get_element<T>(&self, index: u32) -> Result<T>where
T: FromNapiValue,
fn get_element<T>(&self, index: u32) -> Result<T>where
T: FromNapiValue,
Get the element at the given index
If the Object is not an array, ArrayExpected error returned
Sourcefn define_properties(&mut self, properties: &[Property]) -> Result<()>
fn define_properties(&mut self, properties: &[Property]) -> Result<()>
This method allows the efficient definition of multiple properties on a given object.
Sourcefn get_array_length(&self) -> Result<u32>
fn get_array_length(&self) -> Result<u32>
Perform is_array check before get the length
if Object is not array, ArrayExpected error returned
Sourcefn get_array_length_unchecked(&self) -> Result<u32>
fn get_array_length_unchecked(&self) -> Result<u32>
use this API if you can ensure this Object is Array
Sourcefn wrap<T: 'static>(
&mut self,
native_object: T,
size_hint: Option<usize>,
) -> Result<()>
fn wrap<T: 'static>( &mut self, native_object: T, size_hint: Option<usize>, ) -> Result<()>
Wrap the native value T to this Object
the T will be dropped when this Object is finalized
Sourcefn unwrap<T: 'static>(&self) -> Result<&mut T>
fn unwrap<T: 'static>(&self) -> Result<&mut T>
Get the wrapped native value from the Object
Return the InvalidArg error if the Object is not wrapped the T
Sourcefn remove_wrapped<T: 'static>(&mut self) -> Result<()>
fn remove_wrapped<T: 'static>(&mut self) -> Result<()>
Remove the wrapped native value from the Object
Return the InvalidArg error if the Object is not wrapped the T
Sourcefn add_finalizer<T, Hint, F>(
&mut self,
native: T,
finalize_hint: Hint,
finalize_cb: F,
) -> Result<()>where
T: 'static,
Hint: 'static,
F: FnOnce(FinalizeContext<T, Hint>) + 'static,
fn add_finalizer<T, Hint, F>(
&mut self,
native: T,
finalize_hint: Hint,
finalize_cb: F,
) -> Result<()>where
T: 'static,
Hint: 'static,
F: FnOnce(FinalizeContext<T, Hint>) + 'static,
Adds a finalize_cb callback which will be called when the JavaScript object in js_object has been garbage-collected.
This API can be called multiple times on a single JavaScript object.
Sourcefn freeze(&mut self) -> Result<()>
fn freeze(&mut self) -> Result<()>
This method freezes a given object. This prevents new properties from being added to it, existing properties from being removed, prevents changing the enumerability, configurability, or writability of existing properties, and prevents the values of existing properties from being changed. It also prevents the object’s prototype from being changed. This is described in Section 19.1.2.6 of the ECMA-262 specification.
Sourcefn seal(&mut self) -> Result<()>
fn seal(&mut self) -> Result<()>
This method seals a given object. This prevents new properties from being added to it, as well as marking all existing properties as non-configurable. This is described in Section 19.1.2.20 of the ECMA-262 specification.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.