From 0928bc5aba36e47ef5c330cb1157d351bd1e72ab Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Wed, 22 Aug 2018 17:40:12 +0000 Subject: Use UnownedPtr<> in IJS_Runtime. Change-Id: I9f5f3c54144163b5ac188e38fcb8d8fa93d4bd7a Reviewed-on: https://pdfium-review.googlesource.com/40951 Reviewed-by: Lei Zhang Commit-Queue: Tom Sepez --- fxjs/ijs_runtime.cpp | 7 +++++++ fxjs/ijs_runtime.h | 15 +++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) (limited to 'fxjs') diff --git a/fxjs/ijs_runtime.cpp b/fxjs/ijs_runtime.cpp index afbdaefca4..50abd39c8b 100644 --- a/fxjs/ijs_runtime.cpp +++ b/fxjs/ijs_runtime.cpp @@ -13,6 +13,13 @@ #include "fxjs/cjs_runtime.h" #endif +IJS_Runtime::ScopedEventContext::ScopedEventContext(IJS_Runtime* pRuntime) + : m_pRuntime(pRuntime), m_pContext(pRuntime->NewEventContext()) {} + +IJS_Runtime::ScopedEventContext::~ScopedEventContext() { + m_pRuntime->ReleaseEventContext(m_pContext.Release()); +} + // static void IJS_Runtime::Initialize(unsigned int slot, void* isolate) { #ifdef PDF_ENABLE_V8 diff --git a/fxjs/ijs_runtime.h b/fxjs/ijs_runtime.h index 9f15abaee0..d74bb94929 100644 --- a/fxjs/ijs_runtime.h +++ b/fxjs/ijs_runtime.h @@ -11,6 +11,7 @@ #include "core/fxcrt/fx_string.h" #include "core/fxcrt/fx_system.h" +#include "core/fxcrt/unowned_ptr.h" #include "third_party/base/optional.h" #ifdef PDF_ENABLE_XFA @@ -36,17 +37,15 @@ class IJS_Runtime { class ScopedEventContext { public: - explicit ScopedEventContext(IJS_Runtime* pRuntime) - : m_pRuntime(pRuntime), m_pContext(pRuntime->NewEventContext()) {} + explicit ScopedEventContext(IJS_Runtime* pRuntime); + ~ScopedEventContext(); - ~ScopedEventContext() { m_pRuntime->ReleaseEventContext(m_pContext); } - - IJS_EventContext* Get() const { return m_pContext; } - IJS_EventContext* operator->() const { return m_pContext; } + IJS_EventContext* Get() const { return m_pContext.Get(); } + IJS_EventContext* operator->() const { return m_pContext.Get(); } private: - IJS_Runtime* m_pRuntime; - IJS_EventContext* m_pContext; + UnownedPtr m_pRuntime; + UnownedPtr m_pContext; }; static void Initialize(unsigned int slot, void* isolate); -- cgit v1.2.3