pub struct Value<'a> { /* private fields */ }Expand description
Value with lifetime
Methods from Deref<Target = JSValue>§
Sourcepub fn to_atom(&self, ctx: &ContextImpl) -> Result<Atom, i32>
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.
Sourcepub fn arith_cmp(
&self,
ctx: &ContextImpl,
other: JSValue,
) -> Result<Option<Ordering>, i32>
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
Sourcepub fn arith_eq(&self, ctx: &ContextImpl, other: Self) -> Result<bool, i32>
pub fn arith_eq(&self, ctx: &ContextImpl, other: Self) -> Result<bool, i32>
test arithmatical equality (no-strict-eq): self == other?
Sourcepub fn is_same(&self, other: Self) -> bool
pub fn is_same(&self, other: Self) -> bool
test if two values are strictly same. (-0, 0) not same
Sourcepub fn is_same0(&self, other: Self) -> bool
pub fn is_same0(&self, other: Self) -> bool
test if two values are strictly same. (-0, 0) is same
Sourcepub fn sort_cmp(&self, ctx: &ContextImpl, other: Self) -> Result<Ordering, i32>
pub fn sort_cmp(&self, ctx: &ContextImpl, other: Self) -> Result<Ordering, i32>
get order of self and other.
Sourcepub fn opaque(&self) -> Option<NonNull<c_void>>
pub fn opaque(&self) -> Option<NonNull<c_void>>
if the value is a user class instance, returns the opaque pointer if available
pub fn opaque_ref<T>(&self) -> Option<&T>
pub fn as_object_AsyncFunction(&self) -> Option<&AsyncFunction>
pub fn as_object_AsyncFunction_mut(&mut self) -> Option<&mut AsyncFunction>
Sourcepub fn call_async(
&self,
ctx: &mut ContextImpl,
this_obj: JSValue,
args: &[JSValue],
flags: i32,
) -> Result<Promise, i32>
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
pub fn as_object_BCFunction(&self) -> Option<&BCFunction>
pub fn as_object_BCFunction_mut(&mut self) -> Option<&mut BCFunction>
Sourcepub fn ensure_function(&self, ctx: &ContextImpl) -> Result<&Self, i32>
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.
pub fn as_object_BytecodeFunction(&self) -> Option<&BytecodeFunction>
pub fn as_object_BytecodeFunction_mut( &mut self, ) -> Option<&mut BytecodeFunction>
pub fn as_object_BoundFunction(&self) -> Option<&BoundFunction>
pub fn as_object_BoundFunction_mut(&mut self) -> Option<&mut BoundFunction>
Sourcepub fn call(
&self,
ctx: &ContextImpl,
this_obj: JSValue,
args: &[JSValue],
) -> JSResult
pub fn call( &self, ctx: &ContextImpl, this_obj: JSValue, args: &[JSValue], ) -> JSResult
call self value. if value is not callable, returns ‘not function error’.
Sourcepub fn invoke(
&self,
ctx: &ContextImpl,
method: Atom,
args: &[JSValue],
) -> JSResult
pub fn invoke( &self, ctx: &ContextImpl, method: Atom, args: &[JSValue], ) -> JSResult
call function self.method
Sourcepub fn invoke_defined(
&self,
ctx: &ContextImpl,
method: Atom,
args: &[JSValue],
) -> Result<Option<JSResult>, i32>
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.
Sourcepub fn invoke_callable(
&self,
ctx: &ContextImpl,
method: Atom,
args: &[JSValue],
) -> Result<Option<JSResult>, i32>
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
pub fn as_object_NativeFunctionWithData( &self, ) -> Option<&NativeFunctionWithData>
pub fn as_object_NativeFunctionWithData_mut( &mut self, ) -> Option<&mut NativeFunctionWithData>
Sourcepub fn match_native_callback(&self, callback: Callback, magic: i32) -> bool
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.
pub fn install_fields( &mut self, ctx: &ContextImpl, entries: &'static [FieldDef], ) -> Result<(), i32>
Sourcepub fn is_integral(&self, ctx: &ContextImpl) -> Result<bool, i32>
pub fn is_integral(&self, ctx: &ContextImpl) -> Result<bool, i32>
test if the value is an intergral number. returns Err if test has exception.
Sourcepub fn to_number(&self, ctx: &ContextImpl) -> Result<JSValue, i32>
pub fn to_number(&self, ctx: &ContextImpl) -> Result<JSValue, i32>
Convert value to number Int or Float64 (could be NaN).
Sourcepub fn to_numeric(&self, ctx: &ContextImpl) -> Result<JSValue, i32>
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()
pub fn coerce_to_u8_clamp(&self, ctx: &ContextImpl) -> Result<u8, i32>
pub fn to_i32_saturating(&self, ctx: &ContextImpl) -> Result<i32, i32>
pub fn to_i32_clamp( &self, ctx: &ContextImpl, min: i32, max: i32, min_offset: i32, ) -> Result<i32, i32>
pub fn to_u32(&self, ctx: &ContextImpl) -> Result<u32, i32>
pub fn to_i64_saturating(&self, ctx: &ContextImpl) -> Result<i64, i32>
Sourcepub fn to_i64_clamp(
&self,
ctx: &ContextImpl,
min: i64,
max: i64,
neg_offset: i64,
) -> Result<i64, i32>
pub fn to_i64_clamp( &self, ctx: &ContextImpl, min: i64, max: i64, neg_offset: i64, ) -> Result<i64, i32>
[min, max] is inclusive range.
Sourcepub fn to_length(&self, ctx: &ContextImpl) -> Result<i64, i32>
pub fn to_length(&self, ctx: &ContextImpl) -> Result<i64, i32>
convert value to length between [0, MAX_SAFE_INTEGER].
pub fn as_object(&self) -> Option<&Object>
pub fn as_object_mut(&mut self) -> Option<&mut Object>
pub unsafe fn as_object_unchecked(&self) -> &Object
pub unsafe fn as_object_mut_unchecked(&mut self) -> &mut Object
Sourcepub fn objectify(&self, ctx: &ContextImpl) -> Result<Object, i32>
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
pub fn is_constructor(&self) -> bool
pub fn prevent_extensions(&mut self, ctx: &ContextImpl) -> Result<bool, i32>
Sourcepub fn seal(&mut self, ctx: &ContextImpl, freeze: bool) -> Result<(), i32>
pub fn seal(&mut self, ctx: &ContextImpl, freeze: bool) -> Result<(), i32>
Seal self if it is an object.
Sourcepub fn is_sealed(
&mut self,
ctx: &ContextImpl,
is_frozen: bool,
) -> Result<bool, i32>
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.
Sourcepub fn retrive_object_payload(
&self,
ctx: &ContextImpl,
class_id: ClassID,
) -> Result<&ObjectPayload, i32>
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.
Sourcepub fn retrive_object_payload_mut(
&mut self,
ctx: &ContextImpl,
class_id: ClassID,
) -> Result<&mut ObjectPayload, i32>
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.
Sourcepub fn check_brand(&self, ctx: &ContextImpl, func: JSValue) -> Result<bool, i32>
pub fn check_brand(&self, ctx: &ContextImpl, func: JSValue) -> Result<bool, i32>
check if self has own property suggested by func.<home_object>.<brand>.
Sourcepub fn add_brand(
&mut self,
ctx: &ContextImpl,
home_obj: JSValue,
) -> Result<(), i32>
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.
pub fn set_private_field( &mut self, ctx: &ContextImpl, name: JSValue, val: JSValue, ) -> Result<(), i32>
pub fn get_private_field(&self, ctx: &ContextImpl, name: JSValue) -> JSResult
Sourcepub fn define_private_field(
&mut self,
ctx: &ContextImpl,
name: JSValue,
val: JSValue,
) -> Result<(), i32>
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
Sourcepub fn define_property_value(
&mut self,
ctx: &ContextImpl,
prop: Atom,
value: JSValue,
flags: u32,
) -> Result<bool, i32>
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.
pub fn define_property_value_str( &mut self, ctx: &ContextImpl, prop: &str, val: JSValue, flags: u32, ) -> Result<bool, i32>
pub fn define_property_value_u32( &mut self, ctx: &ContextImpl, idx: u32, val: JSValue, flags: u32, ) -> Result<bool, i32>
pub fn define_property_value_i64( &mut self, ctx: &ContextImpl, idx: i64, val: JSValue, flags: u32, ) -> Result<bool, i32>
pub fn define_property_getset( &mut self, ctx: &ContextImpl, prop: Atom, getter: JSValue, setter: JSValue, flags: u32, ) -> Result<bool, i32>
pub fn create_data_property_u32( &mut self, ctx: &ContextImpl, idx: i64, val: JSValue, flags: u32, ) -> Result<bool, i32>
Sourcepub fn delete_property(
&mut self,
ctx: &ContextImpl,
prop: Atom,
flags: u32,
) -> Result<bool, i32>
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
pub fn delete_property_i64( &mut self, ctx: &ContextImpl, idx: i64, flags: u32, ) -> Result<bool, i32>
Sourcepub fn get_property(&self, ctx: &ContextImpl, prop: Atom) -> JSResult
pub fn get_property(&self, ctx: &ContextImpl, prop: Atom) -> JSResult
get property by prop atom
Sourcepub fn get_property_value(&self, ctx: &ContextImpl, prop: JSValue) -> JSResult
pub fn get_property_value(&self, ctx: &ContextImpl, prop: JSValue) -> JSResult
get property by prop value
Sourcepub fn get_property_str(&self, ctx: &ContextImpl, prop: &str) -> JSResult
pub fn get_property_str(&self, ctx: &ContextImpl, prop: &str) -> JSResult
get property by str prop
Sourcepub fn get_property_u32(&self, ctx: &ContextImpl, idx: u32) -> JSResult
pub fn get_property_u32(&self, ctx: &ContextImpl, idx: u32) -> JSResult
get property by u32 prop
pub fn get_property_i64(&self, ctx: &ContextImpl, idx: i64) -> JSResult
Sourcepub fn try_get_property_i64(
&self,
ctx: &ContextImpl,
idx: i64,
) -> Result<Option<JSValue>, i32>
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.
Sourcepub fn get_own_property_kvs(
&self,
ctx: &ContextImpl,
flags: i32,
kind: JSIteratorKindEnum,
) -> Result<Box<[(JSValue, JSValue)]>, i32>
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 contextflags- Property filter flagskind- Iteration mode (keys, values, or entries)
Similar to JavaScript’s Object.keys(), Object.values(), Object.entries()
Sourcepub fn has_own_property(
&self,
ctx: &ContextImpl,
prop: Atom,
) -> Result<bool, i32>
pub fn has_own_property( &self, ctx: &ContextImpl, prop: Atom, ) -> Result<bool, i32>
test if own property prop exists.
pub fn has_own_property_str( &self, ctx: &ContextImpl, prop: &str, ) -> Result<bool, i32>
Sourcepub fn get_own_property(
&mut self,
ctx: &ContextImpl,
prop: Atom,
) -> Result<Option<JSPropertyDescriptor>, i32>
pub fn get_own_property( &mut self, ctx: &ContextImpl, prop: Atom, ) -> Result<Option<JSPropertyDescriptor>, i32>
get description of own property.
Sourcepub fn is_extensible(&self, ctx: &ContextImpl) -> Result<bool, i32>
pub fn is_extensible(&self, ctx: &ContextImpl) -> Result<bool, i32>
return Err() if exception (Proxy object only) or TRUE/FALSE
pub fn has_property(&self, ctx: &ContextImpl, prop: Atom) -> Result<bool, i32>
Sourcepub fn copy_data_properties_from(
&mut self,
ctx: &ContextImpl,
source: &Self,
excluded: &Self,
setprop: bool,
) -> Result<(), i32>
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)
Sourcepub fn get_length_prop(&self, ctx: &ContextImpl) -> Result<i64, i32>
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]
pub fn set_property( &self, ctx: &ContextImpl, prop: Atom, val: Self, ) -> Result<bool, i32>
pub fn set_property_value( &mut self, ctx: &ContextImpl, prop: Self, val: Self, flags: u32, ) -> Result<bool, i32>
pub fn set_property_u32( &mut self, ctx: &ContextImpl, idx: u32, val: Self, ) -> Result<bool, i32>
pub fn set_property_i64( &mut self, ctx: &ContextImpl, idx: i64, val: Self, ) -> Result<bool, i32>
pub fn set_property_str( &mut self, ctx: &ContextImpl, prop: &str, val: Self, ) -> Result<bool, i32>
Sourcepub fn prototype(&self, ctx: &ContextImpl) -> JSResult
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.
Sourcepub unsafe fn string_unchecked(&self) -> &StringRef
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.
Sourcepub fn to_string_or_symbol(&self, ctx: &ContextImpl) -> Result<Self, i32>
pub fn to_string_or_symbol(&self, ctx: &ContextImpl) -> Result<Self, i32>
Convert self to string or symbol value. (string is preferred)
Sourcepub fn to_propkey(&self, ctx: &ContextImpl) -> Result<JSValue, i32>
pub fn to_propkey(&self, ctx: &ContextImpl) -> Result<JSValue, i32>
An alias for JSValue::to_string_or_symbol.
Sourcepub fn to_string(&self, ctx: &ContextImpl) -> Result<StringRef, i32>
pub fn to_string(&self, ctx: &ContextImpl) -> Result<StringRef, i32>
Coerce value self to string.
if self is symbol, will return Err.
Sourcepub fn to_string_non_undefined_or_null(
&self,
ctx: &ContextImpl,
) -> Result<StringRef, i32>
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.
Sourcepub fn to_locale_string(&self, ctx: &ContextImpl) -> Result<JSValue, i32>
pub fn to_locale_string(&self, ctx: &ContextImpl) -> Result<JSValue, i32>
Invoking toLocaleString() method.
Sourcepub fn type_of(&self) -> Atom
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.
Sourcepub fn instance_of(&self, ctx: &ContextImpl, ctor: JSValue) -> Result<bool, i32>
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
Sourcepub fn to_primitive(&self, ctx: &ContextImpl, hint: i32) -> Result<JSValue, i32>
pub fn to_primitive(&self, ctx: &ContextImpl, hint: i32) -> Result<JSValue, i32>
Coerce value to primitive (non-object) value
Sourcepub fn inspect(&self, ctx: &ContextImpl) -> Result<String, i32>
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.
pub fn is_exception(&self) -> bool
pub fn is_null(&self) -> bool
pub fn is_undefined(&self) -> bool
pub fn is_undefined_or_null(&self) -> bool
pub fn is_object(&self) -> bool
pub fn is_string(&self) -> bool
pub fn is_symbol(&self) -> bool
pub fn is_bool(&self) -> bool
pub fn is_int(&self) -> bool
pub fn is_float64(&self) -> bool
pub fn is_number(&self) -> bool
pub fn is_module(&self) -> bool
pub fn is_uninitialized(&self) -> bool
pub fn is_htmldda(&self) -> bool
Sourcepub fn is_function(&self) -> bool
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
callhandler
pub fn is_error(&self) -> bool
pub fn as_object_Array(&self) -> Option<&Array>
pub fn as_object_Array_mut(&mut self) -> Option<&mut Array>
Sourcepub fn is_array(&self, ctx: &ContextImpl) -> Result<bool, i32>
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
Sourcepub fn is_fast_array(&self) -> bool
pub fn is_fast_array(&self) -> bool
test if value is fast array (could be one of Array, Argument, TypedArray fast array).
Sourcepub fn with_fast_array_values<R>(
&self,
f: impl FnOnce(&[JSValue]) -> R,
) -> Option<R>
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.
Sourcepub fn with_fast_array_values_mut<R>(
&mut self,
f: impl FnOnce(&mut Vec<JSValue>) -> R,
) -> Option<R>
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.
Sourcepub fn to_array_length(
&self,
ctx: &ContextImpl,
is_array_ctor: bool,
) -> Result<u32, i32>
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].
Sourcepub fn to_index(&self, ctx: &ContextImpl) -> Result<i64, i32>
pub fn to_index(&self, ctx: &ContextImpl) -> Result<i64, i32>
coerce value to array index, which is in range [0, MAX_SAFE_INTEGER].
pub fn as_object_ArrayBuffer(&self) -> Option<&ArrayBuffer>
pub fn as_object_ArrayBuffer_mut(&mut self) -> Option<&mut ArrayBuffer>
pub fn as_object_AsyncGeneratorFunction( &self, ) -> Option<&AsyncGeneratorFunction>
pub fn as_object_AsyncGeneratorFunction_mut( &mut self, ) -> Option<&mut AsyncGeneratorFunction>
pub fn as_object_AsyncFromSyncIterator(&self) -> Option<&AsyncFromSyncIterator>
pub fn as_object_AsyncFromSyncIterator_mut( &mut self, ) -> Option<&mut AsyncFromSyncIterator>
Sourcepub fn get_iterator(
&self,
ctx: &ContextImpl,
is_async: bool,
) -> Result<Option<Object>, i32>
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 thatselfis not iterable.
Sourcepub fn get_iterator_must(
&self,
ctx: &ContextImpl,
is_async: bool,
) -> Result<Object, i32>
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.
Sourcepub fn iter<'a>(&self, ctx: &'a ContextImpl) -> Result<ObjectIter<'a>, i32>
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.