Enum JsValue

Source
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

Source

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.

Source

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

Source

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:

Source

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

Source

pub fn add(&self, other: &Self, context: &mut Context) -> JsResult<JsValue>

Source

pub fn sub(&self, other: &Self, context: &mut Context) -> JsResult<JsValue>

Source

pub fn mul(&self, other: &Self, context: &mut Context) -> JsResult<JsValue>

Source

pub fn div(&self, other: &Self, context: &mut Context) -> JsResult<JsValue>

Source

pub fn rem(&self, other: &Self, context: &mut Context) -> JsResult<JsValue>

Source

pub fn pow(&self, other: &Self, context: &mut Context) -> JsResult<JsValue>

Source

pub fn bitand(&self, other: &Self, context: &mut Context) -> JsResult<JsValue>

Source

pub fn bitor(&self, other: &Self, context: &mut Context) -> JsResult<JsValue>

Source

pub fn bitxor(&self, other: &Self, context: &mut Context) -> JsResult<JsValue>

Source

pub fn shl(&self, other: &Self, context: &mut Context) -> JsResult<JsValue>

Source

pub fn shr(&self, other: &Self, context: &mut Context) -> JsResult<JsValue>

Source

pub fn ushr(&self, other: &Self, context: &mut Context) -> JsResult<JsValue>

Source

pub fn neg(&self, context: &mut Context) -> JsResult<JsValue>

Source

pub fn not(&self, _: &mut Context) -> JsResult<bool>

Source

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:

Source

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:

Source

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:

Source

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

pub fn ge(&self, other: &Self, context: &mut Context) -> JsResult<bool>

The greater than or equal operator (>=) returns true if the left operand is greater than or equal to the right operand, and false otherwise.

More Information:

Source§

impl JsValue

Source

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

Source

pub fn new<T>(value: T) -> Self
where T: Into<Self>,

Create a new JsValue.

Source

pub fn undefined() -> Self

Creates a new undefined value.

Source

pub fn null() -> Self

Creates a new null value.

Source

pub fn nan() -> Self

Creates a new number with NaN value.

Source

pub fn positive_inifnity() -> Self

Creates a new number with Infinity value.

Source

pub fn negative_inifnity() -> Self

Creates a new number with -Infinity value.

Source

pub fn is_object(&self) -> bool

Returns true if the value is an object

Source

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

Source

pub fn is_symbol(&self) -> bool

Returns true if the value is a symbol.

Source

pub fn as_symbol(&self) -> Option<JsSymbol>

Source

pub fn is_function(&self) -> bool

Returns true if the value is a function

Source

pub fn is_undefined(&self) -> bool

Returns true if the value is undefined.

Source

pub fn is_null(&self) -> bool

Returns true if the value is null.

Source

pub fn is_null_or_undefined(&self) -> bool

Returns true if the value is null or undefined.

Source

pub fn is_double(&self) -> bool

Returns true if the value is a 64-bit floating-point number.

Source

pub fn is_integer(&self) -> bool

Returns true if the value is integer.

Source

pub fn is_number(&self) -> bool

Returns true if the value is a number.

Source

pub fn as_number(&self) -> Option<f64>

Source

pub fn is_string(&self) -> bool

Returns true if the value is a string.

Source

pub fn as_string(&self) -> Option<&JsString>

Returns the string if the values is a string, otherwise None.

Source

pub fn is_boolean(&self) -> bool

Returns true if the value is a boolean.

Source

pub fn as_boolean(&self) -> Option<bool>

Source

pub fn is_bigint(&self) -> bool

Returns true if the value is a bigint.

Source

pub fn as_bigint(&self) -> Option<&JsBigInt>

Returns an optional reference to a BigInt if the value is a BigInt primitive.

Source

pub fn to_boolean(&self) -> bool

Converts the value to a bool type.

More information:

Source

pub fn set_data(&self, data: ObjectData)

Set the kind of an object.

Source

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.

https://tc39.es/ecma262/#sec-toprimitive

Source

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.

Source

pub fn display(&self) -> ValueDisplay<'_>

Returns an object that implements Display.

§Examples
use boa::JsValue;

let value = JsValue::new(3);

println!("{}", value.display());
Source

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.

Source

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

See: https://tc39.es/ecma262/#sec-toobject

Source

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.

See https://tc39.es/ecma262/#sec-topropertykey

Source

pub fn to_numeric(&self, context: &mut Context) -> JsResult<Numeric>

It returns value converted to a numeric value of type Number or BigInt.

See: https://tc39.es/ecma262/#sec-tonumeric

Source

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

See: https://tc39.es/ecma262/#sec-touint32

Source

