diff --git a/source/scriptinterface/ScriptConversions.h b/source/scriptinterface/ScriptConversions.h index 1814123dfd..095ec6cf89 100644 --- a/source/scriptinterface/ScriptConversions.h +++ b/source/scriptinterface/ScriptConversions.h @@ -86,13 +86,13 @@ template<> bool ScriptInterface::FromJSVal >(JSContext* cx, JS::H return FromJSVal_vector(cx, v, out); \ } -template static bool FromJSProperty(JSContext* cx, JS::HandleValue v, const char* name, T& out) +template bool ScriptInterface::FromJSProperty(JSContext* cx, const JS::HandleValue val, const char* name, T& ret) { - if (!v.isObject()) + if (!val.isObject()) return false; JSAutoRequest rq(cx); - JS::RootedObject obj(cx, &v.toObject()); + JS::RootedObject obj(cx, &val.toObject()); bool hasProperty; if (!JS_HasProperty(cx, obj, name, &hasProperty) || !hasProperty) @@ -102,7 +102,7 @@ template static bool FromJSProperty(JSContext* cx, JS::HandleValue v if (!JS_GetProperty(cx, obj, name, &value)) return false; - return ScriptInterface::FromJSVal(cx, value, out); + return FromJSVal(cx, value, ret); } #endif //INCLUDED_SCRIPTCONVERSIONS diff --git a/source/scriptinterface/ScriptInterface.h b/source/scriptinterface/ScriptInterface.h index e4d2323be6..323a1531c7 100644 --- a/source/scriptinterface/ScriptInterface.h +++ b/source/scriptinterface/ScriptInterface.h @@ -282,6 +282,11 @@ public: */ template static void ToJSVal(JSContext* cx, JS::MutableHandleValue ret, T const& val); + /** + * Convert a named property of an object to a C++ type. + */ + template static bool FromJSProperty(JSContext* cx, const JS::HandleValue val, const char* name, T& ret); + /** * MaybeGC tries to determine whether garbage collection in cx's runtime would free up enough memory to be worth the amount of time it would take. * This calls JS_MaybeGC directly, which does not do incremental GC. Usually you should prefer MaybeIncrementalRuntimeGC.