From b165ffb64e59998ec6d5f76c82bd2fe53734b3cd Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Wed, 11 Jul 2018 17:23:53 +0000 Subject: Use JSGetObject() in more places. Change-Id: I7f26709bdad56cc2712f21e8e644be7c53ec5ec4 Reviewed-on: https://pdfium-review.googlesource.com/37513 Reviewed-by: dsinclair Commit-Queue: Lei Zhang --- fxjs/cjs_app.cpp | 15 ++++----------- fxjs/cjs_document.cpp | 33 +++++++++++---------------------- fxjs/cjs_runtime.cpp | 8 +++----- 3 files changed, 18 insertions(+), 38 deletions(-) diff --git a/fxjs/cjs_app.cpp b/fxjs/cjs_app.cpp index 4648f462b4..ad155b787c 100644 --- a/fxjs/cjs_app.cpp +++ b/fxjs/cjs_app.cpp @@ -102,12 +102,8 @@ CJS_App::CJS_App(v8::Local pObject, CJS_Runtime* pRuntime) CJS_App::~CJS_App() = default; CJS_Return CJS_App::get_active_docs(CJS_Runtime* pRuntime) { - CJS_Document* pJSDocument = nullptr; v8::Local pObj = pRuntime->GetThisObj(); - if (CFXJS_Engine::GetObjDefnID(pObj) == CJS_Document::GetObjDefnID()) { - pJSDocument = - static_cast(CFXJS_Engine::GetObjectPrivate(pObj)); - } + CJS_Document* pJSDocument = JSGetObject(pObj); v8::Local aDocs = pRuntime->NewArray(); pRuntime->PutArrayElement( aDocs, 0, @@ -398,14 +394,11 @@ void CJS_App::ClearTimerCommon(CJS_Runtime* pRuntime, return; v8::Local pObj = pRuntime->ToObject(param); - if (CFXJS_Engine::GetObjDefnID(pObj) != CJS_TimerObj::GetObjDefnID()) - return; - - CJS_Object* pJSObj = CFXJS_Engine::GetObjectPrivate(pObj); - if (!pJSObj) + CJS_TimerObj* pTimer = JSGetObject(pObj); + if (!pTimer) return; - GlobalTimer::Cancel(static_cast(pJSObj)->GetTimerID()); + GlobalTimer::Cancel(pTimer->GetTimerID()); } CJS_Return CJS_App::execMenuItem( diff --git a/fxjs/cjs_document.cpp b/fxjs/cjs_document.cpp index 35e3e53437..f5b0af4c13 100644 --- a/fxjs/cjs_document.cpp +++ b/fxjs/cjs_document.cpp @@ -354,22 +354,16 @@ CJS_Return CJS_Document::print( if (nLength == 9) { if (params[8]->IsObject()) { v8::Local pObj = pRuntime->ToObject(params[8]); - if (CFXJS_Engine::GetObjDefnID(pObj) == - CJS_PrintParamsObj::GetObjDefnID()) { - v8::Local pObj = pRuntime->ToObject(params[8]); - CJS_Object* pJSObj = CFXJS_Engine::GetObjectPrivate(pObj); - if (pJSObj) { - CJS_PrintParamsObj* printObj = - static_cast(pJSObj); - bUI = printObj->GetUI(); - nStart = printObj->GetStart(); - nEnd = printObj->GetEnd(); - bSilent = printObj->GetSilent(); - bShrinkToFit = printObj->GetShrinkToFit(); - bPrintAsImage = printObj->GetPrintAsImage(); - bReverse = printObj->GetReverse(); - bAnnotations = printObj->GetAnnotations(); - } + CJS_PrintParamsObj* pPrintObj = JSGetObject(pObj); + if (pPrintObj) { + bUI = pPrintObj->GetUI(); + nStart = pPrintObj->GetStart(); + nEnd = pPrintObj->GetEnd(); + bSilent = pPrintObj->GetSilent(); + bShrinkToFit = pPrintObj->GetShrinkToFit(); + bPrintAsImage = pPrintObj->GetPrintAsImage(); + bReverse = pPrintObj->GetReverse(); + bAnnotations = pPrintObj->GetAnnotations(); } } } else { @@ -1109,13 +1103,8 @@ CJS_Return CJS_Document::addIcon( if (!params[1]->IsObject()) return CJS_Return(JSMessage::kTypeError); - v8::Local pJSIcon = pRuntime->ToObject(params[1]); - if (CFXJS_Engine::GetObjDefnID(pJSIcon) != CJS_Icon::GetObjDefnID()) - return CJS_Return(JSMessage::kTypeError); - v8::Local pObj = pRuntime->ToObject(params[1]); - CJS_Object* obj = CFXJS_Engine::GetObjectPrivate(pObj); - if (!obj) + if (!JSGetObject(pObj)) return CJS_Return(JSMessage::kTypeError); WideString swIconName = pRuntime->ToWideString(params[0]); diff --git a/fxjs/cjs_runtime.cpp b/fxjs/cjs_runtime.cpp index f867e31340..96253c08bf 100644 --- a/fxjs/cjs_runtime.cpp +++ b/fxjs/cjs_runtime.cpp @@ -161,12 +161,10 @@ void CJS_Runtime::SetFormFillEnvToDocument() { v8::Context::Scope context_scope(context); v8::Local pThis = GetThisObj(); - if (pThis.IsEmpty() || - CFXJS_Engine::GetObjDefnID(pThis) != CJS_Document::GetObjDefnID()) { + if (pThis.IsEmpty()) return; - } - auto* pJSDocument = - static_cast(CFXJS_Engine::GetObjectPrivate(pThis)); + + CJS_Document* pJSDocument = JSGetObject(pThis); if (!pJSDocument) return; -- cgit v1.2.3