Skip to main content

Value

Struct Value 

Source
pub struct Value<'a> { /* private fields */ }
Expand description

Value with lifetime

Methods from Deref<Target = JSValue>§

Source

pub fn to_atom(&self, ctx: &ContextImpl) -> Result<Atom, i32>

convert value to atom. if value is not string or symbol, corece value to string then convert to atom.

Note: returned atom is cloned, caller should free it after use.

Source

pub fn arith_cmp( &self, ctx: &ContextImpl, other: JSValue, ) -> Result<Option<Ordering>, i32>

arithmatic compare of two values. returns None only if value converted to NaN

Source

pub fn arith_eq(&self, ctx: &ContextImpl, other: Self) -> Result<bool, i32>

test arithmatical equality (no-strict-eq): self == other?

Source

pub fn strict_eq(&self, other: Self) -> bool

test strict equality (strict-eq): self === other?

Source

pub fn is_same(&self, other: Self) -> bool

test if two values are strictly same. (-0, 0) not same

Source

pub fn is_same0(&self, other: Self) -> bool

test if two values are strictly same. (-0, 0) is same

Source

pub fn sort_cmp(&self, ctx: &ContextImpl, other: Self) -> Result<Ordering, i32>

get order of self and other.

Source

pub fn opaque(&self) -> Option<NonNull<c_void>>

if the value is a user class instance, returns the opaque pointer if available

Source

pub fn opaque_ref<T>(&self) -> Option<&T>

Source

pub fn as_object_AsyncFunction(&self) -> Option<&AsyncFunction>

Source

pub fn as_object_AsyncFunction_mut(&mut self) -> Option<&mut AsyncFunction>

Source

pub fn call_async( &self, ctx: &mut ContextImpl, this_obj: JSValue, args: &[JSValue], flags: i32, ) -> Result<Promise, i32>

if value is a bytecode function, call it in async manner

Source

pub fn as_object_BCFunction(&self) -> Option<&BCFunction>

Source

pub fn as_object_BCFunction_mut(&mut self) -> Option<&mut BCFunction>

Source

pub fn ensure_function(&self, ctx: &ContextImpl) -> Result<&Self, i32>

check if value self is a function or a callable object. raise exception if not.

Source

pub fn as_object_BytecodeFunction(&self) -> Option<&BytecodeFunction>

Source

pub fn as_object_BytecodeFunction_mut( &mut self, ) -> Option<&mut BytecodeFunction>

Source

pub fn as_object_BoundFunction(&self) -> Option<&BoundFunction>

Source

pub fn as_object_BoundFunction_mut(&mut self) -> Option<&mut BoundFunction>

Source

pub fn call( &self, ctx: &ContextImpl, this_obj: JSValue, args: &[JSValue], ) -> JSResult

call self value. if value is not callable, returns ‘not function error’.

Source

pub fn invoke( &self, ctx: &ContextImpl, method: Atom, args: &[JSValue], ) -> JSResult

call function self.method

Source

pub fn invoke_defined( &self, ctx: &ContextImpl, method: Atom, args: &[JSValue], ) -> Result<Option<JSResult>, i32>

call self.method function if property method is neither null nor undefined. otherwise, returns None.

Source

pub fn invoke_callable( &self, ctx: &ContextImpl, method: Atom, args: &[JSValue], ) -> Result<Option<JSResult>, i32>

call self.method if property method is callable. otherwise, returns None

method is not consumed

Source

pub fn as_object_NativeFunctionWithData( &self, ) -> Option<&NativeFunctionWithData>

Source

pub fn as_object_NativeFunctionWithData_mut( &mut self, ) -> Option<&mut NativeFunctionWithData>

Source

pub fn match_native_callback(&self, callback: Callback, magic: i32) -> bool

Checks if a JSValue is native function of specific type. Matches both the callback pointer and magic.

Source

