Changeset View
Changeset View
Standalone View
Standalone View
source/scriptinterface/ScriptInterface.h
Show First 20 Lines • Show All 204 Lines • ▼ Show 20 Lines | public: | ||||
template<typename T> | template<typename T> | ||||
bool SetPropertyInt(JS::HandleValue obj, int name, const T& value, bool constant = false, bool enumerate = true) const; | bool SetPropertyInt(JS::HandleValue obj, int name, const T& value, bool constant = false, bool enumerate = true) const; | ||||
/** | /** | ||||
* Get the named property on the given object. | * Get the named property on the given object. | ||||
*/ | */ | ||||
template<typename T> | template<typename T> | ||||
bool GetProperty(JS::HandleValue obj, const char* name, T& out) const; | bool GetProperty(JS::HandleValue obj, const char* name, T& out) const; | ||||
/** | |||||
* Get the named property of the given object. | |||||
*/ | |||||
bool GetProperty(JS::HandleValue obj, const char* name, JS::MutableHandleValue out) const; | bool GetProperty(JS::HandleValue obj, const char* name, JS::MutableHandleValue out) const; | ||||
bool GetProperty(JS::HandleValue obj, const char* name, JS::MutableHandleObject out) const; | bool GetProperty(JS::HandleValue obj, const char* name, JS::MutableHandleObject out) const; | ||||
template<typename T> | |||||
static bool GetProperty(const ScriptRequest& rq, JS::HandleValue obj, const char* name, T& out); | |||||
static bool GetProperty(const ScriptRequest& rq, JS::HandleValue obj, const char* name, JS::MutableHandleValue out); | |||||
static bool GetProperty(const ScriptRequest& rq, JS::HandleValue obj, const char* name, JS::MutableHandleObject out); | |||||
/** | /** | ||||
* Get the integer-named property on the given object. | * Get the integer-named property on the given object. | ||||
*/ | */ | ||||
template<typename T> | template<typename T> | ||||
bool GetPropertyInt(JS::HandleValue obj, int name, T& out) const; | bool GetPropertyInt(JS::HandleValue obj, int name, T& out) const; | ||||
/** | |||||
* Get the named property of the given object. | |||||
*/ | |||||
bool GetPropertyInt(JS::HandleValue obj, int name, JS::MutableHandleValue out) const; | bool GetPropertyInt(JS::HandleValue obj, int name, JS::MutableHandleValue out) const; | ||||
bool GetPropertyInt(JS::HandleValue obj, int name, JS::MutableHandleObject out) const; | |||||
template<typename T> | |||||
static bool GetPropertyInt(const ScriptRequest& rq, JS::HandleValue obj, int name, T& out); | |||||
static bool GetPropertyInt(const ScriptRequest& rq, JS::HandleValue obj, int name, JS::MutableHandleValue out); | |||||
static bool GetPropertyInt(const ScriptRequest& rq, JS::HandleValue obj, int name, JS::MutableHandleObject out); | |||||
/** | /** | ||||
* Check the named property has been defined on the given object. | * Check the named property has been defined on the given object. | ||||
*/ | */ | ||||
bool HasProperty(JS::HandleValue obj, const char* name) const; | bool HasProperty(JS::HandleValue obj, const char* name) const; | ||||
/** | /** | ||||
* Get an object from the global scope or any lexical scope. | * Get an object from the global scope or any lexical scope. | ||||
▲ Show 20 Lines • Show All 201 Lines • ▼ Show 20 Lines | static bool CreateObject_(const ScriptRequest& rq, JS::MutableHandleObject obj, const char* propertyName, const T& propertyValue, Args const&... args) | ||||
return CreateObject_(rq, obj, args...) && JS_DefineProperty(rq.cx, obj, propertyName, val, JSPROP_ENUMERATE); | return CreateObject_(rq, obj, args...) && JS_DefineProperty(rq.cx, obj, propertyName, val, JSPROP_ENUMERATE); | ||||
} | } | ||||
bool CallFunction_(JS::HandleValue val, const char* name, JS::HandleValueArray argv, JS::MutableHandleValue ret) const; | bool CallFunction_(JS::HandleValue val, const char* name, JS::HandleValueArray argv, JS::MutableHandleValue ret) const; | ||||
bool SetGlobal_(const char* name, JS::HandleValue value, bool replace, bool constant, bool enumerate); | bool SetGlobal_(const char* name, JS::HandleValue value, bool replace, bool constant, bool enumerate); | ||||
bool SetProperty_(JS::HandleValue obj, const char* name, JS::HandleValue value, bool constant, bool enumerate) const; | bool SetProperty_(JS::HandleValue obj, const char* name, JS::HandleValue value, bool constant, bool enumerate) const; | ||||
bool SetProperty_(JS::HandleValue obj, const wchar_t* name, JS::HandleValue value, bool constant, bool enumerate) const; | bool SetProperty_(JS::HandleValue obj, const wchar_t* name, JS::HandleValue value, bool constant, bool enumerate) const; | ||||
bool SetPropertyInt_(JS::HandleValue obj, int name, JS::HandleValue value, bool constant, bool enumerate) const; | bool SetPropertyInt_(JS::HandleValue obj, int name, JS::HandleValue value, bool constant, bool enumerate) const; | ||||
bool GetProperty_(JS::HandleValue obj, const char* name, JS::MutableHandleValue out) const; | |||||
bool GetPropertyInt_(JS::HandleValue obj, int name, JS::MutableHandleValue value) const; | |||||
struct CustomType | struct CustomType | ||||
{ | { | ||||
JS::PersistentRootedObject m_Prototype; | JS::PersistentRootedObject m_Prototype; | ||||
JSClass* m_Class; | JSClass* m_Class; | ||||
JSNative m_Constructor; | JSNative m_Constructor; | ||||
}; | }; | ||||
void Register(const char* name, JSNative fptr, size_t nargs) const; | void Register(const char* name, JSNative fptr, size_t nargs) const; | ||||
▲ Show 20 Lines • Show All 127 Lines • ▼ Show 20 Lines | bool ScriptInterface::SetPropertyInt(JS::HandleValue obj, int name, const T& value, bool constant, bool enumerate) const | ||||
AssignOrToJSVal(rq, &val, value); | AssignOrToJSVal(rq, &val, value); | ||||
return SetPropertyInt_(obj, name, val, constant, enumerate); | return SetPropertyInt_(obj, name, val, constant, enumerate); | ||||
} | } | ||||
template<typename T> | template<typename T> | ||||
bool ScriptInterface::GetProperty(JS::HandleValue obj, const char* name, T& out) const | bool ScriptInterface::GetProperty(JS::HandleValue obj, const char* name, T& out) const | ||||
{ | { | ||||
ScriptRequest rq(this); | ScriptRequest rq(this); | ||||
return GetProperty(rq, obj, name, out); | |||||
} | |||||
template<typename T> | |||||
bool ScriptInterface::GetProperty(const ScriptRequest& rq, JS::HandleValue obj, const char* name, T& out) | |||||
{ | |||||
JS::RootedValue val(rq.cx); | JS::RootedValue val(rq.cx); | ||||
if (!GetProperty_(obj, name, &val)) | if (!GetProperty(rq, obj, name, &val)) | ||||
return false; | return false; | ||||
return FromJSVal(rq, val, out); | return FromJSVal(rq, val, out); | ||||
} | } | ||||
template<typename T> | template<typename T> | ||||
bool ScriptInterface::GetPropertyInt(JS::HandleValue obj, int name, T& out) const | bool ScriptInterface::GetPropertyInt(JS::HandleValue obj, int name, T& out) const | ||||
{ | { | ||||
ScriptRequest rq(this); | ScriptRequest rq(this); | ||||
return GetPropertyInt(rq, obj, name, out); | |||||
} | |||||
template<typename T> | |||||
bool ScriptInterface::GetPropertyInt(const ScriptRequest& rq, JS::HandleValue obj, int name, T& out) | |||||
{ | |||||
JS::RootedValue val(rq.cx); | JS::RootedValue val(rq.cx); | ||||
if (!GetPropertyInt_(obj, name, &val)) | if (!GetPropertyInt(rq, obj, name, &val)) | ||||
return false; | return false; | ||||
return FromJSVal(rq, val, out); | return FromJSVal(rq, val, out); | ||||
} | } | ||||
template<typename T> | template<typename T> | ||||
bool ScriptInterface::Eval(const char* code, T& ret) const | bool ScriptInterface::Eval(const char* code, T& ret) const | ||||
{ | { | ||||
ScriptRequest rq(this); | ScriptRequest rq(this); | ||||
JS::RootedValue rval(rq.cx); | JS::RootedValue rval(rq.cx); | ||||
if (!Eval(code, &rval)) | if (!Eval(code, &rval)) | ||||
return false; | return false; | ||||
return FromJSVal(rq, rval, ret); | return FromJSVal(rq, rval, ret); | ||||
} | } | ||||
#endif // INCLUDED_SCRIPTINTERFACE | #endif // INCLUDED_SCRIPTINTERFACE |
Wildfire Games · Phabricator