v8toolkit  0.0.1
Utility library for embedding V8 Javascript engine in a c++ program
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
v8toolkit::DebugContext Class Reference

#include <debugger.h>

Inheritance diagram for v8toolkit::DebugContext:
Inheritance graph
[legend]
Collaboration diagram for v8toolkit::DebugContext:
Collaboration graph
[legend]

Public Member Functions

 DebugContext (std::shared_ptr< v8toolkit::Isolate > isolate_helper, v8::Local< v8::Context > context, short port)
 
virtual void runMessageLoopOnPause (int contextGroupId) override
 
virtual void quitMessageLoopOnPause () override
 
std::string const & get_frame_id () const
 
std::string get_base_url () const
 
v8::Local< v8::Context > ensureDefaultContextInGroup (int group_id) override
 
WebsocketChannelget_channel ()
 
v8_inspector::V8InspectorSession & get_session ()
 
void reset_session ()
 
void shutdown ()
 
std::vector< ScriptPtr > const & get_scripts () const
 
std::vector< v8::Global< v8::Function > > const & get_functions () const
 
void register_external_script (v8::Local< v8::Script > external_script, std::string const &source_code)
 
void register_external_function (v8::Global< v8::Function > external_function)
 
v8::Global< v8::Context > const & get_global_context () const
 
 operator v8::Isolate * () const
 
 operator v8::Local< v8::Context > () const
 
 operator v8::Global< v8::Context > () const
 
v8::Local< v8::Context > get_context () const
 
v8::Isolate * get_isolate () const
 
std::shared_ptr< Isolateget_isolate_helper () const
 
std::shared_ptr< Scriptcompile (const std::string &source, const std::string &filename="Unspecified")
 
std::shared_ptr< Scriptcompile (const v8::Local< v8::String > source, const std::string &filename="Unspecified")
 
std::shared_ptr< Scriptcompile_from_file (const std::string &filename)
 
v8::Global< v8::Value > run (const v8::Global< v8::Script > &script)
 
v8::Global< v8::Value > run (const std::string &source)
 
v8::Global< v8::Value > run (const v8::Local< v8::Value > script)
 
v8::Global< v8::Value > run_from_file (const std::string &filename)
 
std::future< std::pair< ScriptPtr, v8::Global< v8::Value > > > run_async (const std::string &source, std::launch launch_policy=std::launch::async|std::launch::deferred)
 
std::thread run_thread (const v8::Global< v8::Script > &script)
 
std::thread run_thread (const std::string &source)
 
std::thread run_thread (const v8::Local< v8::Value > script)
 
void run_detached (const v8::Global< v8::Script > &script)
 
void run_detached (const std::string &source)
 
void run_detached (const v8::Local< v8::Value > script)
 
template<class Callable >
auto operator() (Callable &&callable) -> std::result_of_t< Callable()>
 
template<class Callable >
auto operator() (Callable &&callable) -> std::result_of_t< Callable(v8::Isolate *)>
 
template<class Callable >
auto operator() (Callable &&callable) -> typename std::result_of< Callable(v8::Isolate *, v8::Local< v8::Context >)>::type
 
template<class Function >
void add_function (std::string name, Function function)
 
void add_variable (std::string name, v8::Local< v8::Value > variable)
 
template<class Variable >
void expose_variable (std::string name, Variable &variable)
 
template<class Variable >
void expose_variable_readonly (std::string name, Variable &variable)
 
v8::Local< v8::Value > json (const std::string &json)
 
template<class T >
v8::Local< v8::Value > wrap_object (T *object)
 
boost::uuids::uuid const & get_uuid () const
 
std::string get_uuid_string () const
 
std::string get_url (std::string const &name) const
 
Script const & get_script_by_id (int64_t script_id)
 
v8::Local< v8::Function > get_function_by_id (int64_t script_id)
 
v8::Local< v8::Value > require (std::string const &filename, std::vector< std::string > const &paths)
 
void require_directory (std::string const &directory_name)
 

Public Attributes

bool paused = false
 
v8::Isolate *const isolate
 shortcut to the v8::isolate object instead of always going through the Isolate More...
 

Static Public Attributes

static const int kContextGroupId = 1
 

Detailed Description

Definition at line 271 of file debugger.h.

Constructor & Destructor Documentation

v8toolkit::DebugContext::DebugContext ( std::shared_ptr< v8toolkit::Isolate isolate_helper,
v8::Local< v8::Context >  context,
short  port 
)

