Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
GrayJS::cJSXEngine Class Reference

#include <cJSXEngine.h>

Inheritance diagram for GrayJS::cJSXEngine:
GrayLib::cXObjPackFactory Gray::cSingletonSmart< cJSXEngine > Gray::cSingleton< TYPE > Gray::cRefBase Gray::cSingletonStatic< TYPE > Gray::cSingletonRegister IUnknown Gray::CObject Gray::cHeapObject Gray::IHeapObject

Public Member Functions

virtual cXObjPackPtr CreateXObjFile (const FILECHAR_t *pszFilePath) override
 
 cJSXEngine ()
 
virtual ~cJSXEngine ()
 
bool InitJSX ()
 
void ExitJSX ()
 
bool IsInitJSX () const noexcept
 
cJSXContextPtr CreateJSXContext ()
 
cJSXContextPtr GetJSXContextCurrent (bool bCreate=true)
 
int CvtVartoJSValArray (cNewPtr< GRAY_jsval > &rVals, cJSContext *pjsCx, const cVariant &vVal)
 
bool CvtVartoJSVal (cJSContext *pjsCx, GRAY_jsval *vp, const cVariant &vVal)
 
cJSXObjectPtr AssocJSXObject (cJSContext *pjsCx, cXObject *pObj, cJSObject *pjsObject)
 
cJSXObjectPtr NewJSXObject (cJSContext *pjsCx, cXObject *pObj, cJSObject *pjsObjProto, cJSObject *pjsObjParent)
 
cJSXObjectPtr FindJSXObject (cXObject *pObj) const
 
cJSXObjectPtr GetJSXObject (cJSContext *pjsCx, cXObject *pObj)
 
cJSXObjectPtr FindJSXObject (cJSContext *pjsCx, cJSObject *pjsObject)
 
cJSObjectget_JSObjectGlobal () const
 
cJSXObjectPtr CreateJSXObjectGlobal (cJSContext *pjsCx)
 
void CheckJSObjectsCache (cJSContext *pjsCx)
 
void FinalizeJSObject (cJSContext *pjsCx, cJSObject *pjsObject)
 
 UNITTEST_FRIEND (cJSXEngine)
 
- Public Member Functions inherited from GrayLib::cXObjPackFactory
 cXObjPackFactory (const FILECHAR_t *pszExt)
 
virtual ~cXObjPackFactory ()
 
bool IsFileExt (const FILECHAR_t *pszExt) const
 
- Public Member Functions inherited from Gray::CObject
virtual ~CObject ()
 
virtual bool isValidCheck () const noexcept
 < memory allocation and structure definitions are valid. More...
 
virtual void AssertValid () const
 < memory allocation and structure definitions are valid. More...
 
virtual void Serialize (cArchive &a)
 
- Public Member Functions inherited from Gray::cHeapObject
 cHeapObject ()
 
virtual ~cHeapObject ()
 
bool IsValidInsideN (INT_PTR index) const
 
bool IsValidInsidePtr (void const *pTest) const
 
virtual size_t GetHeapStatsThis (OUT ITERATE_t &iAllocCount) const
 
virtual bool isValidCheck () const noexcept
 
- Public Member Functions inherited from Gray::cRefBase
 cRefBase (int iRefCount=0) noexcept
 
virtual ~cRefBase ()
 
int get_RefCount () const noexcept
 
HASHCODE_t get_HashCode () const noexcept
 
 STDMETHOD_ (HASHCODE_t, get_HashCodeX)() const noexcept
 
virtual void onFinalRelease ()
 
bool isValidObj () const noexcept
 
 STDMETHOD_ (ULONG, AddRef)(void) override
 
 STDMETHOD_ (ULONG, Release)(void) override
 
STDMETHOD() QueryInterface (const IID &riid, void __RPC_FAR *__RPC_FAR *ppvObject) override
 
void IncRefCount ()
 
void DecRefCount ()
 
bool isStaticConstruct () const noexcept
 
void StaticConstruct ()
 
void StaticDestruct ()
 
bool isDestructing () noexcept
 
void SetDestructing ()
 

Static Public Member Functions

static GRAY_JSBool _cdecl SetProperty (JSContext *pjsCx, JSObject *pjsObj, GRAY_jsval id, GRAY_jsval *vp)
 
static GRAY_JSBool _cdecl GetProperty (JSContext *pjsCx, JSObject *pjsObj, GRAY_jsval idPropRaw, GRAY_jsval *pvalRet)
 
static GRAY_JSBool _cdecl MethodInvoke (JSContext *pjsCx, JSObject *pjsObj, UINT argc, GRAY_jsval *pargv, GRAY_jsval *prval)
 
