JsValue Struct

A JavaScript value: undefined, null, a boolean, a number, a string, a symbol, a BigInt or an object. The default value is undefined. Numbers are not allocated; the other values reference a JsCell.

public readonly struct JsValue : IEquatable<JsValue>
Implements

Constructors

NameDescription
JsValue(double)Creates a number value.

JsValue(double)

JsValue.cs

Creates a number value.

public JsValue(double value)

Parameters

value double

Properties

NameDescription
FalseGets the false value.
IsBigIntGets whether the value is a BigInt.
IsBooleanGets whether the value is a boolean.
IsCallableGets whether the value is a function (an object with a [[Call]] internal method).
IsNullGets whether the value is null.
IsNullOrUndefinedGets whether the value is undefined or null.
IsNumberGets whether the value is a number.
IsObjectGets whether the value is an object.
IsStringGets whether the value is a string.
IsSymbolGets whether the value is a symbol.
IsUndefinedGets whether the value is undefined.
KindGets the type of the value.
NullGets the null value.
TrueGets the true value.
UndefinedGets the undefined value.

Gets the false value.

public static JsValue False { get; }

Property value

JsValue

IsBigInt

JsValue.cs

Gets whether the value is a BigInt.

public bool IsBigInt { get; }

Property value

bool

IsBoolean

JsValue.cs

Gets whether the value is a boolean.

public bool IsBoolean { get; }

Property value

bool

IsCallable

JsValue.cs

Gets whether the value is a function (an object with a [[Call]] internal method).

public bool IsCallable { get; }

Property value

bool

Gets whether the value is null.

public bool IsNull { get; }

Property value

bool

IsNullOrUndefined

JsValue.cs

Gets whether the value is undefined or null.

public bool IsNullOrUndefined { get; }

Property value

bool

IsNumber

JsValue.cs

Gets whether the value is a number.

public bool IsNumber { get; }

Property value

bool

IsObject

JsValue.cs

Gets whether the value is an object.

public bool IsObject { get; }

Property value

bool

IsString

JsValue.cs

Gets whether the value is a string.

public bool IsString { get; }

Property value

bool

IsSymbol

JsValue.cs

Gets whether the value is a symbol.

public bool IsSymbol { get; }

Property value

bool

IsUndefined

JsValue.cs

Gets whether the value is undefined.

public bool IsUndefined { get; }

Property value

bool

Gets the type of the value.

public JsValueKind Kind { get; }

Property value

JsValueKind

Gets the null value.

public static JsValue Null { get; }

Property value

JsValue

Gets the true value.

public static JsValue True { get; }

Property value

JsValue

Undefined

JsValue.cs

Gets the undefined value.

public static JsValue Undefined { get; }

Property value

JsValue

Methods

