Exact rooting for CallConstructor.

Refs #2415
Refs #2462

This was SVN commit r15601.
This commit is contained in:
Yves
2014-08-02 16:30:15 +00:00
parent 736d934107
commit c818b8e475
4 changed files with 30 additions and 19 deletions
@@ -708,6 +708,9 @@ void CComponentManager::AddSystemComponents(bool skipScriptedComponents, bool sk
IComponent* CComponentManager::ConstructComponent(CEntityHandle ent, ComponentTypeId cid)
{
JSContext* cx = m_ScriptInterface.GetContext();
JSAutoRequest rq(cx);
std::map<ComponentTypeId, ComponentType>::const_iterator it = m_ComponentTypesById.find(cid);
if (it == m_ComponentTypesById.end())
{
@@ -729,11 +732,14 @@ IComponent* CComponentManager::ConstructComponent(CEntityHandle ent, ComponentTy
std::map<entity_id_t, IComponent*>& emap2 = m_ComponentsByTypeId[cid];
// If this is a scripted component, construct the appropriate JS object first
jsval obj = JSVAL_NULL;
JS::RootedValue obj(cx);
// TODO: Check if this temporary root can be removed after SpiderMonkey 31 upgrade
JS::RootedValue tmpCtor(cx, ct.ctor.get());
if (ct.type == CT_Script)
{
obj = m_ScriptInterface.CallConstructor(ct.ctor.get(), 0, JSVAL_VOID);
if (JSVAL_IS_VOID(obj))
JS::AutoValueVector argv(cx); // TODO: With SpiderMonkey 31, we can pass JS::HandleValueArray::empty()
m_ScriptInterface.CallConstructor(tmpCtor, argv, &obj);
if (obj.isNull())
{
LOGERROR(L"Script component constructor failed");
return NULL;