[][src]Enum boa::Value

pub enum Value {
    Null,
    Undefined,
    Boolean(bool),
    String(RcString),
    Rational(f64),
    Integer(i32),
    BigInt(RcBigInt),
    Object(GcObject),
    Symbol(RcSymbol),
}

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(RcString)

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(RcBigInt)

BigInt - holds any arbitrary large signed integer.

Object(GcObject)

Object - An object, such as Math, represented by a binary tree of string keys to Javascript values.

Symbol(RcSymbol)

Symbol - A Symbol Primitive type.

Implementations

impl Value[src]

pub fn strict_equals(&self, other: &Self) -> bool[src]

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.

pub fn equals(&self, other: &Self, context: &mut Context) -> Result<bool>[src]

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

impl Value[src]

pub fn add(&self, other: &Self, context: &mut Context) -> Result<Value>[src]

pub fn sub(&self, other: &Self, context: &mut Context) -> Result<Value>[src]

pub fn mul(&self, other: &Self, context: &mut Context) -> Result<Value>[src]

pub fn div(&self, other: &Self, context: &mut Context) -> Result<Value>[src]

pub fn rem(&self, other: &Self, context: &mut Context) -> Result<Value>[src]

pub fn pow(&self, other: &Self, context: &mut Context) -> Result<Value>[src]

pub fn bitand(&self, other: &Self, context: &mut Context) -> Result<Value>[src]

pub fn bitor(&self, other: &Self, context: &mut Context) -> Result<Value>[src]

pub fn bitxor(&self, other: &Self, context: &mut Context) -> Result<Value>[src]

pub fn shl(&self, other: &Self, context: &mut Context) -> Result<Value>[src]

pub fn shr(&self, other: &Self, context: &mut Context) -> Result<Value>[src]

pub fn ushr(&self, other: &Self, context: &mut Context) -> Result<Value>[src]

pub fn neg(&self, context: &mut Context) -> Result<Value>[src]

pub fn not(&self, _: &mut Context) -> Result<bool>[src]

pub fn abstract_relation(
    &self,
    other: &Self,
    left_first: bool,
    context: &mut Context
) -> Result<AbstractRelation>
[src]

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:

pub fn lt(&self, other: &Self, context: &mut Context) -> Result<bool>[src]

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

More Information:

pub fn le(&self, other: &Self, context: &mut Context) -> Result<bool>[src]

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:

pub fn gt(&self, other: &Self, context: &mut Context) -> Result<bool>[src]

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

More Information:

pub fn ge(&self, other: &Self, context: &mut Context) -> Result<bool>[src]

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:

impl Value[src]

pub fn get_type(&self) -> Type[src]

Get the type of the value.

This is similar to typeof as described at https://tc39.es/ecma262/#sec-typeof-operator but instead of returning a string it returns a Type enum which implements fmt::Display to allow getting the string if required using to_string().

impl Value[src]

pub fn undefined() -> Self[src]

Creates a new undefined value.

pub fn null() -> Self[src]

Creates a new null value.

pub fn nan() -> Self[src]

Creates a new number with NaN value.

pub fn string<S>(value: S) -> Self where
    S: Into<RcString>, 
[src]

Creates a new string value.

pub fn rational<N>(value: N) -> Self where
    N: Into<f64>, 
[src]

Creates a new number value.

pub fn integer<I>(value: I) -> Self where
    I: Into<i32>, 
[src]

Creates a new number value.

pub fn number<N>(value: N) -> Self where
    N: Into<f64>, 
[src]

Creates a new number value.

pub fn bigint<B>(value: B) -> Self where
    B: Into<RcBigInt>, 
[src]

Creates a new bigint value.

pub fn boolean(value: bool) -> Self[src]

Creates a new boolean value.

pub fn object(object: Object) -> Self[src]

Creates a new object value.

pub fn symbol(symbol: RcSymbol) -> Self[src]

Creates a new symbol value.

pub fn new_object(context: &Context) -> Self[src]

Returns a new empty object

pub fn from_json(json: JSONValue, context: &mut Context) -> Self[src]

Convert from a JSON value to a JS value

pub fn to_json(&self, context: &mut Context) -> Result<JSONValue>[src]

Converts the Value to JSON.

pub fn is_extensible(&self) -> bool[src]

This will tell us if we can exten an object or not, not properly implemented yet

For now always returns true.

For scalar types it should be false, for objects check the private field for extensibilaty. By default true.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/seal would turn extensible to false https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze would also turn extensible to false

pub fn is_object(&self) -> bool[src]

Returns true if the value is an object

pub fn as_object(&self) -> Option<GcObject>[src]

pub fn is_symbol(&self) -> bool[src]

Returns true if the value is a symbol.

pub fn as_symbol(&self) -> Option<RcSymbol>[src]

pub fn is_function(&self) -> bool[src]

Returns true if the value is a function

pub fn is_undefined(&self) -> bool[src]

Returns true if the value is undefined.

pub fn is_null(&self) -> bool[src]

Returns true if the value is null.

pub fn is_null_or_undefined(&self) -> bool[src]

Returns true if the value is null or undefined.

pub fn is_double(&self) -> bool[src]

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

pub fn is_integer(&self) -> bool[src]

Returns true if the value is integer.

pub fn is_number(&self) -> bool[src]

Returns true if the value is a number.

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

