v8toolkit  0.0.1
Utility library for embedding V8 Javascript engine in a c++ program
Public Member Functions | Protected Types | Protected Attributes | List of all members
v8toolkit::JSWrapper< T > Class Template Reference

#include <sample2.h>

Inheritance diagram for v8toolkit::JSWrapper< T >:
Inheritance graph
[legend]
Collaboration diagram for v8toolkit::JSWrapper< T >:
Collaboration graph
[legend]

Public Member Functions

 JSWrapper (v8::Local< v8::Context > context, v8::Local< v8::Object > object, v8::Local< v8::FunctionTemplate > created_by)
 
v8::Local< v8::Object > get_javascript_object () const
 

Protected Types

using BASE_TYPE = Base
 

Protected Attributes

v8::Isolate * isolate
 
v8::Global< v8::Context > global_context
 
v8::Global< v8::Object > global_js_object
 
v8::Global< v8::FunctionTemplate > global_created_by
 
bool called_from_javascript = false
 

Detailed Description

template<class T>
class v8toolkit::JSWrapper< T >

C++ types to be extended in javascript must inherit from this class. Example: class MyClass{}; class JSMyClass : public MyClass, public JSWrapper {}; Now, JSMyClass can be used as a MyClass, but will intercept calls to its methods and attempt to use the javascript object to fulfill them, falling back to the C++ class methods of MyClass when necessary Any class inheriting from this (e.g. JSMyClass) must have the first two parameters of its constructor be a v8::Local<v8::Context>, v8::Local<v8::Object>

Definition at line 22 of file sample2.h.

Member Typedef Documentation

template<class T>
using v8toolkit::JSWrapper< T >::BASE_TYPE = Base
protected

Definition at line 78 of file bidirectional.h.

Constructor & Destructor Documentation

template<class T>
v8toolkit::JSWrapper< T >::JSWrapper ( v8::Local< v8::Context >  context,
v8::Local< v8::Object >  object,
v8::Local< v8::FunctionTemplate >  created_by 
)
inline

Definition at line 81 of file bidirectional.h.

Member Function Documentation

v8::Local<v8::Object> v8toolkit::JSWrapperBase::get_javascript_object ( ) const
inlineinherited

Definition at line 61 of file bidirectional.h.

Referenced by v8toolkit::CastToJS< JSWrapper< T > >::operator()().

Here is the caller graph for this function:

Member Data Documentation

v8::Isolate* v8toolkit::JSWrapperBase::isolate
protectedinherited

Definition at line 38 of file bidirectional.h.

v8::Global<v8::Context> v8toolkit::JSWrapperBase::global_context
protectedinherited

Definition at line 39 of file bidirectional.h.

v8::Global<v8::Object> v8toolkit::JSWrapperBase::global_js_object
protectedinherited

Definition at line 40 of file bidirectional.h.

v8::Global<v8::FunctionTemplate> v8toolkit::JSWrapperBase::global_created_by
protectedinherited

Definition at line 41 of file bidirectional.h.

bool v8toolkit::JSWrapperBase::called_from_javascript = false
mutableprotectedinherited

It's easy to end up in infinite recursion where the JSWrapper object looks for a javascript implementation to call instead of calling the native C++ implementation, but finds its own JS_ACCESS function that its already in an proceeds to call itself. This flag stops that from happening - at least in naive situations. Marked as mutable because it needs to be changed even from within const methods

Definition at line 49 of file bidirectional.h.


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