ark::js::JavaScriptRuntime
Defined in header “ark/js/js_runtime.hh”.
Allows construction of a javascript engine, which allows you to execute javascript code from within your C++ code (and retrieve the results/variables again).
Methods
-
JavaScriptRuntime()
Constructor. Initializes a new engine. -
~JavaScriptRuntime()
Destructor. Tears down the engine. -
JavaScriptValue evaluate(const std::string & code)
Evaluates the given javascript code, executing it within the runtime’s context. This may affect global state (within the runtime) permenantly. Will throw if there is an exception, with more detail. -
void add_transformer(const std::string & extension, std::shared_ptr< AbstractModuleTransformer > transformer)
Adds a new tranformer to this runtime for the given extension. This transformer will trigger whenever a file with the given extension is imported. -
JavaScriptValue load_module(const std::string & module_name, const std::string & code)
Loads the given javascript code as a module, returning a reference to the module namespace. This will still execute the code in the global namespace. Will throw if there is an exception. -
JavaScriptValue global_value(const std::string & name)
Returns the global value of the field given by name. -
JavaScriptValue allocate_value(const Type & type)
Allocates a new value and returns it. This value can be used within argument lists for making calls.The type can be one of int64, double, bool, or std::string.
-
JavaScriptValue allocate_null_value()
Allocates a null value. -
JavaScriptValue allocate_undefined_value()
Allocates a undefined value. -
JavaScriptValue allocate_object()
Allocates a new object. -
JavaScriptValue call(const std::string & name, const std::vector< JavaScriptValue > & arguments)
Invokes the given JavaScript function (by name) in the global namespace. The provided vector of arguments will be passed to the function, and the resulting value will be returned. -
JavaScriptValue call(const JavaScriptValue & this_object, const std::string & name, const std::vector< JavaScriptValue > & arguments)
Invokes the given JavaScript function (by name) in the given object. The provided vector of arguments will be passed to the function, and the resulting value will be returned. -
JavaScriptValue call(const JavaScriptValue & this_object, const JavaScriptValue & function, const std::string & name, const std::vector< JavaScriptValue > & arguments)
Invokes the given JavaScript function (by value) in the given object. The provided vector of arguments will be passed to the function, and the resulting value will be returned. The name provided will be used for debugging only. -
void register_log_callback(JavaScriptLogCallback callback)
Registers a log callback. Receives log statements coming from the console.[log/warn/error] functions. -
void collect_garbage()
Runs the garbage collector.