Ticket #5376: remove_workaround_while_leaving_serialization_unfixed.patch

File remove_workaround_while_leaving_serialization_unfixed.patch, 4.6 KB (added by elexis, 5 years ago)
  • binaries/data/mods/public/globalscripts/vector.js

     
    429429{
    430430    return new Vector3D(v.x / f, v.y / f, v.z / f);
    431431};
    432 
    433 
    434 // make the prototypes easily accessible to C++
    435 const Vector2Dprototype = Vector2D.prototype;
    436 const Vector3Dprototype = Vector3D.prototype;
  • source/scriptinterface/ScriptInterface.cpp

     
    6767    JSCompartment* m_comp;
    6868    boost::rand48* m_rng;
    6969    JS::PersistentRootedObject m_nativeScope; // native function scope object
    70 
    71     typedef std::map<ScriptInterface::CACHED_VAL, JS::PersistentRootedValue> ScriptValCache;
    72     ScriptValCache m_ScriptValCache;
    7370};
    7471
    7572namespace
     
    450447    return pCxPrivate;
    451448}
    452449
    453 JS::Value ScriptInterface::GetCachedValue(CACHED_VAL valueIdentifier) const
    454 {
    455     std::map<ScriptInterface::CACHED_VAL, JS::PersistentRootedValue>::const_iterator it = m->m_ScriptValCache.find(valueIdentifier);
    456     ENSURE(it != m->m_ScriptValCache.end());
    457     return it->second.get();
    458 }
    459 
    460 
    461450bool ScriptInterface::LoadGlobalScripts()
    462451{
    463452    // Ignore this failure in tests
     
    473462            LOGERROR("LoadGlobalScripts: Failed to load script %s", path.string8());
    474463            return false;
    475464        }
    476 
    477     JSAutoRequest rq(m->m_cx);
    478     JS::RootedValue proto(m->m_cx);
    479     JS::RootedObject global(m->m_cx, m->m_glob);
    480     if (JS_GetProperty(m->m_cx, global, "Vector2Dprototype", &proto))
    481         m->m_ScriptValCache[CACHE_VECTOR2DPROTO].init(GetJSRuntime(), proto);
    482     if (JS_GetProperty(m->m_cx, global, "Vector3Dprototype", &proto))
    483         m->m_ScriptValCache[CACHE_VECTOR3DPROTO].init(GetJSRuntime(), proto);
    484465    return true;
    485466}
    486467
  • source/scriptinterface/ScriptInterface.h

     
    115115     */
    116116    bool LoadGlobalScripts();
    117117
    118     enum CACHED_VAL { CACHE_VECTOR2DPROTO, CACHE_VECTOR3DPROTO };
    119     JS::Value GetCachedValue(CACHED_VAL valueIdentifier) const;
    120 
    121118    /**
    122119     * Replace the default JS random number geenrator with a seeded, network-sync'd one.
    123120     */
  • source/simulation2/scripting/EngineScriptConversions.cpp

     
    177177
    178178template<> void ScriptInterface::ToJSVal<CFixedVector3D>(JSContext* cx, JS::MutableHandleValue ret, const CFixedVector3D& val)
    179179{
     180    debug_printf("ToJSVal<CFixedVector3D>\n");
     181
    180182    JSAutoRequest rq(cx);
    181183
    182     // apply the Vector3D prototype to the return value;
    183184    ScriptInterface::CxPrivate* pCxPrivate = ScriptInterface::GetScriptInterfaceAndCBData(cx);
    184     JS::RootedObject proto(cx, &pCxPrivate->pScriptInterface->GetCachedValue(ScriptInterface::CACHE_VECTOR3DPROTO).toObject());
     185
     186    JS::RootedObject global(cx, &pCxPrivate->pScriptInterface->GetGlobalObject().toObject());
     187
     188    JS::RootedValue valueVector3D(cx);
     189    JS_GetProperty(cx, global, "Vector3D", &valueVector3D);
     190
     191    JS::RootedObject objectVector3D(cx, &valueVector3D.toObject());
     192
     193    JS::RootedObject proto(cx);
     194    JS_GetPrototype(cx, objectVector3D, &proto);
     195
    185196    JS::RootedObject obj(cx, JS_NewObjectWithGivenProto(cx, nullptr, proto));
    186197
    187198    if (!obj)
     
    224235
    225236template<> void ScriptInterface::ToJSVal<CFixedVector2D>(JSContext* cx, JS::MutableHandleValue ret, const CFixedVector2D& val)
    226237{
     238    debug_printf("ToJSVal<CFixedVector2D>\n");
     239
    227240    JSAutoRequest rq(cx);
    228241
    229     // apply the Vector2D prototype to the return value
    230242    ScriptInterface::CxPrivate* pCxPrivate = ScriptInterface::GetScriptInterfaceAndCBData(cx);
    231     JS::RootedObject proto(cx, &pCxPrivate->pScriptInterface->GetCachedValue(ScriptInterface::CACHE_VECTOR2DPROTO).toObject());
     243
     244    JS::RootedObject global(cx, &pCxPrivate->pScriptInterface->GetGlobalObject().toObject());
     245
     246    JS::RootedValue valueVector2D(cx);
     247    JS_GetProperty(cx, global, "Vector2D", &valueVector2D);
     248
     249    JS::RootedObject objectVector2D(cx, &valueVector2D.toObject());
     250
     251    JS::RootedObject proto(cx);
     252    JS_GetPrototype(cx, objectVector2D, &proto);
     253
    232254    JS::RootedObject obj(cx, JS_NewObjectWithGivenProto(cx, nullptr, proto));
     255
    233256    if (!obj)
    234257    {
    235258        ret.setUndefined();