diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-12-06 03:12:09 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-12-06 03:12:09 +0000 |
commit | 4bd2ad8cf901134cabae0c56524a05a542c118fd (patch) | |
tree | 08414ce353909c495b004c78fa3fca22132a65f9 /fxjs/fxjs_v8.h | |
parent | 6eda94d78313f18a8f0708c4492d0962649fa709 (diff) | |
download | pdfium-4bd2ad8cf901134cabae0c56524a05a542c118fd.tar.xz |
Move V8 helper methods to their own class.
This CL extracts the V8 helper methods from the CFXJS_Engine and places
them in a CJS_V8 class which the engine inherits from. This will allow
inheriting the CJS_V8 class into CFXJSE_Engine to share the
helper methods.
Change-Id: I58a7cd7ebac3af303ecbeee84c6940186a0f1dc6
Reviewed-on: https://pdfium-review.googlesource.com/20470
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'fxjs/fxjs_v8.h')
-rw-r--r-- | fxjs/fxjs_v8.h | 50 |
1 files changed, 3 insertions, 47 deletions
diff --git a/fxjs/fxjs_v8.h b/fxjs/fxjs_v8.h index eee85e031d..4575235755 100644 --- a/fxjs/fxjs_v8.h +++ b/fxjs/fxjs_v8.h @@ -22,6 +22,7 @@ #include <vector> #include "core/fxcrt/fx_string.h" +#include "fxjs/cjs_v8.h" #ifdef PDF_ENABLE_XFA // Header for CFXJSE_RuntimeData. FXJS_V8 doesn't interpret this class, @@ -127,10 +128,10 @@ bool FXJS_GetIsolate(v8::Isolate** pResultIsolate); // Get the global isolate's ref count. size_t FXJS_GlobalIsolateRefCount(); -class CFXJS_Engine { +class CFXJS_Engine : public CJS_V8 { public: explicit CFXJS_Engine(v8::Isolate* pIsolate); - ~CFXJS_Engine(); + ~CFXJS_Engine() override; using Constructor = void (*)(CFXJS_Engine* pEngine, v8::Local<v8::Object> obj); @@ -139,8 +140,6 @@ class CFXJS_Engine { static CFXJS_Engine* CurrentEngineFromIsolate(v8::Isolate* pIsolate); static int GetObjDefnID(v8::Local<v8::Object> pObj); - v8::Isolate* GetIsolate() const { return m_isolate; } - // Always returns a valid, newly-created objDefnID. int DefineObj(const char* sObjName, FXJSOBJTYPE eObjType, @@ -174,66 +173,23 @@ class CFXJS_Engine { // Called after FXJS_InitializeEngine call made. int Execute(const WideString& script, FXJSErr* perror); - v8::Local<v8::Context> NewLocalContext(); - v8::Local<v8::Context> GetPersistentContext(); v8::Local<v8::Object> GetThisObj(); - v8::Local<v8::Value> NewNull(); - v8::Local<v8::Value> NewUndefined(); - v8::Local<v8::Array> NewArray(); - v8::Local<v8::Number> NewNumber(int number); - v8::Local<v8::Number> NewNumber(double number); - v8::Local<v8::Number> NewNumber(float number); - v8::Local<v8::Boolean> NewBoolean(bool b); - v8::Local<v8::String> NewString(const ByteStringView& str); - v8::Local<v8::String> NewString(const WideStringView& str); - v8::Local<v8::Date> NewDate(double d); v8::Local<v8::Object> NewFxDynamicObj(int nObjDefnID, bool bStatic = false); - int ToInt32(v8::Local<v8::Value> pValue); - bool ToBoolean(v8::Local<v8::Value> pValue); - double ToDouble(v8::Local<v8::Value> pValue); - WideString ToWideString(v8::Local<v8::Value> pValue); - v8::Local<v8::Object> ToObject(v8::Local<v8::Value> pValue); - v8::Local<v8::Array> ToArray(v8::Local<v8::Value> pValue); - - // Arrays. - unsigned GetArrayLength(v8::Local<v8::Array> pArray); - v8::Local<v8::Value> GetArrayElement(v8::Local<v8::Array> pArray, - unsigned index); - unsigned PutArrayElement(v8::Local<v8::Array> pArray, - unsigned index, - v8::Local<v8::Value> pValue); - - // Objects. - std::vector<WideString> GetObjectPropertyNames(v8::Local<v8::Object> pObj); - v8::Local<v8::Value> GetObjectProperty(v8::Local<v8::Object> pObj, - const WideString& PropertyName); - void PutObjectProperty(v8::Local<v8::Object> pObj, - const WideString& PropertyName, - v8::Local<v8::Value> pValue); - // Native object binding. void SetObjectPrivate(v8::Local<v8::Object> pObj, void* p); void* GetObjectPrivate(v8::Local<v8::Object> pObj); static void FreeObjectPrivate(void* p); static void FreeObjectPrivate(v8::Local<v8::Object> pObj); - void SetConstArray(const WideString& name, v8::Local<v8::Array> array); - v8::Local<v8::Array> GetConstArray(const WideString& name); - void Error(const WideString& message); protected: CFXJS_Engine(); - void SetIsolate(v8::Isolate* pIsolate) { m_isolate = pIsolate; } - private: - v8::Isolate* m_isolate; - v8::Global<v8::Context> m_V8PersistentContext; std::vector<v8::Global<v8::Object>*> m_StaticObjects; - std::map<WideString, v8::Global<v8::Array>> m_ConstArrays; }; #endif // FXJS_FXJS_V8_H_ |