Changeset View
Changeset View
Standalone View
Standalone View
source/scriptinterface/ScriptInterface.h
Show First 20 Lines • Show All 136 Lines • ▼ Show 20 Lines | public: | ||||
JS::Value GetGlobalObject() const; | JS::Value GetGlobalObject() const; | ||||
/** | /** | ||||
* Set the named property on the global object. | * Set the named property on the global object. | ||||
* If @p replace is true, an existing property will be overwritten; otherwise attempts | * If @p replace is true, an existing property will be overwritten; otherwise attempts | ||||
* to set an already-defined value will fail. | * to set an already-defined value will fail. | ||||
*/ | */ | ||||
template<typename T> | template<typename T> | ||||
bool SetGlobal(const char* name, const T& value, bool replace = false); | bool SetGlobal(const char* name, const T& value, bool replace = false, bool constant = true, bool enumerate = true); | ||||
/** | /** | ||||
* Set the named property on the given object. | * Set the named property on the given object. | ||||
* Optionally makes it {ReadOnly, DontDelete, DontEnum}. | * Optionally makes it {ReadOnly, DontDelete, DontEnum}. | ||||
*/ | */ | ||||
template<typename T> | template<typename T> | ||||
bool SetProperty(JS::HandleValue obj, const char* name, const T& value, bool constant = false, bool enumerate = true) const; | bool SetProperty(JS::HandleValue obj, const char* name, const T& value, bool constant = false, bool enumerate = true) const; | ||||
▲ Show 20 Lines • Show All 203 Lines • ▼ Show 20 Lines | public: | ||||
template <typename T> | template <typename T> | ||||
static T AssignOrFromJSVal(JSContext* cx, const JS::HandleValue& val, bool& ret); | static T AssignOrFromJSVal(JSContext* cx, const JS::HandleValue& val, bool& ret); | ||||
private: | private: | ||||
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 Eval_(const char* code, JS::MutableHandleValue ret) const; | bool Eval_(const char* code, JS::MutableHandleValue ret) const; | ||||
bool Eval_(const wchar_t* 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 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 readonly, bool enumerate) const; | bool SetProperty_(JS::HandleValue obj, const char* name, JS::HandleValue value, bool readonly, bool enumerate) const; | ||||
bool SetProperty_(JS::HandleValue obj, const wchar_t* name, JS::HandleValue value, bool readonly, bool enumerate) const; | bool SetProperty_(JS::HandleValue obj, const wchar_t* name, JS::HandleValue value, bool readonly, bool enumerate) const; | ||||
bool SetPropertyInt_(JS::HandleValue obj, int name, JS::HandleValue value, bool readonly, bool enumerate) const; | bool SetPropertyInt_(JS::HandleValue obj, int name, JS::HandleValue value, bool readonly, bool enumerate) const; | ||||
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 GetPropertyInt_(JS::HandleValue obj, int name, JS::MutableHandleValue value) const; | bool GetPropertyInt_(JS::HandleValue obj, int name, JS::MutableHandleValue value) const; | ||||
static bool IsExceptionPending(JSContext* cx); | static bool IsExceptionPending(JSContext* cx); | ||||
static const JSClass* GetClass(JS::HandleObject obj); | static const JSClass* GetClass(JS::HandleObject obj); | ||||
static void* GetPrivate(JS::HandleObject obj); | static void* GetPrivate(JS::HandleObject obj); | ||||
▲ Show 20 Lines • Show All 109 Lines • ▼ Show 20 Lines | |||||
template<> | template<> | ||||
inline JS::HandleValue ScriptInterface::AssignOrFromJSVal<JS::HandleValue>(JSContext* UNUSED(cx), const JS::HandleValue& val, bool& ret) | inline JS::HandleValue ScriptInterface::AssignOrFromJSVal<JS::HandleValue>(JSContext* UNUSED(cx), const JS::HandleValue& val, bool& ret) | ||||
{ | { | ||||
ret = true; | ret = true; | ||||
return val; | return val; | ||||
} | } | ||||
template<typename T> | template<typename T> | ||||
bool ScriptInterface::SetGlobal(const char* name, const T& value, bool replace) | bool ScriptInterface::SetGlobal(const char* name, const T& value, bool replace, bool constant, bool enumerate) | ||||
{ | { | ||||
JSAutoRequest rq(GetContext()); | JSAutoRequest rq(GetContext()); | ||||
JS::RootedValue val(GetContext()); | JS::RootedValue val(GetContext()); | ||||
AssignOrToJSVal(GetContext(), &val, value); | AssignOrToJSVal(GetContext(), &val, value); | ||||
return SetGlobal_(name, val, replace); | return SetGlobal_(name, val, replace, constant, enumerate); | ||||
} | } | ||||
template<typename T> | template<typename T> | ||||
bool ScriptInterface::SetProperty(JS::HandleValue obj, const char* name, const T& value, bool readonly, bool enumerate) const | bool ScriptInterface::SetProperty(JS::HandleValue obj, const char* name, const T& value, bool readonly, bool enumerate) const | ||||
{ | { | ||||
JSAutoRequest rq(GetContext()); | JSAutoRequest rq(GetContext()); | ||||
JS::RootedValue val(GetContext()); | JS::RootedValue val(GetContext()); | ||||
AssignOrToJSVal(GetContext(), &val, value); | AssignOrToJSVal(GetContext(), &val, value); | ||||
▲ Show 20 Lines • Show All 61 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator