Represents a Jerryscript value. More...
#include <Types.h>
Classes | |
struct | As |
Used by as() method. More... | |
Public Types | |
using | List = Vector< Value > |
Public Member Functions | |
Value () | |
Construct An empty (unused) value. More... | |
Value (const OwnedValue &value) | |
Construct a Value and take ownership of the given native value. More... | |
Value (const CopyValue &value) | |
Construct a Value using a copy (or reference to) the given native value. More... | |
Value (const StringValue &value) | |
Construct a string Value from the given native value. More... | |
Value (const Undefined &value) | |
Value (const Null &value) | |
Value (const Value &value) | |
Copy constructor. More... | |
Value (Value &&value) | |
Move constructor. More... | |
~Value () | |
Value & | operator= (const Value &value) |
Assignment copy operator. More... | |
Value & | operator= (Value &&value) |
Assignment move operator. More... | |
Value & | reset (jerry_value_t value=jerry_value_t(Ecma::VALUE_EMPTY)) |
Reset contents of object to new value (default is unassigned) More... | |
jerry_value_t | release () |
Get raw/native value and release ownership. More... | |
Type | type () const |
Get value type. More... | |
Object | toObject () const |
Create a new object from this value. More... | |
Value | toString () const |
Create a new string value from this value. More... | |
size_t | readString (unsigned offset, char *buffer, size_t length) const |
Get content from within a string value. More... | |
String | subString (unsigned offset, size_t length) const |
Get content from within a string value. More... | |
operator String () const | |
Support intrinsic cast to Wiring String. More... | |
template<typename T > | |
T | as () const |
Get value of object with specific type. e.g. value.as<int>() . More... | |
Construct a value from a simple type | |
Value (int value) | |
Integer. More... | |
Value (unsigned value) | |
Unsigned integer. More... | |
Value (double value) | |
floating-point More... | |
Value (bool value) | |
Boolean. More... | |
Value (const String &s) | |
Wiring String. More... | |
Value (const char *s) | |
NUL-terminated 'C' string. More... | |
Value (const FSTR::String &s) | |
Flash String. More... | |
Get raw/native value for use with jerryscript C API | |
const jerry_value_t & | get () const |
const get() More... | |
jerry_value_t & | get () |
get() More... | |
Checks on value type | |
bool | isCallable () const |
Is this object a function? If so, can cast to Callable type. More... | |
bool | isArray () const |
Can this object be accessed as an array? If so, can cast to Array type. More... | |
bool | isError () const |
Determine if value represents an error. If so, can cast to Error type. More... | |
bool | isEmpty () const |
An empty Value contains nothing, i.e. no javascript type has been assigned. This gets interpreted as 'undefined' if any attempt is made to use it in javascript. More... | |
bool | isDefined () const |
Contains a javascript value, but contents undefined. More... | |
bool | isBoolean () const |
A true/false value type. More... | |
bool | isFalse () const |
Is this a Boolean type set to False? More... | |
bool | isTrue () const |
Is this a Boolean type set to True? More... | |
bool | isNull () const |
Is this a NULL value? More... | |
bool | isString () const |
Is this a String? More... | |
bool | isObject () const |
Is this an Object type? If so, can cast to Object class. More... | |
bool | isNumber () const |
Does this value contain a Number? More... | |
Detailed Description
Represents a Jerryscript value.
This class resembles std::unique_ptr
to manage a raw/native jerry_value_t
value. The get()
, reset()
and release()
methods all behave in the same manner.
In addition, it provides intrinsic casts from numeric/boolean C++ types plus String
.
You can therefore create a value like this::
If you need to working with floating point values be sure to compile with JERRY_COMPACT_PROFILE=0
.
IMPORTANT: When dealing with raw/native values, ALWAYS use either OwnedValue
or CopyValue
casts.
- This is correct: Value value = OwnedValue{jerry_create_object()};
- This is wrong: Value value = jerry_create_object(); // Ends up with memory leak plus garbage
Member Typedef Documentation
◆ List
using Jerryscript::Value::List = Vector<Value> |
Constructor & Destructor Documentation
◆ Value() [1/15]
|
inline |
Construct An empty (unused) value.
◆ Value() [2/15]
|
inline |
Construct a Value and take ownership of the given native value.
◆ Value() [3/15]
|
inline |
Construct a Value using a copy (or reference to) the given native value.
◆ Value() [4/15]
|
inline |
Construct a string Value from the given native value.
◆ Value() [5/15]
|
inline |
◆ Value() [6/15]
|
inline |
◆ Value() [7/15]
|
inline |
Copy constructor.
◆ Value() [8/15]
|
inline |
Move constructor.
◆ Value() [9/15]
Jerryscript::Value::Value | ( | int | value | ) |
Integer.
◆ Value() [10/15]
Jerryscript::Value::Value | ( | unsigned | value | ) |
Unsigned integer.
◆ Value() [11/15]
|
inline |
floating-point
◆ Value() [12/15]
|
inline |
Boolean.
◆ Value() [13/15]
◆ Value() [14/15]
|
inline |
NUL-terminated 'C' string.
◆ Value() [15/15]
|
inline |
Flash String.
◆ ~Value()
|
inline |
Member Function Documentation
◆ as()
|
inline |
Get value of object with specific type. e.g. value.as<int>()
.
Return value will revert to sensible default if conversion cannot be completed. If in doubt, check type first.
◆ get() [1/2]
|
inline |
◆ get() [2/2]
|
inline |
const get()
◆ isArray()
|
inline |
Can this object be accessed as an array? If so, can cast to Array
type.
◆ isBoolean()
|
inline |
A true/false value type.
◆ isCallable()
|
inline |
Is this object a function? If so, can cast to Callable
type.
◆ isDefined()
|
inline |
Contains a javascript value, but contents undefined.
◆ isEmpty()
|
inline |
An empty Value contains nothing, i.e. no javascript type has been assigned. This gets interpreted as 'undefined' if any attempt is made to use it in javascript.
◆ isError()
|
inline |
Determine if value represents an error. If so, can cast to Error
type.
◆ isFalse()
|
inline |
Is this a Boolean type set to False?
◆ isNull()
|
inline |
Is this a NULL value?
◆ isNumber()
|
inline |
Does this value contain a Number?
◆ isObject()
|
inline |
◆ isString()
|
inline |
Is this a String?
◆ isTrue()
|
inline |
Is this a Boolean type set to True?
◆ operator String()
◆ operator=() [1/2]
◆ operator=() [2/2]
◆ readString()
size_t Jerryscript::Value::readString | ( | unsigned | offset, |
char * | buffer, | ||
size_t | length | ||
) | const |
Get content from within a string value.
- Parameters
-
offset First character position to read, starting from 0 buffer Where to store character data length Number of characters to read
- Return values
-
size_t Number of characters read
◆ release()
|
inline |
Get raw/native value and release ownership.
◆ reset()
|
inline |
Reset contents of object to new value (default is unassigned)
◆ subString()
Get content from within a string value.
- Parameters
-
offset First character position to read, starting from 0 length Number of characters to read
- Return values
-
String Requested range, or nullptr if value is not a string
◆ toObject()
Object Jerryscript::Value::toObject | ( | ) | const |
Create a new object from this value.
◆ toString()
|
inline |
Create a new string value from this value.
◆ type()
|
inline |
Get value type.
The documentation for this class was generated from the following file: