Ticket #4053: autorequestfix_v2.patch

File autorequestfix_v2.patch, 8.3 KB (added by elexis, 8 years ago)

Found some more by searching for all occurances of JS::RootedValue, JS::RootedObject and GetContext (grep -R 'GetContext();' -A 1).

  • source/gui/GUIManager.cpp

    void CGUIManager::PopPageCB(shared_ptr<S  
    115115    shared_ptr<ScriptInterface::StructuredClone> initDataClone = m_PageStack.back().initData;
    116116    PopPage();
    117117
    118118    shared_ptr<ScriptInterface> scriptInterface = m_PageStack.back().gui->GetScriptInterface();
    119119    JSContext* cx = scriptInterface->GetContext();
     120    JSAutoRequest rq(cx);
     121
    120122    JS::RootedValue initDataVal(cx);
    121123    if (!initDataClone)
    122124    {
    123125        LOGERROR("Called PopPageCB when initData (which should contain the callback function name) isn't set!");
    124126        return;
  • source/network/NetTurnManager.cpp

    void CNetTurnManager::AddCommand(int cli  
    300300        debug_warn(L"Received command for invalid turn");
    301301        return;
    302302    }
    303303
    304304    m_Simulation2.GetScriptInterface().FreezeObject(data, true);
    305     m_QueuedCommands[turn - (m_CurrentTurn+1)][client].emplace_back(player, m_Simulation2.GetScriptInterface().GetContext(), data);
     305
     306    JSContext* cx = m_Simulation2.GetScriptInterface().GetContext();
     307    JSAutoRequest rq(cx);
     308
     309    m_QueuedCommands[turn - (m_CurrentTurn+1)][client].emplace_back(player, cx, data);
    306310}
    307311
    308312void CNetTurnManager::FinishedAllCommands(u32 turn, u32 turnLength)
    309313{
    310314    NETTURN_LOG((L"FinishedAllCommands(%d, %d)\n", turn, turnLength));
    void CNetReplayTurnManager::DoTurn(u32 t  
    564568{
    565569    debug_printf("Executing turn %u of %u\n", turn, m_FinalTurn);
    566570
    567571    m_TurnLength = m_ReplayTurnLengths[turn];
    568572
     573    JSContext* cx = m_Simulation2.GetScriptInterface().GetContext();
     574    JSAutoRequest rq(cx);
     575
    569576    // Simulate commands for that turn
    570577    for (const std::pair<player_id_t, std::string>& p : m_ReplayCommands[turn])
    571578    {
    572         JS::RootedValue command(m_Simulation2.GetScriptInterface().GetContext());
     579        JS::RootedValue command(cx);
    573580        m_Simulation2.GetScriptInterface().ParseJSON(p.second, &command);
    574581        AddCommand(m_ClientId, p.first, command, m_CurrentTurn + 1);
    575582    }
    576583
    577584    if (turn == m_FinalTurn)
  • source/ps/Game.cpp

    bool CGame::StartVisualReplay(const std:  
    183183    std::string type;
    184184    ENSURE((*m_ReplayStream >> type).good() && type == "start");
    185185
    186186    std::string line;
    187187    std::getline(*m_ReplayStream, line);
    188     JS::RootedValue attribs(scriptInterface.GetContext());
     188
     189    JSContext* cx = scriptInterface.GetContext();
     190    JSAutoRequest rq(cx);
     191
     192    JS::RootedValue attribs(cx);
    189193    scriptInterface.ParseJSON(line, &attribs);
    190194    StartGame(&attribs, "");
    191195
    192196    return true;
    193197}
  • source/ps/scripting/JSInterface_VFS.cpp

    JS::Value JSI_VFS::BuildDirEntList(Scrip  
    8989    if (!filterStr.empty())
    9090        filter = filterStr.c_str();
    9191 
    9292    int flags = recurse ? vfs::DIR_RECURSIVE : 0;
    9393
     94    JSContext* cx = pCxPrivate->pScriptInterface->GetContext();
     95    JSAutoRequest rq(cx);
     96
    9497    // build array in the callback function
    95     BuildDirEntListState state(pCxPrivate->pScriptInterface->GetContext());
     98    BuildDirEntListState state(cx);
    9699    vfs::ForEachFile(g_VFS, path, BuildDirEntListCB, (uintptr_t)&state, filter, flags);
    97100
    98101    return OBJECT_TO_JSVAL(state.filename_array);
    99102}
    100103
  • source/simulation2/components/CCmpAIManager.cpp

    public:  
    296296        JS::HandleValue position, JS::HandleValue goal, pass_class_t passClass)
    297297    {
    298298        ENSURE(pCxPrivate->pCBData);
    299299        CAIWorker* self = static_cast<CAIWorker*> (pCxPrivate->pCBData);
    300300        JSContext* cx(self->m_ScriptInterface->GetContext());
     301        JSAutoRequest rq(cx);
    301302
    302303        CFixedVector2D pos, goalPos;
    303304        std::vector<CFixedVector2D> waypoints;
    304305        JS::RootedValue retVal(cx);
    305306
    public:  
    325326    static JS::Value GetConnectivityGrid(ScriptInterface::CxPrivate* pCxPrivate, pass_class_t passClass)
    326327    {
    327328        ENSURE(pCxPrivate->pCBData);
    328329        CAIWorker* self = static_cast<CAIWorker*> (pCxPrivate->pCBData);
    329330        JSContext* cx(self->m_ScriptInterface->GetContext());
     331        JSAutoRequest rq(cx);
    330332
    331333        JS::RootedValue retVal(cx);
    332334        self->m_ScriptInterface->ToJSVal<Grid<u16> >(cx, &retVal, self->m_LongPathfinder.GetConnectivityGrid(passClass));
    333335        return retVal;
    334336    }
    public:  
    519521    {
    520522        ENSURE(m_CommandsComputed);
    521523
    522524        m_GameState = gameState;
    523525        JSContext* cx = m_ScriptInterface->GetContext();
     526        JSAutoRequest rq(cx);
    524527
    525528        if (dirtinessInformations.dirty)
    526529        {
    527530            m_PassabilityMap = passabilityMap;
    528531            if (dirtinessInformations.globallyDirty)
    public:  
    768771    void RegisterSerializablePrototype(std::wstring name, JS::HandleValue proto)
    769772    {
    770773        // Require unique prototype and name (for reverse lookup)
    771774        // TODO: this is yucky - see comment in Deserialize()
    772775        ENSURE(proto.isObject() && "A serializable prototype has to be an object!");
    773         JS::RootedObject obj(m_ScriptInterface->GetContext(), &proto.toObject());
     776
     777        JSContext* cx = m_ScriptInterface->GetContext();
     778        JSAutoRequest rq(cx);
     779
     780        JS::RootedObject obj(cx, &proto.toObject());
    774781        if (m_SerializablePrototypes->has(obj) || m_DeserializablePrototypes.find(name) != m_DeserializablePrototypes.end())
    775782        {
    776783            LOGERROR("RegisterSerializablePrototype called with same prototype multiple times: p=%p n='%s'", (void *)obj.get(), utf8_from_wstring(name));
    777784            return;
    778785        }
    779         m_SerializablePrototypes->add(m_ScriptInterface->GetContext(), obj, name);
     786        m_SerializablePrototypes->add(cx, obj, name);
    780787        m_DeserializablePrototypes[name] = JS::Heap<JSObject*>(obj);
    781788    }
    782789
    783790private:
    784791    static void Trace(JSTracer *trc, void *data)
  • source/simulation2/components/CCmpCommandQueue.cpp

    public:  
    8080    }
    8181
    8282    virtual void PushLocalCommand(player_id_t player, JS::HandleValue cmd)
    8383    {
    8484        JSContext* cx = GetSimContext().GetScriptInterface().GetContext();
     85        JSAutoRequest rq(cx);
     86
    8587        m_LocalQueue.emplace_back(SimulationCommand(player, cx, cmd));
    8688    }
    8789
    8890    virtual void PostNetworkCommand(JS::HandleValue cmd1)
    8991    {
  • source/simulation2/serialization/BinarySerializer.cpp

    u32 CBinarySerializerScriptImpl::GetScri  
    436436    // If it was already there, return the tag
    437437    u32 tag;
    438438    if (m_ScriptBackrefs.find(obj, tag))
    439439        return tag;
    440440
    441     m_ScriptBackrefs.add(m_ScriptInterface.GetContext(), obj, m_ScriptBackrefsNext);
     441    JSContext* cx = m_ScriptInterface.GetContext();
     442    JSAutoRequest rq(cx);
     443
     444    m_ScriptBackrefs.add(cx, obj, m_ScriptBackrefsNext);
    442445
    443446    m_ScriptBackrefsNext++;
    444447    // Return a non-tag number so callers know they need to serialize the object
    445448    return 0;
    446449}
  • source/simulation2/serialization/StdDeserializer.cpp

    void CStdDeserializer::ScriptString(cons  
    464464
    465465#if BYTE_ORDER != LITTLE_ENDIAN
    466466#error TODO: probably need to convert JS strings from little-endian
    467467#endif
    468468
    469     out.set(JS_NewUCStringCopyN(m_ScriptInterface.GetContext(), (const char16_t*)str.data(), str.length()));
     469    JSContext* cx = m_ScriptInterface.GetContext();
     470    JSAutoRequest rq(cx);
     471
     472    out.set(JS_NewUCStringCopyN(cx, (const char16_t*)str.data(), str.length()));
    470473    if (!out)
    471474        throw PSERROR_Deserialize_ScriptError("JS_NewUCStringCopyN failed");
    472475}
    473476
    474477void CStdDeserializer::ScriptVal(const char* name, JS::MutableHandleValue out)