Shaka Player Embedded
Classes | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
shaka::JsObjectWrapper Class Reference

#include <js_object_wrapper.h>

Inheritance diagram for shaka::JsObjectWrapper:
shaka::Player::Impl shaka::Storage::Impl

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_
 

Detailed Description

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.

Member Typedef Documentation

§ bind_forward

template<typename T >
using shaka::JsObjectWrapper::bind_forward = typename std::add_const<typename std::remove_reference<T>::type>::type&
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.

Constructor & Destructor Documentation

§ JsObjectWrapper()

shaka::JsObjectWrapper::JsObjectWrapper ( )

Definition at line 21 of file js_object_wrapper.cc.

§ ~JsObjectWrapper()

shaka::JsObjectWrapper::~JsObjectWrapper ( )

Definition at line 22 of file js_object_wrapper.cc.

Member Function Documentation

§ AttachEventListener()

JsObjectWrapper::Converter< void >::variant_type shaka::JsObjectWrapper::AttachEventListener ( const std::string &  name,
std::function< void(const Error &)>  on_error,
std::function< void(Handle< JsObject > event)>  handler 
) const
protected

Attaches an event listener so the given callback is called when the given event is called.

Parameters
nameThe name of the event to listen for.
on_errorA callback that is called if there is an error converting the arguments in the listener.
handlerThe callback that is called when the event is raised.

Definition at line 67 of file js_object_wrapper.cc.

§ CallGlobalMethod()

template<typename Ret , typename... Args>
static Converter<Ret>::future_type shaka::JsObjectWrapper::CallGlobalMethod ( const std::vector< std::string > &  global_path,
Args &&...  args 
)
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.

Parameters
global_pathThe "path" to get to the method.
argsThe arguments to pass to the function.
Returns
A Future that will contain the converted return value.

Definition at line 107 of file js_object_wrapper.h.

§ CallMemberFunction()

JsObjectWrapper::Converter< void >::variant_type shaka::JsObjectWrapper::CallMemberFunction ( Handle< JsObject >  that,
const std::string &  name,
int  argc,
LocalVar< JsValue > *  argv,
LocalVar< JsValue > *  result 
)
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.

§ CallMethod()

template<typename Ret , typename... Args>
Converter<Ret>::future_type shaka::JsObjectWrapper::CallMethod ( const std::string &  name,
Args &&...  args 
) const
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.

Parameters
nameThe name of the member method to call.
argsThe arguments to pass to the function.
Returns
A Future that will contain the converted return value.

Definition at line 92 of file js_object_wrapper.h.

§ CallMethodCommon()

template<typename Ret , typename... Args>
static Converter<Ret>::future_type shaka::JsObjectWrapper::CallMethodCommon ( variant< const Global< JsObject > *, std::vector< std::string >>  that,
const std::string &  name,
Args &&...  args 
)
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.

Parameters
thatThe "this" object; either an instance object or a "path" for a global object.
nameThe name of the member to call.
argsThe arguments to pass to the call.
Returns
A Future to the converted return value of the call.

Definition at line 254 of file js_object_wrapper.h.

§ CallMethodRaw()

template<typename Ret , typename... Args>
static void shaka::JsObjectWrapper::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 
)
inlinestaticprotected

Calls the given function and stores the result in the given Promise. This can only be called on the JS main thread.

Parameters
pThe Promise that will be given the results
thatThe "this" object; either an instance object or a "path" for a global object.
nameThe name of the member to call.
argsThe arguments to pass to the call.

Definition at line 186 of file js_object_wrapper.h.

§ ConvertError()

Error shaka::JsObjectWrapper::ConvertError ( Handle< JsValue >  except)
static

Converts the given JavaScript error object into a public Error object.

Definition at line 28 of file js_object_wrapper.cc.

§ GetFieldRaw()

template<typename T >
static Converter<T>::variant_type shaka::JsObjectWrapper::GetFieldRaw ( const std::vector< std::string > &  global_path)
inlinestaticprotected

Gets a field's value and converts it to the given type. This can only be called on the JS main thread.

Parameters
global_pathThe "path" to get to the field.
Returns
The converted value.

Definition at line 168 of file js_object_wrapper.h.

§ GetGlobalField()

template<typename T >
static Converter<T>::future_type shaka::JsObjectWrapper::GetGlobalField ( const std::vector< std::string > &  global_path)
inlinestatic

Gets a field of a global object and returns the converted value.

Parameters
global_pathThe "path" to get to the field.
Returns
A Future that will contain the converted field value.

Definition at line 122 of file js_object_wrapper.h.

§ Init()

void shaka::JsObjectWrapper::Init ( Handle< JsObject >  object)

Sets the object instance to use.

Definition at line 24 of file js_object_wrapper.cc.

§ SHAKA_NON_COPYABLE_OR_MOVABLE_TYPE()

shaka::JsObjectWrapper::SHAKA_NON_COPYABLE_OR_MOVABLE_TYPE ( JsObjectWrapper  )

Member Data Documentation

§ object_

Global<JsObject> shaka::JsObjectWrapper::object_
protected

Definition at line 272 of file js_object_wrapper.h.


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