Pyrogenesis  trunk
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
ScriptRequest Class Reference

Spidermonkey maintains some 'local' state via the JSContext* object. More...

#include <ScriptRequest.h>

Collaboration diagram for ScriptRequest:
Collaboration graph
[legend]

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 ScriptInterfaceGetScriptInterface () 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
 
ScriptRequestoperator= (const ScriptRequest &rq)=delete
 

Private Attributes

const ScriptInterfacem_ScriptInterface
 
JS::Realm * m_FormerRealm
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ ScriptRequest() [1/6]

ScriptRequest::ScriptRequest ( )
privatedelete

◆ ScriptRequest() [2/6]

ScriptRequest::ScriptRequest ( const ScriptRequest rq)
privatedelete

◆ ScriptRequest() [3/6]

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.

◆ ScriptRequest() [4/6]

ScriptRequest::ScriptRequest ( const ScriptInterface scriptInterface)
inline

◆ ScriptRequest() [5/6]

ScriptRequest::ScriptRequest ( std::shared_ptr< ScriptInterface scriptInterface)
inline

◆ ~ScriptRequest()

ScriptRequest::~ScriptRequest ( )

◆ ScriptRequest() [6/6]

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.

Member Function Documentation

◆ GetScriptInterface()

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.

◆ globalValue()

JS::Value ScriptRequest::globalValue ( ) const

◆ operator=()

ScriptRequest& ScriptRequest::operator= ( const ScriptRequest rq)
privatedelete

Member Data Documentation

◆ cx

JSContext* ScriptRequest::cx

◆ glob

JS::HandleObject ScriptRequest::glob

◆ m_FormerRealm

JS::Realm* ScriptRequest::m_FormerRealm
private

◆ m_ScriptInterface

const ScriptInterface& ScriptRequest::m_ScriptInterface
private

◆ nativeScope

JS::HandleObject ScriptRequest::nativeScope

The documentation for this class was generated from the following files: