mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-07-14 14:15:09 +00:00
Replace HandleWrapper and avoid repoint function
JS::Handle<T>::repoint gets removed with SpiderMonkey 38, so the existing solution has to be replaced. The new approach should also be a bit clearer. Named Return Value Optimization (NRVO) should avoid a superfluous temporary for the return value in the generic template function implementation of AssignOrFromJSVal. Refs #3708 This was SVN commit r17695.
This commit is contained in:
@@ -375,6 +375,14 @@ public:
|
||||
{
|
||||
AssignOrToJSVal(cx, handle, a);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
template <typename T>
|
||||
static T AssignOrFromJSVal(JSContext* cx, const JS::HandleValue& val, bool& ret);
|
||||
|
||||
private:
|
||||
|
||||
@@ -476,6 +484,21 @@ inline void ScriptInterface::AssignOrToJSValUnrooted<JS::Value>(JSContext* UNUSE
|
||||
handle.set(a);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T ScriptInterface::AssignOrFromJSVal(JSContext* cx, const JS::HandleValue& val, bool& ret)
|
||||
{
|
||||
T retVal;
|
||||
ret = FromJSVal(cx, val, retVal);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline JS::HandleValue ScriptInterface::AssignOrFromJSVal<JS::HandleValue>(JSContext* UNUSED(cx), const JS::HandleValue& val, bool& ret)
|
||||
{
|
||||
ret = true;
|
||||
return val;
|
||||
}
|
||||
|
||||
template<typename T0>
|
||||
bool ScriptInterface::CallFunctionVoid(JS::HandleValue val, const char* name, const T0& a0)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user