Definition at line 260 of file debugger.cpp.

References v8toolkit::Context::get_context(), v8toolkit::Context::isolate, kContextGroupId, v8toolkit::kInspectorClientIndex, and reset_session().

Here is the call graph for this function:

Member Function Documentation

virtual void v8toolkit::DebugContext::runMessageLoopOnPause ( int  contextGroupId)
inlineoverridevirtual

Definition at line 286 of file debugger.h.

virtual void v8toolkit::DebugContext::quitMessageLoopOnPause ( )
inlineoverridevirtual

Definition at line 294 of file debugger.h.

std::string const& v8toolkit::DebugContext::get_frame_id ( ) const
inline

Definition at line 299 of file debugger.h.

std::string v8toolkit::DebugContext::get_base_url ( ) const
inline

Definition at line 300 of file debugger.h.

v8::Local<v8::Context> v8toolkit::DebugContext::ensureDefaultContextInGroup ( int  group_id)
inlineoverride

Definition at line 303 of file debugger.h.

WebsocketChannel& v8toolkit::DebugContext::get_channel ( )
inline

Definition at line 310 of file debugger.h.

v8_inspector::V8InspectorSession& v8toolkit::DebugContext::get_session ( )
inline

Definition at line 311 of file debugger.h.

Referenced by v8toolkit::WebsocketChannel::WebsocketChannel().

Here is the caller graph for this function:

void v8toolkit::DebugContext::reset_session ( )

Definition at line 257 of file debugger.cpp.

Referenced by DebugContext(), and v8toolkit::WebsocketChannel::WebsocketChannel().

Here is the caller graph for this function:

void v8toolkit::Context::shutdown ( )
inherited

Allows for possible destruction of the Context once all Script objects are released. This clears out all internal references to scripts to stop any circular references. The context will have diminished functionality after shutdown is called on it.

std::vector<ScriptPtr> const& v8toolkit::Context::get_scripts ( ) const
inherited

Returns all the scripts associated with this context

Returns
a vector of all the scripts associated with this context
std::vector<v8::Global<v8::Function> > const& v8toolkit::Context::get_functions ( ) const
inherited

Returns a list of functions compiled directly to this context (vs those in a script)

Returns
a list of functions compiled directly to this context (vs those in a script)
void v8toolkit::Context::register_external_script ( v8::Local< v8::Script >  external_script,
std::string const &  source_code 
)
inherited

Registers an externally created script object with this Context and returns a wrapped Script object

Parameters
external_scriptscript that was created 'by hand' not with a method on this context
Returns
wrapped v8toolkit::Script object
void v8toolkit::Context::register_external_function ( v8::Global< v8::Function >  external_function)
inherited
v8::Global< v8::Context > const & v8toolkit::Context::get_global_context ( ) const
inherited

Returns the global context object - useful for GLOBAL_CONTEXT_SCOPED_RUN

Returns
the global context object

Definition at line 160 of file javascript.cpp.

Referenced by v8toolkit::WebsocketChannel::WebsocketChannel().

Here is the caller graph for this function:

v8toolkit::Context::operator v8::Isolate * ( ) const
inlineinherited

Implicit cast to v8::Isolate *

Definition at line 113 of file javascript.h.

References v8toolkit::Context::isolate.

v8toolkit::Context::operator v8::Local< v8::Context > ( ) const
inlineinherited

Implicit cast to v8::Local<v8::Context>

Definition at line 118 of file javascript.h.

v8toolkit::Context::operator v8::Global< v8::Context > ( ) const
inlineinherited
v8::Local< v8::Context > v8toolkit::Context::get_context ( ) const
inherited
v8::Isolate * v8toolkit::Context::get_isolate ( ) const
inherited

Returns the v8::Isolate * this context is associated with

Definition at line 29 of file javascript.cpp.

References v8toolkit::Context::isolate.

Referenced by v8toolkit::Isolate::add_module_list(), v8toolkit::Context::operator v8::Global< v8::Context >(), v8toolkit::Context::require_directory(), v8toolkit::WebsocketChannel::WebsocketChannel(), and v8toolkit::Context::wrap_object().

Here is the caller graph for this function:

std::shared_ptr< Isolate > v8toolkit::Context::get_isolate_helper ( ) const
inherited

Returns the Isolate wrapping the isolate this context is associated with

Definition at line 35 of file javascript.cpp.

