From 55ccb526913debb3269a33792bbd61b05656ec46 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Tue, 14 Aug 2018 23:40:10 +0000 Subject: Remove optional argument from NewFXJSBoundObject(). Additionally, we have a pre-existing enum type that is more meaningful than just a boolean. Change-Id: Ie6ad13a3c9b22e34dedf7a5a9b5b9cc2a49b1f03 Reviewed-on: https://pdfium-review.googlesource.com/40190 Reviewed-by: Lei Zhang Commit-Queue: Tom Sepez --- fxjs/cfxjs_engine.cpp | 6 +++--- fxjs/cfxjs_engine.h | 3 +-- fxjs/cfxjs_engine_unittest.cpp | 6 ++++-- fxjs/cjs_app.cpp | 8 ++++---- fxjs/cjs_document.cpp | 24 ++++++++++++------------ fxjs/cjs_eventhandler.cpp | 16 ++++++++-------- fxjs/cjs_field.cpp | 8 ++++---- 7 files changed, 36 insertions(+), 35 deletions(-) diff --git a/fxjs/cfxjs_engine.cpp b/fxjs/cfxjs_engine.cpp index 8587b8af98..2a95e4c58d 100644 --- a/fxjs/cfxjs_engine.cpp +++ b/fxjs/cfxjs_engine.cpp @@ -467,7 +467,7 @@ void CFXJS_Engine::InitializeEngine() { } } else if (pObjDef->m_ObjType == FXJSOBJTYPE_STATIC) { v8::Local pObjName = NewString(pObjDef->m_ObjName); - v8::Local obj = NewFXJSBoundObject(i, true); + v8::Local obj = NewFXJSBoundObject(i, FXJSOBJTYPE_STATIC); if (!obj.IsEmpty()) { v8Context->Global()->Set(v8Context, pObjName, obj).FromJust(); m_StaticObjects[i] = v8::Global(GetIsolate(), obj); @@ -542,7 +542,7 @@ Optional CFXJS_Engine::Execute( } v8::Local CFXJS_Engine::NewFXJSBoundObject(int nObjDefnID, - bool bStatic) { + FXJSOBJTYPE type) { v8::Isolate::Scope isolate_scope(GetIsolate()); v8::Local context = GetIsolate()->GetCurrentContext(); FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(GetIsolate()); @@ -562,7 +562,7 @@ v8::Local CFXJS_Engine::NewFXJSBoundObject(int nObjDefnID, if (pObjDef->m_pConstructor) pObjDef->m_pConstructor(this, obj); - if (!bStatic) { + if (type == FXJSOBJTYPE_DYNAMIC) { auto* pIsolateData = FXJS_PerIsolateData::Get(GetIsolate()); if (pIsolateData->m_pDynamicObjsMap) pIsolateData->m_pDynamicObjsMap->SetAndMakeWeak(pObjData, obj); diff --git a/fxjs/cfxjs_engine.h b/fxjs/cfxjs_engine.h index a940f3fc46..63c6732791 100644 --- a/fxjs/cfxjs_engine.h +++ b/fxjs/cfxjs_engine.h @@ -128,8 +128,7 @@ class CFXJS_Engine : public CFX_V8 { Optional Execute(const WideString& script); v8::Local GetThisObj(); - v8::Local NewFXJSBoundObject(int nObjDefnID, - bool bStatic = false); + v8::Local NewFXJSBoundObject(int nObjDefnID, FXJSOBJTYPE type); void Error(const WideString& message); v8::Local GetV8Context() { diff --git a/fxjs/cfxjs_engine_unittest.cpp b/fxjs/cfxjs_engine_unittest.cpp index 64cd3a3e1e..0902fdbb0e 100644 --- a/fxjs/cfxjs_engine_unittest.cpp +++ b/fxjs/cfxjs_engine_unittest.cpp @@ -66,14 +66,16 @@ TEST_F(FXJSEngineUnitTest, GC) { engine()->InitializeEngine(); v8::Context::Scope context_scope(engine()->GetV8Context()); - v8::Local perm = engine()->NewFXJSBoundObject(0, false); + v8::Local perm = + engine()->NewFXJSBoundObject(0, FXJSOBJTYPE_DYNAMIC); EXPECT_FALSE(perm.IsEmpty()); EXPECT_TRUE(perm_created); EXPECT_FALSE(perm_destroyed); { v8::HandleScope inner_handle_scope(isolate()); - v8::Local temp = engine()->NewFXJSBoundObject(1, false); + v8::Local temp = + engine()->NewFXJSBoundObject(1, FXJSOBJTYPE_DYNAMIC); EXPECT_FALSE(temp.IsEmpty()); EXPECT_TRUE(temp_created); EXPECT_FALSE(temp_destroyed); diff --git a/fxjs/cjs_app.cpp b/fxjs/cjs_app.cpp index 485184bfc4..7029ddaf26 100644 --- a/fxjs/cjs_app.cpp +++ b/fxjs/cjs_app.cpp @@ -327,8 +327,8 @@ CJS_Return CJS_App::setInterval( GlobalTimer* pTimerRef = timerRef.get(); m_Timers.insert(std::move(timerRef)); - v8::Local pRetObj = - pRuntime->NewFXJSBoundObject(CJS_TimerObj::GetObjDefnID()); + v8::Local pRetObj = pRuntime->NewFXJSBoundObject( + CJS_TimerObj::GetObjDefnID(), FXJSOBJTYPE_DYNAMIC); if (pRetObj.IsEmpty()) return CJS_Return(JSMessage::kBadObjectError); @@ -356,8 +356,8 @@ CJS_Return CJS_App::setTimeOut( GlobalTimer* pTimerRef = timerRef.get(); m_Timers.insert(std::move(timerRef)); - v8::Local pRetObj = - pRuntime->NewFXJSBoundObject(CJS_TimerObj::GetObjDefnID()); + v8::Local pRetObj = pRuntime->NewFXJSBoundObject( + CJS_TimerObj::GetObjDefnID(), FXJSOBJTYPE_DYNAMIC); if (pRetObj.IsEmpty()) return CJS_Return(JSMessage::kBadObjectError); diff --git a/fxjs/cjs_document.cpp b/fxjs/cjs_document.cpp index fa9826d1ae..7e89e40230 100644 --- a/fxjs/cjs_document.cpp +++ b/fxjs/cjs_document.cpp @@ -247,8 +247,8 @@ CJS_Return CJS_Document::getField( if (pPDFForm->CountFields(wideName) <= 0) return CJS_Return(pRuntime->NewUndefined()); - v8::Local pFieldObj = - pRuntime->NewFXJSBoundObject(CJS_Field::GetObjDefnID()); + v8::Local pFieldObj = pRuntime->NewFXJSBoundObject( + CJS_Field::GetObjDefnID(), FXJSOBJTYPE_DYNAMIC); if (pFieldObj.IsEmpty()) return CJS_Return(JSMessage::kBadObjectError); @@ -1012,8 +1012,8 @@ CJS_Return CJS_Document::getAnnot( if (!pSDKBAAnnot) return CJS_Return(JSMessage::kBadObjectError); - v8::Local pObj = - pRuntime->NewFXJSBoundObject(CJS_Annot::GetObjDefnID()); + v8::Local pObj = pRuntime->NewFXJSBoundObject( + CJS_Annot::GetObjDefnID(), FXJSOBJTYPE_DYNAMIC); if (pObj.IsEmpty()) return CJS_Return(JSMessage::kBadObjectError); @@ -1047,8 +1047,8 @@ CJS_Return CJS_Document::getAnnots( if (!pSDKAnnotCur) return CJS_Return(JSMessage::kBadObjectError); - v8::Local pObj = - pRuntime->NewFXJSBoundObject(CJS_Annot::GetObjDefnID()); + v8::Local pObj = pRuntime->NewFXJSBoundObject( + CJS_Annot::GetObjDefnID(), FXJSOBJTYPE_DYNAMIC); if (pObj.IsEmpty()) return CJS_Return(JSMessage::kBadObjectError); @@ -1119,8 +1119,8 @@ CJS_Return CJS_Document::get_icons(CJS_Runtime* pRuntime) { v8::Local Icons = pRuntime->NewArray(); int i = 0; for (const auto& name : m_IconNames) { - v8::Local pObj = - pRuntime->NewFXJSBoundObject(CJS_Icon::GetObjDefnID()); + v8::Local pObj = pRuntime->NewFXJSBoundObject( + CJS_Icon::GetObjDefnID(), FXJSOBJTYPE_DYNAMIC); if (pObj.IsEmpty()) return CJS_Return(JSMessage::kBadObjectError); @@ -1151,8 +1151,8 @@ CJS_Return CJS_Document::getIcon( if (it == m_IconNames.end()) return CJS_Return(JSMessage::kBadObjectError); - v8::Local pObj = - pRuntime->NewFXJSBoundObject(CJS_Icon::GetObjDefnID()); + v8::Local pObj = pRuntime->NewFXJSBoundObject( + CJS_Icon::GetObjDefnID(), FXJSOBJTYPE_DYNAMIC); if (pObj.IsEmpty()) return CJS_Return(JSMessage::kBadObjectError); @@ -1301,8 +1301,8 @@ CJS_Return CJS_Document::getPageNumWords( CJS_Return CJS_Document::getPrintParams( CJS_Runtime* pRuntime, const std::vector>& params) { - v8::Local pRetObj = - pRuntime->NewFXJSBoundObject(CJS_PrintParamsObj::GetObjDefnID()); + v8::Local pRetObj = pRuntime->NewFXJSBoundObject( + CJS_PrintParamsObj::GetObjDefnID(), FXJSOBJTYPE_DYNAMIC); if (pRetObj.IsEmpty()) return CJS_Return(JSMessage::kBadObjectError); return CJS_Return(JSMessage::kNotSupportedError); diff --git a/fxjs/cjs_eventhandler.cpp b/fxjs/cjs_eventhandler.cpp index 884651a77b..1a4ffbbd01 100644 --- a/fxjs/cjs_eventhandler.cpp +++ b/fxjs/cjs_eventhandler.cpp @@ -576,13 +576,13 @@ bool CJS_EventHandler::Shift() const { CJS_Field* CJS_EventHandler::Source() { CJS_Runtime* pRuntime = m_pJSEventContext->GetJSRuntime(); - v8::Local pDocObj = - pRuntime->NewFXJSBoundObject(CJS_Document::GetObjDefnID()); + v8::Local pDocObj = pRuntime->NewFXJSBoundObject( + CJS_Document::GetObjDefnID(), FXJSOBJTYPE_DYNAMIC); if (pDocObj.IsEmpty()) return nullptr; - v8::Local pFieldObj = - pRuntime->NewFXJSBoundObject(CJS_Field::GetObjDefnID()); + v8::Local pFieldObj = pRuntime->NewFXJSBoundObject( + CJS_Field::GetObjDefnID(), FXJSOBJTYPE_DYNAMIC); if (pFieldObj.IsEmpty()) return nullptr; @@ -602,13 +602,13 @@ CJS_Field* CJS_EventHandler::Source() { CJS_Field* CJS_EventHandler::Target_Field() { CJS_Runtime* pRuntime = m_pJSEventContext->GetJSRuntime(); - v8::Local pDocObj = - pRuntime->NewFXJSBoundObject(CJS_Document::GetObjDefnID()); + v8::Local pDocObj = pRuntime->NewFXJSBoundObject( + CJS_Document::GetObjDefnID(), FXJSOBJTYPE_DYNAMIC); if (pDocObj.IsEmpty()) return nullptr; - v8::Local pFieldObj = - pRuntime->NewFXJSBoundObject(CJS_Field::GetObjDefnID()); + v8::Local pFieldObj = pRuntime->NewFXJSBoundObject( + CJS_Field::GetObjDefnID(), FXJSOBJTYPE_DYNAMIC); if (pFieldObj.IsEmpty()) return nullptr; diff --git a/fxjs/cjs_field.cpp b/fxjs/cjs_field.cpp index cd97372ad0..45715e22a0 100644 --- a/fxjs/cjs_field.cpp +++ b/fxjs/cjs_field.cpp @@ -2274,8 +2274,8 @@ CJS_Return CJS_Field::buttonGetIcon( if (!pFormControl) return CJS_Return(JSMessage::kBadObjectError); - v8::Local pObj = - pRuntime->NewFXJSBoundObject(CJS_Icon::GetObjDefnID()); + v8::Local pObj = pRuntime->NewFXJSBoundObject( + CJS_Icon::GetObjDefnID(), FXJSOBJTYPE_DYNAMIC); if (pObj.IsEmpty()) return CJS_Return(JSMessage::kBadObjectError); @@ -2386,8 +2386,8 @@ CJS_Return CJS_Field::getArray( v8::Local FormFieldArray = pRuntime->NewArray(); int j = 0; for (const auto& pStr : swSort) { - v8::Local pObj = - pRuntime->NewFXJSBoundObject(CJS_Field::GetObjDefnID()); + v8::Local pObj = pRuntime->NewFXJSBoundObject( + CJS_Field::GetObjDefnID(), FXJSOBJTYPE_DYNAMIC); if (pObj.IsEmpty()) return CJS_Return(JSMessage::kBadObjectError); -- cgit v1.2.3