static void _cdecl Finalize (JSContext *pjsCx, JSObject *pjsObj)
 
static GRAY_JSBool _cdecl Resolve (JSContext *pjsCx, JSObject *pjsObj, GRAY_jsval id, GRAY_uintN flags, JSObject **ppjsObj)
 
static GRAY_JSBool _cdecl Construct (JSContext *pjsCx, JSObject *pjsObj, GRAY_uintN argc, GRAY_jsval *argv, GRAY_jsval *rval)
 
static GRAY_JSBool _cdecl AddProperty (JSContext *pjsCx, JSObject *pjsObj, GRAY_jsval idPropRaw, GRAY_jsval *vp)
 
static GRAY_JSBool _cdecl DelProperty (JSContext *pjsCx, JSObject *pjsObj, GRAY_jsval idPropRaw, GRAY_jsval *vp)
 
static void _cdecl ErrorReporter (JSContext *pjsCx, const LOGCHAR_t *message, JSErrorReport *report)
 
static cJSXContextPtr GRAYCALL GetJSXContext (cJSContext *pjsCx)
 
static int GRAYCALL CvtJSValArraytoVar (cVariant &vVal, cJSContext *pjsCx, const GRAY_jsval *argv, int argc)
 
static bool GRAYCALL CvtJSValtoVar (cJSContext *pjsCx, const GRAY_jsval *vp, cVariant &vVal)
 
static cXObjectPtr GRAYCALL GetXObject (cJSContext *pjsCx, cJSObject *pjsObj)
 
static bool IsClassJSXProto (const cScriptableInterfaceDef *pClassDef)
 
- Static Public Member Functions inherited from Gray::cSingleton< TYPE >
static TYPE *__stdcall get_Single ()
 
template<class TYPE2 >
static TYPE2 *__stdcall get_SingleT ()
 
static TYPE &__stdcall I ()
 
- Static Public Member Functions inherited from Gray::cSingletonStatic< TYPE >
static bool isSingleCreated () noexcept
 
static TYPEget_SingleU () noexcept
 
static TYPEget_Single ()
 
template<class TYPE2 >
static TYPE2 *__stdcall get_SingleCast ()
 
static TYPEI () noexcept
 
- Static Public Member Functions inherited from Gray::cSingletonRegister
static void __stdcall ReleaseModule (HMODULE hMod)
 

Public Attributes

cJSRuntimem_pjsRuntime
 library reference. More...
 
cJSXContextPtr m_pJSXContextDef
 the default/global context. used to create m_pJSXObjGlobal More...
 
cArrayRef< cJSXClassm_aJSXClasses
 cache of cJSXClass for each interface. More...
 
cThreadLocalTypeSmart< cJSXContextm_aJSXContexts
 cache of all cJSXContext being used and not used. More...
 
cArraySortHash< cJSXObjectm_aJSXObjects
 cache of all cJSXObjectPtr = JSObject/cXObject created. More...
 
cJSXClassPtr m_pJSXClassBase
 object to ref the common base class. XObject More...
 
cThreadLockCount m_Lock
 
- Public Attributes inherited from GrayLib::cXObjPackFactory
const FILECHAR_tm_pszFileExt
 What file extension are we supporting? i.e. MIME_EXT_scp, etc (includes dot). More...
 

Additional Inherited Members

- Static Public Attributes inherited from Gray::cSingletonRegister
static cThreadLockFast sm_LockSingle
 common lock for all cSingleton. More...
 
- Protected Member Functions inherited from Gray::cSingletonSmart< cJSXEngine >
 cSingletonSmart (cJSXEngine *pObject, const TYPEINFO_t &rAddrCode, int iRefCountStart=0)
 
const void * get_HeapPtr () const noexcept override
 Get the top level (outermost, freeable) class pointer. I can delete get_HeapPtr(). More...
 
- Protected Member Functions inherited from Gray::cSingleton< TYPE >
 cSingleton (TYPE *pObject, const TYPEINFO_t &rAddrCode=typeid(TYPE)) noexcept
 
virtual ~cSingleton ()
 
- Protected Member Functions inherited from Gray::cSingletonStatic< TYPE >
 cSingletonStatic (TYPE *pObject) noexcept
 
virtual ~cSingletonStatic () noexcept
 
- Protected Member Functions inherited from Gray::cSingletonRegister
 cSingletonRegister (const TYPEINFO_t &rAddrCode) noexcept
 
virtual ~cSingletonRegister ()
 
void RegisterSingleton ()
 
- Protected Attributes inherited from Gray::cSingletonRegister
HMODULE m_hModuleLoaded
 What modules loaded this ? So singletons can be destroyed if DLL/SO unloads. More...
 