Referenced by v8toolkit::Context::operator v8::Global< v8::Context >().

Here is the caller graph for this function:

std::shared_ptr< Script > v8toolkit::Context::compile ( const std::string &  source,
const std::string &  filename = "Unspecified" 
)
inherited

Compiles the contents of the passed in string as javascripts Throws v8toolkit::CompilationError on compilation error

Definition at line 67 of file javascript.cpp.

References v8toolkit::Context::get_url(), GLOBAL_CONTEXT_SCOPED_RUN, and v8toolkit::Context::isolate.

Referenced by v8toolkit::Context::compile_from_file(), v8toolkit::Context::operator v8::Global< v8::Context >(), v8toolkit::Context::run(), v8toolkit::Context::run_async(), v8toolkit::Context::run_detached(), and v8toolkit::Context::run_thread().

Here is the call graph for this function:

Here is the caller graph for this function:

std::shared_ptr<Script> v8toolkit::Context::compile ( const v8::Local< v8::String >  source,
const std::string &  filename = "Unspecified" 
)
inherited

Compiles the contents of the passed in v8::String as javascript Throws v8toolkit::CompilationError on compilation error

std::shared_ptr< Script > v8toolkit::Context::compile_from_file ( const std::string &  filename)
inherited

Loads the contents of the given file as javascript Throws v8toolkit::CompilationError on compilation error TODO: what if the file can't be opened?

Definition at line 54 of file javascript.cpp.

References v8toolkit::Context::compile(), and v8toolkit::get_file_contents().

Referenced by v8toolkit::Context::operator v8::Global< v8::Context >(), and v8toolkit::Context::run_from_file().

Here is the call graph for this function:

Here is the caller graph for this function:

v8::Global< v8::Value > v8toolkit::Context::run ( const v8::Global< v8::Script > &  script)
inherited

Runs the previously compiled v8::Script. Throws v8toolkit::ExecutionError on execution error

Definition at line 98 of file javascript.cpp.

References GLOBAL_CONTEXT_SCOPED_RUN, v8toolkit::Context::isolate, and v8toolkit::ReportException().

Referenced by v8toolkit::Context::operator v8::Global< v8::Context >(), v8toolkit::Context::run(), v8toolkit::Script::run_async(), and v8toolkit::Script::run_thread().

Here is the call graph for this function:

Here is the caller graph for this function:

v8::Global< v8::Value > v8toolkit::Context::run ( const std::string &  source)
inherited

Compiles and runs the contents ot the passed in string Throws v8toolkit::CompilationError on compilation error Throws v8toolkit::ExecutionError on execution error

Definition at line 136 of file javascript.cpp.

References v8toolkit::Context::compile().

Here is the call graph for this function:

v8::Global< v8::Value > v8toolkit::Context::run ( const v8::Local< v8::Value >  script)
inherited

Definition at line 146 of file javascript.cpp.

References v8toolkit::Context::run().

Here is the call graph for this function:

v8::Global< v8::Value > v8toolkit::Context::run_from_file ( const std::string &  filename)
inherited

Definition at line 154 of file javascript.cpp.

References v8toolkit::Context::compile_from_file().

Referenced by v8toolkit::Context::operator v8::Global< v8::Context >().

Here is the call graph for this function:

Here is the caller graph for this function:

std::future< std::pair< ScriptPtr, v8::Global< v8::Value > > > v8toolkit::Context::run_async ( const std::string &  source,
std::launch  launch_policy = std::launch::async | std::launch::deferred 
)
inherited

Compiles and runs the contents of the passed in string in a std::async and returns the std::future associated with it. The future has the result of the javascript as well as a shared_ptr to the Script to make sure the value can still be used

While any number of threaded calls can be made, only one context per isolate can be actively running at a time. Additional calls will be queued but will block until they can acquire the v8::Locker object for their isolate TODO: what happens if there are errors in compilation? TODO: what happens if there are errors in execution?

Definition at line 166 of file javascript.cpp.

References v8toolkit::Context::compile().

Referenced by v8toolkit::Context::operator v8::Global< v8::Context >().

Here is the call graph for this function:

Here is the caller graph for this function:

std::thread v8toolkit::Context::run_thread ( const v8::Global< v8::Script > &  script)
inherited

Executes the previously compiled v8::script in a std::thread and returns the std::thread associated with it. It must either be joined or detached before the std::thread object is destroyed While any number of threaded calls can be made, only one context per isolate can be actively running at a time. Additional calls will be queued but will block until they can acquire the v8::Locker object for their isolate TODO: what happens if there are errors in execution?

