mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-06-24 19:28:05 +00:00
More exact stack rooting (CallFunction object).
Changes CallFunction and CallFunctionVoid to use a HandleValue as object parameter. Also changes some JS serialization/deserialization functions to only support the JSAPI rooted types (drop support for CScriptVal and CScriptValRooted there). Some other functions got changed too because they were closely related. Refs #2415 Refs #2462 This was SVN commit r15592.
This commit is contained in:
@@ -64,11 +64,15 @@ void CComponentTypeScript::Deinit()
|
||||
|
||||
void CComponentTypeScript::HandleMessage(const CMessage& msg, bool global)
|
||||
{
|
||||
JSContext* cx = m_ScriptInterface.GetContext();
|
||||
JSAutoRequest rq(cx);
|
||||
|
||||
const char* name = global ? msg.GetScriptGlobalHandlerName() : msg.GetScriptHandlerName();
|
||||
|
||||
CScriptVal msgVal = msg.ToJSValCached(m_ScriptInterface);
|
||||
JS::RootedValue msgVal(cx, msg.ToJSValCached(m_ScriptInterface));
|
||||
|
||||
if (!m_ScriptInterface.CallFunctionVoid(m_Instance.get(), name, msgVal))
|
||||
JS::RootedValue tmpInstance(cx, m_Instance.get()); // TODO: Check if this temporary root can be removed after SpiderMonkey 31 upgrade
|
||||
if (!m_ScriptInterface.CallFunctionVoid(tmpInstance, name, msgVal))
|
||||
LOGERROR(L"Script message handler %hs failed", name);
|
||||
}
|
||||
|
||||
@@ -77,19 +81,23 @@ void CComponentTypeScript::Serialize(ISerializer& serialize)
|
||||
// If the component set Serialize = null, then do no work here
|
||||
if (m_HasNullSerialize)
|
||||
return;
|
||||
|
||||
JSContext* cx = m_ScriptInterface.GetContext();
|
||||
JSAutoRequest rq(cx);
|
||||
JS::RootedValue tmpInstance(cx, m_Instance.get()); // TODO: Check if this temporary root can be removed after SpiderMonkey 31 upgrade
|
||||
|
||||
// Support a custom "Serialize" function, which returns a new object that will be
|
||||
// serialized instead of the component itself
|
||||
if (m_HasCustomSerialize)
|
||||
{
|
||||
CScriptVal val;
|
||||
if (!m_ScriptInterface.CallFunction(m_Instance.get(), "Serialize", val))
|
||||
JS::RootedValue val(cx);
|
||||
if (!m_ScriptInterface.CallFunction(tmpInstance, "Serialize", &val))
|
||||
LOGERROR(L"Script Serialize call failed");
|
||||
serialize.ScriptVal("object", val);
|
||||
}
|
||||
else
|
||||
{
|
||||
serialize.ScriptVal("object", m_Instance.get());
|
||||
serialize.ScriptVal("object", tmpInstance);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,7 +115,7 @@ void CComponentTypeScript::Deserialize(const CParamNode& paramNode, IDeserialize
|
||||
|
||||
// If Serialize = null, we'll still call Deserialize but with undefined argument
|
||||
if (!m_HasNullSerialize)
|
||||
deserialize.ScriptVal("object", val.get());
|
||||
deserialize.ScriptVal("object", &val);
|
||||
|
||||
if (!m_ScriptInterface.CallFunctionVoid(tmpInstance, "Deserialize", val))
|
||||
LOGERROR(L"Script Deserialize call failed");
|
||||
@@ -118,7 +126,7 @@ void CComponentTypeScript::Deserialize(const CParamNode& paramNode, IDeserialize
|
||||
{
|
||||
// Use ScriptObjectAppend so we don't lose the carefully-constructed
|
||||
// prototype/parent of this object
|
||||
deserialize.ScriptObjectAppend("object", m_Instance.getRef());
|
||||
deserialize.ScriptObjectAppend("object", tmpInstance);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user