Molybden API
Loading...
Searching...
No Matches
molybden::JsAccessible< C > Class Template Reference

The base class for defining JavaScript accessible object classes that can be automatically converted to JavaScript objects and vice versa. More...

#include <js_accessible.hpp>

Inheritance diagram for molybden::JsAccessible< C >:
molybden::JsProxyObjectImpl< C > molybden::JsProxyObject

Additional Inherited Members

- Public Member Functions inherited from molybden::JsProxyObject
template<class T >
std::shared_ptr< T > as ()
 Downcasts the object to the appropriate proxy type.
 
template<>
std::shared_ptr< JsProxyObjectas ()
 

Detailed Description

template<class C>
class molybden::JsAccessible< C >

The base class for defining JavaScript accessible object classes that can be automatically converted to JavaScript objects and vice versa.

Derive your custom accessible class from JsAccessible via CRTP pattern: class MyJsAccessibleClass : public JsAccessible<MyJsAccessibleClass> ...

To to make the object method callable from JavaScript, use JS_ACCESSIBLE_METHOD macro in the private section in the end of the class definition: ... public: void Foo(int x); ... private: JS_ACCESSIBLE_METHOD(Foo); }

To make the object field accessible from JavaScript, use JS_ACCESSIBLE_FIELD macro in the private section in the end of the class definition : ... private: int x; ... private: JS_ACCESSIBLE_FILED(x); }

The accessible objects as well as other custom JavaScript proxy objects are distributed and stored via std::shared_ptr, so one have to wrap the object into the shared pointer and only then pass it to the Molybden API. The ownership of the object will be shared between the client code and the library, and it can finally be deleted only if all the pages where it was used are unloaded, and if at the same time it is not referenced by other objects and scopes anymore.

If a class is derived from the JavaScript-accessible class via public or protected inheritance, it also becomes JavaScript-accessible. The custom downcast can be defined via defining the static method: class Base : public JsAccessible<Base> ... class Derived : public Base { ... static std::shared_ptr<Derived> downcast(std::shared_ptr<Base> object); ... }; If RTTI is enabled, the proxy objects are downcasted via dynamic_cast by default. Otherwise, no default downcast is provided and each downcast between the root JavaScript-accessible class and the derived ones should be defined.

JsAccessible provides default implementation of a JavaScript proxy object If you need custom implementation that cannot be achieved with JsAccessible, derive C from JsProxyObjectImpl<C> and implement the interface of JsProxyObject.

Template Parameters
Cthe class to make a proxy of.
See also
JsProxyObjectImpl.
JsProxyObject.

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