1
0
forked from mirrors/0ad

Remove all external usage of CmptPrivate. Header cleanup.

This removes usage of CmptPrivate outside of ScriptInterface.
ScriptRequest can now be used to safely recover the scriptInterface from
a JSContext instead of going through ScriptInterface, which allows more
code cleanup.

Follows 34b1920e7b

Differential Revision: https://code.wildfiregames.com/D3963
This was SVN commit r25442.
This commit is contained in:
wraitii
2021-05-15 13:54:58 +00:00
parent 3ebff376cc
commit 507f44f7f9
20 changed files with 173 additions and 118 deletions
+19 -1
View File
@@ -71,12 +71,30 @@ public:
ScriptRequest(std::shared_ptr<ScriptInterface> scriptInterface) : ScriptRequest(*scriptInterface) {}
~ScriptRequest();
/**
* 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.
*/
ScriptRequest(JSContext* cx);
/**
* 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.
*/
const ScriptInterface& GetScriptInterface() const;
JS::Value globalValue() const;
// Note that JSContext actually changes behind the scenes when creating another ScriptRequest for another realm,
// so be _very_ careful when juggling between different realms.
JSContext* cx;
JS::HandleObject glob;
JS::HandleObject nativeScope;
private:
JS::Realm* m_formerRealm;
const ScriptInterface& m_ScriptInterface;
JS::Realm* m_FormerRealm;
};