pub enum JsValue {
Null,
Undefined,
Boolean(bool),
String(JsString),
Rational(f64),
Integer(i32),
BigInt(JsBigInt),
Object(JsObject),
Symbol(JsSymbol),
}
Expand description
A Javascript value
Variants§
Null
null
- A null value, for when a value doesn’t exist.
Undefined
undefined
- An undefined value, for when a field or index doesn’t exist.
Boolean(bool)
boolean
- A true
/ false
value, for if a certain criteria is met.
String(JsString)
String
- A UTF-8 string, such as "Hello, world"
.
Rational(f64)
Number
- A 64-bit floating point number, such as 3.1415
Integer(i32)
Number
- A 32-bit integer, such as 42
.
BigInt(JsBigInt)
BigInt
- holds any arbitrary large signed integer.
Object(JsObject)
Object
- An object, such as Math
, represented by a binary tree of string keys to Javascript values.
Symbol(JsSymbol)
Symbol
- A Symbol Primitive type.
Implementations§
Source§impl JsValue
impl JsValue
Sourcepub fn strict_equals(&self, other: &Self) -> bool
pub fn strict_equals(&self, other: &Self) -> bool
Strict equality comparison.
This method is executed when doing strict equality comparisons with the ===
operator.
For more information, check https://tc39.es/ecma262/#sec-strict-equality-comparison.
Sourcepub fn equals(&self, other: &Self, context: &mut Context) -> JsResult<bool>
pub fn equals(&self, other: &Self, context: &mut Context) -> JsResult<bool>
Abstract equality comparison.
This method is executed when doing abstract equality comparisons with the ==
operator.
For more information, check https://tc39.es/ecma262/#sec-abstract-equality-comparison
Sourcepub fn same_value(x: &JsValue, y: &JsValue) -> bool
pub fn same_value(x: &JsValue, y: &JsValue) -> bool
The internal comparison abstract operation SameValue(x, y), where x and y are ECMAScript language values, produces true or false.
More information:
Sourcepub fn same_value_zero(x: &JsValue, y: &JsValue) -> bool
pub fn same_value_zero(x: &JsValue, y: &JsValue) -> bool
The internal comparison abstract operation SameValueZero(x, y)
,
where x
and y
are ECMAScript language values, produces true
or false
.
SameValueZero
differs from SameValue only in its treatment of +0
and -0
.
More information:
Source§impl JsValue
impl JsValue
pub fn add(&self, other: &Self, context: &mut Context) -> JsResult<JsValue>
pub fn sub(&self, other: &Self, context: &mut Context) -> JsResult<JsValue>
pub fn mul(&self, other: &Self, context: &mut Context) -> JsResult<JsValue>
pub fn div(&self, other: &Self, context: &mut Context) -> JsResult<JsValue>
pub fn rem(&self, other: &Self, context: &mut Context) -> JsResult<JsValue>
pub fn pow(&self, other: &Self, context: &mut Context) -> JsResult<JsValue>
pub fn bitand(&self, other: &Self, context: &mut Context) -> JsResult<JsValue>
pub fn bitor(&self, other: &Self, context: &mut Context) -> JsResult<JsValue>
pub fn bitxor(&self, other: &Self, context: &mut Context) -> JsResult<JsValue>
pub fn shl(&self, other: &Self, context: &mut Context) -> JsResult<JsValue>
pub fn shr(&self, other: &Self, context: &mut Context) -> JsResult<JsValue>
pub fn ushr(&self, other: &Self, context: &mut Context) -> JsResult<JsValue>
pub fn neg(&self, context: &mut Context) -> JsResult<JsValue>
pub fn not(&self, _: &mut Context) -> JsResult<bool>
Sourcepub fn abstract_relation(
&self,
other: &Self,
left_first: bool,
context: &mut Context,
) -> JsResult<AbstractRelation>
pub fn abstract_relation( &self, other: &Self, left_first: bool, context: &mut Context, ) -> JsResult<AbstractRelation>
Abstract relational comparison
The comparison x < y
, where x
and y
are values, produces true
, false
,
or undefined
(which indicates that at least one operand is NaN
).
In addition to x
and y
the algorithm takes a Boolean flag named LeftFirst
as a parameter.
The flag is used to control the order in which operations with potentially visible side-effects
are performed upon x
and y
. It is necessary because ECMAScript specifies left to right evaluation
of expressions. The default value of LeftFirst is true
and indicates that the x
parameter
corresponds to an expression that occurs to the left of the y
parameter’s corresponding expression.
If LeftFirst
is false
, the reverse is the case and operations must be performed upon y
before x
.
More Information:
Sourcepub fn lt(&self, other: &Self, context: &mut Context) -> JsResult<bool>
pub fn lt(&self, other: &Self, context: &mut Context) -> JsResult<bool>
The less than operator (<
) returns true
if the left operand is less than the right operand,
and false
otherwise.
More Information:
Sourcepub fn le(&self, other: &Self, context: &mut Context) -> JsResult<bool>
pub fn le(&self, other: &Self, context: &mut Context) -> JsResult<bool>
The less than or equal operator (<=
) returns true
if the left operand is less than
or equal to the right operand, and false
otherwise.
More Information:
Sourcepub fn gt(&self, other: &Self, context: &mut Context) -> JsResult<bool>
pub fn gt(&self, other: &Self, context: &mut Context) -> JsResult<bool>
The greater than operator (>
) returns true
if the left operand is greater than
the right operand, and false
otherwise.
More Information:
Source§impl JsValue
impl JsValue
Sourcepub fn get_type(&self) -> Type
pub fn get_type(&self) -> Type
Get the type of a value
This is the abstract operation Type(v), as described in https://tc39.es/ecma262/multipage/ecmascript-data-types-and-values.html#sec-ecmascript-language-types.
Check JsValue::type_of if you need to call the typeof
operator.
Source§impl JsValue
impl JsValue
Sourcepub fn positive_inifnity() -> Self
pub fn positive_inifnity() -> Self
Creates a new number with Infinity
value.
Sourcepub fn negative_inifnity() -> Self
pub fn negative_inifnity() -> Self
Creates a new number with -Infinity
value.
pub fn as_object(&self) -> Option<JsObject>
pub fn as_symbol(&self) -> Option<JsSymbol>
Sourcepub fn is_function(&self) -> bool
pub fn is_function(&self) -> bool
Returns true if the value is a function
Sourcepub fn is_undefined(&self) -> bool
pub fn is_undefined(&self) -> bool
Returns true if the value is undefined.
Sourcepub fn is_null_or_undefined(&self) -> bool
pub fn is_null_or_undefined(&self) -> bool
Returns true if the value is null or undefined.
Sourcepub fn is_integer(&self) -> bool
pub fn is_integer(&self) -> bool
Returns true if the value is integer.
pub fn as_number(&self) -> Option<f64>
Sourcepub fn as_string(&self) -> Option<&JsString>
pub fn as_string(&self) -> Option<&JsString>
Returns the string if the values is a string, otherwise None
.
Sourcepub fn is_boolean(&self) -> bool
pub fn is_boolean(&self) -> bool
Returns true if the value is a boolean.
pub fn as_boolean(&self) -> Option<bool>
Sourcepub fn as_bigint(&self) -> Option<&JsBigInt>
pub fn as_bigint(&self) -> Option<&JsBigInt>
Returns an optional reference to a BigInt
if the value is a BigInt primitive.
Sourcepub fn to_boolean(&self) -> bool
pub fn to_boolean(&self) -> bool
Sourcepub fn set_data(&self, data: ObjectData)
pub fn set_data(&self, data: ObjectData)
Set the kind of an object.
Sourcepub fn to_primitive(
&self,
context: &mut Context,
preferred_type: PreferredType,
) -> JsResult<JsValue>
pub fn to_primitive( &self, context: &mut Context, preferred_type: PreferredType, ) -> JsResult<JsValue>
The abstract operation ToPrimitive takes an input argument and an optional argument PreferredType.
Sourcepub fn to_bigint(&self, context: &mut Context) -> JsResult<JsBigInt>
pub fn to_bigint(&self, context: &mut Context) -> JsResult<JsBigInt>
Converts the value to a BigInt
.
This function is equivelent to BigInt(value)
in JavaScript.
Sourcepub fn display(&self) -> ValueDisplay<'_>
pub fn display(&self) -> ValueDisplay<'_>
Returns an object that implements Display
.
§Examples
use boa::JsValue;
let value = JsValue::new(3);
println!("{}", value.display());
Sourcepub fn to_string(&self, context: &mut Context) -> JsResult<JsString>
pub fn to_string(&self, context: &mut Context) -> JsResult<JsString>
Converts the value to a string.
This function is equivalent to String(value)
in JavaScript.
Sourcepub fn to_object(&self, context: &mut Context) -> JsResult<JsObject>
pub fn to_object(&self, context: &mut Context) -> JsResult<JsObject>
Converts the value to an Object.
This function is equivalent to Object(value)
in JavaScript
Sourcepub fn to_property_key(&self, context: &mut Context) -> JsResult<PropertyKey>
pub fn to_property_key(&self, context: &mut Context) -> JsResult<PropertyKey>
Converts the value to a PropertyKey
, that can be used as a key for properties.
Sourcepub fn to_numeric(&self, context: &mut Context) -> JsResult<Numeric>
pub fn to_numeric(&self, context: &mut Context) -> JsResult<Numeric>
It returns value converted to a numeric value of type Number
or BigInt
.
Sourcepub fn to_u32(&self, context: &mut Context) -> JsResult<u32>
pub fn to_u32(&self, context: &mut Context) -> JsResult<u32>
Converts a value to an integral 32 bit unsigned integer.
This function is equivalent to value | 0
in JavaScript
Sourcepub fn to_i32(&self, context: &mut Context) -> JsResult<i32>
pub fn to_i32(&self, context: &mut Context) -> JsResult<i32>
Converts a value to an integral 32 bit signed integer.
Sourcepub fn to_index(&self, context: &mut Context) -> JsResult<usize>
pub fn to_index(&self, context: &mut Context) -> JsResult<usize>
Converts a value to a non-negative integer if it is a valid integer index value.
Sourcepub fn to_length(&self, context: &mut Context) -> JsResult<usize>
pub fn to_length(&self, context: &mut Context) -> JsResult<usize>
Converts argument to an integer suitable for use as the length of an array-like object.
Sourcepub fn to_integer(&self, context: &mut Context) -> JsResult<f64>
pub fn to_integer(&self, context: &mut Context) -> JsResult<f64>
Converts a value to an integral Number value.
Sourcepub fn to_number(&self, context: &mut Context) -> JsResult<f64>
pub fn to_number(&self, context: &mut Context) -> JsResult<f64>
Converts a value to a double precision floating point.
This function is equivalent to the unary +
operator (+value
) in JavaScript
Sourcepub fn to_numeric_number(&self, context: &mut Context) -> JsResult<f64>
pub fn to_numeric_number(&self, context: &mut Context) -> JsResult<f64>
This is a more specialized version of to_numeric
, including BigInt
.
This function is equivalent to Number(value)
in JavaScript
Sourcepub fn require_object_coercible(
&self,
context: &mut Context,
) -> JsResult<&JsValue>
pub fn require_object_coercible( &self, context: &mut Context, ) -> JsResult<&JsValue>
Check if the Value
can be converted to an Object
The abstract operation RequireObjectCoercible
takes argument argument.
It throws an error if argument is a value that cannot be converted to an Object using ToObject
.
It is defined by Table 15
More information:
pub fn to_property_descriptor( &self, context: &mut Context, ) -> JsResult<PropertyDescriptor>
Sourcepub fn to_integer_or_infinity(
&self,
context: &mut Context,
) -> JsResult<IntegerOrInfinity>
pub fn to_integer_or_infinity( &self, context: &mut Context, ) -> JsResult<IntegerOrInfinity>
Converts argument to an integer, +∞, or -∞.
Trait Implementations§
Source§impl From<&PropertyKey> for JsValue
impl From<&PropertyKey> for JsValue
Source§fn from(property_key: &PropertyKey) -> JsValue
fn from(property_key: &PropertyKey) -> JsValue
Source§impl From<PropertyKey> for JsValue
impl From<PropertyKey> for JsValue
Source§fn from(property_key: PropertyKey) -> JsValue
fn from(property_key: PropertyKey) -> JsValue
Source§impl Trace for JsValue
impl Trace for JsValue
Source§fn finalize_glue(&self)
fn finalize_glue(&self)
impl Eq for JsValue
Auto Trait Implementations§
impl !Freeze for JsValue
impl !RefUnwindSafe for JsValue
impl !Send for JsValue
impl !Sync for JsValue
impl Unpin for JsValue
impl !UnwindSafe for JsValue
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.