- Static Protected Attributes inherited from Gray::cSingletonStatic< TYPE >
static TYPEsm_pThe = nullptr
 pointer to the one and only object of this TYPE. ASSUME automatically init to = nullptr. More...
 

Detailed Description

Just one connection to the JavaScript engine (runtime) per process. cJSXEngine This can be shared across multi threads/contexts. You always need: a JSRuntime per process, cJSXEngine a context per thread, a global object per context, standard classes (e.g. Date).

Constructor & Destructor Documentation

◆ cJSXEngine()

GrayJS::cJSXEngine::cJSXEngine ( )

◆ ~cJSXEngine()

GrayJS::cJSXEngine::~cJSXEngine ( )
virtual

Member Function Documentation

◆ AddProperty()

static GRAY_JSBool _cdecl GrayJS::cJSXEngine::AddProperty ( JSContext pjsCx,
JSObject pjsObj,
GRAY_jsval  idPropRaw,
GRAY_jsval vp 
)
static

◆ AssocJSXObject()

cJSXObjectPtr GrayJS::cJSXEngine::AssocJSXObject ( cJSContext pjsCx,
cXObject pObj,
cJSObject pjsObject 
)

Create the association object. Create a binding for a cXObject and a EXISTING JSObject

◆ CheckJSObjectsCache()

void GrayJS::cJSXEngine::CheckJSObjectsCache ( cJSContext pjsCx)

Make sure all my objects are still valid. Throttle this to get called ONLY periodically

◆ Construct()

static GRAY_JSBool _cdecl GrayJS::cJSXEngine::Construct ( JSContext pjsCx,
JSObject pjsObj,
GRAY_uintN  argc,
GRAY_jsval argv,
GRAY_jsval rval 
)
static

◆ CreateJSXContext()

cJSXContextPtr GrayJS::cJSXEngine::CreateJSXContext ( )

◆ CreateJSXObjectGlobal()

cJSXObjectPtr GrayJS::cJSXEngine::CreateJSXObjectGlobal ( cJSContext pjsCx)

Given a new context. add global objects to it.

◆ CreateXObjFile()

cXObjPackPtr GrayJS::cJSXEngine::CreateXObjFile ( const FILECHAR_t pszFilePath)
overridevirtual

when i have a file of type MIME_EXT_js don't compile it until we need to. assume LoadXObjPack() will be called later.

Implements GrayLib::cXObjPackFactory.

◆ CvtJSValArraytoVar()

int GrayJS::cJSXEngine::CvtJSValArraytoVar ( cVariant vVal,
cJSContext pjsCx,
const GRAY_jsval argv,
int  argc 
)
static

◆ CvtJSValtoVar()

bool GrayJS::cJSXEngine::CvtJSValtoVar ( cJSContext pjsCx,
const GRAY_jsval vp,
cVariant vVal 
)
static

◆ CvtVartoJSVal()

bool GrayJS::cJSXEngine::CvtVartoJSVal ( cJSContext pjsCx,
GRAY_jsval vp,
const cVariant vVal 
)

Convert a cVariant to the equiv JavaScript jsval GRAY_jsval

  • jsObjParent = parent object if creating a new object?.

◆ CvtVartoJSValArray()

int GrayJS::cJSXEngine::CvtVartoJSValArray ( cNewPtr< GRAY_jsval > &  rVals,
cJSContext pjsCx,
const cVariant vVal 
)

Assuming vVal is an array. convert it to an array of JSVal

Returns
cNewPtr<GRAY_jsval> or JS_malloc() ?? MUST delete this later.

◆ DelProperty()

static GRAY_JSBool _cdecl GrayJS::cJSXEngine::DelProperty ( JSContext pjsCx,
JSObject pjsObj,
GRAY_jsval  idPropRaw,
GRAY_jsval vp 
)
static

◆ ErrorReporter()

void _cdecl GrayJS::cJSXEngine::ErrorReporter ( JSContext pjsCx,
const LOGCHAR_t message,
JSErrorReport *  report 
)
static

Pipe this error out to a console that issued a command?

◆ ExitJSX()

void GrayJS::cJSXEngine::ExitJSX ( )

◆ Finalize()

void _cdecl GrayJS::cJSXEngine::Finalize ( JSContext pjsCx,
JSObject pjsObj 
)
static

◆ FinalizeJSObject()

void GrayJS::cJSXEngine::FinalizeJSObject ( cJSContext pjsCx,
cJSObject pjsObject 
)

pjsObject is being deleted.

Note
That doesn't necessarily mean we should destroy cXObject??
pjsCx may be in the process of destruction. that's OK.

◆ FindJSXObject() [1/2]

cJSXObjectPtr GrayJS::cJSXEngine::FindJSXObject ( cJSContext pjsCx,
cJSObject pjsObject 
)

