1
0
forked from 0ad/0ad

SpiderMonkey 38 upgrade: 33/35

Remove a workaround. Note that this removal is incomplete. Based on
patch by leper.

This was SVN commit r18687.
This commit is contained in:
Nicolas Auvray 2016-09-02 16:53:22 +00:00
parent 9b794593db
commit 0cc23c1964
9 changed files with 36 additions and 43 deletions

View File

@ -83,7 +83,7 @@ void CMapReader::LoadMap(const VfsPath& pathname, JSRuntime* rt, JS::HandleValu
m_PlayerID = playerID_;
m_SkipEntities = skipEntities;
m_StartingCameraTarget = INVALID_ENTITY;
m_ScriptSettings.set(rt, settings);
m_ScriptSettings.init(rt, settings);
filename_xml = pathname.ChangeExtension(L".xml");
@ -158,7 +158,7 @@ void CMapReader::LoadRandomMap(const CStrW& scriptFile, JSRuntime* rt, JS::Handl
m_ScriptFile = scriptFile;
pSimulation2 = pSimulation2_;
pSimContext = pSimulation2 ? &pSimulation2->GetSimContext() : NULL;
m_ScriptSettings.set(rt, settings);
m_ScriptSettings.init(rt, settings);
pTerrain = pTerrain_;
pLightEnv = pLightEnv_;
pGameView = pGameView_;
@ -1244,7 +1244,7 @@ int CMapReader::LoadRMSettings()
{
// copy random map settings over to sim
ENSURE(pSimulation2);
pSimulation2->SetMapSettings(m_ScriptSettings.get());
pSimulation2->SetMapSettings(m_ScriptSettings);
return 0;
}
@ -1265,7 +1265,7 @@ int CMapReader::GenerateMap()
scriptPath = L"maps/random/"+m_ScriptFile;
// Stringify settings to pass across threads
std::string scriptSettings = pSimulation2->GetScriptInterface().StringifyJSON(&m_ScriptSettings.get());
std::string scriptSettings = pSimulation2->GetScriptInterface().StringifyJSON(&m_ScriptSettings);
// Try to generate map
m_MapGen->GenerateMap(scriptPath, scriptSettings);
@ -1294,7 +1294,7 @@ int CMapReader::GenerateMap()
}
else
{
m_MapData.set(cx, data);
m_MapData.init(cx, data);
}
}
else
@ -1325,16 +1325,16 @@ int CMapReader::ParseTerrain()
throw PSERROR_Game_World_MapLoadFailed("Error parsing terrain data.\nCheck application log for details"); }
u32 size;
GET_TERRAIN_PROPERTY(m_MapData.get(), size, size)
GET_TERRAIN_PROPERTY(m_MapData, size, size)
m_PatchesPerSide = size / PATCH_SIZE;
// flat heightmap of u16 data
GET_TERRAIN_PROPERTY(m_MapData.get(), height, m_Heightmap)
GET_TERRAIN_PROPERTY(m_MapData, height, m_Heightmap)
// load textures
std::vector<std::string> textureNames;
GET_TERRAIN_PROPERTY(m_MapData.get(), textureNames, textureNames)
GET_TERRAIN_PROPERTY(m_MapData, textureNames, textureNames)
num_terrain_tex = textureNames.size();
while (cur_terrain_tex < num_terrain_tex)
@ -1350,7 +1350,7 @@ int CMapReader::ParseTerrain()
m_Tiles.resize(SQR(size));
JS::RootedValue tileData(cx);
GET_TERRAIN_PROPERTY(m_MapData.get(), tileData, &tileData)
GET_TERRAIN_PROPERTY(m_MapData, tileData, &tileData)
// parse tile data object into flat arrays
std::vector<u16> tileIndex;
@ -1396,7 +1396,7 @@ int CMapReader::ParseEntities()
// parse entities from map data
std::vector<Entity> entities;
if (!pSimulation2->GetScriptInterface().GetProperty(m_MapData.get(), "entities", entities))
if (!pSimulation2->GetScriptInterface().GetProperty(m_MapData, "entities", entities))
LOGWARNING("CMapReader::ParseEntities() failed to get 'entities' property");
CSimulation2& sim = *pSimulation2;
@ -1463,7 +1463,7 @@ int CMapReader::ParseEnvironment()
LOGWARNING("CMapReader::ParseEnvironment() failed to get '%s' property", #prop);
JS::RootedValue envObj(cx);
GET_ENVIRONMENT_PROPERTY(m_MapData.get(), Environment, &envObj)
GET_ENVIRONMENT_PROPERTY(m_MapData, Environment, &envObj)
if (envObj.isUndefined())
{
@ -1568,7 +1568,7 @@ int CMapReader::ParseCamera()
LOGWARNING("CMapReader::ParseCamera() failed to get '%s' property", #prop);
JS::RootedValue cameraObj(cx);
GET_CAMERA_PROPERTY(m_MapData.get(), Camera, &cameraObj)
GET_CAMERA_PROPERTY(m_MapData, Camera, &cameraObj)
if (!cameraObj.isUndefined())
{ // If camera property exists, read values

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2013 Wildfire Games.
/* Copyright (C) 2016 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -123,8 +123,8 @@ private:
// random map data
CStrW m_ScriptFile;
DefPersistentRooted<JS::Value> m_ScriptSettings;
DefPersistentRooted<JS::Value> m_MapData;
JS::PersistentRootedValue m_ScriptSettings;
JS::PersistentRootedValue m_MapData;
CMapGenerator* m_MapGen;

View File

@ -504,9 +504,9 @@ JSObject* IGUIObject::GetJSObject()
// Cache the object when somebody first asks for it, because otherwise
// we end up doing far too much object allocation. TODO: Would be nice to
// not have these objects hang around forever using up memory, though.
if (m_JSObject.uninitialized())
if (!m_JSObject.initialized())
{
m_JSObject.set(cx, m_pGUI->GetScriptInterface()->CreateCustomObject("GUIObject"));
m_JSObject.init(cx, m_pGUI->GetScriptInterface()->CreateCustomObject("GUIObject"));
JS_SetPrivate(m_JSObject.get(), this);
}
return m_JSObject.get();

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2015 Wildfire Games.
/* Copyright (C) 2016 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -542,10 +542,10 @@ private:
CGUI *m_pGUI;
// Internal storage for registered script handlers.
std::map<CStr, JS::Heap<JSObject*> > m_ScriptHandlers;
std::map<CStr, JS::Heap<JSObject*> > m_ScriptHandlers;
// Cached JSObject representing this GUI object
DefPersistentRooted<JSObject*> m_JSObject;
JS::PersistentRootedObject m_JSObject;
};

View File

@ -372,7 +372,7 @@ void CNetServerWorker::Run()
// To avoid the need for JS_SetContextThread, we create and use and destroy
// the script interface entirely within this network thread
m_ScriptInterface = new ScriptInterface("Engine", "Net server", ScriptInterface::CreateRuntime(g_ScriptRuntime));
m_GameAttributes.set(m_ScriptInterface->GetJSRuntime(), JS::UndefinedValue());
m_GameAttributes.init(m_ScriptInterface->GetJSRuntime(), JS::UndefinedValue());
while (true)
{
@ -388,7 +388,6 @@ void CNetServerWorker::Run()
}
// Clear roots before deleting their context
m_GameAttributes.clear();
m_SavedCommands.clear();
SAFE_DELETE(m_ScriptInterface);
@ -682,7 +681,7 @@ void CNetServerWorker::OnUserJoin(CNetServerSession* session)
m_HostGUID = session->GetGUID();
CGameSetupMessage gameSetupMessage(GetScriptInterface());
gameSetupMessage.m_Data = m_GameAttributes.get();
gameSetupMessage.m_Data = m_GameAttributes;
session->SendMessage(&gameSetupMessage);
CPlayerAssignmentMessage assignMessage;
@ -1036,7 +1035,7 @@ bool CNetServerWorker::OnInGame(void* context, CFsmEvent* event)
JSContext* cx = scriptInterface.GetContext();
JSAutoRequest rq(cx);
JS::RootedValue settings(cx);
scriptInterface.GetProperty(server.m_GameAttributes.get(), "settings", &settings);
scriptInterface.GetProperty(server.m_GameAttributes, "settings", &settings);
if (scriptInterface.HasProperty(settings, "CheatsEnabled"))
scriptInterface.GetProperty(settings, "CheatsEnabled", cheatsEnabled);
@ -1341,7 +1340,7 @@ void CNetServerWorker::StartGame()
m_State = SERVER_STATE_LOADING;
// Send the final setup state to all clients
UpdateGameAttributes(&m_GameAttributes.get());
UpdateGameAttributes(&m_GameAttributes);
// Remove players and observers that are not present when the game starts
for (PlayerAssignmentMap::iterator it = m_PlayerAssignments.begin(); it != m_PlayerAssignments.end();)
@ -1358,13 +1357,13 @@ void CNetServerWorker::StartGame()
void CNetServerWorker::UpdateGameAttributes(JS::MutableHandleValue attrs)
{
m_GameAttributes.set(m_ScriptInterface->GetJSRuntime(), attrs);
m_GameAttributes = attrs;
if (!m_Host)
return;
CGameSetupMessage gameSetupMessage(GetScriptInterface());
gameSetupMessage.m_Data = m_GameAttributes.get();
gameSetupMessage.m_Data = m_GameAttributes;
Broadcast(&gameSetupMessage);
}

View File

@ -23,7 +23,7 @@
#include "lib/config2.h"
#include "ps/ThreadUtil.h"
#include "scriptinterface/ScriptVal.h"
#include "scriptinterface/ScriptTypes.h"
#include <vector>
@ -280,7 +280,7 @@ private:
/**
* Stores the most current game attributes.
*/
DefPersistentRooted<JS::Value> m_GameAttributes;
JS::PersistentRootedValue m_GameAttributes;
int m_AutostartPlayers;

View File

@ -68,11 +68,7 @@ struct ScriptInterface_impl
boost::rand48* m_rng;
JS::PersistentRootedObject m_nativeScope; // native function scope object
// TODO: we need DefPersistentRooted to work around a problem with JS::PersistentRooted<T>
// that is already solved in newer versions of SpiderMonkey (related to std::pair and
// and the copy constructor of PersistentRooted<T> taking a non-const reference).
// Switch this to PersistentRooted<T> when upgrading to a newer SpiderMonkey version than v31.
typedef std::map<ScriptInterface::CACHED_VAL, DefPersistentRooted<JS::Value> > ScriptValCache;
typedef std::map<ScriptInterface::CACHED_VAL, JS::PersistentRootedValue> ScriptValCache;
ScriptValCache m_ScriptValCache;
};
@ -440,7 +436,7 @@ ScriptInterface::CxPrivate* ScriptInterface::GetScriptInterfaceAndCBData(JSConte
JS::Value ScriptInterface::GetCachedValue(CACHED_VAL valueIdentifier)
{
std::map<ScriptInterface::CACHED_VAL, DefPersistentRooted<JS::Value>>::iterator it = m->m_ScriptValCache.find(valueIdentifier);
std::map<ScriptInterface::CACHED_VAL, JS::PersistentRootedValue>::iterator it = m->m_ScriptValCache.find(valueIdentifier);
ENSURE(it != m->m_ScriptValCache.end());
return it->second.get();
}
@ -466,9 +462,9 @@ bool ScriptInterface::LoadGlobalScripts()
JS::RootedValue proto(m->m_cx);
JS::RootedObject global(m->m_cx, m->m_glob);
if (JS_GetProperty(m->m_cx, global, "Vector2Dprototype", &proto))
m->m_ScriptValCache[CACHE_VECTOR2DPROTO] = DefPersistentRooted<JS::Value>(GetJSRuntime(), proto);
m->m_ScriptValCache[CACHE_VECTOR2DPROTO].init(GetJSRuntime(), proto);
if (JS_GetProperty(m->m_cx, global, "Vector3Dprototype", &proto))
m->m_ScriptValCache[CACHE_VECTOR3DPROTO] = DefPersistentRooted<JS::Value>(GetJSRuntime(), proto);
m->m_ScriptValCache[CACHE_VECTOR3DPROTO].init(GetJSRuntime(), proto);
return true;
}
@ -548,13 +544,11 @@ void ScriptInterface::DefineCustomObjectType(JSClass *clasp, JSNative constructo
if (obj == NULL)
throw PSERROR_Scripting_DefineType_CreationFailed();
CustomType type;
CustomType& type = m_CustomObjectTypes[typeName];
type.m_Prototype = DefPersistentRooted<JSObject*>(m->m_cx, obj);
type.m_Prototype.init(m->m_cx, obj);
type.m_Class = clasp;
type.m_Constructor = constructor;
m_CustomObjectTypes[typeName] = std::move(type);
}
JSObject* ScriptInterface::CreateCustomObject(const std::string& typeName) const

View File

@ -24,7 +24,6 @@
#include "maths/Fixed.h"
#include "ScriptTypes.h"
#include "ScriptVal.h"
#include "ps/Errors.h"
ERROR_GROUP(Scripting);
@ -414,7 +413,7 @@ private:
m_Constructor = std::move(other.m_Constructor);
}
DefPersistentRooted<JSObject*> m_Prototype;
JS::PersistentRootedObject m_Prototype;
JSClass* m_Class;
JSNative m_Constructor;
};

View File

@ -21,6 +21,7 @@
#include "Entity.h"
#include "Components.h"
#include "scriptinterface/ScriptInterface.h"
#include "scriptinterface/ScriptVal.h"
#include "simulation2/helpers/Player.h"
#include "ps/Filesystem.h"