1
0
forked from mirrors/0ad

CMapGeneratorWorker thread safety issue. Fixes #783.

VFS access moved to main thread, where random map scripts are preloaded
and stored prior to use by the worker thread.
Adds LoadGlobalScript to ScriptInterface, for evaluating script content
in the global scope.

This was SVN commit r9261.
This commit is contained in:
historic_bruno
2011-04-15 05:23:51 +00:00
parent 225346ffc9
commit 481f570a0e
4 changed files with 102 additions and 29 deletions
@@ -790,6 +790,22 @@ bool ScriptInterface::LoadScript(const VfsPath& filename, const std::wstring& co
return ok ? true : false;
}
bool ScriptInterface::LoadGlobalScript(const VfsPath& filename, const std::wstring& code)
{
// Compile the code in strict mode, to encourage better coding practices and
// to possibly help SpiderMonkey with optimisations
std::wstring codeStrict = L"\"use strict\";\n" + code;
utf16string codeUtf16(codeStrict.begin(), codeStrict.end());
uintN lineNo = 0; // put the automatic 'use strict' on line 0, so the real code starts at line 1
jsval rval;
JSBool ok = JS_EvaluateUCScript(m->m_cx, m->m_glob,
reinterpret_cast<const jschar*> (codeUtf16.c_str()), (uintN)(codeUtf16.length()),
utf8_from_wstring(filename.string()).c_str(), lineNo, &rval);
return ok ? true : false;
}
bool ScriptInterface::LoadGlobalScriptFile(const VfsPath& path)
{
debug_assert(ThreadUtil::IsMainThread()); // VFS isn't thread-safe