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 anObject
results in aNumber(NaN)
. Casting aBoolean(false)
usingstring_representation
results in aString('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]
fn is_undefined(&self) -> bool
Returns true if this value is undefined
.
fn is_null(&self) -> bool
Returns true if this value is null
.
fn is_number(&self) -> bool
Returns true if this value is a Number
.
fn into_number(self) -> Option<Number>
Represent the value as a Number
. Does not affect the underlying value.
fn is_string(&self) -> bool
Returns true if this value is a String
.
fn into_string(self) -> Option<String>
Represent the value as a String
. Does not affect the underlying value.
fn is_boolean(&self) -> bool
Returns true if this value is a Boolean
.
fn into_boolean(self) -> Option<Boolean>
Represent the value as a Boolean
. Does not affect the underlying value.
fn is_object(&self) -> bool
Returns true if this value is an Object
.
fn into_object(self) -> Option<Object>
Represent the value as an Object
. Does not affect the underlying value.
fn is_external(&self) -> bool
Returns true if this value is an External
.
fn into_external(self) -> Option<External>
Represent the value as an External
. Does not affect the underlying value.
fn is_function(&self) -> bool
Returns true if this value is a Function
.
fn into_function(self) -> Option<Function>
Represent the value as a Function
. Does not affect the underlying value.
fn is_array(&self) -> bool
Returns true if this value is an Array
.
fn into_array(self) -> Option<Array>
Represent the value as an Array
. Does not affect the underlying value.
fn is_array_buffer(&self) -> bool
Returns true if this value is an ArrayBuffer
.
fn into_array_buffer(self) -> Option<ArrayBuffer>
Represent the value as an ArrayBuffer
. Does not affect the underlying value.
fn is_promise(&self) -> bool
Returns true if this value is a Promise
.
fn into_promise(self) -> Option<Promise>
Represent the value as a Promise
. Does not affect the underlying value.
fn to_string(&self, _guard: &ContextGuard) -> String
Converts the value to a native string, containing the value's string representation.
fn to_integer(&self, _guard: &ContextGuard) -> i32
Converts the value to a native integer, containing the value's integer representation.
fn to_double(&self, _guard: &ContextGuard) -> f64
Converts the value to a native double, containing the value's floating point representation.
fn to_bool(&self, _guard: &ContextGuard) -> bool
Converts the value to a native boolean, containing the value's bool representation.
fn to_json(&self, guard: &ContextGuard) -> Result<String>
Converts the value to a native string, containing the value's JSON representation.
fn boolean_representation(&self, _guard: &ContextGuard) -> Boolean
Creates a new boolean with this value represented as Boolean
.
fn number_representation(&self, _guard: &ContextGuard) -> Number
Creates a new number with this value represented as Number
.
fn object_representation(&self, _guard: &ContextGuard) -> Object
Creates a new object with this value represented as Object
.
fn string_representation(&self, _guard: &ContextGuard) -> String
Creates a new string with this value represented as String
.
fn get_type(&self) -> JsValueType
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.
fn equals(&self, _guard: &ContextGuard, that: &Value) -> bool
Compare two values for equality (==
).
fn strict_equals(&self, _guard: &ContextGuard, that: &Value) -> bool
Compare two values for strict equality (===
).
impl Value
[src]
unsafe fn from_raw(value: JsRef) -> Value
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.
fn as_raw(&self) -> JsRef
Returns the underlying raw pointer.
Trait Implementations
impl From<Function> for Value
[src]
impl From<Promise> for Value
[src]
impl From<Object> for Value
[src]
impl From<Array> for Value
[src]
impl From<ArrayBuffer> for Value
[src]
fn from(child: ArrayBuffer) -> Value
Performs the conversion.
impl From<Boolean> for Value
[src]
impl From<Error> for Value
[src]
impl From<External> for Value
[src]
impl From<Number> for Value
[src]
impl From<String> for Value
[src]
impl PartialEq for Value
[src]
fn eq(&self, other: &Value) -> bool
Use carefully (prefer strict_equals
), this relies on an implicitly
active context.
fn ne(&self, other: &Rhs) -> bool
1.0.0
This method tests for !=
.
impl Debug for Value
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Only use for debugging, it relies on an implicitly active context.
impl Clone for Value
[src]
fn clone(&self) -> Value
Duplicates a reference counted type.
The underlying pointer will be copied, and its reference count will be incremented, returned wrapped as the type.
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl Drop for Value
[src]
fn drop(&mut self)
Decrements the reference counter if the object is recyclable.