pub trait NapiValueT {
Show 27 methods fn from_raw(env: NapiEnv, value: napi_value) -> Self;
fn value(&self) -> JsValue; fn cast<T: NapiValueT>(&self) -> T { ... }
fn coerce_to_bool(&self) -> NapiResult<JsBoolean> { ... }
fn coerce_coerce_to_number(&self) -> NapiResult<JsNumber> { ... }
fn coerce_to_object(&self) -> NapiResult<JsObject> { ... }
fn coerce_to_string(&self) -> NapiResult<JsString> { ... }
fn instance_of(&self, constructor: JsFunction) -> NapiResult<bool> { ... }
fn is_array(&self) -> NapiResult<bool> { ... }
fn is_arraybuffer(&self) -> NapiResult<bool> { ... }
fn is_buffer(&self) -> NapiResult<bool> { ... }
fn is_error(&self) -> NapiResult<bool> { ... }
fn is_typedarray(&self) -> NapiResult<bool> { ... }
fn is_dataview(&self) -> NapiResult<bool> { ... }
fn equals(&self, rhs: impl NapiValueT) -> NapiResult<bool> { ... }
fn kind(&self) -> NapiResult<NapiValuetype> { ... }
fn env(&self) -> NapiEnv { ... }
fn raw(&self) -> napi_value { ... }
fn null(&self) -> NapiResult<JsNull> { ... }
fn undefined(&self) -> NapiResult<JsUndefined> { ... }
fn global(&self) -> NapiResult<JsGlobal> { ... }
fn throw(&self) -> NapiResult<()> { ... }
fn define_properties<P>(&self, properties: P) -> NapiResult<()>
    where
        P: AsRef<[NapiPropertyDescriptor]>
, { ... }
fn gc<Finalizer>(&mut self, finalizer: Finalizer) -> NapiResult<NapiRef>
    where
        Finalizer: FnOnce(NapiEnv) -> NapiResult<()>
, { ... }
fn wrap<T, Finalizer>(
        &mut self,
        data: T,
        finalizer: Finalizer
    ) -> NapiResult<NapiRef>
    where
        Finalizer: FnOnce(NapiEnv, T) -> NapiResult<()>
, { ... }
fn unwrap<T>(&self) -> NapiResult<Option<&mut T>> { ... }
fn remove_wrap<T>(&mut self) -> NapiResult<T> { ... }
}
Expand description

The trait for js value, which just store napi_value raw pointer.

Required methods

construct value from raw pointer

inner value

Provided methods

napi_value type cast

This API implements the abstract operation ToBoolean() as defined in Section 7.1.2 of the ECMAScript Language Specification.

This API implements the abstract operation ToNumber() as defined in Section 7.1.3 of the ECMAScript Language Specification. This function potentially runs JS code if the passed-in value is an object.

This API implements the abstract operation ToObject() as defined in Section 7.1.13 of the ECMAScript Language Specification.

This API implements the abstract operation ToString() as defined in Section 7.1.13 of the ECMAScript Language Specification. This function potentially runs JS code if the passed-in value is an object.

This API represents invoking the instanceof Operator on the object as defined in Section 12.10.4 of the ECMAScript Language Specification.

This API represents invoking the IsArray operation on the object as defined in Section 7.2.2 of the ECMAScript Language Specification.

This API checks if the Object passed in is an array buffer.

This API checks if the Object passed in is a buffer.

This API checks if the Object passed in is a error.

This API checks if the Object passed in is a typed array.

This API checks if the Object passed in is a DataView.

This API represents the invocation of the Strict Equality algorithm as defined in Section 7.2.14 of the ECMAScript Language Specification.

Returns napi_ok if the API succeeded.

  • napi_invalid_arg if the type of value is not a known ECMAScript type and value is not an External value. This API represents behavior similar to invoking the typeof Operator on the object as defined in Section 12.5.5 of the ECMAScript Language Specification. However, there are some differences: It has support for detecting an External value. It detects null as a separate type, while ECMAScript typeof would detect object. If value has a type that is invalid, an error is returned.

the NapiEnv of current value

the raw-handle of current value

get null singleton

get undefined singleton

get global singleton

value is throwable

This method allows the efficient definition of multiple properties on a given object. The properties are defined using property descriptors (see napi_property_descriptor). Given an array of such property descriptors, this API will set the properties on the object one at a time, as defined by DefineOwnProperty() (described in Section 9.1.6 of the ECMA-262 specification).

This is a hook which is fired when the value is gabage-collected. For napi >= 5, we use napi_add_finalizer, For napi < 5, we use napi_wrap.

Wraps a native instance in a JavaScript object. The native instance can be retrieved later using napi_unwrap().

When JavaScript code invokes a constructor for a class that was defined using napi_define_class(), the napi_callback for the constructor is invoked. After constructing an instance of the native class, the callback must then call napi_wrap() to wrap the newly constructed instance in the already-created JavaScript object that is the this argument to the constructor callback. (That this object was created from the constructor function’s prototype, so it already has definitions of all the instance properties and methods.)

Typically when wrapping a class instance, a finalize callback should be provided that simply deletes the native instance that is received as the data argument to the finalize callback.

The optional returned reference is initially a weak reference, meaning it has a reference count of 0. Typically this reference count would be incremented temporarily during async operations that require the instance to remain valid.

Caution: The optional returned reference (if obtained) should be deleted via napi_delete_reference ONLY in response to the finalize callback invocation. If it is deleted before then, then the finalize callback may never be invoked. Therefore, when obtaining a reference a finalize callback is also required in order to enable correct disposal of the reference.

Calling napi_wrap() a second time on an object will return an error. To associate another native instance with the object, use napi_remove_wrap() first.

Retrieves a native instance that was previously wrapped in a JavaScript object using napi_wrap().

When JavaScript code invokes a method or property accessor on the class, the corresponding napi_callback is invoked. If the callback is for an instance method or accessor, then the this argument to the callback is the wrapper object; the wrapped C++ instance that is the target of the call can be obtained then by calling napi_unwrap() on the wrapper object.

NB: if a there is no wrap or the wrap is just removed by NapiValue::remove_wrap, return None.

Retrieves a native instance that was previously wrapped in the JavaScript object js_object using napi_wrap() and removes the wrapping. If a finalize callback was associated with the wrapping, it will no longer be called when the JavaScript object becomes garbage-collected.

Implementors