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
+5 -5
View File
@@ -48,7 +48,7 @@ void JSI_Game::StartGame(ScriptInterface::CmptPrivate* pCmptPrivate, JS::HandleV
// Convert from GUI script context to sim script context
CSimulation2* sim = g_Game->GetSimulation2();
ScriptInterface::Request rqSim(sim->GetScriptInterface());
ScriptRequest rqSim(sim->GetScriptInterface());
JS::RootedValue gameAttribs(rqSim.cx,
sim->GetScriptInterface().CloneValueFromOtherCompartment(*(pCmptPrivate->pScriptInterface), attribs));
@@ -100,8 +100,8 @@ bool JSI_Game::IsPaused(ScriptInterface::CmptPrivate* pCmptPrivate)
{
if (!g_Game)
{
ScriptInterface::Request rq(pCmptPrivate);
JS_ReportError(rq.cx, "Game is not started");
ScriptRequest rq(pCmptPrivate->pScriptInterface);
ScriptException::Raise(rq, "Game is not started");
return false;
}
@@ -112,8 +112,8 @@ void JSI_Game::SetPaused(ScriptInterface::CmptPrivate* pCmptPrivate, bool pause,
{
if (!g_Game)
{
ScriptInterface::Request rq(pCmptPrivate);
JS_ReportError(rq.cx, "Game is not started");
ScriptRequest rq(pCmptPrivate->pScriptInterface);
ScriptException::Raise(rq, "Game is not started");
return;
}