Referenced by v8toolkit::Context::operator v8::Global< v8::Context >(), v8toolkit::Script::run_async(), and v8toolkit::Script::run_detached().

Here is the caller graph for this function:

std::thread v8toolkit::Context::run_thread ( const std::string &  source)
inherited

Compiles and runs the contents of the passed in string in a in a std::thread and returns the std::thread associated with it. It must either be joined or detached before the std::thread object is destroyed While any number of threaded calls can be made, only one context per isolate can be actively running at a time. Additional calls will be queued but will block until they can acquire the v8::Locker object for their isolate TODO: what happens if there are errors in compilation? TODO: what happens if there are errors in execution?

Definition at line 184 of file javascript.cpp.

References v8toolkit::Context::compile().

Here is the call graph for this function:

std::thread v8toolkit::Context::run_thread ( const v8::Local< v8::Value >  script)
inherited

Executes the previously compiled v8::script in a std::thread and returns the std::thread associated with it. It must either be joined or detached before the std::thread object is destroyed While any number of threaded calls can be made, only one context per isolate can be actively running at a time. Additional calls will be queued but will block until they can acquire the v8::Locker object for their isolate TODO: what happens if there are errors in execution?

void v8toolkit::Context::run_detached ( const v8::Global< v8::Script > &  script)
inherited

Executes the previously compiled v8::script in a detached std::thread. While any number of threaded calls can be made, only one context per isolate can be actively running at a time. Additional calls will be queued but will block until they can acquire the v8::Locker object for their isolate TODO: what happens if there are errors in execution?

Referenced by v8toolkit::Context::operator v8::Global< v8::Context >(), and v8toolkit::Script::run_async().

Here is the caller graph for this function:

void v8toolkit::Context::run_detached ( const std::string &  source)
inherited

Compiles and runs the contents of the passed in string in a detached std::thread. While any number of threaded calls can be made, only one context per isolate can be actively running at a time. Additional calls will be queued but will block until they can acquire the v8::Locker object for their isolate TODO: what happens if there are errors in compilation? TODO: what happens if there are errors in execution?

Definition at line 176 of file javascript.cpp.

References v8toolkit::Context::compile().

Here is the call graph for this function:

void v8toolkit::Context::run_detached ( const v8::Local< v8::Value >  script)
inherited

Executes the previously compiled v8::script in a detached std::thread. While any number of threaded calls can be made, only one context per isolate can be actively running at a time. Additional calls will be queued but will block until they can acquire the v8::Locker object for their isolate TODO: what happens if there are errors in execution?

template<class Callable >
auto v8toolkit::Context::operator() ( Callable &&  callable) -> std::result_of_t<Callable()>
inlineinherited

Calls v8toolkit::scoped_run with the associated isolate and context data

Definition at line 266 of file javascript.h.

References GLOBAL_CONTEXT_SCOPED_RUN.

template<class Callable >
auto v8toolkit::Context::operator() ( Callable &&  callable) -> std::result_of_t<Callable(v8::Isolate*)>
inlineinherited

Calls v8toolkit::scoped_run with the associated isolate and context data Passes the v8::Isolate * into the callback

Definition at line 277 of file javascript.h.

References GLOBAL_CONTEXT_SCOPED_RUN.

template<class Callable >
auto v8toolkit::Context::operator() ( Callable &&  callable) -> typename std::result_of<Callable(v8::Isolate*, v8::Local<v8::Context>)>::type
inlineinherited

Calls v8toolkit::scoped_run with the assciated isolate and context data Passes the v8::Isolate * and context into the callback

Definition at line 288 of file javascript.h.

References GLOBAL_CONTEXT_SCOPED_RUN.

template<class Function >
void v8toolkit::Context::add_function ( std::string  name,
Function  function 
)
inlineinherited

Adds a function to this context only See: v8toolkit::add_function

Definition at line 299 of file javascript.h.

References v8toolkit::add_function(), v8toolkit::Context::get_context(), and GLOBAL_CONTEXT_SCOPED_RUN.

Referenced by v8toolkit::Isolate::add_assert().

Here is the call graph for this function:

Here is the caller graph for this function:

void v8toolkit::Context::add_variable ( std::string  name,
v8::Local< v8::Value >  variable 
)
inlineinherited

