logo
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

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.

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

The internal comparison abstract operation SameValue(x, y), where x and y are ECMAScript language values, produces true or false.

More information:

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:

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:

The less than operator (<) returns true if the left operand is less than the right operand, and false otherwise.

More Information:

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:

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

More Information:

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:

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.

Create a new JsValue.

Creates a new undefined value.

Creates a new null value.

Creates a new number with NaN value.

Creates a new number with Infinity value.

Creates a new number with -Infinity value.

Returns true if the value is an object

Returns true if the value is a symbol.

Returns true if the value is a function

Returns true if the value is undefined.

Returns true if the value is null.

Returns true if the value is null or undefined.

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

Returns true if the value is integer.

Returns true if the value is a number.

Returns true if the value is a string.

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

Returns true if the value is a boolean.

Returns true if the value is a bigint.

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

Converts the value to a bool type.

More information:

Set the kind of an object.

The abstract operation ToPrimitive takes an input argument and an optional argument PreferredType.

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

Converts the value to a BigInt.

This function is equivelent to BigInt(value) in JavaScript.

Returns an object that implements Display.

Examples
use boa::JsValue;

let value = JsValue::new(3);

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

Converts the value to a string.

This function is equivalent to String(value) in JavaScript.

Converts the value to an Object.

This function is equivalent to Object(value) in JavaScript

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

Converts the value to a PropertyKey, that can be used as a key for properties.

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

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

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

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

Converts a value to an integral 32 bit signed integer.

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

Converts a value to a non-negative integer if it is a valid integer index value.

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

Converts argument to an integer suitable for use as the length of an array-like object.

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

Converts a value to an integral Number value.

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

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

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

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:

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

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

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

More information:

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Executes the destructor for this type. Read more
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
Marks all contained Gcs.
Increments the root-count of all contained Gcs.
Decrements the root-count of all contained Gcs.
Runs Finalize::finalize() on this object and all contained subobjects Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Compare self to key and return true if they are equal.

Returns the argument unchanged.

Calls U::from(self).

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

Convert the Rust type which implements NativeObject to a &dyn Any.
Convert the Rust type which implements NativeObject to a &mut dyn Any.
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.