JavaScript.h

Bindings for reflect to Mozilla’s Spidermonkey (v1.7.0).

This provides a basic ECMA script runtime with the following runtime support

print()A basic print method.
GC()Run the garbage collector.
Console()Runs a very basic Javascript console.
NativeAn object which provides access to the reflected types by namespace.
Summary
JavaScript.hBindings for reflect to Mozilla’s Spidermonkey (v1.7.0).
JavaScriptRuntimeWraps a JSRuntime, a JSRuntime object represents a single JavaScript object space which can hold multiple contexts.
Functions
SharedRuntime
GetRuntime
JavaScriptContextRepresents a javascript context
Functions
JavaScriptContext
GCRuns the garbage collector.
RegisterFunctionRegisters a function in this context.
RegisterFunction (template)Like RegisterFunction, but takes a regular C function pointer, creates the function::Function object wrapper and marks it for deletion.
Eval (toss result)
Eval (typed result)
EvalAssigns the result of Eval into the variant result.
IncRefIncrements the reference count on a pointer that the java runtime knows about.
DecRef
ThrowErrorThrows an error from a function to the JavaScript runtime.
GetJSContextReturns the native context pointer.
CallContextRetrieves the current context from within a javascript call.
CallArgumentCountRetrieves the number of arguments actually passed to the native function.
CallArgumentRetrieves the argument index passed to the native function through a Variant.
CallArgumentTextRetrieves the argument index as text (converted by javascript).
CallArgumentValueRetrieves the argument index as whatever (converted by Variant).
CallReturnSets the return value of a void native function by variant.
CallReturnValueSets the return value of a void native function by value.

JavaScriptRuntime

class ReflectExport(
   reflect_js
) JavaScriptRuntime : public utility::Shared<JavaScriptRuntime>

Wraps a JSRuntime, a JSRuntime object represents a single JavaScript object space which can hold multiple contexts.  JavaScript objects in different JavaScriptContexts but within the same runtime may be shared.

A SharedRuntime is automatically used by default, client code only needs to instantate a runtime object if they want to have completely seperate runtimes.

Functions

SharedRuntime

static JavaScriptRuntime SharedRuntime()

GetRuntime

JSRuntime *GetRuntime() const

JavaScriptContext

class ReflectExport(reflect_js) JavaScriptContext

Represents a javascript context

Summary
Functions
JavaScriptContext
GCRuns the garbage collector.
RegisterFunctionRegisters a function in this context.
RegisterFunction (template)Like RegisterFunction, but takes a regular C function pointer, creates the function::Function object wrapper and marks it for deletion.
Eval (toss result)
Eval (typed result)
EvalAssigns the result of Eval into the variant result.
IncRefIncrements the reference count on a pointer that the java runtime knows about.
DecRef
ThrowErrorThrows an error from a function to the JavaScript runtime.
GetJSContextReturns the native context pointer.
CallContextRetrieves the current context from within a javascript call.
CallArgumentCountRetrieves the number of arguments actually passed to the native function.
CallArgumentRetrieves the argument index passed to the native function through a Variant.
CallArgumentTextRetrieves the argument index as text (converted by javascript).
CallArgumentValueRetrieves the argument index as whatever (converted by Variant).
CallReturnSets the return value of a void native function by variant.
CallReturnValueSets the return value of a void native function by value.

Functions

JavaScriptContext

JavaScriptContext(
   const JavaScriptRuntime & =  JavaScriptRuntime::SharedRuntime()
)

GC

void GC() const

Runs the garbage collector.

RegisterFunction

bool RegisterFunction(string::ConstString name,  
const function::Function *function,  
bool take_ownership =  false)

Registers a function in this context.

Parameters

namethe javascript name of this function
functionthe function to use
take_ownershipif true, delete the function when destructing this context.

See Also

RegisterFunction (template)

template<typename FunctionType> bool RegisterFunction(
   string::ConstString name,
   FunctionType function
)

Like RegisterFunction, but takes a regular C function pointer, creates the function::Function object wrapper and marks it for deletion.