Creates a global javascript variable to the specified context and sets it to the given javascript value.

Parameters
namename of the JavaScript variable
variableJavaScript value for the variable to refer to

Definition at line 310 of file javascript.h.

References v8toolkit::add_variable(), v8toolkit::Context::get_context(), and GLOBAL_CONTEXT_SCOPED_RUN.

Here is the call graph for this function:

template<class Variable >
void v8toolkit::Context::expose_variable ( std::string  name,
Variable &  variable 
)
inlineinherited

Exposes a C++ variable to this context only see: v8toolkit::expose_variable

Definition at line 321 of file javascript.h.

References v8toolkit::expose_variable(), and v8toolkit::Context::get_context().

Here is the call graph for this function:

template<class Variable >
void v8toolkit::Context::expose_variable_readonly ( std::string  name,
Variable &  variable 
)
inlineinherited
v8::Local< v8::Value > v8toolkit::Context::json ( const std::string &  json)
inherited

Definition at line 40 of file javascript.cpp.

References v8toolkit::get_debug_context().

Referenced by v8toolkit::Context::expose_variable_readonly().

Here is the call graph for this function:

Here is the caller graph for this function:

template<class T >
v8::Local< v8::Value > v8toolkit::Context::wrap_object ( T *  object)
inherited

Returns a javascript object representation of the given c++ object see: votoolkit::V8ClassWrapper

Definition at line 699 of file javascript.h.

References v8toolkit::Context::get_context(), and v8toolkit::Context::get_isolate().

Referenced by v8toolkit::Context::expose_variable_readonly().

Here is the call graph for this function:

Here is the caller graph for this function:

boost::uuids::uuid const & v8toolkit::Context::get_uuid ( ) const
inherited

Definition at line 192 of file javascript.cpp.

Referenced by v8toolkit::Context::expose_variable_readonly().

Here is the caller graph for this function:

std::string v8toolkit::Context::get_uuid_string ( ) const
inherited

Definition at line 195 of file javascript.cpp.

Referenced by v8toolkit::Context::expose_variable_readonly(), and v8toolkit::Context::get_url().

Here is the caller graph for this function:

std::string v8toolkit::Context::get_url ( std::string const &  name) const
inherited

Definition at line 200 of file javascript.cpp.

References v8toolkit::Context::get_uuid_string().

Referenced by v8toolkit::Context::compile(), v8toolkit::Context::expose_variable_readonly(), and v8toolkit::Context::require().

Here is the call graph for this function:

Here is the caller graph for this function:

Script const& v8toolkit::Context::get_script_by_id ( int64_t  script_id)
inherited

Returns the script corresponding to the given id or throws

Parameters
script_idscript id to find
Returns
script with given script_id

Referenced by v8toolkit::Context::expose_variable_readonly().

Here is the caller graph for this function:

v8::Local<v8::Function> v8toolkit::Context::get_function_by_id ( int64_t  script_id)
inherited

Referenced by v8toolkit::Context::expose_variable_readonly().

Here is the caller graph for this function:

v8::Local< v8::Value > v8toolkit::Context::require ( std::string const &  filename,
std::vector< std::string > const &  paths 
)
inherited

Evaluates the specified file and returns the result - can be .js or .json

Parameters
filenamefile containing javascript or json to evaluate
Returns
the result of the evaluation or empty on failure

Definition at line 208 of file javascript.cpp.

References v8toolkit::Context::get_context(), v8toolkit::Context::get_url(), and v8toolkit::require().

Referenced by v8toolkit::Context::expose_variable_readonly(), and v8toolkit::Context::require_directory().

Here is the call graph for this function:

Here is the caller graph for this function:

void v8toolkit::Context::require_directory ( std::string const &  directory_name)
inherited

Definition at line 217 of file javascript.cpp.

References v8toolkit::foreach_file(), v8toolkit::Context::get_isolate(), v8toolkit::Context::isolate, v8toolkit::Context::require(), and v8toolkit::scoped_run().

Referenced by v8toolkit::Context::expose_variable_readonly().

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

const int v8toolkit::DebugContext::kContextGroupId = 1
static

Definition at line 307 of file debugger.h.

Referenced by DebugContext().

bool v8toolkit::DebugContext::paused = false

Definition at line 308 of file debugger.h.

Referenced by v8toolkit::WebsocketChannel::WebsocketChannel().

v8::Isolate* const v8toolkit::Context::isolate
inherited

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