diff options
author | tsepez <tsepez@chromium.org> | 2016-08-15 11:40:12 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-08-15 11:40:12 -0700 |
commit | a4941914bb4411dc4e9053cb344e0349db388007 (patch) | |
tree | 5b5784812bddf80eb4a79ed2597f016f8b72d8ce /fxjs/include/fxjs_v8.h | |
parent | 2ba53c176df1bc5bb963901e7cc42c6a60af24eb (diff) | |
download | pdfium-a4941914bb4411dc4e9053cb344e0349db388007.tar.xz |
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
Diffstat (limited to 'fxjs/include/fxjs_v8.h')
-rw-r--r-- | fxjs/include/fxjs_v8.h | 42 |
1 files changed, 28 insertions, 14 deletions
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 <v8-util.h> #include <v8.h> +#include <map> #include <vector> #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<v8::Object> obj); +using FXJS_CONSTRUCTOR = void (*)(CFXJS_Engine* fxjs, + v8::Local<v8::Object> obj); using FXJS_DESTRUCTOR = void (*)(v8::Local<v8::Object> 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<v8::Context> m_context; + std::vector<v8::Global<v8::Object>*> m_StaticObjects; + std::map<CFX_WideString, v8::Global<v8::Array>> 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<v8::Context>* pV8PersistentContext, std::vector<v8::Global<v8::Object>*>* pStaticObjects); -void FXJS_ReleaseRuntime(v8::Isolate* pIsolate, - v8::Global<v8::Context>* pV8PersistentContext, - std::vector<v8::Global<v8::Object>*>* pStaticObjects); -IJS_Runtime* FXJS_GetRuntimeFromIsolate(v8::Isolate* pIsolate); +void FXJS_ReleaseEngine(v8::Isolate* pIsolate, + v8::Global<v8::Context>* pV8PersistentContext, + std::vector<v8::Global<v8::Object>*>* 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<v8::Context> v8Context, - IJS_Runtime* pIRuntime); +void FXJS_SetEngineForV8Context(v8::Local<v8::Context> 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<v8::Object> FXJS_NewFxDynamicObj(v8::Isolate* pIsolate, - IJS_Runtime* pJSContext, + CFXJS_Engine* pEngine, int nObjDefnID, bool bStatic = false); v8::Local<v8::Object> FXJS_GetThisObj(v8::Isolate* pIsolate); |