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:
Yves
2016-01-23 14:42:59 +00:00
parent b9f1125010
commit 5f86beea6f
4 changed files with 31 additions and 52 deletions
+23
View File
@@ -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)
{