summaryrefslogtreecommitdiff
path: root/fxjs
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-07-28 00:00:25 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-07-28 00:00:25 +0000
commit522d77db501ab7ae33f7d17e4ab456232ca5a70c (patch)
treed53f5d73117cd098bf3ee4ff6e1fc05b59becdb8 /fxjs
parentf19ae5dcd0b618cdeb80d6a1df5b13610d0ff7da (diff)
downloadpdfium-522d77db501ab7ae33f7d17e4ab456232ca5a70c.tar.xz
Add CPDSDK_Annot::AsBAAnnot() checked downcast method
XFA introduces some additional subclasses, so it doesn't hurt to be sure in all cases before making a static cast. Change-Id: I7447ca58be0b57201b39ba40a3fc5f47505cee58 Reviewed-on: https://pdfium-review.googlesource.com/39013 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'fxjs')
-rw-r--r--fxjs/cjs_annot.cpp42
-rw-r--r--fxjs/cjs_document.cpp4
2 files changed, 22 insertions, 24 deletions
diff --git a/fxjs/cjs_annot.cpp b/fxjs/cjs_annot.cpp
index 49db20475a..c4a4f7ab1d 100644
--- a/fxjs/cjs_annot.cpp
+++ b/fxjs/cjs_annot.cpp
@@ -11,14 +11,6 @@
#include "fxjs/js_define.h"
#include "fxjs/js_resources.h"
-namespace {
-
-CPDFSDK_BAAnnot* ToBAAnnot(CPDFSDK_Annot* annot) {
- return static_cast<CPDFSDK_BAAnnot*>(annot);
-}
-
-} // namespace
-
const JSPropertySpec CJS_Annot::PropertySpecs[] = {
{"hidden", get_hidden_static, set_hidden_static},
{"name", get_name_static, set_name_static},
@@ -49,7 +41,7 @@ CJS_Return CJS_Annot::get_hidden(CJS_Runtime* pRuntime) {
if (!m_pAnnot)
return CJS_Return(JSMessage::kBadObjectError);
- CPDF_Annot* pPDFAnnot = ToBAAnnot(m_pAnnot.Get())->GetPDFAnnot();
+ CPDF_Annot* pPDFAnnot = m_pAnnot->AsBAAnnot()->GetPDFAnnot();
return CJS_Return(pRuntime->NewBoolean(
CPDF_Annot::IsAnnotationHidden(pPDFAnnot->GetAnnotDict())));
}
@@ -58,10 +50,12 @@ CJS_Return CJS_Annot::set_hidden(CJS_Runtime* pRuntime,
v8::Local<v8::Value> vp) {
// May invalidate m_pAnnot.
bool bHidden = pRuntime->ToBoolean(vp);
- if (!m_pAnnot)
+
+ CPDFSDK_BAAnnot* pBAAnnot = ToBAAnnot(m_pAnnot.Get());
+ if (!pBAAnnot)
return CJS_Return(JSMessage::kBadObjectError);
- uint32_t flags = ToBAAnnot(m_pAnnot.Get())->GetFlags();
+ uint32_t flags = pBAAnnot->GetFlags();
if (bHidden) {
flags |= ANNOTFLAG_HIDDEN;
flags |= ANNOTFLAG_INVISIBLE;
@@ -73,35 +67,39 @@ CJS_Return CJS_Annot::set_hidden(CJS_Runtime* pRuntime,
flags &= ~ANNOTFLAG_NOVIEW;
flags |= ANNOTFLAG_PRINT;
}
- ToBAAnnot(m_pAnnot.Get())->SetFlags(flags);
-
+ pBAAnnot->SetFlags(flags);
return CJS_Return();
}
CJS_Return CJS_Annot::get_name(CJS_Runtime* pRuntime) {
- if (!m_pAnnot)
+ CPDFSDK_BAAnnot* pBAAnnot = ToBAAnnot(m_pAnnot.Get());
+ if (!pBAAnnot)
return CJS_Return(JSMessage::kBadObjectError);
- return CJS_Return(pRuntime->NewString(
- ToBAAnnot(m_pAnnot.Get())->GetAnnotName().AsStringView()));
+ return CJS_Return(
+ pRuntime->NewString(pBAAnnot->GetAnnotName().AsStringView()));
}
CJS_Return CJS_Annot::set_name(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
// May invalidate m_pAnnot.
WideString annotName = pRuntime->ToWideString(vp);
- if (!m_pAnnot)
+
+ CPDFSDK_BAAnnot* pBAAnnot = ToBAAnnot(m_pAnnot.Get());
+ if (!pBAAnnot)
return CJS_Return(JSMessage::kBadObjectError);
- ToBAAnnot(m_pAnnot.Get())->SetAnnotName(annotName);
+ pBAAnnot->SetAnnotName(annotName);
return CJS_Return();
}
CJS_Return CJS_Annot::get_type(CJS_Runtime* pRuntime) {
- if (!m_pAnnot)
+ CPDFSDK_BAAnnot* pBAAnnot = ToBAAnnot(m_pAnnot.Get());
+ if (!pBAAnnot)
return CJS_Return(JSMessage::kBadObjectError);
+
return CJS_Return(pRuntime->NewString(
- WideString::FromLocal(CPDF_Annot::AnnotSubtypeToString(
- ToBAAnnot(m_pAnnot.Get())->GetAnnotSubtype())
- .AsStringView())
+ WideString::FromLocal(
+ CPDF_Annot::AnnotSubtypeToString(pBAAnnot->GetAnnotSubtype())
+ .AsStringView())
.AsStringView()));
}
diff --git a/fxjs/cjs_document.cpp b/fxjs/cjs_document.cpp
index 4ac2f15abd..b135805363 100644
--- a/fxjs/cjs_document.cpp
+++ b/fxjs/cjs_document.cpp
@@ -1003,7 +1003,7 @@ CJS_Return CJS_Document::getAnnot(
CPDFSDK_AnnotIteration annotIteration(pPageView, false);
CPDFSDK_BAAnnot* pSDKBAAnnot = nullptr;
for (const auto& pSDKAnnotCur : annotIteration) {
- auto* pBAAnnot = static_cast<CPDFSDK_BAAnnot*>(pSDKAnnotCur.Get());
+ auto* pBAAnnot = pSDKAnnotCur->AsBAAnnot();
if (pBAAnnot && pBAAnnot->GetAnnotName() == swAnnotName) {
pSDKBAAnnot = pBAAnnot;
break;
@@ -1054,7 +1054,7 @@ CJS_Return CJS_Document::getAnnots(
auto* pJS_Annot =
static_cast<CJS_Annot*>(CFXJS_Engine::GetObjectPrivate(pObj));
- pJS_Annot->SetSDKAnnot(static_cast<CPDFSDK_BAAnnot*>(pSDKAnnotCur.Get()));
+ pJS_Annot->SetSDKAnnot(pSDKAnnotCur->AsBAAnnot());
pRuntime->PutArrayElement(
annots, i,
pJS_Annot ? v8::Local<v8::Value>(pJS_Annot->ToV8Object())