From 82999fa9d685638561efc6df2c8370c7e7f47676 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Mon, 16 Jul 2018 22:17:46 +0000 Subject: Make JSGetObject() return UnownedPtr. This a convenient place to assert that the callback that is about to be invoked on the object doesn't destroy the object at any point during its execution. Change-Id: Iacb9d4e01603cc6bf316b00fdd062955c903ca5c Reviewed-on: https://pdfium-review.googlesource.com/37970 Commit-Queue: Tom Sepez Reviewed-by: Lei Zhang --- fxjs/cjs_app.cpp | 4 ++-- fxjs/cjs_document.cpp | 2 +- fxjs/cjs_global.cpp | 8 ++++---- fxjs/cjs_runtime.cpp | 2 +- fxjs/js_define.h | 17 +++++++++-------- 5 files changed, 17 insertions(+), 16 deletions(-) diff --git a/fxjs/cjs_app.cpp b/fxjs/cjs_app.cpp index fd98670c51..485184bfc4 100644 --- a/fxjs/cjs_app.cpp +++ b/fxjs/cjs_app.cpp @@ -103,7 +103,7 @@ CJS_App::~CJS_App() = default; CJS_Return CJS_App::get_active_docs(CJS_Runtime* pRuntime) { v8::Local pObj = pRuntime->GetThisObj(); - CJS_Document* pJSDocument = JSGetObject(pObj); + auto pJSDocument = JSGetObject(pObj); v8::Local aDocs = pRuntime->NewArray(); pRuntime->PutArrayElement( aDocs, 0, @@ -394,7 +394,7 @@ void CJS_App::ClearTimerCommon(CJS_Runtime* pRuntime, return; v8::Local pObj = pRuntime->ToObject(param); - CJS_TimerObj* pTimer = JSGetObject(pObj); + auto pTimer = JSGetObject(pObj); if (!pTimer) return; diff --git a/fxjs/cjs_document.cpp b/fxjs/cjs_document.cpp index f5b0af4c13..51e189ec88 100644 --- a/fxjs/cjs_document.cpp +++ b/fxjs/cjs_document.cpp @@ -354,7 +354,7 @@ CJS_Return CJS_Document::print( if (nLength == 9) { if (params[8]->IsObject()) { v8::Local pObj = pRuntime->ToObject(params[8]); - CJS_PrintParamsObj* pPrintObj = JSGetObject(pObj); + auto pPrintObj = JSGetObject(pObj); if (pPrintObj) { bUI = pPrintObj->GetUI(); nStart = pPrintObj->GetStart(); diff --git a/fxjs/cjs_global.cpp b/fxjs/cjs_global.cpp index c9afdcb8b8..efeef56b08 100644 --- a/fxjs/cjs_global.cpp +++ b/fxjs/cjs_global.cpp @@ -32,7 +32,7 @@ template void JSSpecialPropQuery(const char*, v8::Local property, const v8::PropertyCallbackInfo& info) { - Alt* pObj = JSGetObject(info.Holder()); + auto pObj = JSGetObject(info.Holder()); if (!pObj) return; @@ -50,7 +50,7 @@ template void JSSpecialPropGet(const char* class_name, v8::Local property, const v8::PropertyCallbackInfo& info) { - Alt* pObj = JSGetObject(info.Holder()); + auto pObj = JSGetObject(info.Holder()); if (!pObj) return; @@ -75,7 +75,7 @@ void JSSpecialPropPut(const char* class_name, v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) { - Alt* pObj = JSGetObject(info.Holder()); + auto pObj = JSGetObject(info.Holder()); if (!pObj) return; @@ -96,7 +96,7 @@ template void JSSpecialPropDel(const char* class_name, v8::Local property, const v8::PropertyCallbackInfo& info) { - Alt* pObj = JSGetObject(info.Holder()); + auto pObj = JSGetObject(info.Holder()); if (!pObj) return; diff --git a/fxjs/cjs_runtime.cpp b/fxjs/cjs_runtime.cpp index 634c48be74..9329a483f4 100644 --- a/fxjs/cjs_runtime.cpp +++ b/fxjs/cjs_runtime.cpp @@ -162,7 +162,7 @@ void CJS_Runtime::SetFormFillEnvToDocument() { if (pThis.IsEmpty()) return; - CJS_Document* pJSDocument = JSGetObject(pThis); + auto pJSDocument = JSGetObject(pThis); if (!pJSDocument) return; diff --git a/fxjs/js_define.h b/fxjs/js_define.h index 629cf1a02b..ae1557eb02 100644 --- a/fxjs/js_define.h +++ b/fxjs/js_define.h @@ -10,6 +10,7 @@ #include #include +#include "core/fxcrt/unowned_ptr.h" #include "fxjs/cfxjs_engine.h" #include "fxjs/cjs_object.h" #include "fxjs/cjs_return.h" @@ -58,7 +59,7 @@ static void JSConstructor(CFXJS_Engine* pEngine, v8::Local obj) { void JSDestructor(v8::Local obj); template -C* JSGetObject(v8::Local obj) { +UnownedPtr JSGetObject(v8::Local obj) { if (CFXJS_Engine::GetObjDefnID(obj) != C::GetObjDefnID()) return nullptr; @@ -66,7 +67,7 @@ C* JSGetObject(v8::Local obj) { if (!pJSObj) return nullptr; - return static_cast(pJSObj); + return UnownedPtr(static_cast(pJSObj)); } template @@ -74,7 +75,7 @@ void JSPropGetter(const char* prop_name_string, const char* class_name_string, v8::Local property, const v8::PropertyCallbackInfo& info) { - C* pObj = JSGetObject(info.Holder()); + auto pObj = JSGetObject(info.Holder()); if (!pObj) return; @@ -82,7 +83,7 @@ void JSPropGetter(const char* prop_name_string, if (!pRuntime) return; - CJS_Return result = (pObj->*M)(pRuntime); + CJS_Return result = (pObj.Get()->*M)(pRuntime); if (result.HasError()) { pRuntime->Error(JSFormatErrorString(class_name_string, prop_name_string, result.Error())); @@ -99,7 +100,7 @@ void JSPropSetter(const char* prop_name_string, v8::Local property, v8::Local value, const v8::PropertyCallbackInfo& info) { - C* pObj = JSGetObject(info.Holder()); + auto pObj = JSGetObject(info.Holder()); if (!pObj) return; @@ -107,7 +108,7 @@ void JSPropSetter(const char* prop_name_string, if (!pRuntime) return; - CJS_Return result = (pObj->*M)(pRuntime, value); + CJS_Return result = (pObj.Get()->*M)(pRuntime, value); if (result.HasError()) { pRuntime->Error(JSFormatErrorString(class_name_string, prop_name_string, result.Error())); @@ -120,7 +121,7 @@ template & info) { - C* pObj = JSGetObject(info.Holder()); + auto pObj = JSGetObject(info.Holder()); if (!pObj) return; @@ -132,7 +133,7 @@ void JSMethod(const char* method_name_string, for (unsigned int i = 0; i < (unsigned int)info.Length(); i++) parameters.push_back(info[i]); - CJS_Return result = (pObj->*M)(pRuntime, parameters); + CJS_Return result = (pObj.Get()->*M)(pRuntime, parameters); if (result.HasError()) { pRuntime->Error(JSFormatErrorString(class_name_string, method_name_string, result.Error())); -- cgit v1.2.3