Eval (toss result)

bool Eval(string::Fragment script) const

Eval (typed result)

template<typename T> bool Eval(string::Fragment script,
&result) const

Eval

bool Eval(string::Fragment script,
Variant &result) const

Assigns the result of Eval into the variant result.

Returns

trueif the evaluation and assignment executed successfully
falseif the evaluation threw an exception or assignment failed.

IncRef

template<typename T> void IncRef(*object) const

Increments the reference count on a pointer that the java runtime knows about.  When java finalizes the assoicated object, the pointer will not be deleted if it has a positive reference count.  The default reference count on an object is one, functions that allocate new objects for javascript should DecRef the reference count.  Note that an IncRef-ed object will never be deleted by the object system if it never makes it to the java runtime.

DecRef

template<typename T> void DecRef(*object) const

ThrowError

void ThrowError(const char *format,
 ...) const

Throws an error from a function to the JavaScript runtime.

GetJSContext

JSContext *GetJSContext() const

Returns the native context pointer.

CallContext

static const JavaScriptContext *CallContext()

Retrieves the current context from within a javascript call.

CallArgumentCount

static int CallArgumentCount()

Retrieves the number of arguments actually passed to the native function.

CallArgument

static bool CallArgument(int index,
Variant &variant)

Retrieves the argument index passed to the native function through a Variant.

CallArgumentText

static const char *CallArgumentText(int index)

Retrieves the argument index as text (converted by javascript).  Should be the same as Eval(“String(arguments[index])”)

CallArgumentValue

template<typename T> static bool CallArgumentValue(int index,
&value)

Retrieves the argument index as whatever (converted by Variant).

CallReturn

static bool CallReturn(Variant &value)

Sets the return value of a void native function by variant.

CallReturnValue

template<typename T> static bool CallReturnValue(const &value)

Sets the return value of a void native function by value.

class ReflectExport(
   reflect_js
) JavaScriptRuntime : public utility::Shared<JavaScriptRuntime>
Wraps a JSRuntime, a JSRuntime object represents a single JavaScript object space which can hold multiple contexts.
static JavaScriptRuntime SharedRuntime()
JSRuntime *GetRuntime() const
class ReflectExport(reflect_js) JavaScriptContext
Represents a javascript context
JavaScriptContext(
   const JavaScriptRuntime & =  JavaScriptRuntime::SharedRuntime()
)
void GC() const
Runs the garbage collector.
bool RegisterFunction(string::ConstString name,  
const function::Function *function,  
bool take_ownership =  false)
Registers a function in this context.
template<typename FunctionType> bool RegisterFunction(
   string::ConstString name,
   FunctionType function
)
Like RegisterFunction, but takes a regular C function pointer, creates the function::Function object wrapper and marks it for deletion.
bool Eval(string::Fragment script) const
template<typename T> bool Eval(string::Fragment script,
&result) const
bool Eval(string::Fragment script,
Variant &result) const
Assigns the result of Eval into the variant result.
template<typename T> void IncRef(*object) const
Increments the reference count on a pointer that the java runtime knows about.
template<typename T> void DecRef(*object) const
void ThrowError(const char *format,
 ...) const
Throws an error from a function to the JavaScript runtime.
JSContext *GetJSContext() const
Returns the native context pointer.
static const JavaScriptContext *CallContext()
Retrieves the current context from within a javascript call.
static int CallArgumentCount()
Retrieves the number of arguments actually passed to the native function.
static bool CallArgument(int index,
Variant &variant)
Retrieves the argument index passed to the native function through a Variant.
class ReflectExport(reflect) Variant
Variants represent objects of any reflected type.
static const char *CallArgumentText(int index)
Retrieves the argument index as text (converted by javascript).
template<typename T> static bool CallArgumentValue(int index,
&value)
Retrieves the argument index as whatever (converted by Variant).
static bool CallReturn(Variant &value)
Sets the return value of a void native function by variant.
template<typename T> static bool CallReturnValue(const &value)
Sets the return value of a void native function by value.
Close