pub fn is_string(&self) -> bool[src]

Returns true if the value is a string.

pub fn as_string(&self) -> Option<&RcString>[src]

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

pub fn is_boolean(&self) -> bool[src]

Returns true if the value is a boolean.

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

pub fn is_bigint(&self) -> bool[src]

Returns true if the value is a bigint.

pub fn as_bigint(&self) -> Option<&BigInt>[src]

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

pub fn to_boolean(&self) -> bool[src]

Converts the value to a bool type.

More information:

pub fn remove_property<Key>(&self, key: Key) -> bool where
    Key: Into<PropertyKey>, 
[src]

Removes a property from a Value object.

It will return a boolean based on if the value was removed, if there was no value to remove false is returned.

pub fn get_property<Key>(&self, key: Key) -> Option<PropertyDescriptor> where
    Key: Into<PropertyKey>, 
[src]

Resolve the property in the object.

A copy of the Property is returned.

pub fn get_field<K>(&self, key: K, context: &mut Context) -> Result<Self> where
    K: Into<PropertyKey>, 
[src]

Resolve the property in the object and get its value, or undefined if this is not an object or the field doesn't exist get_field receives a Property from get_prop(). It should then return the [[Get]] result value if that's set, otherwise fall back to [[Value]] TODO: this function should use the get Value if its set

pub fn has_field<K>(&self, key: K) -> bool where
    K: Into<PropertyKey>, 
[src]

Check to see if the Value has the field, mainly used by environment records.

pub fn set_field<K, V>(
    &self,
    key: K,
    value: V,
    context: &mut Context
) -> Result<Value> where
    K: Into<PropertyKey>,
    V: Into<Value>, 
[src]

Set the field in the value

pub fn set_data(&self, data: ObjectData)[src]

Set the kind of an object.

pub fn set_property<K, P>(&self, key: K, property: P) where
    K: Into<PropertyKey>,
    P: Into<PropertyDescriptor>, 
[src]

Set the property in the value.

pub fn to_primitive(
    &self,
    context: &mut Context,
    preferred_type: PreferredType
) -> Result<Value>
[src]

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

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

pub fn to_bigint(&self, context: &mut Context) -> Result<RcBigInt>[src]

Converts the value to a BigInt.

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

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

Returns an object that implements Display.

Examples

use boa::Value;

let value = Value::number(3);

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

pub fn to_string(&self, context: &mut Context) -> Result<RcString>[src]

Converts the value to a string.

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

pub fn to_object(&self, context: &mut Context) -> Result<GcObject>[src]

Converts the value to an Object.

This function is equivalent to Object(value) in JavaScript

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

pub fn to_property_key(&self, context: &mut Context) -> Result<PropertyKey>[src]

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

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

pub fn to_numeric(&self, context: &mut Context) -> Result<Numeric>[src]

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

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

pub fn to_u32(&self, context: &mut Context) -> Result<u32>[src]

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

pub fn to_i32(&self, context: &mut Context) -> Result<i32>[src]

Converts a value to an integral 32 bit signed integer.

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

pub fn to_index(&self, context: &mut Context) -> Result<usize>[src]

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

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

pub fn to_length(&self, context: &mut Context) -> Result<usize>[src]

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

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

pub fn to_integer(&self, context: &mut Context) -> Result<f64>[src]

Converts a value to an integral Number value.

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

pub fn to_number(&self, context: &mut Context) -> Result<f64>[src]

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

pub fn to_numeric_number(&self, context: &mut Context) -> Result<f64>[src]

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

pub fn require_object_coercible(&self, context: &mut Context) -> Result<&Value>[src]

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
) -> Result<PropertyDescriptor>
[src]

pub fn to_integer_or_infinity(
    &self,
    context: &mut Context
) -> Result<IntegerOrInfinity>
[src]

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

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

Trait Implementations

impl Clone for Value[src]

impl Debug for Value[src]

impl Default for Value[src]

impl Drop for Value[src]

impl Eq for Value[src]

impl Finalize for Value[src]

impl<T> From<&'_ [T]> for Value where
    T: Clone + Into<Value>, 
[src]

impl From<&'_ Box<str, Global>> for Value[src]

impl From<&'_ PropertyKey> for Value[src]

impl From<&'_ Value> for Value[src]

impl From<&'_ str> for Value[src]

impl From<()> for Value[src]

impl From<BigInt> for Value[src]

impl From<Box<str, Global>> for Value[src]

impl From<GcObject> for Value[src]

impl From<Numeric> for Value[src]

impl From<Object> for Value[src]

impl<T> From<Option<T>> for Value where
    T: Into<Value>, 
[src]

impl From<PropertyKey> for Value[src]

impl From<RcBigInt> for Value[src]

impl From<RcString> for Value[src]

impl From<RcSymbol> for Value[src]

impl From<String> for Value[src]

impl<T> From<Vec<T, Global>> for Value where
    T: Into<Value>, 
[src]

impl From<bool> for Value[src]

impl From<char> for Value[src]

impl From<f64> for Value[src]

impl From<i32> for Value[src]

impl From<u32> for Value[src]

impl From<usize> for Value[src]

impl Hash for Value[src]

impl PartialEq<Value> for Value[src]

impl Trace for Value[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

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

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> NativeObject for T where
    T: Any + Debug + Trace
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

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