Struct chakracore::value::Value [] [src]

pub struct Value(_);

A JavaScript value, base class for all types.

All values are tied to a specific context and should not be reused in between.

The underlying object is represented as a JsValueRef, a reference to a ChakraCore value.

This type implements the Debug trait, but it should be used carefully. It assumes there is an active context (the same context that the value was created with).

Do not get intimidated by all the conversion methods. They are very easy to grok — there are three different types:

into_*

These do not modify any data. They only check the type of the underlying value. If the value is the designated type (e.g Object), the underlying pointer is copied and returned wrapped as the specific type.

*_representation

These create a new value, by casting to a specific type using JavaScript semantics. For example; calling number_representation on an Object results in a Number(NaN). Casting a Boolean(false) using string_representation results in a String('false').

to_*

These are utility functions to easily retrieve a native representation of the internal value. The chain of actions performed is the following: into_*() -> [*_representation()] -> value(). A call to *_representation is only performed if required (i.e a string is not redundantly converted to a string).

Methods

impl Value
[src]

Returns true if this value is undefined.

Returns true if this value is null.

Returns true if this value is a Number.

Represent the value as a Number. Does not affect the underlying value.

Returns true if this value is a String.

Represent the value as a String. Does not affect the underlying value.

Returns true if this value is a Boolean.

Represent the value as a Boolean. Does not affect the underlying value.

Returns true if this value is an Object.

Represent the value as an Object. Does not affect the underlying value.

Returns true if this value is an External.

Represent the value as an External. Does not affect the underlying value.

Returns true if this value is a Function.

Represent the value as a Function. Does not affect the underlying value.

Returns true if this value is an Array.

Represent the value as an Array. Does not affect the underlying value.

Returns true if this value is an ArrayBuffer.

Represent the value as an ArrayBuffer. Does not affect the underlying value.

Returns true if this value is a Promise.

Represent the value as a Promise. Does not affect the underlying value.

Converts the value to a native string, containing the value's string representation.

Converts the value to a native integer, containing the value's integer representation.

Converts the value to a native double, containing the value's floating point representation.

Converts the value to a native boolean, containing the value's bool representation.

Converts the value to a native string, containing the value's JSON representation.

Creates a new boolean with this value represented as Boolean.

Creates a new number with this value represented as Number.

Creates a new object with this value represented as Object.

Creates a new string with this value represented as String.

Returns the type of the value. This method should be used with consideration. It does not keep track of custom types, such as External. It only returns the runtime's definition of a type.

Compare two values for equality (==).

Compare two values for strict equality (===).

impl Value
[src]

Creates an instance from a raw pointer.

This is used for managing the lifetime of JSRT objects. They are tracked using reference counting; incrementing with from_raw, and decrementing with drop.

This is required to support items stored on the heap, since the JSRT runtime only observes the stack.

If used in conjunction with a Property or any Value, it is assumed a Context is active.

Returns the underlying raw pointer.

Trait Implementations

impl From<Function> for Value
[src]

Performs the conversion.

impl From<Promise> for Value
[src]

Performs the conversion.

impl From<Object> for Value
[src]

Performs the conversion.

impl From<Array> for Value
[src]

Performs the conversion.

impl From<ArrayBuffer> for Value
[src]

Performs the conversion.

impl From<Boolean> for Value
[src]

Performs the conversion.

impl From<Error> for Value
[src]

Performs the conversion.

impl From<External> for Value
[src]

Performs the conversion.

impl From<Number> for Value
[src]

Performs the conversion.

impl From<String> for Value
[src]

Performs the conversion.

impl PartialEq for Value
[src]

Use carefully (prefer strict_equals), this relies on an implicitly active context.

This method tests for !=.

impl Debug for Value
[src]

Only use for debugging, it relies on an implicitly active context.

impl Clone for Value
[src]

Duplicates a reference counted type.

The underlying pointer will be copied, and its reference count will be incremented, returned wrapped as the type.

Performs copy-assignment from source. Read more

impl Drop for Value
[src]

Decrements the reference counter if the object is recyclable.