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

GetIterator ( obj [ , hint [ , method ] ] )

More information:

Abstract operation OrdinaryHasInstance ( C, O )

More information:

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 operation InstanceofOperator ( V, target )

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:

Converts a serde_json::Value to a JsValue.

Example
use boa_engine::{Context, JsValue};

let data = r#"
    {
        "name": "John Doe",
        "age": 43,
        "phones": [
            "+44 1234567",
            "+44 2345678"
        ]
     }"#;

let json: serde_json::Value = serde_json::from_str(data).unwrap();

let mut context = Context::default();
let value = JsValue::from_json(&json, &mut context).unwrap();

Converts the JsValue to a serde_json::Value.

Example
use boa_engine::{Context, JsValue};

let data = r#"
    {
        "name": "John Doe",
        "age": 43,
        "phones": [
            "+44 1234567",
            "+44 2345678"
        ]
     }"#;

let json: serde_json::Value = serde_json::from_str(data).unwrap();

let mut context = Context::default();
let value = JsValue::from_json(&json, &mut context).unwrap();

let back_to_json = value.to_json(&mut context).unwrap();

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

It determines if the value is a callable function with a [[Call]] internal method.

More information:

Returns true if the value is a constructor object.

Returns true if the value is a promise object.

Returns true if the value is a symbol.

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 argumenPreferredTypepe.

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

7.1.13 ToBigInt ( argument )

More information:

Returns an object that implements Display.

By default the internals are not shown, but they can be toggled with ValueDisplay::internals method.

Examples
use boa_engine::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

7.1.10 ToInt8 ( argument )

More information:

7.1.11 ToUint8 ( argument )

More information:

7.1.12 ToUint8Clamp ( argument )

More information:

7.1.8 ToInt16 ( argument )

More information:

7.1.9 ToUint16 ( argument )

More information:

7.1.15 ToBigInt64 ( argument )

More information:

7.1.16 ToBigUint64 ( argument )

More information:

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

Abstract operation ToIntegerOrInfinity ( argument )

This method converts a Value to an integer representing its Number value with fractional part truncated, or to +∞ or -∞ when that Number value is infinite.

More information:

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:

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
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.
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
Converts self into T using Into<T>. 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.
Pipes by value. This is generally the method you want to use. Read more
Borrows self and passes that borrow into the pipe function. Read more
Mutably borrows self and passes that borrow into the pipe function. Read more
Borrows self, then passes self.borrow() into the pipe function. Read more
Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
Borrows self, then passes self.as_ref() into the pipe function.
Mutably borrows self, then passes self.as_mut() into the pipe function. Read more
Borrows self, then passes self.deref() into the pipe function.
Mutably borrows self, then passes self.deref_mut() into the pipe function. Read more
Immutable access to a value. Read more
Mutable access to a value. Read more
Immutable access to the Borrow<B> of a value. Read more
Mutable access to the BorrowMut<B> of a value. Read more
Immutable access to the AsRef<R> view of a value. Read more
Mutable access to the AsMut<R> view of a value. Read more
Immutable access to the Deref::Target of a value. Read more
Mutable access to the Deref::Target of a value. Read more
Calls .tap() only in debug builds, and is erased in release builds.
Calls .tap_mut() only in debug builds, and is erased in release builds. Read more
Calls .tap_borrow() only in debug builds, and is erased in release builds. Read more
Calls .tap_borrow_mut() only in debug builds, and is erased in release builds. Read more
Calls .tap_ref() only in debug builds, and is erased in release builds. Read more
Calls .tap_ref_mut() only in debug builds, and is erased in release builds. Read more
Calls .tap_deref() only in debug builds, and is erased in release builds. Read more
Calls .tap_deref_mut() only in debug builds, and is erased in release builds. Read more
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
Attempts to convert self into T using TryInto<T>. 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.