0ad/source/scriptinterface/ScriptEngine.h
Itms 64b477625d Upgrade SpiderMonkey to version 45.0.2, refs #4893.
- Various build changes, in particular NSPR is not needed on Unix
anymore
- Add js/Initialization.h to source/scriptinterface/ScriptEngine.h
- Use nullptr instead of JS::NullPtr(), see
https://bugzilla.mozilla.org/show_bug.cgi?id=1164602
- Remove `JS::RuntimeOptionsRef.varObjFix`, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1171177
- Remove uses of `AutoIdArray`, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1191529
- `JS_InternUCStringN` has been renamed, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1178581
- `JS::Evaluate` now takes scope chains explicitly, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1097987
- Array functions (such as `JS_IsArrayObject`) are fallible and output
to params, see https://bugzilla.mozilla.org/show_bug.cgi?id=f3d35d8
- Remove `JSCLASS_CACHED_PROTO_WIDTH` workaround in our code, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1236373
- Remove compile'n go (`setCompileAndGo`) and replace it by
`setIsRunOnce` which will become the default in the future, see
https://bugzilla.mozilla.org/show_bug.cgi?id=679939
- Mark shared memory in direct access operations
(`JS_GetUint16ArrayData` and `JS_GetUint8ArrayData`), see
https://bugzilla.mozilla.org/show_bug.cgi?id=1176214
- Use new `JS::ObjectOpResult`, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1113369

Thanks to wraitii, elexis, Krinkle and historic_bruno for contributions
and comments, and to gentz, madpilot, s0600204 and Stan for testing and
indirect contributions.

Differential Revision: https://code.wildfiregames.com/D1510
This was SVN commit r22627.
2019-08-07 22:37:43 +00:00

56 lines
1.8 KiB
C++

/* Copyright (C) 2019 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* 0 A.D. is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef INCLUDED_SCRIPTENGINE
#define INCLUDED_SCRIPTENGINE
#include "ScriptTypes.h"
#include "ps/Singleton.h"
#include "js/Initialization.h"
/**
* A class using the RAII (Resource Acquisition Is Initialization) idiom to manage initialization
* and shutdown of the SpiderMonkey script engine. It also keeps a count of active script runtimes
* in order to validate the following constraints:
* 1. JS_Init must be called before any ScriptRuntimes are initialized
* 2. JS_Shutdown must be called after all ScriptRuntimes have been destroyed
*/
class ScriptEngine : public Singleton<ScriptEngine>
{
public:
ScriptEngine()
{
ENSURE(m_Runtimes.empty() && "JS_Init must be called before any runtimes are created!");
JS_Init();
}
~ScriptEngine()
{
ENSURE(m_Runtimes.empty() && "All runtimes must be destroyed before calling JS_ShutDown!");
JS_ShutDown();
}
void RegisterRuntime(const JSRuntime* rt) { m_Runtimes.push_back(rt); }
void UnRegisterRuntime(const JSRuntime* rt) { m_Runtimes.remove(rt); }
private:
std::list<const JSRuntime*> m_Runtimes;
};
#endif // INCLUDED_SCRIPTENGINE