Jerryscript::Object Class Reference

Objects support named properties. More...

#include <Types.h>

Inheritance diagram for Jerryscript::Object:
Collaboration diagram for Jerryscript::Object:

Classes

struct  NamedItem
 Iterator and operator[] access uses this wrapper class so items may be written or read. More...
 

Public Types

using List = Vector< Object >
 
- Public Types inherited from Jerryscript::Value
using List = Vector< Value >
 

Public Member Functions

 Object ()
 Default constructor creates a new, empty object. More...
 
 Object (const Value &value)
 
 Object (Value &&value)
 
Array keys () const
 Get list of property names. More...
 
Value runFunction (const String &name, Value &arg)
 Call a specified JavaScript function with exactly one argument. More...
 
Value runFunction (const String &name, std::initializer_list< Value > args={})
 Call a specified JavaScript function with zero or more arguments. More...
 
bool registerFunction (const String &name, jerry_external_handler_t handler)
 Register an external function so it may be called from javascript. More...
 
bool unregisterFunction (const String &name)
 Unregister an external function. More...
 
Callable getFunction (const String &name)
 Retrieve the given property as a function. More...
 
 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 (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...
 
Access object properties by name
NamedItem operator[] (const String &name)
 operator[] uses NamedItem proxy object so value can be assigned or read More...
 
const Value operator[] (const String &name) const
 const operator[] returns Value directly More...
 
Value setProperty (const Value &name, const Value &value)
 Set a property value. More...
 
Value getProperty (const Value &name) const
 Get a property value. More...
 
bool hasProperty (const Value &name) const
 Determine if a property exists. More...
 
bool removeProperty (const Value &name)
 Remove a property. More...
 
- Public Member Functions inherited from Jerryscript::Value
 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 ()
 
Valueoperator= (const Value &value)
 Assignment copy operator. More...
 
Valueoperator= (Value &&value)
 Assignment move operator. More...
 
Valuereset (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 >
as () const
 Get value of object with specific type. e.g. value.as<int>(). More...
 
 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...
 
const jerry_value_t & get () const
 const get() More...
 
jerry_value_t & get ()
 get() More...
 
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

Objects support named properties.

Member Typedef Documentation

◆ List

Constructor & Destructor Documentation

◆ Object() [1/3]

Jerryscript::Object::Object ( )
inline

Default constructor creates a new, empty object.

◆ Object() [2/3]

Jerryscript::Object::Object ( const Value value)
inline

◆ Object() [3/3]

Jerryscript::Object::Object ( Value &&  value)
inline

Member Function Documentation

◆ getFunction()

Callable Jerryscript::Object::getFunction ( const String name)

Retrieve the given property as a function.

Return values
Thecallable object, or error (property not found or isn't callable)

◆ getProperty()

Value Jerryscript::Object::getProperty ( const Value name) const
inline

Get a property value.

Parameters
nameProperty name
Return values
ValueThe property value, or Error

◆ hasProperty()

bool Jerryscript::Object::hasProperty ( const Value name) const
inline

Determine if a property exists.

Parameters
nameProperty name
Return values
booltrue if property exists

◆ keys()

Array Jerryscript::Object::keys ( ) const

Get list of property names.

◆ operator[]() [1/2]

NamedItem Jerryscript::Object::operator[] ( const String name)
inline

operator[] uses NamedItem proxy object so value can be assigned or read

◆ operator[]() [2/2]

const Value Jerryscript::Object::operator[] ( const String name) const
inline

const operator[] returns Value directly

◆ registerFunction()

bool Jerryscript::Object::registerFunction ( const String name,
jerry_external_handler_t  handler 
)
inline

Register an external function so it may be called from javascript.

Parameters
nameName of the function (property name)
handlerThe function handler, see Function.h for details
booltrue on success

◆ removeProperty()

bool Jerryscript::Object::removeProperty ( const Value name)
inline

Remove a property.

Parameters
nameProperty name
Return values
booltrue on success

◆ runFunction() [1/2]

Value Jerryscript::Object::runFunction ( const String name,
std::initializer_list< Value args = {} 
)

Call a specified JavaScript function with zero or more arguments.

Parameters
nameName of function to run (a property name)
Return values
ValueReturn value from function, or Error

◆ runFunction() [2/2]

Value Jerryscript::Object::runFunction ( const String name,
Value arg 
)

Call a specified JavaScript function with exactly one argument.

Parameters
nameName of function to run (a property name)
argThe argument
Return values
ValueReturn value from function, or Error

◆ setProperty()

Value Jerryscript::Object::setProperty ( const Value name,
const Value value 
)
inline

Set a property value.

Parameters
nameProperty name
valueValue to set
Return values
Valuetrue on success, otherwise Error

◆ unregisterFunction()

bool Jerryscript::Object::unregisterFunction ( const String name)
inline

Unregister an external function.

Parameters
nameName of the function
booltrue on success

◆ Value() [1/15]

Jerryscript::Value::Value
inline

Construct An empty (unused) value.

◆ Value() [2/15]

Jerryscript::Value::Value
inline

Boolean.

◆ Value() [3/15]

Jerryscript::Value::Value
inline

NUL-terminated 'C' string.

◆ Value() [4/15]

Jerryscript::Value::Value
inline

Construct a Value using a copy (or reference to) the given native value.

◆ Value() [5/15]

Jerryscript::Value::Value
inline

Flash String.

◆ Value() [6/15]

Jerryscript::Value::Value
inline

◆ Value() [7/15]

Jerryscript::Value::Value
inline

Construct a Value and take ownership of the given native value.

◆ Value() [8/15]

Jerryscript::Value::Value
inline

Wiring String.

◆ Value() [9/15]

Jerryscript::Value::Value
inline

Construct a string Value from the given native value.

◆ Value() [10/15]

Jerryscript::Value::Value
inline

◆ Value() [11/15]

Jerryscript::Value::Value
inline

Copy constructor.

◆ Value() [12/15]

Jerryscript::Value::Value
inline

floating-point

◆ Value() [13/15]

Jerryscript::Value::Value

Integer.

◆ Value() [14/15]

Jerryscript::Value::Value

Unsigned integer.

◆ Value() [15/15]

Jerryscript::Value::Value
inline

Move constructor.


The documentation for this class was generated from the following file: