H3D API  2.4.1
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
H3D::SpiderMonkeySAI Class Reference

The SpiderMonkeySAI class is an implementation of the X3D Ecmascript SAI specification using SpiderMonkey(the Javascript engine used by Firefox) More...

#include <H3D/SpiderMonkeySAI.h>

Classes

class  CallbackFunctionDispatcher
 The CallbackFunctionDispatcher class handles the calls of the ecmascript callback functions for the fields. More...
 

Public Member Functions

 SpiderMonkeySAI ()
 Constructor.
 
bool initializeScriptEngine (Script *s)
 Initialize the script engine for the given script, adding all types, attributes, functions etc . More...
 
string loadScript (const string &s, const string &filename)
 Run the script specified by s. More...
 
void uninitializeScriptEngine ()
 Release all resources allocated for the script engine.
 
bool isInitialized ()
 Returns true if the script engine has been initialized.
 
virtual bool addField (Field *field)
 Add an interface to a field to the script engine. More...
 

Protected Member Functions

string fieldNameToCallbackName (const string &n)
 Given a field name it returns the name used for the callback function in the global namespace. More...
 

Protected Attributes

JSRuntime * rt
 The script engine runtime used.
 
JSContext * cx
 The script engine context used.
 
JSObject * global
 The global object including all global properties and functions.
 
Scriptscript_node
 The Script node this script engine is used for,.
 
H3DUniquePtr< CallbackFunctionDispatchercallbackFunctionDispatcher
 Field that handles calling of callback functions as events are received.
 

Detailed Description

The SpiderMonkeySAI class is an implementation of the X3D Ecmascript SAI specification using SpiderMonkey(the Javascript engine used by Firefox)

Member Function Documentation

◆ addField()

bool SpiderMonkeySAI::addField ( Field field)
virtual

Add an interface to a field to the script engine.

It will be added to the global namespace with the property name equal to the name of the field.

found ) {

References isInitialized().

Referenced by H3D::Script::addField(), and loadScript().

◆ fieldNameToCallbackName()

string SpiderMonkeySAI::fieldNameToCallbackName ( const string &  n)
protected

Given a field name it returns the name used for the callback function in the global namespace.

According to the Ecmascript X3D specification the callback function and the field property name should be the same. This is not possible in SpiderMonkey so we rename the callback function to the name returned by this function.

Referenced by loadScript().

◆ initializeScriptEngine()

bool SpiderMonkeySAI::initializeScriptEngine ( Script s)

Initialize the script engine for the given script, adding all types, attributes, functions etc .

Needs to be called before any other function are called.

References cx, rt, and script_node.

◆ loadScript()

string SpiderMonkeySAI::loadScript ( const string &  s,
const string &  filename 
)

Run the script specified by s.

Parameters
sA string with the script code to run.
filenameA filename/identifier identifying the source of the string. Used for error messages.

References addField(), cx, H3D::H3DDynamicFieldsObject::endField(), fieldNameToCallbackName(), H3D::H3DDynamicFieldsObject::firstField(), global, H3D::SpiderMonkey::haveFunction(), and script_node.


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