summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fxjs/cjx_node.cpp27
-rw-r--r--fxjs/cjx_node.h2
-rw-r--r--xfa/fxfa/parser/cxfa_widgetdata.cpp16
3 files changed, 19 insertions, 26 deletions
diff --git a/fxjs/cjx_node.cpp b/fxjs/cjx_node.cpp
index 7ebf5da25b..e207ae488d 100644
--- a/fxjs/cjx_node.cpp
+++ b/fxjs/cjx_node.cpp
@@ -288,10 +288,10 @@ pdfium::Optional<WideString> CJX_Node::TryAttribute(XFA_Attribute eAttr,
return TryCData(pAttr->eName, bUseDefault);
case XFA_AttributeType::Boolean: {
- bool bValue;
- if (!TryBoolean(pAttr->eName, bValue, bUseDefault))
+ pdfium::Optional<bool> value = TryBoolean(pAttr->eName, bUseDefault);
+ if (!value)
return {};
- return {bValue ? L"1" : L"0"};
+ return {*value ? L"1" : L"0"};
}
case XFA_AttributeType::Integer: {
pdfium::Optional<int32_t> iValue = TryInteger(pAttr->eName, bUseDefault);
@@ -2995,22 +2995,16 @@ void CJX_Node::Script_Encrypt_Format(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute) {}
-bool CJX_Node::TryBoolean(XFA_Attribute eAttr, bool& bValue, bool bUseDefault) {
+pdfium::Optional<bool> CJX_Node::TryBoolean(XFA_Attribute eAttr,
+ bool bUseDefault) {
void* pValue = nullptr;
void* pKey = GetMapKey_Element(GetXFANode()->GetElementType(), eAttr);
- if (GetMapModuleValue(pKey, pValue)) {
- bValue = !!pValue;
- return true;
- }
+ if (GetMapModuleValue(pKey, pValue))
+ return {!!pValue};
if (!bUseDefault)
- return false;
-
- pdfium::Optional<bool> ret = GetXFANode()->GetDefaultBoolean(eAttr);
- if (!ret)
- return false;
+ return {};
- bValue = *ret;
- return true;
+ return GetXFANode()->GetDefaultBoolean(eAttr);
}
bool CJX_Node::SetBoolean(XFA_Attribute eAttr, bool bValue, bool bNotify) {
@@ -3019,8 +3013,7 @@ bool CJX_Node::SetBoolean(XFA_Attribute eAttr, bool bValue, bool bNotify) {
}
bool CJX_Node::GetBoolean(XFA_Attribute eAttr) {
- bool bValue;
- return TryBoolean(eAttr, bValue, true) ? bValue : false;
+ return TryBoolean(eAttr, true).value_or(false);
}
bool CJX_Node::SetInteger(XFA_Attribute eAttr, int32_t iValue, bool bNotify) {
diff --git a/fxjs/cjx_node.h b/fxjs/cjx_node.h
index 81af0dfe73..8cf167938c 100644
--- a/fxjs/cjx_node.h
+++ b/fxjs/cjx_node.h
@@ -88,7 +88,7 @@ class CJX_Node : public CJX_Object {
bool SetEnum(XFA_Attribute eAttr, XFA_ATTRIBUTEENUM eValue, bool bNotify);
XFA_ATTRIBUTEENUM GetEnum(XFA_Attribute eAttr);
- bool TryBoolean(XFA_Attribute eAttr, bool& bValue, bool bUseDefault);
+ pdfium::Optional<bool> TryBoolean(XFA_Attribute eAttr, bool bUseDefault);
bool SetBoolean(XFA_Attribute eAttr, bool bValue, bool bNotify);
bool GetBoolean(XFA_Attribute eAttr);
diff --git a/xfa/fxfa/parser/cxfa_widgetdata.cpp b/xfa/fxfa/parser/cxfa_widgetdata.cpp
index 9613383879..5dd680ab8c 100644
--- a/xfa/fxfa/parser/cxfa_widgetdata.cpp
+++ b/xfa/fxfa/parser/cxfa_widgetdata.cpp
@@ -1226,10 +1226,10 @@ bool CXFA_WidgetData::GetBarcodeAttribute_ModuleHeight(int32_t* val) {
}
bool CXFA_WidgetData::GetBarcodeAttribute_PrintChecksum(bool* val) {
- bool bPrintCheckDigit;
- if (GetUIChild()->JSNode()->TryBoolean(XFA_Attribute::PrintCheckDigit,
- bPrintCheckDigit, true)) {
- *val = bPrintCheckDigit;
+ pdfium::Optional<bool> printCheckDigit =
+ GetUIChild()->JSNode()->TryBoolean(XFA_Attribute::PrintCheckDigit, true);
+ if (printCheckDigit) {
+ *val = *printCheckDigit;
return true;
}
return false;
@@ -1264,12 +1264,12 @@ bool CXFA_WidgetData::GetBarcodeAttribute_TextLocation(int32_t* val) {
}
bool CXFA_WidgetData::GetBarcodeAttribute_Truncate(bool* val) {
- bool bTruncate;
- if (!GetUIChild()->JSNode()->TryBoolean(XFA_Attribute::Truncate, bTruncate,
- true))
+ pdfium::Optional<bool> truncate =
+ GetUIChild()->JSNode()->TryBoolean(XFA_Attribute::Truncate, true);
+ if (!truncate)
return false;
- *val = bTruncate;
+ *val = *truncate;
return true;
}