Granada  1.54.0
Structured layer on top of C++ REST SDK for building server applications in C++. Granada implements sessions, server side plug-in framework, C++ OAuth 2.0 server, data storage access, server script running, server browsing.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
granada::runner::SpiderMonkeyJavascriptRunner Class Reference

#include <spidermonkey_javascript_runner.h>

Inheritance diagram for granada::runner::SpiderMonkeyJavascriptRunner:
granada::runner::Runner

Public Member Functions

 SpiderMonkeyJavascriptRunner ()
 
virtual ~SpiderMonkeyJavascriptRunner ()
 
std::string Run (const std::string &_script)
 
virtual std::shared_ptr
< granada::Functions
functions ()
 
virtual std::vector< std::string > extensions ()
 
- Public Member Functions inherited from granada::runner::Runner
 Runner ()
 
virtual ~Runner ()
 

Protected Member Functions

void Init ()
 
void Destroy ()
 

Static Protected Member Functions

static bool FunctionWrapper (JSContext *cx, unsigned argc, JS::Value *vp)
 

Protected Attributes

const std::string runner_initialization_error_ = "{\"" + default_strings::runner_error + "\":\"" + default_errors::runner_initialization_error + "\"}"
 

Static Protected Attributes

static JSClass global_class_
 
static std::shared_ptr
< granada::Functions
functions_
 
static std::string extensions_arr_ [1]
 
static std::vector< std::string > extensions_
 

Detailed Description

Run javascript using Mozilla's JavaScript engine: Spider Monkey. Spider monkey version 38 is used. https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey

Recommendation: read Mozilla performance docummentation and specialy the Memory profiling and leak detection tools https://developer.mozilla.org/en-US/docs/Mozilla/Performance

If you are using Valgrind to detect memory leaks please read: https://developer.mozilla.org/en-US/docs/Mozilla/Testing/Valgrind

Constructor & Destructor Documentation

granada::runner::SpiderMonkeyJavascriptRunner::SpiderMonkeyJavascriptRunner ( )
inline

Constructor.

virtual granada::runner::SpiderMonkeyJavascriptRunner::~SpiderMonkeyJavascriptRunner ( )
inlinevirtual

Destructor.

Member Function Documentation

void granada::runner::SpiderMonkeyJavascriptRunner::Destroy ( )
protected

Free all resources used by the JS engine, not associated with specific runtimes.

virtual std::vector<std::string> granada::runner::SpiderMonkeyJavascriptRunner::extensions ( )
inlinevirtual

Returns a vector with the extensions of the scripts/executables Extensions examples: ["js"], ["sh"], ["exe"], ["js","sh"]

Returns
Vector with the extensions.

Reimplemented from granada::runner::Runner.

virtual std::shared_ptr<granada::Functions> granada::runner::SpiderMonkeyJavascriptRunner::functions ( )
inlinevirtual

Returns a pointer to the collection of functions that can be called from the script/executable.

Returns
Pointer to the collection of functions that can be called from the script/executable.

Reimplemented from granada::runner::Runner.

static bool granada::runner::SpiderMonkeyJavascriptRunner::FunctionWrapper ( JSContext *  cx,
unsigned  argc,
JS::Value *  vp 
)
staticprotected

Wraps the c++ functions that called from the javascript, so the arguments are parsed to a web::json::value and the return to the javascript is also a JSON object.

Parameters
cxMozilla spidermonkey JSContext. A context can run scripts. https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/JSAPI_reference/JSRuntime
argcNumber of argument. (2nd argument of JSNative).
vpA pointer to the argument value array. Arguments that the script is passing to the function, includes the name of the function to call. See functions() to retrieve the functions collection.
Returns
False if there has been an error, true, if everything went OK.
void granada::runner::SpiderMonkeyJavascriptRunner::Init ( )
protected

Initializes the JS engine so that further operations can be performed. It is currently not possible to initialize this runner multiple times without calling Destroy() method.

std::string granada::runner::SpiderMonkeyJavascriptRunner::Run ( const std::string &  _script)
virtual

Run given javascript script and returns the return/response of the script in form of string.

Parameters
_scriptJavascript script.
Returns
Return/Response returned by the script run.

Reimplemented from granada::runner::Runner.

Member Data Documentation

std::vector<std::string> granada::runner::SpiderMonkeyJavascriptRunner::extensions_
staticprotected

Vector with the extensions of the scripts/executables, its content comes from the extensions_arr_ array. Extensions examples: ["js"], ["sh"], ["exe"], ["js","sh"]

std::string granada::runner::SpiderMonkeyJavascriptRunner::extensions_arr_[1]
staticprotected

Array with the extensions of the scripts/executables, will be inserted in the extensions_ vector. Extensions examples: ["js"], ["sh"], ["exe"], ["js","sh"]

std::shared_ptr<granada::Functions> granada::runner::SpiderMonkeyJavascriptRunner::functions_
staticprotected

Pointer to the collection of the c++ functions that can be called from the javascript.

JSClass granada::runner::SpiderMonkeyJavascriptRunner::global_class_
staticprotected
const std::string granada::runner::SpiderMonkeyJavascriptRunner::runner_initialization_error_ = "{\"" + default_strings::runner_error + "\":\"" + default_errors::runner_initialization_error + "\"}"
protected

Runner initialization error stringified json. Used to respond in the Run functions when there is such error.


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