Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
|
Spidermonkey maintains some 'local' state via the JSContext* object. More...
#include <ScriptRequest.h>
Public Member Functions | |
ScriptRequest (const ScriptInterface &scriptInterface) | |
NB: the definitions are in scriptinterface.cpp, because these access members of the PImpled implementation of ScriptInterface, and that seemed more convenient. More... | |
ScriptRequest (const ScriptInterface *scriptInterface) | |
ScriptRequest (std::shared_ptr< ScriptInterface > scriptInterface) | |
~ScriptRequest () | |
ScriptRequest (JSContext *cx) | |
Create a script request from a JSContext. More... | |
const ScriptInterface & | GetScriptInterface () const |
Return the scriptInterface active when creating this ScriptRequest. More... | |
JS::Value | globalValue () const |
Public Attributes | |
JSContext * | cx |
JS::HandleObject | glob |
JS::HandleObject | nativeScope |
Private Member Functions | |
ScriptRequest ()=delete | |
ScriptRequest (const ScriptRequest &rq)=delete | |
ScriptRequest & | operator= (const ScriptRequest &rq)=delete |
Private Attributes | |
const ScriptInterface & | m_ScriptInterface |
JS::Realm * | m_FormerRealm |
Spidermonkey maintains some 'local' state via the JSContext* object.
This object is an argument to most JSAPI functions. Furthermore, this state is Realm (~ global) dependent. For many reasons, including GC safety, The JSContext* Realm must be set up correctly when accessing it. 'Entering' and 'Leaving' realms must be done in a LIFO manner. SM recommends using JSAutoRealm, which provides an RAII option.
ScriptRequest combines both of the above in a single convenient package, providing safe access to the JSContext*, the global object, and ensuring that the proper realm has been entered. Most scriptinterface/ functions will take a ScriptRequest, to ensure proper rooting. You may sometimes have to create one from a ScriptInterface.
Be particularly careful when manipulating several script interfaces.
|
privatedelete |
|
privatedelete |
ScriptRequest::ScriptRequest | ( | const ScriptInterface & | scriptInterface | ) |
NB: the definitions are in scriptinterface.cpp, because these access members of the PImpled implementation of ScriptInterface, and that seemed more convenient.
Constructor for ScriptRequest - here because it needs access into ScriptInterface_impl.
|
inline |
|
inline |
ScriptRequest::~ScriptRequest | ( | ) |
ScriptRequest::ScriptRequest | ( | JSContext * | cx | ) |
Create a script request from a JSContext.
This can be used to get the script interface in a JSNative function. In general, you shouldn't have to rely on this otherwise.
const ScriptInterface & ScriptRequest::GetScriptInterface | ( | ) | const |
Return the scriptInterface active when creating this ScriptRequest.
Note that this is multi-request safe: even if another ScriptRequest is created, it will point to the original scriptInterface, and thus can be used to re-enter the realm.
JS::Value ScriptRequest::globalValue | ( | ) | const |
|
privatedelete |
JSContext* ScriptRequest::cx |
JS::HandleObject ScriptRequest::glob |
|
private |
|
private |
JS::HandleObject ScriptRequest::nativeScope |