From 98b356a36bc9291a4f222d092afeeea0d5b5f379 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Mon, 16 Jul 2018 21:35:06 +0000 Subject: Use UnownedPtr<> to v8::Isolates. Isolates are long-lived, but this may catch a few things. Introduce CFX_V8IsolateDeleter for unique_ptr usage. Fix Dispose()/SetIsolate(nullptr) ordering in cjs_runtime.cpp Remove one unused isolate member. Flip protected -> private in one place. Change-Id: I26cdd120f799192e93b0d9d04dcde8f348dc21f3 Reviewed-on: https://pdfium-review.googlesource.com/37931 Reviewed-by: Lei Zhang Commit-Queue: Tom Sepez --- fxjs/cfx_v8.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'fxjs/cfx_v8.h') diff --git a/fxjs/cfx_v8.h b/fxjs/cfx_v8.h index 08a18935ea..04468d5281 100644 --- a/fxjs/cfx_v8.h +++ b/fxjs/cfx_v8.h @@ -20,7 +20,7 @@ class CFX_V8 { explicit CFX_V8(v8::Isolate* pIsolate); virtual ~CFX_V8(); - v8::Isolate* GetIsolate() const { return m_isolate; } + v8::Isolate* GetIsolate() const { return m_pIsolate.Get(); } v8::Local NewNull(); v8::Local NewUndefined(); @@ -59,10 +59,11 @@ class CFX_V8 { v8::Local pValue); protected: - void SetIsolate(v8::Isolate* pIsolate) { m_isolate = pIsolate; } + void SetIsolate(v8::Isolate* pIsolate) { m_pIsolate = pIsolate; } + void DisposeIsolate(); private: - v8::Isolate* m_isolate; + UnownedPtr m_pIsolate; }; class CFX_V8ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { @@ -72,4 +73,9 @@ class CFX_V8ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { void Free(void* data, size_t length) override; }; +// Use with std::unique_ptr to dispose of isolates correctly. +struct CFX_V8IsolateDeleter { + inline void operator()(v8::Isolate* ptr) { ptr->Dispose(); } +}; + #endif // FXJS_CFX_V8_H_ -- cgit v1.2.3