Quite a lot of stack rooting related changes.

Changes GetProperty, SetProperty and HasProperty and a few other
functions to take handles. The conversions to CScriptVal or
CScriptValRooted at some places should be removed in the future. I've
done that to avoid an even larger patch.

Refs #2415
Refs #2462

This was SVN commit r15568.
This commit is contained in:
Yves
2014-07-26 22:33:16 +00:00
parent e818b08344
commit 28bdd8540f
25 changed files with 801 additions and 619 deletions
+29 -27
View File
@@ -190,27 +190,27 @@ public:
* Optionally makes it {ReadOnly, DontDelete, DontEnum}.
*/
template<typename T>
bool SetProperty(jsval 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);
/**
* Set the named property on the given object.
* Optionally makes it {ReadOnly, DontDelete, DontEnum}.
*/
template<typename T>
bool SetProperty(jsval 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);
/**
* Set the integer-named property on the given object.
* Optionally makes it {ReadOnly, DontDelete, DontEnum}.
*/
template<typename T>
bool SetPropertyInt(jsval 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);
/**
* Get the named property on the given object.
*/
template<typename T>
bool GetProperty(jsval obj, const char* name, T& out);
bool GetProperty(JS::HandleValue obj, const char* name, T& out);
/**
* Get the named property of the given object.
@@ -220,7 +220,7 @@ public:
* |out| using the & operator.
*/
template<typename T>
bool GetProperty(jsval obj, const char* name, JS::Rooted<T>* out);
bool GetProperty(JS::HandleValue obj, const char* name, JS::Rooted<T>* out);
/**
* Get the named property of the given object.
@@ -228,21 +228,23 @@ public:
* to GetProperty as |out| parameter directly (usually when you get it as a function parameter).
*/
template<typename T>
bool GetProperty(jsval obj, const char* name, JS::MutableHandle<T> out);
bool GetProperty(JS::HandleValue obj, const char* name, JS::MutableHandle<T> out);
/**
* Get the integer-named property on the given object.
*/
template<typename T>
bool GetPropertyInt(jsval obj, int name, T& out);
bool GetPropertyInt(JS::HandleValue obj, int name, T& out);
/**
* Get the integer-named property on the given object.
* This version is for taking JS::MutableHandle<T> out parameters. Check the comment for GetProperty for
* background information
* This overload takes JS::Rooted<T>* and converts it to JS::MutableHandle<T> in the function body because implicit
* conversion is not supported for templates.
* It's used in the case where a JS::Rooted<T> gets created inside the same function and then passed to GetPropertyInt as
* |out| using the & operator.
*/
template<typename T>
bool GetPropertyInt(jsval obj, int name, JS::Rooted<T>* out);
bool GetPropertyInt(JS::HandleValue obj, int name, JS::Rooted<T>* out);
/**
* Get the named property of the given object.
@@ -250,12 +252,12 @@ public:
* to GetPropertyInt as |out| parameter directly (usually when you get it as a function parameter).
*/
template<typename T>
bool GetPropertyInt(jsval obj, int name, JS::MutableHandle<T> out);
bool GetPropertyInt(JS::HandleValue obj, int name, JS::MutableHandle<T> out);
/**
* Check the named property has been defined on the given object.
*/
bool HasProperty(jsval obj, const char* name);
bool HasProperty(JS::HandleValue obj, const char* name);
bool EnumeratePropertyNamesWithPrefix(JS::HandleValue objVal, const char* prefix, std::vector<std::string>& out);
@@ -410,11 +412,11 @@ private:
bool Eval_(const char* code, JS::MutableHandleValue ret);
bool Eval_(const wchar_t* code, JS::MutableHandleValue ret);
bool SetGlobal_(const char* name, jsval value, bool replace);
bool SetProperty_(jsval obj, const char* name, jsval value, bool readonly, bool enumerate);
bool SetProperty_(jsval obj, const wchar_t* name, jsval value, bool readonly, bool enumerate);
bool SetPropertyInt_(jsval obj, int name, jsval value, bool readonly, bool enumerate);
bool GetProperty_(jsval obj, const char* name, JS::MutableHandleValue out);
bool GetPropertyInt_(jsval obj, int name, JS::MutableHandleValue value);
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 GetProperty_(JS::HandleValue obj, const char* name, JS::MutableHandleValue out);
bool GetPropertyInt_(JS::HandleValue obj, int name, JS::MutableHandleValue value);
static bool IsExceptionPending(JSContext* cx);
static JSClass* GetClass(JSObject* obj);
static void* GetPrivate(JSObject* obj);
@@ -529,7 +531,7 @@ bool ScriptInterface::SetGlobal(const char* name, const T& value, bool replace)
}
template<typename T>
bool ScriptInterface::SetProperty(jsval 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)
{
JSAutoRequest rq(GetContext());
JS::RootedValue val(GetContext());
@@ -538,7 +540,7 @@ bool ScriptInterface::SetProperty(jsval obj, const char* name, const T& value, b
}
template<typename T>
bool ScriptInterface::SetProperty(jsval 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)
{
JSAutoRequest rq(GetContext());
JS::RootedValue val(GetContext());
@@ -547,7 +549,7 @@ bool ScriptInterface::SetProperty(jsval obj, const wchar_t* name, const T& value
}
template<typename T>
bool ScriptInterface::SetPropertyInt(jsval 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)
{
JSAutoRequest rq(GetContext());
JS::RootedValue val(GetContext());
@@ -556,7 +558,7 @@ bool ScriptInterface::SetPropertyInt(jsval obj, int name, const T& value, bool r
}
template<typename T>
bool ScriptInterface::GetProperty(jsval obj, const char* name, T& out)
bool ScriptInterface::GetProperty(JS::HandleValue obj, const char* name, T& out)
{
JSContext* cx = GetContext();
JSAutoRequest rq(cx);
@@ -567,7 +569,7 @@ bool ScriptInterface::GetProperty(jsval obj, const char* name, T& out)
}
template<typename T>
bool ScriptInterface::GetProperty(jsval obj, const char* name, JS::Rooted<T>* out)
bool ScriptInterface::GetProperty(JS::HandleValue obj, const char* name, JS::Rooted<T>* out)
{
JS::MutableHandle<T> handleOut(out);
if (! GetProperty_(obj, name, handleOut))
@@ -576,7 +578,7 @@ bool ScriptInterface::GetProperty(jsval obj, const char* name, JS::Rooted<T>* ou
}
template<typename T>
bool ScriptInterface::GetProperty(jsval obj, const char* name, JS::MutableHandle<T> out)
bool ScriptInterface::GetProperty(JS::HandleValue obj, const char* name, JS::MutableHandle<T> out)
{
if (! GetProperty_(obj, name, out))
return false;
@@ -584,7 +586,7 @@ bool ScriptInterface::GetProperty(jsval obj, const char* name, JS::MutableHandle
}
template<typename T>
bool ScriptInterface::GetPropertyInt(jsval obj, int name, T& out)
bool ScriptInterface::GetPropertyInt(JS::HandleValue obj, int name, T& out)
{
JSAutoRequest rq(GetContext());
JS::RootedValue val(GetContext());
@@ -594,7 +596,7 @@ bool ScriptInterface::GetPropertyInt(jsval obj, int name, T& out)
}
template<typename T>
bool ScriptInterface::GetPropertyInt(jsval obj, int name, JS::Rooted<T>* out)
bool ScriptInterface::GetPropertyInt(JS::HandleValue obj, int name, JS::Rooted<T>* out)
{
JS::MutableHandle<T> handleOut(out);
if (! GetPropertyInt_(obj, name, handleOut))
@@ -603,7 +605,7 @@ bool ScriptInterface::GetPropertyInt(jsval obj, int name, JS::Rooted<T>* out)
}
template<typename T>
bool ScriptInterface::GetPropertyInt(jsval obj, int name, JS::MutableHandle<T> out)
bool ScriptInterface::GetPropertyInt(JS::HandleValue obj, int name, JS::MutableHandle<T> out)
{
if (! GetPropertyInt_(obj, name, out))
return false;