mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-06-21 01:04:06 +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:
@@ -78,7 +78,7 @@ bool VisualReplay::ReadCacheFile(const ScriptInterface& scriptInterface, JS::Mut
|
||||
CStr cacheStr((std::istreambuf_iterator<char>(cacheStream)), std::istreambuf_iterator<char>());
|
||||
cacheStream.close();
|
||||
|
||||
ScriptInterface::Request rq(scriptInterface);
|
||||
ScriptRequest rq(scriptInterface);
|
||||
|
||||
JS::RootedValue cachedReplays(rq.cx);
|
||||
if (scriptInterface.ParseJSON(cacheStr, &cachedReplays))
|
||||
@@ -96,7 +96,7 @@ bool VisualReplay::ReadCacheFile(const ScriptInterface& scriptInterface, JS::Mut
|
||||
|
||||
void VisualReplay::StoreCacheFile(const ScriptInterface& scriptInterface, JS::HandleObject replays)
|
||||
{
|
||||
ScriptInterface::Request rq(scriptInterface);
|
||||
ScriptRequest rq(scriptInterface);
|
||||
|
||||
JS::RootedValue replaysRooted(rq.cx, JS::ObjectValue(*replays));
|
||||
std::ofstream cacheStream(OsString(GetTempCacheFilePath()).c_str(), std::ofstream::out | std::ofstream::trunc);
|
||||
@@ -111,7 +111,7 @@ void VisualReplay::StoreCacheFile(const ScriptInterface& scriptInterface, JS::Ha
|
||||
JS::HandleObject VisualReplay::ReloadReplayCache(const ScriptInterface& scriptInterface, bool compareFiles)
|
||||
{
|
||||
TIMER(L"ReloadReplayCache");
|
||||
ScriptInterface::Request rq(scriptInterface);
|
||||
ScriptRequest rq(scriptInterface);
|
||||
|
||||
// Maps the filename onto the index and size
|
||||
typedef std::map<OsPath, std::pair<u32, off_t>> replayCacheMap;
|
||||
@@ -229,7 +229,7 @@ JS::Value VisualReplay::GetReplays(const ScriptInterface& scriptInterface, bool
|
||||
{
|
||||
TIMER(L"GetReplays");
|
||||
|
||||
ScriptInterface::Request rq(scriptInterface);
|
||||
ScriptRequest rq(scriptInterface);
|
||||
JS::RootedObject replays(rq.cx, ReloadReplayCache(scriptInterface, compareFiles));
|
||||
// Only take entries with data
|
||||
JS::RootedValue replaysWithoutNullEntries(rq.cx);
|
||||
@@ -366,7 +366,7 @@ JS::Value VisualReplay::LoadReplayData(const ScriptInterface& scriptInterface, c
|
||||
// Parse header / first line
|
||||
CStr header;
|
||||
std::getline(*replayStream, header);
|
||||
ScriptInterface::Request rq(scriptInterface);
|
||||
ScriptRequest rq(scriptInterface);
|
||||
JS::RootedValue attribs(rq.cx);
|
||||
if (!scriptInterface.ParseJSON(header, &attribs))
|
||||
{
|
||||
@@ -426,7 +426,7 @@ bool VisualReplay::DeleteReplay(const OsPath& replayDirectory)
|
||||
JS::Value VisualReplay::GetReplayAttributes(ScriptInterface::CmptPrivate* pCmptPrivate, const OsPath& directoryName)
|
||||
{
|
||||
// Create empty JS object
|
||||
ScriptInterface::Request rq(pCmptPrivate);
|
||||
ScriptRequest rq(pCmptPrivate->pScriptInterface);
|
||||
JS::RootedValue attribs(rq.cx);
|
||||
ScriptInterface::CreateObject(rq, &attribs);
|
||||
|
||||
@@ -450,7 +450,7 @@ JS::Value VisualReplay::GetReplayAttributes(ScriptInterface::CmptPrivate* pCmptP
|
||||
void VisualReplay::AddReplayToCache(const ScriptInterface& scriptInterface, const CStrW& directoryName)
|
||||
{
|
||||
TIMER(L"AddReplayToCache");
|
||||
ScriptInterface::Request rq(scriptInterface);
|
||||
ScriptRequest rq(scriptInterface);
|
||||
|
||||
JS::RootedValue replayData(rq.cx, LoadReplayData(scriptInterface, OsPath(directoryName)));
|
||||
if (replayData.isNull())
|
||||
@@ -485,7 +485,7 @@ JS::Value VisualReplay::GetReplayMetadata(ScriptInterface::CmptPrivate* pCmptPri
|
||||
if (!HasReplayMetadata(directoryName))
|
||||
return JS::NullValue();
|
||||
|
||||
ScriptInterface::Request rq(pCmptPrivate);
|
||||
ScriptRequest rq(pCmptPrivate->pScriptInterface);
|
||||
JS::RootedValue metadata(rq.cx);
|
||||
|
||||
std::ifstream* stream = new std::ifstream(OsString(GetDirectoryPath() / directoryName / L"metadata.json").c_str());
|
||||
|
||||
Reference in New Issue
Block a user