From a4941914bb4411dc4e9053cb344e0349db388007 Mon Sep 17 00:00:00 2001 From: tsepez Date: Mon, 15 Aug 2016 11:40:12 -0700 Subject: Move some v8 objects from CJS back into FXJS Create a new class to hold these, CFXJS_Engine (could have been called Runtime, but there are too many "Runtimes" already). In a subsequent patch, all the FXJS_*() functions that take an isolate as the first argument can become methods on the engine. CJS_ must still manage the isolates; this happens outside the engine. The IJS_Runtime abstraction moves up to fpdfsdk/javascript; it remains to allow for either a real JS library or a stubb one to be linked (for non-js builds). Review-Url: https://codereview.chromium.org/2241483004 --- fxjs/include/fxjs_v8.h | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) (limited to 'fxjs/include') diff --git a/fxjs/include/fxjs_v8.h b/fxjs/include/fxjs_v8.h index 5e12b082be..52afc491b2 100644 --- a/fxjs/include/fxjs_v8.h +++ b/fxjs/include/fxjs_v8.h @@ -17,16 +17,17 @@ #include #include +#include #include #include "core/fxcrt/include/fx_string.h" +class CFXJS_Engine; class CFXJS_ObjDefinition; -// FXJS_V8 places no restrictions on these two classes; it merely passes them +// FXJS_V8 places no restrictions on this class; it merely passes it // on to caller-provided methods. class IJS_Context; // A description of the event that caused JS execution. -class IJS_Runtime; // A native runtime, typically owns the v8::Context. #ifdef PDF_ENABLE_XFA // FXJS_V8 places no interpreation on this calass; it merely passes it @@ -124,12 +125,25 @@ class FXJS_ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { void Free(void* data, size_t length) override; }; -using FXJS_CONSTRUCTOR = void (*)(IJS_Runtime* cc, v8::Local obj); +using FXJS_CONSTRUCTOR = void (*)(CFXJS_Engine* fxjs, + v8::Local obj); using FXJS_DESTRUCTOR = void (*)(v8::Local obj); void FXJS_Initialize(unsigned int embedderDataSlot, v8::Isolate* pIsolate); void FXJS_Release(); +class CFXJS_Engine { + public: + CFXJS_Engine(); + ~CFXJS_Engine(); + + protected: + v8::Isolate* m_isolate; + v8::Global m_context; + std::vector*> m_StaticObjects; + std::map> m_ConstArrays; +}; + // Gets the global isolate set by FXJS_Initialize(), or makes a new one each // time if there is no such isolate. Returns true if a new isolate had to be // created. @@ -172,30 +186,30 @@ void FXJS_DefineGlobalConst(v8::Isolate* pIsolate, v8::FunctionCallback pConstGetter); // Called after FXJS_Define* calls made. -void FXJS_InitializeRuntime( +void FXJS_InitializeEngine( v8::Isolate* pIsolate, - IJS_Runtime* pIRuntime, + CFXJS_Engine* pEngine, v8::Global* pV8PersistentContext, std::vector*>* pStaticObjects); -void FXJS_ReleaseRuntime(v8::Isolate* pIsolate, - v8::Global* pV8PersistentContext, - std::vector*>* pStaticObjects); -IJS_Runtime* FXJS_GetRuntimeFromIsolate(v8::Isolate* pIsolate); +void FXJS_ReleaseEngine(v8::Isolate* pIsolate, + v8::Global* pV8PersistentContext, + std::vector*>* pStaticObjects); +CFXJS_Engine* FXJS_GetCurrentEngineFromIsolate(v8::Isolate* pIsolate); #ifdef PDF_ENABLE_XFA -// Called as part of FXJS_InitializeRuntime, exposed so PDF can make its +// Called as part of FXJS_InitializeEngine, exposed so PDF can make its // own contexts compatible with XFA or vice versa. -void FXJS_SetRuntimeForV8Context(v8::Local v8Context, - IJS_Runtime* pIRuntime); +void FXJS_SetEngineForV8Context(v8::Local v8Context, + CFXJS_Engine* pEngine); #endif // PDF_ENABLE_XFA -// Called after FXJS_InitializeRuntime call made. +// Called after FXJS_InitializeEngine call made. int FXJS_Execute(v8::Isolate* pIsolate, const CFX_WideString& script, FXJSErr* perror); v8::Local FXJS_NewFxDynamicObj(v8::Isolate* pIsolate, - IJS_Runtime* pJSContext, + CFXJS_Engine* pEngine, int nObjDefnID, bool bStatic = false); v8::Local FXJS_GetThisObj(v8::Isolate* pIsolate); -- cgit v1.2.3