NameDescription
AsBigInt()Gets the integer of a BigInt value.
AsBoolean()Gets the boolean of a boolean value.
AsNumber()Gets the number of a number value.
AsObject()Gets the object of an object value.
AsString()Gets the string of a string value.
AsSymbol()Gets the symbol of a symbol value.
Equals(JsValue)Compares two values with the SameValue algorithm (https://tc39.es/ecma262/#sec-samevalue).
Equals(object?)Compares the value with another JsValue with the SameValue algorithm.
FromBigInt(BigInteger)Creates a BigInt value.
FromBoolean(bool)Creates a boolean value.
FromNumber(double)Creates a number value.
FromObject(JsObject?)Creates an object value, or null when the object is null.
FromString(string)Creates a string value.
GetHashCode()Gets a hash code consistent with SameValue.
ToString()Returns a representation of the value for debugging; it never runs JavaScript code (use ToString of JsOperations for the ToString operation).
TryGetBoolean(bool)Gets the boolean of the value; returns false when the value is not a boolean (no conversion).
TryGetNumber(double)Gets the number of the value; returns false when the value is not a number (no conversion).
TryGetObject()Gets the object of the value, or null when the value is not an object.
TryGetString(string?)Gets the string of the value; returns false when the value is not a string (no conversion).

AsBigInt()

JsValue.cs

Gets the integer of a BigInt value.

public BigInteger AsBigInt()

Returns

BigInteger

Exceptions

InvalidOperationException
The value is not a BigInt (use JsEngine.ToBigInt to convert it).

AsBoolean()

JsValue.cs

Gets the boolean of a boolean value.

public bool AsBoolean()

Returns

bool

Exceptions

InvalidOperationException
The value is not a boolean (use JsValue.TryGetBoolean, or JsEngine.ToBoolean to convert it).

AsNumber()

JsValue.cs

Gets the number of a number value.

public double AsNumber()

Returns

double

Exceptions

InvalidOperationException
The value is not a number (use JsValue.TryGetNumber, or JsEngine.ToNumber to convert it).

AsObject()

JsValue.cs

Gets the object of an object value.

public JsObject AsObject()

Returns

JsObject

Exceptions

InvalidOperationException
The value is not an object (use JsValue.TryGetObject, or JsEngine.ToObject to convert it).

AsString()

JsValue.cs

Gets the string of a string value.

public string AsString()

Returns

string

Exceptions

InvalidOperationException
The value is not a string (use JsValue.TryGetString, or JsEngine.ToString to convert it).

AsSymbol()

JsValue.cs

Gets the symbol of a symbol value.

public JsSymbol AsSymbol()

Returns

JsSymbol

Exceptions

InvalidOperationException
The value is not a symbol.

Equals overloads

Equals(JsValue)

JsValue.cs

Compares two values with the SameValue algorithm (https://tc39.es/ecma262/#sec-samevalue).

public bool Equals(JsValue other)
Parameters
other JsValue
Returns

bool

Equals(object?)

JsValue.cs

Compares the value with another JsValue with the SameValue algorithm.

public override bool Equals(object? obj)
Parameters
obj object?
Returns

bool

FromBigInt(BigInteger)

JsValue.cs

Creates a BigInt value.

public static JsValue FromBigInt(BigInteger value)

Parameters

value BigInteger

Returns

JsValue

FromBoolean(bool)

JsValue.cs

Creates a boolean value.

public static JsValue FromBoolean(bool value)

Parameters

value bool

Returns

JsValue

FromNumber(double)

JsValue.cs

Creates a number value.

public static JsValue FromNumber(double value)

Parameters

value double

Returns

JsValue

FromObject(JsObject?)

JsValue.cs

Creates an object value, or null when the object is null.

public static JsValue FromObject(JsObject? value)

Parameters

value JsObject?

Returns

JsValue

FromString(string)

JsValue.cs

Creates a string value.

public static JsValue FromString(string value)

Parameters

value string

Returns

JsValue

GetHashCode()

JsValue.cs

Gets a hash code consistent with SameValue.

public override int GetHashCode()

Returns

int

ToString()

JsValue.cs

Returns a representation of the value for debugging; it never runs JavaScript code (use ToString of JsOperations for the ToString operation).

public override string ToString()

Returns

string

TryGetBoolean(bool)

JsValue.cs

Gets the boolean of the value; returns false when the value is not a boolean (no conversion).

public bool TryGetBoolean(out bool value)

Parameters

value bool

Returns

bool

TryGetNumber(double)

JsValue.cs

Gets the number of the value; returns false when the value is not a number (no conversion).

public bool TryGetNumber(out double value)

Parameters

value double

Returns

bool

TryGetObject()

JsValue.cs

Gets the object of the value, or null when the value is not an object.

public JsObject? TryGetObject()

Returns

JsObject?

TryGetString(string?)

JsValue.cs

Gets the string of the value; returns false when the value is not a string (no conversion).

public bool TryGetString(out string? value)

Parameters

value string?

Returns

bool

Operators

NameDescription
operator ==(JsValue, JsValue)Compares two values with the SameValue algorithm.
implicit operator JsValue(JsObject?)Converts an object to a value (null when the object is null).
implicit operator JsValue(JsSymbol)Converts a symbol to a value.
implicit operator JsValue(bool)Converts a boolean to a value.
implicit operator JsValue(double)Converts a number to a value.
implicit operator JsValue(int)Converts a number to a value.
implicit operator JsValue(string)Converts a string to a value.
operator !=(JsValue, JsValue)Compares two values with the SameValue algorithm.

operator ==(JsValue, JsValue)

JsValue.cs

Compares two values with the SameValue algorithm.

public static bool operator ==(JsValue left, JsValue right)

Parameters

left JsValue
right JsValue

Returns

bool

op_Implicit overloads

implicit operator JsValue(JsObject?)

JsValue.cs

Converts an object to a value (null when the object is null).

public static implicit operator JsValue(JsObject? value)
Parameters
value JsObject?
Returns

JsValue

implicit operator JsValue(JsSymbol)

JsValue.cs

Converts a symbol to a value.

public static implicit operator JsValue(JsSymbol value)
Parameters
value JsSymbol
Returns

JsValue

implicit operator JsValue(bool)

JsValue.cs

Converts a boolean to a value.

public static implicit operator JsValue(bool value)
Parameters
value bool
Returns

JsValue

implicit operator JsValue(double)

JsValue.cs

Converts a number to a value.

public static implicit operator JsValue(double value)
Parameters
value double
Returns

JsValue

implicit operator JsValue(int)

JsValue.cs

Converts a number to a value.

public static implicit operator JsValue(int value)
Parameters
value int
Returns

JsValue

implicit operator JsValue(string)

JsValue.cs

Converts a string to a value.

public static implicit operator JsValue(string value)
Parameters
value string
Returns

JsValue

operator !=(JsValue, JsValue)

JsValue.cs

Compares two values with the SameValue algorithm.

public static bool operator !=(JsValue left, JsValue right)

Parameters

left JsValue
right JsValue

Returns

bool