summaryrefslogtreecommitdiff
path: root/fxjs
diff options
context:
space:
mode:
Diffstat (limited to 'fxjs')
-rw-r--r--fxjs/cjx_node.cpp29
-rw-r--r--fxjs/cjx_node.h2
2 files changed, 11 insertions, 20 deletions
diff --git a/fxjs/cjx_node.cpp b/fxjs/cjx_node.cpp
index a1b2f048dc..0e0f2d0274 100644
--- a/fxjs/cjx_node.cpp
+++ b/fxjs/cjx_node.cpp
@@ -294,11 +294,11 @@ bool CJX_Node::GetAttribute(XFA_Attribute eAttr,
return true;
}
case XFA_AttributeType::Integer: {
- int32_t iValue;
- if (!TryInteger(pAttr->eName, iValue, bUseDefault))
+ pdfium::Optional<int32_t> iValue = TryInteger(pAttr->eName, bUseDefault);
+ if (!iValue)
return false;
- wsValue.Format(L"%d", iValue);
+ wsValue.Format(L"%d", *iValue);
return true;
}
case XFA_AttributeType::Measure: {
@@ -3038,28 +3038,19 @@ bool CJX_Node::SetInteger(XFA_Attribute eAttr, int32_t iValue, bool bNotify) {
}
int32_t CJX_Node::GetInteger(XFA_Attribute eAttr) {
- int32_t iValue;
- return TryInteger(eAttr, iValue, true) ? iValue : 0;
+ return TryInteger(eAttr, true).value_or(0);
}
-bool CJX_Node::TryInteger(XFA_Attribute eAttr,
- int32_t& iValue,
- bool bUseDefault) {
+pdfium::Optional<int32_t> CJX_Node::TryInteger(XFA_Attribute eAttr,
+ bool bUseDefault) {
void* pKey = GetMapKey_Element(GetXFANode()->GetElementType(), eAttr);
void* pValue = nullptr;
- if (GetMapModuleValue(pKey, pValue)) {
- iValue = (int32_t)(uintptr_t)pValue;
- return true;
- }
+ if (GetMapModuleValue(pKey, pValue))
+ return {static_cast<int32_t>(reinterpret_cast<uintptr_t>(pValue))};
if (!bUseDefault)
- return false;
-
- pdfium::Optional<int32_t> ret = GetXFANode()->GetDefaultInteger(eAttr);
- if (!ret)
- return false;
+ return {};
- iValue = *ret;
- return true;
+ return GetXFANode()->GetDefaultInteger(eAttr);
}
bool CJX_Node::TryEnum(XFA_Attribute eAttr,
diff --git a/fxjs/cjx_node.h b/fxjs/cjx_node.h
index 2e9360d451..6c95673d25 100644
--- a/fxjs/cjx_node.h
+++ b/fxjs/cjx_node.h
@@ -69,7 +69,7 @@ class CJX_Node : public CJX_Object {
bool bSyncData);
WideString GetContent(bool bScriptModify);
- bool TryInteger(XFA_Attribute eAttr, int32_t& iValue, bool bUseDefault);
+ pdfium::Optional<int32_t> TryInteger(XFA_Attribute eAttr, bool bUseDefault);
bool SetInteger(XFA_Attribute eAttr, int32_t iValue, bool bNotify);
int32_t GetInteger(XFA_Attribute eAttr);