Class jac::ValueWrapper
template <bool managed>
ClassList > jac > ValueWrapper
A wrapper around JSValue with RAII. More...
#include <values.h>
Inherited by the following classes: jac::ExceptionWrapper, jac::ObjectWrapper
Public Functions
Type | Name |
---|---|
ValueWrapper (ContextRef ctx, JSValue val) Wrap an existing JSValue. If managed is true, JSValue will be freed when the Value is destroyed. |
|
ValueWrapper (const ValueWrapper & other) |
|
ValueWrapper (ValueWrapper && other) |
|
JSValue & | getVal () Get reference to the underlying JSValue. |
bool | isArray () Check if the Value is an array. |
bool | isFunction () Check if the Value is a function. |
bool | isNull () Check if the Value is null. |
bool | isObject () Check if the Value is an object. |
bool | isUndefined () Check if the Value is undefined. |
std::pair< ContextRef, JSValue > | loot () Release ownership of the JSValue. The JSValue will have to be freed manually. |
operator ValueWeak () |
|
ValueWrapper & | operator= (const ValueWrapper & other) |
ValueWrapper & | operator= (ValueWrapper && other) |
Value | stringify (int indent=0) Convert the Value to a JSON representation. |
T | to () Convert the Value to a specified type. |
StringView | toString () Convert the Value to a StringView . |
~ValueWrapper () |
Public Static Functions
Type | Name |
---|---|
Value | from (ContextRef ctx, T val) Create a new Value by converting a given value. |
Value | fromJSON (ContextRef ctx, std::string json, std::string filename="<json>", bool extended=false) Create a new Value from a given JSON string. |
Value | null (ContextRef ctx) Create a new Value containing null. |
Value | undefined (ContextRef ctx) Create a new Value containing undefined. |
Protected Attributes
Type | Name |
---|---|
ContextRef | _ctx |
JSValue | _val |
Detailed Description
Template parameters:
managed
whether the JSValue should be freed when the wrapper is destroyed.
Public Functions Documentation
function ValueWrapper [1/3]
Wrap an existing JSValue. If managed is true, JSValue will be freed when the Value is destroyed.
Note:
Used internally when directly working with QuickJS API. New Value should be created using Value::from<T>(), Value::undefined(), etc.
Parameters:
ctx
context to work inval
JSValue to wrap
function ValueWrapper [2/3]
function ValueWrapper [3/3]
function getVal
Get reference to the underlying JSValue.
Returns:
JSValue reference
function isArray
Check if the Value is an array.
Returns:
true if the Value is an array, false otherwise
function isFunction
Check if the Value is a function.
Returns:
true if the Value is a function, false otherwise
function isNull
Check if the Value is null.
Returns:
true if the Value is null, false otherwise
function isObject
Check if the Value is an object.
Returns:
true if the Value is an object, false otherwise
function isUndefined
Check if the Value is undefined.
Returns:
true if the Value is undefined, false otherwise
function loot
Release ownership of the JSValue. The JSValue will have to be freed manually.
Note:
After this call, the Value is in an undefined state.
Returns:
Pair of ContextRef and JSValue
function operator ValueWeak
function operator=
function operator=
function stringify
Convert the Value to a JSON representation.
Parameters:
indent
indentation level
Returns:
Value containing the JSON representation
function to
Convert the Value to a specified type.
Template parameters:
T
Type to convert to
Returns:
The converted value
function toString
Convert the Value to a StringView .
Returns:
The StringView
function ~ValueWrapper
Public Static Functions Documentation
function from
Create a new Value by converting a given value.
Template parameters:
T
Type of the value
Parameters:
ctx
context to work inval
value to convert
Returns:
The resulting Value
function fromJSON
Create a new Value from a given JSON string.
static inline Value jac::ValueWrapper::fromJSON (
ContextRef ctx,
std::string json,
std::string filename="<json>",
bool extended=false
)
Parameters:
ctx
context to work injson
JSON stringfilename
filename to use as the source of the JSONextended
whether to use extended JSON
Returns:
The resulting Value
function null
Create a new Value containing null.
Parameters:
ctx
context to work in
Returns:
The resulting Value
function undefined
Create a new Value containing undefined.
Parameters:
ctx
context to work in
Returns:
The resulting Value
Protected Attributes Documentation
variable _ctx
variable _val
Friends Documentation
friend operator<<
The documentation for this class was generated from the following file src/jac/machine/values.h