Molybden API
|
A JavaScript array. More...
#include <js_array.hpp>
Public Types | |
using | Private = JsArrayImpl |
Public Types inherited from molybden::JsObject | |
using | Private = JsObjectImpl |
Public Member Functions | |
JsArray (std::unique_ptr< Private > impl) | |
JsValue | get (uint32_t index) |
Returns the element by the specified index. | |
template<class T > | |
void | set (uint32_t index, T &&value) |
Inserts the specified element into the array at the specified index . | |
uint32_t | length () |
Returns the length of the JavaScript array. | |
std::vector< JsValue > | toVector () |
Fetches the JavaScript array values to a vector. | |
Public Member Functions inherited from molybden::JsObject | |
JsObject (std::unique_ptr< Private > impl) | |
std::shared_ptr< molybden::Frame > | frame () |
Returns the shared pointer to the Frame instance of this JavaScript object. | |
template<class T > | |
std::shared_ptr< T > | as () |
Returns the shared pointer of type T to this object if it represents one, or nullptr otherwise. | |
template<class... T> | |
JsReturnValue | call (const std::string &method_name, T &&... args) |
Executes the method with the given method_name and the args in the JavaScript object. | |
template<class T > | |
bool | putProperty (const std::string &name, T &&value) |
Creates a new property with the given name or updates the existing one in the current JavaScript object and returns true if the property with the given name was created or updated successfully. | |
bool | removeProperty (const std::string &name) |
Removes a property with the given name in the JavaScript object and returns true if the property was successfully removed. | |
JsValue | getProperty (const std::string &name) |
Returns the value of the JavaScript object's property with the given name . | |
std::vector< std::string > | propertyNames () |
Returns an immutable list of the names of the properties of this JavaScript object, including properties from the prototype objects. | |
std::vector< std::string > | ownPropertyNames () |
Returns an immutable list of the names of the properties of this JavaScript object, excluding properties from the prototype objects. | |
bool | hasProperty (const std::string &name) |
Checks whether the JavaScript object has a property or function with the given name . | |
template<> | |
std::shared_ptr< JsArray > | as () |
template<> | |
std::shared_ptr< JsObject > | as () |
Additional Inherited Members | |
Protected Attributes inherited from molybden::JsObject | |
std::unique_ptr< Private > | impl_ |
A JavaScript array.
An array object can be passed between Java and JavaScript as a method argument or a return value. The object lifetime is bound to the lifetime of the frame this object belongs to.
When the owner frame is unloaded, all the JavaScript objects are automatically disposed. Access to the already disposed JavaScript object will have no effect.
JsValue molybden::JsArray::get | ( | uint32_t | index | ) |
Returns the element by the specified index.
index | the element's index. |
void molybden::JsArray::set | ( | uint32_t | index, |
T && | value | ||
) |
Inserts the specified element
into the array at the specified index
.
If there is an existing element at the specified index
, it will be replaced. If the index
exceeds the array size, the array will be extended and the elements between the last inserted item and the index
will be set to undefined
.
The type mapping rules are the following:
C++ | JavaScript |
---|---|
double | Double |
std::string | String |
bool | Boolean |
std::shared_ptr<SomeJsObject> | Object |
std::shared_ptr<JsArray> | Array |
std::shared_ptr<SomeJsProxyObject> | Proxy Object |
where
SomeJsObject
is JsObject
or derived;SomeJsProxyObject
is JsProxyObject
or derived.Other types cannot be automatically converted to JavaScript values, and first must be converted to one of the types above.
std::vector< JsValue > molybden::JsArray::toVector | ( | ) |
Fetches the JavaScript array values to a vector.
Use this method instead get(uint32_t)
when you need to obtain the full array or a significant part. toVector
reads the whole array with one RPC call in contrast to get(uint32_t)
that involves an RPC request for each call. This can probably create a performance bottleneck.