v8toolkit
0.0.1
Utility library for embedding V8 Javascript engine in a c++ program
|
#include <debugger.h>
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 |
WebsocketChannel & | get_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< Isolate > | get_isolate_helper () const |
std::shared_ptr< Script > | compile (const std::string &source, const std::string &filename="Unspecified") |
std::shared_ptr< Script > | compile (const v8::Local< v8::String > source, const std::string &filename="Unspecified") |
std::shared_ptr< Script > | compile_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 |
Definition at line 271 of file debugger.h.
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().
|
inlineoverridevirtual |
Definition at line 286 of file debugger.h.
|
inlineoverridevirtual |
Definition at line 294 of file debugger.h.
|
inline |
Definition at line 299 of file debugger.h.
|
inline |
Definition at line 300 of file debugger.h.
|
inlineoverride |
Definition at line 303 of file debugger.h.
|
inline |
Definition at line 310 of file debugger.h.
|
inline |
Definition at line 311 of file debugger.h.
Referenced by v8toolkit::WebsocketChannel::WebsocketChannel().
void v8toolkit::DebugContext::reset_session | ( | ) |
Definition at line 257 of file debugger.cpp.
Referenced by DebugContext(), and v8toolkit::WebsocketChannel::WebsocketChannel().
|
inherited |
|
inherited |
Returns all the scripts associated with this context
|
inherited |
Returns a list of functions compiled directly to this context (vs those in a script)
|
inherited |
Registers an externally created script object with this Context and returns a wrapped Script object
external_script | script that was created 'by hand' not with a method on this context |
|
inherited |
|
inherited |
Returns the global context object - useful for GLOBAL_CONTEXT_SCOPED_RUN
Definition at line 160 of file javascript.cpp.
Referenced by v8toolkit::WebsocketChannel::WebsocketChannel().
|
inlineinherited |
Implicit cast to v8::Isolate *
Definition at line 113 of file javascript.h.
References v8toolkit::Context::isolate.
|
inlineinherited |
Implicit cast to v8::Local<v8::Context>
Definition at line 118 of file javascript.h.
|
inlineinherited |
Implicit cast to v8::Global<v8::Context>
Definition at line 123 of file javascript.h.
References v8toolkit::Context::compile(), v8toolkit::Context::compile_from_file(), v8toolkit::Context::get_context(), v8toolkit::Context::get_isolate(), v8toolkit::Context::get_isolate_helper(), v8toolkit::Context::isolate, v8toolkit::Context::run(), v8toolkit::Context::run_async(), v8toolkit::Context::run_detached(), v8toolkit::Context::run_from_file(), and v8toolkit::Context::run_thread().
|
inherited |
Returns a Local copy of the associated v8::Context
Definition at line 24 of file javascript.cpp.
References v8toolkit::Context::isolate.
Referenced by v8toolkit::Context::add_function(), v8toolkit::Context::add_variable(), DebugContext(), v8toolkit::Context::expose_variable(), v8toolkit::Context::expose_variable_readonly(), v8toolkit::Context::operator v8::Global< v8::Context >(), v8toolkit::Context::require(), and v8toolkit::Context::wrap_object().
|
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().
|
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 >().
|
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().
|
inherited |
Compiles the contents of the passed in v8::String as javascript Throws v8toolkit::CompilationError on compilation error
|
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().
|
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().
|
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().
|
inherited |
Definition at line 146 of file javascript.cpp.
References v8toolkit::Context::run().
|
inherited |
Definition at line 154 of file javascript.cpp.
References v8toolkit::Context::compile_from_file().
Referenced by v8toolkit::Context::operator v8::Global< v8::Context >().
|
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 >().
|
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().
|
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().
|
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?
|
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().
|
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().
|
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?
|
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.
|
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.
|
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.
|
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().
|
inlineinherited |
Creates a global javascript variable to the specified context and sets it to the given javascript value.
name | name of the JavaScript variable |
variable | JavaScript 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.
|
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().
|
inlineinherited |
Definition at line 327 of file javascript.h.
References v8toolkit::expose_variable_readonly(), v8toolkit::Context::get_context(), v8toolkit::Context::get_function_by_id(), v8toolkit::Context::get_script_by_id(), v8toolkit::Context::get_url(), v8toolkit::Context::get_uuid(), v8toolkit::Context::get_uuid_string(), v8toolkit::Context::json(), v8toolkit::Context::require(), v8toolkit::Context::require_directory(), and v8toolkit::Context::wrap_object().
|
inherited |
Definition at line 40 of file javascript.cpp.
References v8toolkit::get_debug_context().
Referenced by v8toolkit::Context::expose_variable_readonly().
|
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().
|
inherited |
Definition at line 192 of file javascript.cpp.
Referenced by v8toolkit::Context::expose_variable_readonly().
|
inherited |
Definition at line 195 of file javascript.cpp.
Referenced by v8toolkit::Context::expose_variable_readonly(), and v8toolkit::Context::get_url().
|
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().
|
inherited |
Returns the script corresponding to the given id or throws
script_id | script id to find |
Referenced by v8toolkit::Context::expose_variable_readonly().
|
inherited |
Referenced by v8toolkit::Context::expose_variable_readonly().
|
inherited |
Evaluates the specified file and returns the result - can be .js or .json
filename | file containing javascript or json to evaluate |
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().
|
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().
|
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().
|
inherited |
shortcut to the v8::isolate object instead of always going through the Isolate
Definition at line 69 of file javascript.h.
Referenced by v8toolkit::Context::compile(), v8toolkit::Platform::create_isolate(), DebugContext(), v8toolkit::Context::get_context(), v8toolkit::Context::get_isolate(), v8toolkit::Isolate::get_isolate(), v8toolkit::Context::operator v8::Global< v8::Context >(), v8toolkit::Context::operator v8::Isolate *(), v8toolkit::Isolate::operator v8::Isolate *(), v8toolkit::Context::require_directory(), and v8toolkit::Context::run().