◆ FindJSXObject() [2/2]

cJSXObjectPtr GrayJS::cJSXEngine::FindJSXObject ( cXObject pObj) const

Find the cJSXObject that corresponds to this IXObject.

◆ get_JSObjectGlobal()

cJSObject * GrayJS::cJSXEngine::get_JSObjectGlobal ( ) const

◆ GetJSXContext()

cJSXContextPtr GRAYCALL GrayJS::cJSXEngine::GetJSXContext ( cJSContext pjsCx)
static

Get cJSXContextPtr from JSContext

◆ GetJSXContextCurrent()

cJSXContextPtr GrayJS::cJSXEngine::GetJSXContextCurrent ( bool  bCreate = true)

get a cJSXContext that is attached to the current thread. Create if necessary

◆ GetJSXObject()

cJSXObjectPtr GrayJS::cJSXEngine::GetJSXObject ( cJSContext pjsCx,
cXObject pObj 
)

Find (or Create) a JSObject to represent the cXObject Is the cXObject already in my cache?

◆ GetProperty()

GRAY_JSBool _cdecl GrayJS::cJSXEngine::GetProperty ( JSContext pjsCx,
JSObject pjsObj,
GRAY_jsval  idPropRaw,
GRAY_jsval pvalRet 
)
static

JavaScript Gets the property of a cXObject.

◆ GetXObject()

cXObjectPtr GRAYCALL GrayJS::cJSXEngine::GetXObject ( cJSContext pjsCx,
cJSObject pjsObj 
)
static

Find the cJSXObject/cXObject attached to this JSObject pjsObj. if any.

◆ InitJSX()

bool GrayJS::cJSXEngine::InitJSX ( )

Init the engine

◆ IsClassJSXProto()

bool GrayJS::cJSXEngine::IsClassJSXProto ( const cScriptableInterfaceDef pClassDef)
static

Could use JS_GetClass() on object as well?

◆ IsInitJSX()

bool GrayJS::cJSXEngine::IsInitJSX ( ) const
inlinenoexcept

◆ MethodInvoke()

GRAY_JSBool _cdecl GrayJS::cJSXEngine::MethodInvoke ( JSContext pjsCx,
JSObject pjsObj,
UINT  argc,
GRAY_jsval pargv,
GRAY_jsval prval 
)
static

Invoke a C++ method from JavaScript stub. JSNative

Note
The jscript engine makes this call difficult. It wants to invoke a unique stub for each method itself. So call via a thunk table to identify the method.
  • pMethod = ( nullptr = use the last referenced prop)

◆ NewJSXObject()

cJSXObjectPtr GrayJS::cJSXEngine::NewJSXObject ( cJSContext pjsCx,
cXObject pObj,
cJSObject pjsObjProto,
cJSObject pjsObjParent 
)

Create a binding for a cXObject and a NEW JSObject

◆ Resolve()

static GRAY_JSBool _cdecl GrayJS::cJSXEngine::Resolve ( JSContext pjsCx,
JSObject pjsObj,
GRAY_jsval  id,
GRAY_uintN  flags,
JSObject **  ppjsObj 
)
static

◆ SetProperty()

GRAY_JSBool _cdecl GrayJS::cJSXEngine::SetProperty ( JSContext pjsCx,
JSObject pjsObj,
GRAY_jsval  id,
GRAY_jsval vp 
)
static

◆ UNITTEST_FRIEND()

GrayJS::cJSXEngine::UNITTEST_FRIEND ( cJSXEngine  )

Member Data Documentation

◆ m_aJSXClasses

cArrayRef<cJSXClass> GrayJS::cJSXEngine::m_aJSXClasses

cache of cJSXClass for each interface.

!< [ SCRIPTINTERFACEID_MAX ]

◆ m_aJSXContexts

cThreadLocalTypeSmart< cJSXContext > GrayJS::cJSXEngine::m_aJSXContexts

cache of all cJSXContext being used and not used.

◆ m_aJSXObjects

cArraySortHash<cJSXObject> GrayJS::cJSXEngine::m_aJSXObjects

cache of all cJSXObjectPtr = JSObject/cXObject created.

◆ m_Lock

cThreadLockCount GrayJS::cJSXEngine::m_Lock
mutable

◆ m_pjsRuntime

cJSRuntime* GrayJS::cJSXEngine::m_pjsRuntime

library reference.

◆ m_pJSXClassBase

cJSXClassPtr GrayJS::cJSXEngine::m_pJSXClassBase

object to ref the common base class. XObject

◆ m_pJSXContextDef

cJSXContextPtr GrayJS::cJSXEngine::m_pJSXContextDef

the default/global context. used to create m_pJSXObjGlobal


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