pub fn to_i32(&self, context: &mut Context) -> JsResult<i32>

Converts a value to an integral 32 bit signed integer.

See: https://tc39.es/ecma262/#sec-toint32

Source

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.

See: https://tc39.es/ecma262/#sec-toindex

Source

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.

See: https://tc39.es/ecma262/#sec-tolength

Source

pub fn to_integer(&self, context: &mut Context) -> JsResult<f64>

Converts a value to an integral Number value.

See: https://tc39.es/ecma262/#sec-tointeger

Source

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

See: https://tc39.es/ecma262/#sec-tonumber

Source

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

See: https://tc39.es/ecma262/#sec-tonumeric

Source

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:

Source

pub fn to_property_descriptor( &self, context: &mut Context, ) -> JsResult<PropertyDescriptor>

Source

pub fn to_integer_or_infinity( &self, context: &mut Context, ) -> JsResult<IntegerOrInfinity>

Converts argument to an integer, +∞, or -∞.

See: https://tc39.es/ecma262/#sec-tointegerorinfinity

Source

pub fn type_of(&self) -> JsString

typeof operator. Returns a string representing the type of the given ECMA Value.

More information:

Trait Implementations§

Source§

impl Clone for JsValue

Source§

fn clone(&self) -> JsValue

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 Debug for JsValue

Source§

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

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

impl Default for JsValue

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drop for JsValue

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Finalize for JsValue

Source§

impl<T> From<&[T]> for JsValue
where T: Clone + Into<JsValue>,

Source§

fn from(value: &[T]) -> Self

Converts to this type from the input type.
Source§

impl From<&JsValue> for JsValue

Source§

fn from(value: &JsValue) -> Self

Converts to this type from the input type.
Source§

impl From<&PropertyKey> for JsValue

Source§

fn from(property_key: &PropertyKey) -> JsValue

Converts to this type from the input type.
Source§

impl From<()> for JsValue

Source§

fn from(_: ()) -> Self

Converts to this type from the input type.
Source§

impl From<JsBigInt> for JsValue

Source§

fn from(value: JsBigInt) -> Self

Converts to this type from the input type.
Source§

impl From<JsObject> for JsValue

Source§

fn from(object: JsObject) -> Self

Converts to this type from the input type.
Source§

impl From<JsSymbol> for JsValue

Source§

fn from(value: JsSymbol) -> Self

Converts to this type from the input type.
Source§

impl From<Numeric> for JsValue

Source§

fn from(value: Numeric) -> Self

Converts to this type from the input type.
Source§

impl From<Object> for JsValue

Source§

fn from(object: Object) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Option<T>> for JsValue
where T: Into<JsValue>,

Source§

fn from(value: Option<T>) -> Self

Converts to this type from the input type.
Source§

impl From<PropertyKey> for JsValue

Source§

fn from(property_key: PropertyKey) -> JsValue

Converts to this type from the input type.
Source§

impl<T> From<T> for JsValue
where T: Into<JsString>,

Source§

fn from(value: T) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Vec<T>> for JsValue
where T: Into<JsValue>,

Source§

fn from(value: Vec<T>) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for JsValue

Source§

fn from(value: bool) -> Self

Converts to this type from the input type.
Source§

impl From<char> for JsValue

Source§

fn from(value: char) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for JsValue

Source§

fn from(value: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for JsValue

Source§

fn from(value: i32) -> JsValue

Converts to this type from the input type.
Source§

impl From<i64> for JsValue

Source§

fn from(value: i64) -> JsValue

Converts to this type from the input type.
Source§

impl From<u32> for JsValue

Source§

fn from(value: u32) -> JsValue

Converts to this type from the input type.
Source§

impl From<u64> for JsValue

Source§

fn from(value: u64) -> JsValue

Converts to this type from the input type.
Source§

impl From<usize> for JsValue

Source§

fn from(value: usize) -> JsValue

Converts to this type from the input type.
Source§

impl Hash for JsValue

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for JsValue

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Trace for JsValue

Source§

unsafe fn trace(&self)

Marks all contained Gcs.
Source§

unsafe fn root(&self)

Increments the root-count of all contained Gcs.
Source§

unsafe fn unroot(&self)

Decrements the root-count of all contained Gcs.
Source§

fn finalize_glue(&self)

Runs Finalize::finalize() on this object and all contained subobjects
Source§

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> 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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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<T> NativeObject for T
where T: Any + Debug + Trace,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert the Rust type which implements NativeObject to a &dyn Any.
Source§

fn as_mut_any(&mut self) -> &mut (dyn Any + 'static)

Convert the Rust type which implements NativeObject to a &mut dyn Any.
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V