Shaka Player Embedded
|
#include <js_object_wrapper.h>
Classes | |
struct | Converter |
struct | Converter< void, Dummy > |
Public Member Functions | |
JsObjectWrapper () | |
~JsObjectWrapper () | |
SHAKA_NON_COPYABLE_OR_MOVABLE_TYPE (JsObjectWrapper) | |
template<typename Ret , typename... Args> | |
Converter< Ret >::future_type | CallMethod (const std::string &name, Args &&... args) const |
void | Init (Handle< JsObject > object) |
Static Public Member Functions | |
template<typename Ret , typename... Args> | |
static Converter< Ret >::future_type | CallGlobalMethod (const std::vector< std::string > &global_path, Args &&... args) |
template<typename T > | |
static Converter< T >::future_type | GetGlobalField (const std::vector< std::string > &global_path) |
static Error | ConvertError (Handle< JsValue > except) |
Protected Types | |
template<typename T > | |
using | bind_forward = typename std::add_const< typename std::remove_reference< T >::type >::type & |
Protected Member Functions | |
Converter< void >::variant_type | AttachEventListener (const std::string &name, std::function< void(const Error &)> on_error, std::function< void(Handle< JsObject > event)> handler) const |
Static Protected Member Functions | |
static Converter< void >::variant_type | CallMemberFunction (Handle< JsObject > that, const std::string &name, int argc, LocalVar< JsValue > *argv, LocalVar< JsValue > *result) |
template<typename T > | |
static Converter< T >::variant_type | GetFieldRaw (const std::vector< std::string > &global_path) |
template<typename Ret , typename... Args> | |
static void | CallMethodRaw (std::shared_ptr< std::promise< typename Converter< Ret >::variant_type >> p, variant< const Global< JsObject > *, std::vector< std::string >> that, const std::string &name, Args &&... args) |
template<typename Ret , typename... Args> | |
static Converter< Ret >::future_type | CallMethodCommon (variant< const Global< JsObject > *, std::vector< std::string >> that, const std::string &name, Args &&... args) |
Protected Attributes | |
Global< JsObject > | object_ |
A helper that wraps a JavaScript-defined object. This is meant to be used by the public types. This means this object holds a strong reference to the given JavaScript object and this returns the public types instead of using internal types (e.g. JsError).
Definition at line 45 of file js_object_wrapper.h.
|
protected |
When using std::bind, the arguments are stored in fields within the returned object. But we use perfect forwarding to accept arguments, so we may accept an lvalue or an rvalue. This means we need to convert the type we get to a const-lvalue so the field can be passed to the function.
Definition at line 240 of file js_object_wrapper.h.
shaka::JsObjectWrapper::JsObjectWrapper | ( | ) |
Definition at line 21 of file js_object_wrapper.cc.
shaka::JsObjectWrapper::~JsObjectWrapper | ( | ) |
Definition at line 22 of file js_object_wrapper.cc.
|
protected |
Attaches an event listener so the given callback is called when the given event is called.
name | The name of the event to listen for. |
on_error | A callback that is called if there is an error converting the arguments in the listener. |
handler | The callback that is called when the event is raised. |
Definition at line 67 of file js_object_wrapper.cc.
|
inlinestatic |
Calls the given global method and converts the returned value to the given type. If the function returns a Promise, this waits for the Promise to resolve first.
global_path | The "path" to get to the method. |
args | The arguments to pass to the function. |
Definition at line 107 of file js_object_wrapper.h.
|
staticprotected |
Calls the given member of the given object. If this throws an error, this returns it; otherwise it stores the return value in |*result|. This can only be called on the JS main thread.
Definition at line 89 of file js_object_wrapper.cc.
|
inline |
Calls the given member method and converts the returned value to the given type. If the function returns a Promise, this waits for the Promise to resolve first.
name | The name of the member method to call. |
args | The arguments to pass to the function. |
Definition at line 92 of file js_object_wrapper.h.
|
inlinestaticprotected |
Calls the given function, returning a Promise to the value. If this is called form the main thread, invokes it immediately; otherwise schedules it to be called later.
that | The "this" object; either an instance object or a "path" for a global object. |
name | The name of the member to call. |
args | The arguments to pass to the call. |
Definition at line 254 of file js_object_wrapper.h.
|
inlinestaticprotected |
Calls the given function and stores the result in the given Promise. This can only be called on the JS main thread.
p | The Promise that will be given the results |
that | The "this" object; either an instance object or a "path" for a global object. |
name | The name of the member to call. |
args | The arguments to pass to the call. |
Definition at line 186 of file js_object_wrapper.h.
|
static |
Converts the given JavaScript error object into a public Error object.
Definition at line 28 of file js_object_wrapper.cc.
|
inlinestaticprotected |
Gets a field's value and converts it to the given type. This can only be called on the JS main thread.
global_path | The "path" to get to the field. |
Definition at line 168 of file js_object_wrapper.h.
|
inlinestatic |
Gets a field of a global object and returns the converted value.
global_path | The "path" to get to the field. |
Definition at line 122 of file js_object_wrapper.h.
void shaka::JsObjectWrapper::Init | ( | Handle< JsObject > | object | ) |
Sets the object instance to use.
Definition at line 24 of file js_object_wrapper.cc.
shaka::JsObjectWrapper::SHAKA_NON_COPYABLE_OR_MOVABLE_TYPE | ( | JsObjectWrapper | ) |
|
protected |
Definition at line 272 of file js_object_wrapper.h.