diff --git a/source/scriptinterface/ScriptInterface.cpp b/source/scriptinterface/ScriptInterface.cpp index 63e633756a..0f6297ffd9 100644 --- a/source/scriptinterface/ScriptInterface.cpp +++ b/source/scriptinterface/ScriptInterface.cpp @@ -1135,16 +1135,18 @@ bool ScriptInterface::SetPrototype(JS::HandleValue obj, JS::HandleValue proto) return JS_SetPrototype(m->m_cx, &obj.toObject(), &proto.toObject()); } -bool ScriptInterface::FreezeObject(jsval obj, bool deep) +bool ScriptInterface::FreezeObject(JS::HandleValue objVal, bool deep) { JSAutoRequest rq(m->m_cx); - if (!obj.isObject()) + if (!objVal.isObject()) return false; + + JS::RootedObject obj(m->m_cx, &objVal.toObject()); if (deep) - return JS_DeepFreezeObject(m->m_cx, &obj.toObject()); + return JS_DeepFreezeObject(m->m_cx, obj); else - return JS_FreezeObject(m->m_cx, &obj.toObject()); + return JS_FreezeObject(m->m_cx, obj); } bool ScriptInterface::LoadScript(const VfsPath& filename, const std::string& code) diff --git a/source/scriptinterface/ScriptInterface.h b/source/scriptinterface/ScriptInterface.h index 19fa57ea67..31253bf4ae 100644 --- a/source/scriptinterface/ScriptInterface.h +++ b/source/scriptinterface/ScriptInterface.h @@ -258,7 +258,7 @@ public: bool SetPrototype(JS::HandleValue obj, JS::HandleValue proto); - bool FreezeObject(jsval obj, bool deep); + bool FreezeObject(JS::HandleValue objVal, bool deep); bool Eval(const char* code); diff --git a/source/simulation2/components/CCmpAIManager.cpp b/source/simulation2/components/CCmpAIManager.cpp index 25353daae6..980730c718 100644 --- a/source/simulation2/components/CCmpAIManager.cpp +++ b/source/simulation2/components/CCmpAIManager.cpp @@ -572,7 +572,7 @@ public: // Since the template data is shared between AI players, freeze it // to stop any of them changing it and confusing the other players m_EntityTemplates = CScriptValRooted(cx, tmpEntityTemplates); - m_ScriptInterface->FreezeObject(m_EntityTemplates.get(), true); + m_ScriptInterface->FreezeObject(tmpEntityTemplates, true); } void Serialize(std::ostream& stream, bool isDebug)