Pyrogenesis
trunk
|
Abstraction around a SpiderMonkey JSContext. More...
#include <ScriptInterface.h>
Classes | |
struct | CustomType |
struct | CxPrivate |
struct | MaybeRef |
class | StructuredClone |
Structured clones are a way to serialize 'simple' JS values into a buffer that can safely be passed between contexts and runtimes and threads. More... | |
Public Types | |
enum | CACHED_VAL { CACHE_VECTOR2DPROTO, CACHE_VECTOR3DPROTO } |
Public Member Functions | |
ScriptInterface (const char *nativeScopeName, const char *debugName, const shared_ptr< ScriptRuntime > &runtime) | |
Constructor. More... | |
~ScriptInterface () | |
void | SetCallbackData (void *pCBData) |
JSContext * | GetContext () const |
JSRuntime * | GetJSRuntime () const |
shared_ptr< ScriptRuntime > | GetRuntime () const |
bool | LoadGlobalScripts () |
Load global scripts that most script contexts need, located in the /globalscripts directory. More... | |
JS::Value | GetCachedValue (CACHED_VAL valueIdentifier) const |
bool | ReplaceNondeterministicRNG (boost::rand48 &rng) |
Replace the default JS random number geenrator with a seeded, network-sync'd one. More... | |
void | CallConstructor (JS::HandleValue ctor, JS::HandleValueArray argv, JS::MutableHandleValue out) const |
Call a constructor function, equivalent to JS "new ctor(arg)". More... | |
JSObject * | CreateCustomObject (const std::string &typeName) const |
void | DefineCustomObjectType (JSClass *clasp, JSNative constructor, uint minArgs, JSPropertySpec *ps, JSFunctionSpec *fs, JSPropertySpec *static_ps, JSFunctionSpec *static_fs) |
jsval | GetGlobalObject () |
JSClass * | GetGlobalClass () |
template<typename T > | |
bool | SetGlobal (const char *name, const T &value, bool replace=false) |
Set the named property on the global object. More... | |
template<typename T > | |
bool | SetProperty (JS::HandleValue obj, const char *name, const T &value, bool constant=false, bool enumerate=true) |
Set the named property on the given object. More... | |
template<typename T > | |
bool | SetProperty (JS::HandleValue obj, const wchar_t *name, const T &value, bool constant=false, bool enumerate=true) |
Set the named property on the given object. More... | |
template<typename T > | |
bool | SetPropertyInt (JS::HandleValue obj, int name, const T &value, bool constant=false, bool enumerate=true) |
Set the integer-named property on the given object. More... | |
template<typename T > | |
bool | GetProperty (JS::HandleValue obj, const char *name, T &out) const |
Get the named property on the given object. More... | |
bool | GetProperty (JS::HandleValue obj, const char *name, JS::MutableHandleValue out) const |
Get the named property of the given object. More... | |
bool | GetProperty (JS::HandleValue obj, const char *name, JS::MutableHandleObject out) const |
template<typename T > | |
bool | GetPropertyInt (JS::HandleValue obj, int name, T &out) const |
Get the integer-named property on the given object. More... | |
bool | GetPropertyInt (JS::HandleValue obj, int name, JS::MutableHandleValue out) const |
Get the named property of the given object. More... | |
bool | HasProperty (JS::HandleValue obj, const char *name) const |
Check the named property has been defined on the given object. More... | |
bool | EnumeratePropertyNamesWithPrefix (JS::HandleValue objVal, const char *prefix, std::vector< std::string > &out) const |
bool | SetPrototype (JS::HandleValue obj, JS::HandleValue proto) |
bool | FreezeObject (JS::HandleValue objVal, bool deep) const |
bool | Eval (const char *code) const |
template<typename CHAR > | |
bool | Eval (const CHAR *code, JS::MutableHandleValue out) const |
template<typename T , typename CHAR > | |
bool | Eval (const CHAR *code, T &out) const |
std::string | ToString (JS::MutableHandleValue obj, bool pretty=false) const |
Convert an object to a UTF-8 encoded string, either with JSON (if pretty == true and there is no JSON error) or with toSource(). More... | |
bool | ParseJSON (const std::string &string_utf8, JS::MutableHandleValue out) const |
Parse a UTF-8-encoded JSON string. More... | |
void | ReadJSONFile (const VfsPath &path, JS::MutableHandleValue out) const |
Read a JSON file. More... | |
std::string | StringifyJSON (JS::MutableHandleValue obj, bool indent=true) const |
Stringify to a JSON string, UTF-8 encoded. More... | |
void | ReportError (const char *msg) const |
Report the given error message through the JS error reporting mechanism, and throw a JS exception. More... | |
bool | LoadScript (const VfsPath &filename, const std::string &code) const |
Load and execute the given script in a new function scope. More... | |
bool | LoadGlobalScript (const VfsPath &filename, const std::wstring &code) const |
Load and execute the given script in the global scope. More... | |
bool | LoadGlobalScriptFile (const VfsPath &path) const |
Load and execute the given script in the global scope. More... | |
JS::Value | CloneValueFromOtherContext (ScriptInterface &otherContext, JS::HandleValue val) |
Construct a new value (usable in this ScriptInterface's context) by cloning a value from a different context. More... | |
void | MaybeGC () |
MaybeGC tries to determine whether garbage collection in cx's runtime would free up enough memory to be worth the amount of time it would take. More... | |
void | ForceGC () |
Triggers a full non-incremental garbage collection immediately. More... | |
bool | MathRandom (double &nbr) |
MathRandom (this function) calls the random number generator assigned to this ScriptInterface instance and returns the generated number. More... | |
shared_ptr< StructuredClone > | WriteStructuredClone (JS::HandleValue v) |
void | ReadStructuredClone (const shared_ptr< StructuredClone > &ptr, JS::MutableHandleValue ret) |
template<typename R , typename... Ts> | |
bool | CallFunction (JS::HandleValue val, const char *name, R &ret, const Ts &...params) const |
template<typename R , typename... Ts> | |
bool | CallFunction (JS::HandleValue val, const char *name, JS::Rooted< R > *ret, const Ts &...params) const |
template<typename R , typename... Ts> | |
bool | CallFunction (JS::HandleValue val, const char *name, JS::MutableHandle< R > ret, const Ts &...params) const |
template<typename... Ts> | |
bool | CallFunctionVoid (JS::HandleValue val, const char *name, const Ts &...params) const |
template<> | |
void | ToJSVal (JSContext *cx, JS::MutableHandleValue ret, SDL_Event_ const &val) |
template<> | |
void | ToJSVal (JSContext *cx, JS::MutableHandleValue ret, IGUIObject *const &val) |
template<> | |
void | ToJSVal (JSContext *cx, JS::MutableHandleValue ret, const CGUIString &val) |
template<> | |
bool | FromJSVal (JSContext *cx, JS::HandleValue v, CGUIString &out) |
template<> | |
bool | FromJSVal (JSContext *cx, JS::HandleValue v, bool &out) |
template<> | |
bool | FromJSVal (JSContext *cx, JS::HandleValue v, float &out) |
template<> | |
bool | FromJSVal (JSContext *cx, JS::HandleValue v, double &out) |
template<> | |
bool | FromJSVal (JSContext *cx, JS::HandleValue v, i32 &out) |
template<> | |
bool | FromJSVal (JSContext *cx, JS::HandleValue v, u32 &out) |
template<> | |
bool | FromJSVal (JSContext *cx, JS::HandleValue v, u16 &out) |
template<> | |
bool | FromJSVal (JSContext *cx, JS::HandleValue v, u8 &out) |
template<> | |
bool | FromJSVal (JSContext *cx, JS::HandleValue v, Path &out) |
template<> | |
bool | FromJSVal (JSContext *cx, JS::HandleValue v, CStr8 &out) |
template<> | |
bool | FromJSVal (JSContext *cx, JS::HandleValue v, CStrW &out) |
template<> | |
bool | FromJSVal (JSContext *cx, JS::HandleValue v, Entity &out) |
template<> | |
void | ToJSVal (JSContext *cx, JS::MutableHandleValue ret, const bool &val) |
template<> | |
void | ToJSVal (JSContext *cx, JS::MutableHandleValue ret, const float &val) |
template<> | |
void | ToJSVal (JSContext *cx, JS::MutableHandleValue ret, const double &val) |
template<> | |
void | ToJSVal (JSContext *cx, JS::MutableHandleValue ret, const i32 &val) |
template<> | |
void | ToJSVal (JSContext *cx, JS::MutableHandleValue ret, const u16 &val) |
template<> | |
void | ToJSVal (JSContext *cx, JS::MutableHandleValue ret, const u8 &val) |
template<> | |
void | ToJSVal (JSContext *cx, JS::MutableHandleValue ret, const u32 &val) |
template<> | |
void | ToJSVal (JSContext *cx, JS::MutableHandleValue ret, const Path &val) |
template<> | |
void | ToJSVal (JSContext *cx, JS::MutableHandleValue ret, const wchar_t *const &val) |
template<> | |
void | ToJSVal (JSContext *cx, JS::MutableHandleValue ret, const char *const &val) |
template<> | |
void | ToJSVal (JSContext *cx, JS::MutableHandleValue ret, const CStrW &val) |
template<> | |
void | ToJSVal (JSContext *cx, JS::MutableHandleValue ret, const CStr8 &val) |
template<> | |
void | ToJSVal (JSContext *cx, JS::MutableHandleValue ret, const CVector2D &val) |
template<> | |
bool | FromJSVal (JSContext *cx, JS::HandleValue v, CVector2D &out) |
template<> | |
void | ToJSVal (JSContext *cx, JS::MutableHandleValue ret, IComponent *const &val) |
template<> | |
void | ToJSVal (JSContext *cx, JS::MutableHandleValue ret, CParamNode const &val) |
template<> | |
void | ToJSVal (JSContext *cx, JS::MutableHandleValue ret, const CParamNode *const &val) |
template<> | |
bool | FromJSVal (JSContext *cx, JS::HandleValue v, CColor &out) |
template<> | |
void | ToJSVal (JSContext *cx, JS::MutableHandleValue ret, CColor const &val) |
template<> | |
bool | FromJSVal (JSContext *cx, JS::HandleValue v, fixed &out) |
template<> | |
void | ToJSVal (JSContext *cx, JS::MutableHandleValue ret, const fixed &val) |
template<> | |
bool | FromJSVal (JSContext *cx, JS::HandleValue v, CFixedVector3D &out) |
template<> | |
void | ToJSVal (JSContext *cx, JS::MutableHandleValue ret, const CFixedVector3D &val) |
template<> | |
bool | FromJSVal (JSContext *cx, JS::HandleValue v, CFixedVector2D &out) |
template<> | |
void | ToJSVal (JSContext *cx, JS::MutableHandleValue ret, const CFixedVector2D &val) |
template<> | |
void | ToJSVal (JSContext *cx, JS::MutableHandleValue ret, const Grid< u8 > &val) |
template<> | |
void | ToJSVal (JSContext *cx, JS::MutableHandleValue ret, const Grid< u16 > &val) |
template<> | |
bool | FromJSVal (JSContext *cx, JS::HandleValue v, TNSpline &out) |
template<> | |
bool | FromJSVal (JSContext *cx, JS::HandleValue v, CCinemaPath &out) |
Static Public Member Functions | |
static shared_ptr< ScriptRuntime > | CreateRuntime (shared_ptr< ScriptRuntime > parentRuntime=shared_ptr< ScriptRuntime >(), int runtimeSize=DEFAULT_RUNTIME_SIZE, int heapGrowthBytesGCTrigger=DEFAULT_HEAP_GROWTH_BYTES_GCTRIGGER) |
Returns a runtime, which can used to initialise any number of ScriptInterfaces contexts. More... | |
static CxPrivate * | GetScriptInterfaceAndCBData (JSContext *cx) |
template<typename T > | |
static bool | FromJSVal (JSContext *cx, const JS::HandleValue val, T &ret) |
Convert a jsval to a C++ type. More... | |
template<typename T > | |
static void | ToJSVal (JSContext *cx, JS::MutableHandleValue ret, T const &val) |
Convert a C++ type to a jsval. More... | |
template<typename T > | |
static void | AssignOrToJSVal (JSContext *cx, JS::MutableHandleValue handle, const T &a) |
Converts |a| if needed and assigns it to |handle|. More... | |
template<typename T > | |
static void | AssignOrToJSValUnrooted (JSContext *cx, JS::MutableHandleValue handle, const T &a) |
The same as AssignOrToJSVal, but also allows JS::Value for T. More... | |
template<typename T > | |
static T | AssignOrFromJSVal (JSContext *cx, const JS::HandleValue &val, bool &ret) |
Converts |val| to T if needed or just returns it if it's a handle. More... | |
template<typename... Ts> | |
static size_t | nargs () |
Public Attributes | |
struct ScriptInterface::CxPrivate | m_CxPrivate |
Private Member Functions | |
NONCOPYABLE (ScriptInterface) | |
bool | CallFunction_ (JS::HandleValue val, const char *name, JS::HandleValueArray argv, JS::MutableHandleValue ret) const |
bool | Eval_ (const char *code, JS::MutableHandleValue ret) const |
bool | Eval_ (const wchar_t *code, JS::MutableHandleValue ret) const |
bool | SetGlobal_ (const char *name, JS::HandleValue value, bool replace) |
bool | SetProperty_ (JS::HandleValue obj, const char *name, JS::HandleValue value, bool readonly, bool enumerate) |
bool | SetProperty_ (JS::HandleValue obj, const wchar_t *name, JS::HandleValue value, bool readonly, bool enumerate) |
bool | SetPropertyInt_ (JS::HandleValue obj, int name, JS::HandleValue value, bool readonly, bool enumerate) |
bool | GetProperty_ (JS::HandleValue obj, const char *name, JS::MutableHandleValue out) const |
bool | GetPropertyInt_ (JS::HandleValue obj, int name, JS::MutableHandleValue value) const |
void | Register (const char *name, JSNative fptr, size_t nargs) |
Static Private Member Functions | |
static bool | IsExceptionPending (JSContext *cx) |
static const JSClass * | GetClass (JS::HandleObject obj) |
static void * | GetPrivate (JS::HandleObject obj) |
Private Attributes | |
std::unique_ptr< ScriptInterface_impl > | m |
boost::rand48 * | m_rng |
std::map< std::string, CustomType > | m_CustomObjectTypes |
Abstraction around a SpiderMonkey JSContext.
Thread-safety:
ScriptInterface::ScriptInterface | ( | const char * | nativeScopeName, |
const char * | debugName, | ||
const shared_ptr< ScriptRuntime > & | runtime | ||
) |
Constructor.
nativeScopeName | Name of global object that functions (via RegisterFunction) will be placed into, as a scoping mechanism; typically "Engine" |
debugName | Name of this interface for CScriptStats purposes. |
runtime | ScriptRuntime to use when initializing this interface. |
ScriptInterface::~ScriptInterface | ( | ) |
|
inlinestatic |
Converts |val| to T if needed or just returns it if it's a handle.
This is meant for use in other templates where we want to use the same code for JS::HandleValue and other types.
|
inlinestatic |
Converts |a| if needed and assigns it to |handle|.
This is meant for use in other templates where we want to use the same code for JS::RootedValue&/JS::HandleValue and other types. Note that functions are meant to take JS::HandleValue instead of JS::RootedValue&, but this implicit conversion does not work for templates (exact type matches required for type deduction). A similar functionality could also be implemented as a ToJSVal specialization. The current approach was preferred because "conversions" from JS::HandleValue to JS::MutableHandleValue are unusual and should not happen "by accident".
|
inlinestatic |
The same as AssignOrToJSVal, but also allows JS::Value for T.
In most cases it's not safe to use the plain (unrooted) JS::Value type, but this can happen quite easily with template functions. The idea is that the linker prints an error if AssignOrToJSVal is used with JS::Value. If the specialization for JS::Value should be allowed, you can use this "unrooted" version of AssignOrToJSVal.
void ScriptInterface::CallConstructor | ( | JS::HandleValue | ctor, |
JS::HandleValueArray | argv, | ||
JS::MutableHandleValue | out | ||
) | const |
Call a constructor function, equivalent to JS "new ctor(arg)".
ctor | An object that can be used as constructor |
argv | Constructor arguments |
out | The new object; On error an error message gets logged and out is Null (out.isNull() == true). |
bool ScriptInterface::CallFunction | ( | JS::HandleValue | val, |
const char * | name, | ||
R & | ret, | ||
const Ts &... | params | ||
) | const |
bool ScriptInterface::CallFunction | ( | JS::HandleValue | val, |
const char * | name, | ||
JS::Rooted< R > * | ret, | ||
const Ts &... | params | ||
) | const |
bool ScriptInterface::CallFunction | ( | JS::HandleValue | val, |
const char * | name, | ||
JS::MutableHandle< R > | ret, | ||
const Ts &... | params | ||
) | const |
|
private |
bool ScriptInterface::CallFunctionVoid | ( | JS::HandleValue | val, |
const char * | name, | ||
const Ts &... | params | ||
) | const |
JS::Value ScriptInterface::CloneValueFromOtherContext | ( | ScriptInterface & | otherContext, |
JS::HandleValue | val | ||
) |
Construct a new value (usable in this ScriptInterface's context) by cloning a value from a different context.
Complex values (functions, XML, etc) won't be cloned correctly, but basic types and cyclic references should be fine.
JSObject * ScriptInterface::CreateCustomObject | ( | const std::string & | typeName | ) | const |
|
static |
Returns a runtime, which can used to initialise any number of ScriptInterfaces contexts.
Values created in one context may be used in any other context from the same runtime (but not any other runtime). Each runtime should only ever be used on a single thread.
runtimeSize | Maximum size in bytes of the new runtime |
void ScriptInterface::DefineCustomObjectType | ( | JSClass * | clasp, |
JSNative | constructor, | ||
uint | minArgs, | ||
JSPropertySpec * | ps, | ||
JSFunctionSpec * | fs, | ||
JSPropertySpec * | static_ps, | ||
JSFunctionSpec * | static_fs | ||
) |
bool ScriptInterface::EnumeratePropertyNamesWithPrefix | ( | JS::HandleValue | objVal, |
const char * | prefix, | ||
std::vector< std::string > & | out | ||
) | const |
bool ScriptInterface::Eval | ( | const char * | code | ) | const |
bool ScriptInterface::Eval | ( | const CHAR * | code, |
JS::MutableHandleValue | out | ||
) | const |
bool ScriptInterface::Eval | ( | const CHAR * | code, |
T & | out | ||
) | const |
|
private |
|
private |
void ScriptInterface::ForceGC | ( | ) |
Triggers a full non-incremental garbage collection immediately.
That should only be required in special cases and normally you should try to use MaybeIncrementalRuntimeGC instead.
bool ScriptInterface::FreezeObject | ( | JS::HandleValue | objVal, |
bool | deep | ||
) | const |
bool ScriptInterface::FromJSVal | ( | JSContext * | cx, |
JS::HandleValue | v, | ||
bool & | out | ||
) |
bool ScriptInterface::FromJSVal | ( | JSContext * | cx, |
JS::HandleValue | v, | ||
float & | out | ||
) |
bool ScriptInterface::FromJSVal | ( | JSContext * | cx, |
JS::HandleValue | v, | ||
double & | out | ||
) |
bool ScriptInterface::FromJSVal | ( | JSContext * | cx, |
JS::HandleValue | v, | ||
i32 & | out | ||
) |
bool ScriptInterface::FromJSVal | ( | JSContext * | cx, |
JS::HandleValue | v, | ||
CColor & | out | ||
) |
bool ScriptInterface::FromJSVal | ( | JSContext * | cx, |
JS::HandleValue | v, | ||
u32 & | out | ||
) |
bool ScriptInterface::FromJSVal | ( | JSContext * | cx, |
JS::HandleValue | v, | ||
u16 & | out | ||
) |
bool ScriptInterface::FromJSVal | ( | JSContext * | cx, |
JS::HandleValue | v, | ||
u8 & | out | ||
) |
bool ScriptInterface::FromJSVal | ( | JSContext * | cx, |
JS::HandleValue | v, | ||
CGUIString & | out | ||
) |
bool ScriptInterface::FromJSVal | ( | JSContext * | cx, |
JS::HandleValue | v, | ||
fixed & | out | ||
) |
bool ScriptInterface::FromJSVal | ( | JSContext * | cx, |
JS::HandleValue | v, | ||
Path & | out | ||
) |
bool ScriptInterface::FromJSVal | ( | JSContext * | cx, |
JS::HandleValue | v, | ||
CFixedVector3D & | out | ||
) |
bool ScriptInterface::FromJSVal | ( | JSContext * | cx, |
JS::HandleValue | v, | ||
CStr8 & | out | ||
) |
bool ScriptInterface::FromJSVal | ( | JSContext * | cx, |
JS::HandleValue | v, | ||
CStrW & | out | ||
) |
bool ScriptInterface::FromJSVal | ( | JSContext * | cx, |
JS::HandleValue | v, | ||
Entity & | out | ||
) |
bool ScriptInterface::FromJSVal | ( | JSContext * | cx, |
JS::HandleValue | v, | ||
CFixedVector2D & | out | ||
) |
|
static |
Convert a jsval to a C++ type.
(This might trigger GC.)
bool ScriptInterface::FromJSVal | ( | JSContext * | cx, |
JS::HandleValue | v, | ||
TNSpline & | out | ||
) |
bool ScriptInterface::FromJSVal | ( | JSContext * | cx, |
JS::HandleValue | v, | ||
CVector2D & | out | ||
) |
bool ScriptInterface::FromJSVal | ( | JSContext * | cx, |
JS::HandleValue | v, | ||
CCinemaPath & | out | ||
) |
JS::Value ScriptInterface::GetCachedValue | ( | CACHED_VAL | valueIdentifier | ) | const |
|
staticprivate |
JSContext * ScriptInterface::GetContext | ( | ) | const |
JSClass * ScriptInterface::GetGlobalClass | ( | ) |
jsval ScriptInterface::GetGlobalObject | ( | ) |
JSRuntime * ScriptInterface::GetJSRuntime | ( | ) | const |
|
staticprivate |
bool ScriptInterface::GetProperty | ( | JS::HandleValue | obj, |
const char * | name, | ||
T & | out | ||
) | const |
Get the named property on the given object.
bool ScriptInterface::GetProperty | ( | JS::HandleValue | obj, |
const char * | name, | ||
JS::MutableHandleValue | out | ||
) | const |
Get the named property of the given object.
bool ScriptInterface::GetProperty | ( | JS::HandleValue | obj, |
const char * | name, | ||
JS::MutableHandleObject | out | ||
) | const |
|
private |
bool ScriptInterface::GetPropertyInt | ( | JS::HandleValue | obj, |
int | name, | ||
T & | out | ||
) | const |
Get the integer-named property on the given object.
bool ScriptInterface::GetPropertyInt | ( | JS::HandleValue | obj, |
int | name, | ||
JS::MutableHandleValue | out | ||
) | const |
Get the named property of the given object.
|
private |
shared_ptr< ScriptRuntime > ScriptInterface::GetRuntime | ( | ) | const |
|
static |
bool ScriptInterface::HasProperty | ( | JS::HandleValue | obj, |
const char * | name | ||
) | const |
Check the named property has been defined on the given object.
|
staticprivate |
bool ScriptInterface::LoadGlobalScript | ( | const VfsPath & | filename, |
const std::wstring & | code | ||
) | const |
Load and execute the given script in the global scope.
filename | Name for debugging purposes (not used to load the file) |
code | JS code to execute |
bool ScriptInterface::LoadGlobalScriptFile | ( | const VfsPath & | path | ) | const |
Load and execute the given script in the global scope.
bool ScriptInterface::LoadGlobalScripts | ( | ) |
Load global scripts that most script contexts need, located in the /globalscripts directory.
VFS must be initialized.
bool ScriptInterface::LoadScript | ( | const VfsPath & | filename, |
const std::string & | code | ||
) | const |
Load and execute the given script in a new function scope.
filename | Name for debugging purposes (not used to load the file) |
code | JS code to execute |
bool ScriptInterface::MathRandom | ( | double & | nbr | ) |
MathRandom (this function) calls the random number generator assigned to this ScriptInterface instance and returns the generated number.
Math_random (with underscore, not this function) is a global function, but different random number generators can be stored per ScriptInterface. It calls MathRandom of the current ScriptInterface instance.
void ScriptInterface::MaybeGC | ( | ) |
MaybeGC tries to determine whether garbage collection in cx's runtime would free up enough memory to be worth the amount of time it would take.
This calls JS_MaybeGC directly, which does not do incremental GC. Usually you should prefer MaybeIncrementalRuntimeGC.
|
inlinestatic |
|
private |
bool ScriptInterface::ParseJSON | ( | const std::string & | string_utf8, |
JS::MutableHandleValue | out | ||
) | const |
Parse a UTF-8-encoded JSON string.
Returns the unmodified value on error and prints an error message.
void ScriptInterface::ReadJSONFile | ( | const VfsPath & | path, |
JS::MutableHandleValue | out | ||
) | const |
Read a JSON file.
Returns the unmodified value on error and prints an error message.
void ScriptInterface::ReadStructuredClone | ( | const shared_ptr< StructuredClone > & | ptr, |
JS::MutableHandleValue | ret | ||
) |
|
private |
bool ScriptInterface::ReplaceNondeterministicRNG | ( | boost::rand48 & | rng | ) |
Replace the default JS random number geenrator with a seeded, network-sync'd one.
void ScriptInterface::ReportError | ( | const char * | msg | ) | const |
void ScriptInterface::SetCallbackData | ( | void * | pCBData | ) |
bool ScriptInterface::SetGlobal | ( | const char * | name, |
const T & | value, | ||
bool | replace = false |
||
) |
Set the named property on the global object.
If replace
is true, an existing property will be overwritten; otherwise attempts to set an already-defined value will fail.
|
private |
bool ScriptInterface::SetProperty | ( | JS::HandleValue | obj, |
const char * | name, | ||
const T & | value, | ||
bool | constant = false , |
||
bool | enumerate = true |
||
) |
Set the named property on the given object.
Optionally makes it {ReadOnly, DontDelete, DontEnum}.
bool ScriptInterface::SetProperty | ( | JS::HandleValue | obj, |
const wchar_t * | name, | ||
const T & | value, | ||
bool | constant = false , |
||
bool | enumerate = true |
||
) |
Set the named property on the given object.
Optionally makes it {ReadOnly, DontDelete, DontEnum}.
|
private |
|
private |
bool ScriptInterface::SetPropertyInt | ( | JS::HandleValue | obj, |
int | name, | ||
const T & | value, | ||
bool | constant = false , |
||
bool | enumerate = true |
||
) |
Set the integer-named property on the given object.
Optionally makes it {ReadOnly, DontDelete, DontEnum}.
|
private |
bool ScriptInterface::SetPrototype | ( | JS::HandleValue | obj, |
JS::HandleValue | proto | ||
) |
std::string ScriptInterface::StringifyJSON | ( | JS::MutableHandleValue | obj, |
bool | indent = true |
||
) | const |
Stringify to a JSON string, UTF-8 encoded.
Returns an empty string on error.
void ScriptInterface::ToJSVal | ( | JSContext * | cx, |
JS::MutableHandleValue | ret, | ||
SDL_Event_ const & | val | ||
) |
void ScriptInterface::ToJSVal | ( | JSContext * | cx, |
JS::MutableHandleValue | ret, | ||
IComponent *const & | val | ||
) |
void ScriptInterface::ToJSVal | ( | JSContext * | cx, |
JS::MutableHandleValue | ret, | ||
CParamNode const & | val | ||
) |
void ScriptInterface::ToJSVal | ( | JSContext * | cx, |
JS::MutableHandleValue | ret, | ||
const CParamNode *const & | val | ||
) |
void ScriptInterface::ToJSVal | ( | JSContext * | cx, |
JS::MutableHandleValue | ret, | ||
CColor const & | val | ||
) |
void ScriptInterface::ToJSVal | ( | JSContext * | cx, |
JS::MutableHandleValue | ret, | ||
IGUIObject *const & | val | ||
) |
void ScriptInterface::ToJSVal | ( | JSContext * | cx, |
JS::MutableHandleValue | ret, | ||
const CGUIString & | val | ||
) |
void ScriptInterface::ToJSVal | ( | JSContext * | cx, |
JS::MutableHandleValue | ret, | ||
const fixed & | val | ||
) |
void ScriptInterface::ToJSVal | ( | JSContext * | cx, |
JS::MutableHandleValue | ret, | ||
const CFixedVector3D & | val | ||
) |
void ScriptInterface::ToJSVal | ( | JSContext * | cx, |
JS::MutableHandleValue | ret, | ||
const bool & | val | ||
) |
void ScriptInterface::ToJSVal | ( | JSContext * | cx, |
JS::MutableHandleValue | ret, | ||
const float & | val | ||
) |
void ScriptInterface::ToJSVal | ( | JSContext * | cx, |
JS::MutableHandleValue | ret, | ||
const CFixedVector2D & | val | ||
) |
void ScriptInterface::ToJSVal | ( | JSContext * | cx, |
JS::MutableHandleValue | ret, | ||
const double & | val | ||
) |
void ScriptInterface::ToJSVal | ( | JSContext * | cx, |
JS::MutableHandleValue | ret, | ||
const i32 & | val | ||
) |
void ScriptInterface::ToJSVal | ( | JSContext * | cx, |
JS::MutableHandleValue | ret, | ||
const u16 & | val | ||
) |
void ScriptInterface::ToJSVal | ( | JSContext * | cx, |
JS::MutableHandleValue | ret, | ||
const u8 & | val | ||
) |
void ScriptInterface::ToJSVal | ( | JSContext * | cx, |
JS::MutableHandleValue | ret, | ||
const u32 & | val | ||
) |
void ScriptInterface::ToJSVal | ( | JSContext * | cx, |
JS::MutableHandleValue | ret, | ||
const Grid< u8 > & | val | ||
) |
void ScriptInterface::ToJSVal | ( | JSContext * | cx, |
JS::MutableHandleValue | ret, | ||
const Path & | val | ||
) |
void ScriptInterface::ToJSVal | ( | JSContext * | cx, |
JS::MutableHandleValue | ret, | ||
const wchar_t *const & | val | ||
) |
void ScriptInterface::ToJSVal | ( | JSContext * | cx, |
JS::MutableHandleValue | ret, | ||
const Grid< u16 > & | val | ||
) |
void ScriptInterface::ToJSVal | ( | JSContext * | cx, |
JS::MutableHandleValue | ret, | ||
const char *const & | val | ||
) |
|
static |
Convert a C++ type to a jsval.
(This might trigger GC. The return value must be rooted if you don't want it to be collected.) NOTE: We are passing the JS::Value by reference instead of returning it by value. The reason is a memory corruption problem that appears to be caused by a bug in Visual Studio. Details here: http://www.wildfiregames.com/forum/index.php?showtopic=17289&p=285921
void ScriptInterface::ToJSVal | ( | JSContext * | cx, |
JS::MutableHandleValue | ret, | ||
const CStrW & | val | ||
) |
void ScriptInterface::ToJSVal | ( | JSContext * | cx, |
JS::MutableHandleValue | ret, | ||
const CStr8 & | val | ||
) |
void ScriptInterface::ToJSVal | ( | JSContext * | cx, |
JS::MutableHandleValue | ret, | ||
const CVector2D & | val | ||
) |
std::string ScriptInterface::ToString | ( | JS::MutableHandleValue | obj, |
bool | pretty = false |
||
) | const |
Convert an object to a UTF-8 encoded string, either with JSON (if pretty == true and there is no JSON error) or with toSource().
We have to use a mutable handle because JS_Stringify requires that for unknown reasons.
shared_ptr< ScriptInterface::StructuredClone > ScriptInterface::WriteStructuredClone | ( | JS::HandleValue | v | ) |
|
private |
|
private |
struct ScriptInterface::CxPrivate ScriptInterface::m_CxPrivate |
|
private |