mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-09-21 20:06:40 +00:00
Improve JS Exception handling.
- Check for pending exceptions after function calls and script executions. - Call LOGERROR instead of JS_ReportError when there is a conversion error in FromJSVal, since that can only be called from C++ (where JS errors don't really make sense). Instead, C++ callers of FromJSVal should handle the failure and, themselves, either report an error or simply do something else. - Wrap JS_ReportError since that makes updating it later easier. This isn't a systematical fix since ToJSVal also ought return a boolean for failures, and we probably should trigger errors instead of warnings on 'implicit' conversions, rather a preparation diff. Part of the SM52 migration, stage: SM45 compatible (actually SM52 incompatible, too). Based on a patch by: Itms Comments by: Vladislavbelov, Stan` Refs #742, #4893 Differential Revision: https://code.wildfiregames.com/D3093 This was SVN commit r24187.
This commit is contained in:
@@ -170,7 +170,7 @@ public:
|
||||
std::vector<SimulationCommand> newCommands;
|
||||
newCommands.reserve(commands.size());
|
||||
|
||||
ScriptInterface::Request rqNew(newScript);
|
||||
ScriptRequest rqNew(newScript);
|
||||
for (const SimulationCommand& command : commands)
|
||||
{
|
||||
JS::RootedValue tmpCommand(rqNew.cx, newScript.CloneValueFromOtherCompartment(oldScript, command.data));
|
||||
@@ -421,7 +421,7 @@ void CSimulation2Impl::Update(int turnLength, const std::vector<SimulationComman
|
||||
|
||||
// Load the trigger scripts after we have loaded the simulation.
|
||||
{
|
||||
ScriptInterface::Request rq2(m_SecondaryComponentManager->GetScriptInterface());
|
||||
ScriptRequest rq2(m_SecondaryComponentManager->GetScriptInterface());
|
||||
JS::RootedValue mapSettingsCloned(rq2.cx,
|
||||
m_SecondaryComponentManager->GetScriptInterface().CloneValueFromOtherCompartment(
|
||||
scriptInterface, m_MapSettings));
|
||||
@@ -733,14 +733,14 @@ ScriptInterface& CSimulation2::GetScriptInterface() const
|
||||
|
||||
void CSimulation2::PreInitGame()
|
||||
{
|
||||
ScriptInterface::Request rq(GetScriptInterface());
|
||||
ScriptRequest rq(GetScriptInterface());
|
||||
JS::RootedValue global(rq.cx, rq.globalValue());
|
||||
GetScriptInterface().CallFunctionVoid(global, "PreInitGame");
|
||||
}
|
||||
|
||||
void CSimulation2::InitGame()
|
||||
{
|
||||
ScriptInterface::Request rq(GetScriptInterface());
|
||||
ScriptRequest rq(GetScriptInterface());
|
||||
JS::RootedValue global(rq.cx, rq.globalValue());
|
||||
|
||||
JS::RootedValue settings(rq.cx);
|
||||
@@ -839,14 +839,14 @@ void CSimulation2::GetMapSettings(JS::MutableHandleValue ret)
|
||||
|
||||
void CSimulation2::LoadPlayerSettings(bool newPlayers)
|
||||
{
|
||||
ScriptInterface::Request rq(GetScriptInterface());
|
||||
ScriptRequest rq(GetScriptInterface());
|
||||
JS::RootedValue global(rq.cx, rq.globalValue());
|
||||
GetScriptInterface().CallFunctionVoid(global, "LoadPlayerSettings", m->m_MapSettings, newPlayers);
|
||||
}
|
||||
|
||||
void CSimulation2::LoadMapSettings()
|
||||
{
|
||||
ScriptInterface::Request rq(GetScriptInterface());
|
||||
ScriptRequest rq(GetScriptInterface());
|
||||
|
||||
JS::RootedValue global(rq.cx, rq.globalValue());
|
||||
|
||||
@@ -982,7 +982,7 @@ std::string CSimulation2::GetMapSizes()
|
||||
std::string CSimulation2::GetAIData()
|
||||
{
|
||||
const ScriptInterface& scriptInterface = GetScriptInterface();
|
||||
ScriptInterface::Request rq(scriptInterface);
|
||||
ScriptRequest rq(scriptInterface);
|
||||
JS::RootedValue aiData(rq.cx, ICmpAIManager::GetAIs(scriptInterface));
|
||||
|
||||
// Build single JSON string with array of AI data
|
||||
|
||||
Reference in New Issue
Block a user