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:
wraitii
2020-11-15 18:29:17 +00:00
parent 88bc973530
commit 25490bfec3
79 changed files with 810 additions and 667 deletions
@@ -51,7 +51,7 @@ public:
virtual void Serialize(ISerializer& serialize)
{
ScriptInterface::Request rq(GetSimContext().GetScriptInterface());
ScriptRequest rq(GetSimContext().GetScriptInterface());
serialize.NumberU32_Unbounded("num commands", (u32)m_LocalQueue.size());
for (size_t i = 0; i < m_LocalQueue.size(); ++i)
@@ -63,7 +63,7 @@ public:
virtual void Deserialize(const CParamNode& UNUSED(paramNode), IDeserializer& deserialize)
{
ScriptInterface::Request rq(GetSimContext().GetScriptInterface());
ScriptRequest rq(GetSimContext().GetScriptInterface());
u32 numCmds;
deserialize.NumberU32_Unbounded("num commands", numCmds);
@@ -79,13 +79,13 @@ public:
virtual void PushLocalCommand(player_id_t player, JS::HandleValue cmd)
{
ScriptInterface::Request rq(GetSimContext().GetScriptInterface());
ScriptRequest rq(GetSimContext().GetScriptInterface());
m_LocalQueue.emplace_back(SimulationCommand(player, rq.cx, cmd));
}
virtual void PostNetworkCommand(JS::HandleValue cmd1)
{
ScriptInterface::Request rq(GetSimContext().GetScriptInterface());
ScriptRequest rq(GetSimContext().GetScriptInterface());
// TODO: This is a workaround because we need to pass a MutableHandle to StringifyJSON.
JS::RootedValue cmd(rq.cx, cmd1.get());
@@ -101,7 +101,7 @@ public:
virtual void FlushTurn(const std::vector<SimulationCommand>& commands)
{
const ScriptInterface& scriptInterface = GetSimContext().GetScriptInterface();
ScriptInterface::Request rq(scriptInterface);
ScriptRequest rq(scriptInterface);
JS::RootedValue global(rq.cx, rq.globalValue());
std::vector<SimulationCommand> localCommands;