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:

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
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.

Recommendation: read Mozilla performance docummentation and specialy the Memory profiling and leak detection tools

If you are using Valgrind to detect memory leaks please read:

Constructor & Destructor Documentation

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


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


Member Function Documentation

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

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

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

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

Vector with the extensions.

Reimplemented from granada::runner::Runner.

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

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

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 

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.

cxMozilla spidermonkey JSContext. A context can run scripts.
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.
False if there has been an error, true, if everything went OK.
void granada::runner::SpiderMonkeyJavascriptRunner::Init ( )

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)

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

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

Reimplemented from granada::runner::Runner.

Member Data Documentation

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

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]

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_

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

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

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: