From 36aae4fc09a353e01738bf0bbc302a21ba21ed07 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Mon, 4 Jun 2018 19:44:37 +0000 Subject: Make CJS_Objects track CJS_Runtime (and hence the document itself) Precursor to removing some more v8::Context slot dependency. There's a cost to maintaining the set of observers, but since these objects are tied to V8 lifetimes, not C++ lifetimes, we want to be very wary of the document going away unexpectedly. Change-Id: I579f58a460aa50b88cb861227c9aca9a8a83ce12 Reviewed-on: https://pdfium-review.googlesource.com/33471 Commit-Queue: Tom Sepez Reviewed-by: dsinclair --- fxjs/cjs_object.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'fxjs/cjs_object.h') diff --git a/fxjs/cjs_object.h b/fxjs/cjs_object.h index 8254af98de..c33fd7710f 100644 --- a/fxjs/cjs_object.h +++ b/fxjs/cjs_object.h @@ -10,6 +10,7 @@ #include #include +#include "core/fxcrt/unowned_ptr.h" #include "fpdfsdk/cpdfsdk_helpers.h" #include "fxjs/cfxjs_engine.h" #include "fxjs/cjs_runtime.h" @@ -49,17 +50,19 @@ class CJS_Object { const JSMethodSpec methods[], size_t count); - explicit CJS_Object(v8::Local pObject); + CJS_Object(v8::Local pObject, CJS_Runtime* pRuntime); virtual ~CJS_Object(); - virtual void InitInstance(IJS_Runtime* pIRuntime); + virtual void InitInstance(); - v8::Local ToV8Object() { return m_pV8Object.Get(m_pIsolate); } - v8::Isolate* GetIsolate() const { return m_pIsolate; } + v8::Local ToV8Object() { return m_pV8Object.Get(GetIsolate()); } + v8::Isolate* GetIsolate() const { return m_pIsolate.Get(); } + CJS_Runtime* GetRuntime() const { return m_pRuntime.Get(); } - protected: + private: + UnownedPtr m_pIsolate; v8::Global m_pV8Object; - v8::Isolate* m_pIsolate; + CJS_Runtime::ObservedPtr m_pRuntime; }; #endif // FXJS_CJS_OBJECT_H_ -- cgit v1.2.3