forked from mirrors/0ad
Pass ScriptInterface as a const ref where possible.
Reviewed By: elexis Differential Revision: https://code.wildfiregames.com/D739 This was SVN commit r20028.
This commit is contained in:
@@ -59,7 +59,8 @@ template <typename T> struct MaybeRef;
|
||||
// Define RegisterFunction<TR, T0..., f>
|
||||
#define OVERLOADS(z, i, data) \
|
||||
template <typename R, TYPENAME_T0_HEAD(z,i) R (*fptr) ( ScriptInterface::CxPrivate* T0_TAIL_MAYBE_REF(z,i) )> \
|
||||
void RegisterFunction(const char* name) { \
|
||||
void RegisterFunction(const char* name) const \
|
||||
{ \
|
||||
Register(name, call<R T0_TAIL(z,i), fptr>, nargs<T0(z,i)>()); \
|
||||
}
|
||||
BOOST_PP_REPEAT(SCRIPT_INTERFACE_MAX_ARGS, OVERLOADS, ~)
|
||||
|
||||
@@ -56,7 +56,7 @@ struct ScriptInterface_impl
|
||||
{
|
||||
ScriptInterface_impl(const char* nativeScopeName, const shared_ptr<ScriptRuntime>& runtime);
|
||||
~ScriptInterface_impl();
|
||||
void Register(const char* name, JSNative fptr, uint nargs);
|
||||
void Register(const char* name, JSNative fptr, uint nargs) const;
|
||||
|
||||
// Take care to keep this declaration before heap rooted members. Destructors of heap rooted
|
||||
// members have to be called before the runtime destructor.
|
||||
@@ -393,7 +393,7 @@ ScriptInterface_impl::~ScriptInterface_impl()
|
||||
JS_DestroyContext(m_cx);
|
||||
}
|
||||
|
||||
void ScriptInterface_impl::Register(const char* name, JSNative fptr, uint nargs)
|
||||
void ScriptInterface_impl::Register(const char* name, JSNative fptr, uint nargs) const
|
||||
{
|
||||
JSAutoRequest rq(m_cx);
|
||||
JS::RootedObject nativeScope(m_cx, m_nativeScope);
|
||||
@@ -489,7 +489,7 @@ bool ScriptInterface::ReplaceNondeterministicRNG(boost::rand48& rng)
|
||||
return false;
|
||||
}
|
||||
|
||||
void ScriptInterface::Register(const char* name, JSNative fptr, size_t nargs)
|
||||
void ScriptInterface::Register(const char* name, JSNative fptr, size_t nargs) const
|
||||
{
|
||||
m->Register(name, fptr, (uint)nargs);
|
||||
}
|
||||
@@ -612,7 +612,7 @@ bool ScriptInterface::SetGlobal_(const char* name, JS::HandleValue value, bool r
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool ScriptInterface::SetProperty_(JS::HandleValue obj, const char* name, JS::HandleValue value, bool constant, bool enumerate)
|
||||
bool ScriptInterface::SetProperty_(JS::HandleValue obj, const char* name, JS::HandleValue value, bool constant, bool enumerate) const
|
||||
{
|
||||
JSAutoRequest rq(m->m_cx);
|
||||
uint attrs = 0;
|
||||
@@ -630,7 +630,7 @@ bool ScriptInterface::SetProperty_(JS::HandleValue obj, const char* name, JS::Ha
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ScriptInterface::SetProperty_(JS::HandleValue obj, const wchar_t* name, JS::HandleValue value, bool constant, bool enumerate)
|
||||
bool ScriptInterface::SetProperty_(JS::HandleValue obj, const wchar_t* name, JS::HandleValue value, bool constant, bool enumerate) const
|
||||
{
|
||||
JSAutoRequest rq(m->m_cx);
|
||||
uint attrs = 0;
|
||||
@@ -649,7 +649,7 @@ bool ScriptInterface::SetProperty_(JS::HandleValue obj, const wchar_t* name, JS:
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ScriptInterface::SetPropertyInt_(JS::HandleValue obj, int name, JS::HandleValue value, bool constant, bool enumerate)
|
||||
bool ScriptInterface::SetPropertyInt_(JS::HandleValue obj, int name, JS::HandleValue value, bool constant, bool enumerate) const
|
||||
{
|
||||
JSAutoRequest rq(m->m_cx);
|
||||
uint attrs = 0;
|
||||
@@ -1103,7 +1103,7 @@ void ScriptInterface::ForceGC()
|
||||
JS_GC(this->GetJSRuntime());
|
||||
}
|
||||
|
||||
JS::Value ScriptInterface::CloneValueFromOtherContext(ScriptInterface& otherContext, JS::HandleValue val)
|
||||
JS::Value ScriptInterface::CloneValueFromOtherContext(const ScriptInterface& otherContext, JS::HandleValue val) const
|
||||
{
|
||||
PROFILE("CloneValueFromOtherContext");
|
||||
JSAutoRequest rq(m->m_cx);
|
||||
@@ -1124,7 +1124,7 @@ ScriptInterface::StructuredClone::~StructuredClone()
|
||||
JS_ClearStructuredClone(m_Data, m_Size, NULL, NULL);
|
||||
}
|
||||
|
||||
shared_ptr<ScriptInterface::StructuredClone> ScriptInterface::WriteStructuredClone(JS::HandleValue v)
|
||||
shared_ptr<ScriptInterface::StructuredClone> ScriptInterface::WriteStructuredClone(JS::HandleValue v) const
|
||||
{
|
||||
JSAutoRequest rq(m->m_cx);
|
||||
u64* data = NULL;
|
||||
@@ -1141,7 +1141,7 @@ shared_ptr<ScriptInterface::StructuredClone> ScriptInterface::WriteStructuredClo
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ScriptInterface::ReadStructuredClone(const shared_ptr<ScriptInterface::StructuredClone>& ptr, JS::MutableHandleValue ret)
|
||||
void ScriptInterface::ReadStructuredClone(const shared_ptr<ScriptInterface::StructuredClone>& ptr, JS::MutableHandleValue ret) const
|
||||
{
|
||||
JSAutoRequest rq(m->m_cx);
|
||||
JS_ReadStructuredClone(m->m_cx, ptr->m_Data, ptr->m_Size, JS_STRUCTURED_CLONE_VERSION, ret, NULL, NULL);
|
||||
|
||||
@@ -151,21 +151,21 @@ public:
|
||||
* Optionally makes it {ReadOnly, DontDelete, DontEnum}.
|
||||
*/
|
||||
template<typename T>
|
||||
bool SetProperty(JS::HandleValue obj, const char* name, const T& value, bool constant = false, bool enumerate = true);
|
||||
bool SetProperty(JS::HandleValue obj, const char* name, const T& value, bool constant = false, bool enumerate = true) const;
|
||||
|
||||
/**
|
||||
* Set the named property on the given object.
|
||||
* Optionally makes it {ReadOnly, DontDelete, DontEnum}.
|
||||
*/
|
||||
template<typename T>
|
||||
bool SetProperty(JS::HandleValue obj, const wchar_t* name, const T& value, bool constant = false, bool enumerate = true);
|
||||
bool SetProperty(JS::HandleValue obj, const wchar_t* name, const T& value, bool constant = false, bool enumerate = true) const;
|
||||
|
||||
/**
|
||||
* Set the integer-named property on the given object.
|
||||
* Optionally makes it {ReadOnly, DontDelete, DontEnum}.
|
||||
*/
|
||||
template<typename T>
|
||||
bool SetPropertyInt(JS::HandleValue obj, int name, const T& value, bool constant = false, bool enumerate = true);
|
||||
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.
|
||||
@@ -266,7 +266,7 @@ public:
|
||||
* Complex values (functions, XML, etc) won't be cloned correctly, but basic
|
||||
* types and cyclic references should be fine.
|
||||
*/
|
||||
JS::Value CloneValueFromOtherContext(ScriptInterface& otherContext, JS::HandleValue val);
|
||||
JS::Value CloneValueFromOtherContext(const ScriptInterface& otherContext, JS::HandleValue val) const;
|
||||
|
||||
/**
|
||||
* Convert a jsval to a C++ type. (This might trigger GC.)
|
||||
@@ -319,8 +319,8 @@ public:
|
||||
size_t m_Size;
|
||||
};
|
||||
|
||||
shared_ptr<StructuredClone> WriteStructuredClone(JS::HandleValue v);
|
||||
void ReadStructuredClone(const shared_ptr<StructuredClone>& ptr, JS::MutableHandleValue ret);
|
||||
shared_ptr<StructuredClone> WriteStructuredClone(JS::HandleValue v) const;
|
||||
void ReadStructuredClone(const shared_ptr<StructuredClone>& ptr, JS::MutableHandleValue ret) const;
|
||||
|
||||
/**
|
||||
* Converts |a| if needed and assigns it to |handle|.
|
||||
@@ -360,9 +360,9 @@ private:
|
||||
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 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 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 GetPropertyInt_(JS::HandleValue obj, int name, JS::MutableHandleValue value) const;
|
||||
static bool IsExceptionPending(JSContext* cx);
|
||||
@@ -394,7 +394,7 @@ private:
|
||||
JSClass* m_Class;
|
||||
JSNative m_Constructor;
|
||||
};
|
||||
void Register(const char* name, JSNative fptr, size_t nargs);
|
||||
void Register(const char* name, JSNative fptr, size_t nargs) const;
|
||||
|
||||
// Take care to keep this declaration before heap rooted members. Destructors of heap rooted
|
||||
// members have to be called before the runtime destructor.
|
||||
@@ -409,7 +409,7 @@ public:
|
||||
// This declares:
|
||||
//
|
||||
// template <R, T0..., TR (*fptr) (void* cbdata, T0...)>
|
||||
// void RegisterFunction(const char* functionName);
|
||||
// void RegisterFunction(const char* functionName) const;
|
||||
//
|
||||
// template <R, T0..., TR (*fptr) (void* cbdata, T0...)>
|
||||
// static JSNative call;
|
||||
@@ -494,7 +494,7 @@ bool ScriptInterface::SetGlobal(const char* name, const T& value, bool replace)
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool ScriptInterface::SetProperty(JS::HandleValue obj, const char* name, const T& value, bool readonly, bool enumerate)
|
||||
bool ScriptInterface::SetProperty(JS::HandleValue obj, const char* name, const T& value, bool readonly, bool enumerate) const
|
||||
{
|
||||
JSAutoRequest rq(GetContext());
|
||||
JS::RootedValue val(GetContext());
|
||||
@@ -503,7 +503,7 @@ bool ScriptInterface::SetProperty(JS::HandleValue obj, const char* name, const T
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool ScriptInterface::SetProperty(JS::HandleValue obj, const wchar_t* name, const T& value, bool readonly, bool enumerate)
|
||||
bool ScriptInterface::SetProperty(JS::HandleValue obj, const wchar_t* name, const T& value, bool readonly, bool enumerate) const
|
||||
{
|
||||
JSAutoRequest rq(GetContext());
|
||||
JS::RootedValue val(GetContext());
|
||||
@@ -512,7 +512,7 @@ bool ScriptInterface::SetProperty(JS::HandleValue obj, const wchar_t* name, cons
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool ScriptInterface::SetPropertyInt(JS::HandleValue obj, int name, const T& value, bool readonly, bool enumerate)
|
||||
bool ScriptInterface::SetPropertyInt(JS::HandleValue obj, int name, const T& value, bool readonly, bool enumerate) const
|
||||
{
|
||||
JSAutoRequest rq(GetContext());
|
||||
JS::RootedValue val(GetContext());
|
||||
|
||||
@@ -188,7 +188,7 @@ public:
|
||||
handle_templates_test(script, val, &out, nbrVal);
|
||||
}
|
||||
|
||||
void handle_templates_test(ScriptInterface& script, JS::HandleValue val, JS::MutableHandleValue out, JS::HandleValue nbrVal)
|
||||
void handle_templates_test(const ScriptInterface& script, JS::HandleValue val, JS::MutableHandleValue out, JS::HandleValue nbrVal)
|
||||
{
|
||||
int nbr = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user