pub fn install_fields( &mut self, ctx: &ContextImpl, entries: &'static [FieldDef], ) -> Result<(), i32>

Source

pub fn is_integral(&self, ctx: &ContextImpl) -> Result<bool, i32>

test if the value is an intergral number. returns Err if test has exception.

Source

pub fn to_number(&self, ctx: &ContextImpl) -> Result<JSValue, i32>

Convert value to number Int or Float64 (could be NaN).

Source

pub fn to_numeric(&self, ctx: &ContextImpl) -> Result<JSValue, i32>

Convert value to Int, Float64 (could be NaN) value, or Err. Because BigInt is not supported, this method is same as coerce_to_number()

Source

pub fn coerce_to_u8_clamp(&self, ctx: &ContextImpl) -> Result<u8, i32>

Source

pub fn to_i32(&self, ctx: &ContextImpl) -> Result<i32, i32>

coerce value to i32.

Source

pub fn to_i32_saturating(&self, ctx: &ContextImpl) -> Result<i32, i32>

Source

pub fn to_i32_clamp( &self, ctx: &ContextImpl, min: i32, max: i32, min_offset: i32, ) -> Result<i32, i32>

Source

pub fn to_u32(&self, ctx: &ContextImpl) -> Result<u32, i32>

Source

pub fn to_i64_saturating(&self, ctx: &ContextImpl) -> Result<i64, i32>

Source

pub fn to_i64_clamp( &self, ctx: &ContextImpl, min: i64, max: i64, neg_offset: i64, ) -> Result<i64, i32>

[min, max] is inclusive range.

Source

pub fn to_f64(&self, ctx: &ContextImpl) -> Result<f64, i32>

coerce value to f64.

Source

pub fn to_length(&self, ctx: &ContextImpl) -> Result<i64, i32>

convert value to length between [0, MAX_SAFE_INTEGER].

Source

pub fn as_object(&self) -> Option<&Object>

Source

pub fn as_object_mut(&mut self) -> Option<&mut Object>

Source

pub unsafe fn as_object_unchecked(&self) -> &Object

Source

pub unsafe fn as_object_mut_unchecked(&mut self) -> &mut Object

Source

pub fn objectify(&self, ctx: &ContextImpl) -> Result<Object, i32>

Migrage value to object. Handles primitive wrapping according to ES6 ToObject conversion rules.

For example:

  • object => object (as-is)
  • 10 => [object 10]
  • true => [object true]
  • “abc” => [object “abc”]
  • Symbol() => [object Symbol()]
  • null, undefined => Error
Source

pub fn is_constructor(&self) -> bool

Source

pub fn prevent_extensions(&mut self, ctx: &ContextImpl) -> Result<bool, i32>

Source

pub fn seal(&mut self, ctx: &ContextImpl, freeze: bool) -> Result<(), i32>

Seal self if it is an object.

Source

pub fn is_sealed( &mut self, ctx: &ContextImpl, is_frozen: bool, ) -> Result<bool, i32>

check if value is sealed. Object value will check property, Non-object value is always treated as sealed.

Source

pub fn retrive_object_payload( &self, ctx: &ContextImpl, class_id: ClassID, ) -> Result<&ObjectPayload, i32>

get object value’s payload borrow ref. if the value is not an object, or optionally is not the required class_id, throws type error.

Source

pub fn retrive_object_payload_mut( &mut self, ctx: &ContextImpl, class_id: ClassID, ) -> Result<&mut ObjectPayload, i32>

get object value’s payload borrow ref. if the value is not an object, or optionally is not the required class_id, throws type error.

Source

pub fn check_brand(&self, ctx: &ContextImpl, func: JSValue) -> Result<bool, i32>

check if self has own property suggested by func.<home_object>.<brand>.

Source

pub fn add_brand( &mut self, ctx: &ContextImpl, home_obj: JSValue, ) -> Result<(), i32>

assign ‘home_obj’ a symbol as its ident, store that symbol in home_obj. field. if self is an object, then defined a property with the home_obj’s symbol as key.

Source

pub fn set_private_field( &mut self, ctx: &ContextImpl, name: JSValue, val: JSValue, ) -> Result<(), i32>

Source

pub fn get_private_field(&self, ctx: &ContextImpl, name: JSValue) -> JSResult

Source

pub fn define_private_field( &mut self, ctx: &ContextImpl, name: JSValue, val: JSValue, ) -> Result<(), i32>

Private fields can be added even on non extensible objects or Proxies

Source

pub fn define_property_value( &mut self, ctx: &ContextImpl, prop: Atom, value: JSValue, flags: u32, ) -> Result<bool, i32>

add or update a property with value. Note: prop is not consumed.

Source

pub fn define_property_value_str( &mut self, ctx: &ContextImpl, prop: &str, val: JSValue, flags: u32, ) -> Result<bool, i32>

Source

pub fn define_property_value_u32( &mut self, ctx: &ContextImpl, idx: u32, val: JSValue, flags: u32, ) -> Result<bool, i32>

Source

pub fn define_property_value_i64( &mut self, ctx: &ContextImpl, idx: i64, val: JSValue, flags: u32, ) -> Result<bool, i32>

Source

pub fn define_property_getset( &mut self, ctx: &ContextImpl, prop: Atom, getter: JSValue, setter: JSValue, flags: u32, ) -> Result<bool, i32>

Source

pub fn create_data_property_u32( &mut self, ctx: &ContextImpl, idx: i64, val: JSValue, flags: u32, ) -> Result<bool, i32>

👎Deprecated: use JSValue::define_property_value_i64() or JSValue::define_property_value_u32()
Source

pub fn delete_property( &mut self, ctx: &ContextImpl, prop: Atom, flags: u32, ) -> Result<bool, i32>

如果属性不可配置或无效对象则返回 false, 出现异常时返回 Err. flags 可以是 0、JS_PROP_THROW 或 JS_PROP_THROW_STRICT

Source

pub fn delete_property_i64( &mut self, ctx: &ContextImpl, idx: i64, flags: u32, ) -> Result<bool, i32>

Source

pub fn get_property(&self, ctx: &ContextImpl, prop: Atom) -> JSResult

get property by prop atom

Source

pub fn get_property_value(&self, ctx: &ContextImpl, prop: JSValue) -> JSResult

get property by prop value

Source

pub fn get_property_str(&self, ctx: &ContextImpl, prop: &str) -> JSResult

get property by str prop

Source

pub fn get_property_u32(&self, ctx: &ContextImpl, idx: u32) -> JSResult

get property by u32 prop

Source

pub fn get_property_i64(&self, ctx: &ContextImpl, idx: i64) -> JSResult

Source

pub fn try_get_property_i64( &self, ctx: &ContextImpl, idx: i64, ) -> Result<Option<JSValue>, i32>

Check if self has a generalized numeric property idx. If yes, get property value of the prop idx. Returns Err for exception, Ok(Some(_)) if property exists, Ok(None) if proprty does not exist.

Source

pub fn get_own_property_kvs( &self, ctx: &ContextImpl, flags: i32, kind: JSIteratorKindEnum, ) -> Result<Box<[(JSValue, JSValue)]>, i32>

Gets object’s own properties [key, value] pairs.

Returns list of [key, value] pairs, sorted according to js specification.

##Arguments##

  • ctx - JavaScript context
  • flags - Property filter flags
  • kind - Iteration mode (keys, values, or entries)

Similar to JavaScript’s Object.keys(), Object.values(), Object.entries()

Source

pub fn has_own_property( &self, ctx: &ContextImpl, prop: Atom, ) -> Result<bool, i32>

test if own property prop exists.

Source

pub fn has_own_property_str( &self, ctx: &ContextImpl, prop: &str, ) -> Result<bool, i32>

Source

pub fn get_own_property( &mut self, ctx: &ContextImpl, prop: Atom, ) -> Result<Option<JSPropertyDescriptor>, i32>

get description of own property.

Source

pub fn is_extensible(&self, ctx: &ContextImpl) -> Result<bool, i32>

return Err() if exception (Proxy object only) or TRUE/FALSE

Source

pub fn has_property(&self, ctx: &ContextImpl, prop: Atom) -> Result<bool, i32>

Source

pub fn copy_data_properties_from( &mut self, ctx: &ContextImpl, source: &Self, excluded: &Self, setprop: bool, ) -> Result<(), i32>

copy and assign enumerable properties from source value to self. equivelent to js Object::assign(self, source)

Source

pub fn get_length_prop(&self, ctx: &ContextImpl) -> Result<i64, i32>

Read length property defined on self. if length property is null or undefined, returns 0.

Returned length is in range [0, MAX_SAFE_INTEGER]

Source

pub fn set_property( &self, ctx: &ContextImpl, prop: Atom, val: Self, ) -> Result<bool, i32>

Source

pub fn set_property_value( &mut self, ctx: &ContextImpl, prop: Self, val: Self, flags: u32, ) -> Result<bool, i32>

Source

pub fn set_property_u32( &mut self, ctx: &ContextImpl, idx: u32, val: Self, ) -> Result<bool, i32>

Source

pub fn set_property_i64( &mut self, ctx: &ContextImpl, idx: i64, val: Self, ) -> Result<bool, i32>

Source

pub fn set_property_str( &mut self, ctx: &ContextImpl, prop: &str, val: Self, ) -> Result<bool, i32>

Source

pub fn prototype(&self, ctx: &ContextImpl) -> JSResult

Get prototype of value. Returns an object value if it has prototype, NULL for no prototype. Returns Err in case of Proxy object.

Source

pub unsafe fn string_unchecked(&self) -> &StringRef

get a reference to value’s string description. won’t change value’s ref_count. will panic if value is not string type.

Source

pub fn to_string_or_symbol(&self, ctx: &ContextImpl) -> Result<Self, i32>

Convert self to string or symbol value. (string is preferred)

Source

pub fn to_propkey(&self, ctx: &ContextImpl) -> Result<JSValue, i32>

Source

pub fn to_string(&self, ctx: &ContextImpl) -> Result<StringRef, i32>

Coerce value self to string. if self is symbol, will return Err.

Source

pub fn to_string_non_undefined_or_null( &self, ctx: &ContextImpl, ) -> Result<StringRef, i32>

Coerce value val to string, but null or undefined are forbidden.

Source

pub fn to_locale_string(&self, ctx: &ContextImpl) -> Result<JSValue, i32>

Invoking toLocaleString() method.

Source

pub fn type_of(&self) -> Atom

get typeof value, equivalent to js typeof val

Note: returned atom is not cloned, if caller want keep reference, should clone it.

Source

pub fn instance_of(&self, ctx: &ContextImpl, ctor: JSValue) -> Result<bool, i32>

Test if value self is instance of ctor. Equivalent to self instanceof ctor

Source

pub fn to_primitive(&self, ctx: &ContextImpl, hint: i32) -> Result<JSValue, i32>

Coerce value to primitive (non-object) value

Source

pub fn to_bool(&self) -> Result<bool, i32>

coerce value to bool

Source

pub fn inspect(&self, ctx: &ContextImpl) -> Result<String, i32>

Get inspect representation string of self value. inspect() string is only used for interactive prompting, use to_string() for other cases.

Source

pub fn is_exception(&self) -> bool

Source

pub fn is_null(&self) -> bool

Source

pub fn is_undefined(&self) -> bool

Source

pub fn is_undefined_or_null(&self) -> bool

Source

pub fn is_object(&self) -> bool

Source

pub fn is_string(&self) -> bool

Source

pub fn is_symbol(&self) -> bool

Source

pub fn is_bool(&self) -> bool

Source

pub fn is_int(&self) -> bool

Source

pub fn is_float64(&self) -> bool

Source

pub fn is_number(&self) -> bool

Source

pub fn is_module(&self) -> bool

Source

pub fn is_uninitialized(&self) -> bool

Source

pub fn is_htmldda(&self) -> bool

Source

pub fn is_function(&self) -> bool

Test if value self can be called, that means value is a:

  • Compiled bytecode functions
  • Proxy objects that wrapping a function
  • Objects of native class which has call handler
Source

pub fn is_error(&self) -> bool

Source

pub fn as_object_Array(&self) -> Option<&Array>

Source

pub fn as_object_Array_mut(&mut self) -> Option<&mut Array>

Source

pub fn is_array(&self, ctx: &ContextImpl) -> Result<bool, i32>

check if self is an Array object return Err if exception (proxy case) or TRUE/FALSE

Source

pub fn is_fast_array(&self) -> bool

test if value is fast array (could be one of Array, Argument, TypedArray fast array).

Source

pub fn with_fast_array_values<R>( &self, f: impl FnOnce(&[JSValue]) -> R, ) -> Option<R>

if value is Array or Argument class, and is fast array, returns values slice.

Source

pub fn with_fast_array_values_mut<R>( &mut self, f: impl FnOnce(&mut Vec<JSValue>) -> R, ) -> Option<R>

if value is Array or Argument class, and is a fast array, run closure with values slice, otherwise returns None.

Source

pub fn to_array_length( &self, ctx: &ContextImpl, is_array_ctor: bool, ) -> Result<u32, i32>

coerce value to array length, which is in range [0, 2^32-1].

Source

pub fn to_index(&self, ctx: &ContextImpl) -> Result<i64, i32>

coerce value to array index, which is in range [0, MAX_SAFE_INTEGER].

Source

pub fn as_object_ArrayBuffer(&self) -> Option<&ArrayBuffer>

Source

pub fn as_object_ArrayBuffer_mut(&mut self) -> Option<&mut ArrayBuffer>

Source

pub fn as_object_AsyncGeneratorFunction( &self, ) -> Option<&AsyncGeneratorFunction>

Source

pub fn as_object_AsyncGeneratorFunction_mut( &mut self, ) -> Option<&mut AsyncGeneratorFunction>

Source

pub fn as_object_AsyncFromSyncIterator(&self) -> Option<&AsyncFromSyncIterator>

Source

pub fn as_object_AsyncFromSyncIterator_mut( &mut self, ) -> Option<&mut AsyncFromSyncIterator>

Source

pub fn get_iterator( &self, ctx: &ContextImpl, is_async: bool, ) -> Result<Option<Object>, i32>

Get self’s iterator object by calling [Symbol.iterator] or [Symbol.asyncIterator] method.

  • In case when is_async=true and method [Symbol.asyncIterator] is not defined, try wrapping [Symbol.iterator] iterator (if any) into AsyncFromSyncIterator object.

  • If neither [Symbol.iterator] nor [Symbol.asyncIterator] are defined, returns None indicating that self is not iterable.

Source

pub fn get_iterator_must( &self, ctx: &ContextImpl, is_async: bool, ) -> Result<Object, i32>

Same as [get_iterator()], but will raise ‘not iterable’ error if get_iterator() returns None.

Source

pub fn iter<'a>(&self, ctx: &'a ContextImpl) -> Result<ObjectIter<'a>, i32>

Return an object that implements Iterator trait to iterate JSValue. The iterator uses next() method to retrive next value.

Source

pub fn as_object_MapIterator(&self) -> Option<&MapIterator>

Source

pub fn as_object_MapIterator_mut(&mut self) -> Option<&mut MapIterator>

Source

pub fn as_object_MapSet(&self) -> Option<&MapSet>

Source

pub fn as_object_MapSet_mut(&mut self) -> Option<&mut MapSet>

Source

pub fn as_object_Promise(&self) -> Option<&Promise>

Source

pub fn as_object_Promise_mut(&mut self) -> Option<&mut Promise>

Source

pub fn as_object_PromiseResolveFunc(&self) -> Option<&PromiseResolveFunc>

Source

pub fn as_object_PromiseResolveFunc_mut( &mut self, ) -> Option<&mut PromiseResolveFunc>

Source

pub fn as_object_Proxy(&self) -> Option<&Proxy>

Source

pub fn as_object_Proxy_mut(&mut self) -> Option<&mut Proxy>

Source

pub fn as_object_RegExp(&self) -> Option<&RegExp>

Source

pub fn as_object_RegExp_mut(&mut self) -> Option<&mut RegExp>

Source

pub fn as_object_DataView(&self) -> Option<&DataView>

Source

pub fn as_object_DataView_mut(&mut self) -> Option<&mut DataView>

Source

pub fn as_object_TypedArray(&self) -> Option<&TypedArray>

Source

pub fn as_object_TypedArray_mut(&mut self) -> Option<&mut TypedArray>

Trait Implementations§

Source§

impl<'a> Clone for Value<'a>

Source§

fn clone(&self) -> Value<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Value<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Deref for Value<'a>

Source§

type Target = JSValue

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<'a> DerefMut for Value<'a>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<'a> From<JSValue> for Value<'a>

Source§

fn from(value: JSValue) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<Value<'a>> for JSValue

Source§

fn from(value: Value<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a> Copy for Value<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Value<'a>

§

impl<'a> !RefUnwindSafe for Value<'a>

§

impl<'a> !Send for Value<'a>

§

impl<'a> !Sync for Value<'a>

§

impl<'a> Unpin for Value<'a>

§

impl<'a> !UnwindSafe for Value<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.