Ticket #5376: remove_workaround_while_leaving_serialization_unfixed.patch
File remove_workaround_while_leaving_serialization_unfixed.patch, 4.6 KB (added by , 5 years ago) |
---|
-
binaries/data/mods/public/globalscripts/vector.js
429 429 { 430 430 return new Vector3D(v.x / f, v.y / f, v.z / f); 431 431 }; 432 433 434 // make the prototypes easily accessible to C++435 const Vector2Dprototype = Vector2D.prototype;436 const Vector3Dprototype = Vector3D.prototype; -
source/scriptinterface/ScriptInterface.cpp
67 67 JSCompartment* m_comp; 68 68 boost::rand48* m_rng; 69 69 JS::PersistentRootedObject m_nativeScope; // native function scope object 70 71 typedef std::map<ScriptInterface::CACHED_VAL, JS::PersistentRootedValue> ScriptValCache;72 ScriptValCache m_ScriptValCache;73 70 }; 74 71 75 72 namespace … … 450 447 return pCxPrivate; 451 448 } 452 449 453 JS::Value ScriptInterface::GetCachedValue(CACHED_VAL valueIdentifier) const454 {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 461 450 bool ScriptInterface::LoadGlobalScripts() 462 451 { 463 452 // Ignore this failure in tests … … 473 462 LOGERROR("LoadGlobalScripts: Failed to load script %s", path.string8()); 474 463 return false; 475 464 } 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);484 465 return true; 485 466 } 486 467 -
source/scriptinterface/ScriptInterface.h
115 115 */ 116 116 bool LoadGlobalScripts(); 117 117 118 enum CACHED_VAL { CACHE_VECTOR2DPROTO, CACHE_VECTOR3DPROTO };119 JS::Value GetCachedValue(CACHED_VAL valueIdentifier) const;120 121 118 /** 122 119 * Replace the default JS random number geenrator with a seeded, network-sync'd one. 123 120 */ -
source/simulation2/scripting/EngineScriptConversions.cpp
177 177 178 178 template<> void ScriptInterface::ToJSVal<CFixedVector3D>(JSContext* cx, JS::MutableHandleValue ret, const CFixedVector3D& val) 179 179 { 180 debug_printf("ToJSVal<CFixedVector3D>\n"); 181 180 182 JSAutoRequest rq(cx); 181 183 182 // apply the Vector3D prototype to the return value;183 184 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 185 196 JS::RootedObject obj(cx, JS_NewObjectWithGivenProto(cx, nullptr, proto)); 186 197 187 198 if (!obj) … … 224 235 225 236 template<> void ScriptInterface::ToJSVal<CFixedVector2D>(JSContext* cx, JS::MutableHandleValue ret, const CFixedVector2D& val) 226 237 { 238 debug_printf("ToJSVal<CFixedVector2D>\n"); 239 227 240 JSAutoRequest rq(cx); 228 241 229 // apply the Vector2D prototype to the return value230 242 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 232 254 JS::RootedObject obj(cx, JS_NewObjectWithGivenProto(cx, nullptr, proto)); 255 233 256 if (!obj) 234 257 { 235 258 ret.setUndefined();