Add some missing const to CJX_Object getters
-- Organize each section in header with const methods first.
Change-Id: I1536afc52b9b252af815a2821a086457e610332d
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/80410
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/fxjs/xfa/cjx_object.cpp b/fxjs/xfa/cjx_object.cpp
index c82bddb..ccb70a2 100644
--- a/fxjs/xfa/cjx_object.cpp
+++ b/fxjs/xfa/cjx_object.cpp
@@ -197,7 +197,7 @@
FXJSE_ThrowMessage(str.ToUTF8().AsStringView());
}
-bool CJX_Object::HasAttribute(XFA_Attribute eAttr) {
+bool CJX_Object::HasAttribute(XFA_Attribute eAttr) const {
uint32_t key = GetMapKey_Element(GetXFAObject()->GetElementType(), eAttr);
return HasMapModuleKey(key);
}
@@ -244,7 +244,7 @@
SetMapModuleString(key, wsValue);
}
-WideString CJX_Object::GetAttributeByString(WideStringView attr) {
+WideString CJX_Object::GetAttributeByString(WideStringView attr) const {
Optional<WideString> result;
Optional<XFA_ATTRIBUTEINFO> enum_attr = XFA_GetAttributeByName(attr);
if (enum_attr.has_value())
@@ -254,12 +254,12 @@
return result.value_or(WideString());
}
-WideString CJX_Object::GetAttributeByEnum(XFA_Attribute attr) {
+WideString CJX_Object::GetAttributeByEnum(XFA_Attribute attr) const {
return TryAttribute(attr, true).value_or(WideString());
}
Optional<WideString> CJX_Object::TryAttribute(XFA_Attribute eAttr,
- bool bUseDefault) {
+ bool bUseDefault) const {
switch (GetXFANode()->GetAttributeType(eAttr)) {
case XFA_AttributeType::Enum: {
Optional<XFA_AttributeValue> value = TryEnum(eAttr, bUseDefault);
@@ -299,7 +299,8 @@
RemoveMapModuleKey(GetMapKey_Custom(wsAttr));
}
-Optional<bool> CJX_Object::TryBoolean(XFA_Attribute eAttr, bool bUseDefault) {
+Optional<bool> CJX_Object::TryBoolean(XFA_Attribute eAttr,
+ bool bUseDefault) const {
uint32_t key = GetMapKey_Element(GetXFAObject()->GetElementType(), eAttr);
Optional<int32_t> value = GetMapModuleValueFollowingChain(key);
if (value.has_value())
@@ -317,7 +318,7 @@
}
}
-bool CJX_Object::GetBoolean(XFA_Attribute eAttr) {
+bool CJX_Object::GetBoolean(XFA_Attribute eAttr) const {
return TryBoolean(eAttr, true).value_or(false);
}
@@ -673,11 +674,12 @@
}
}
-WideString CJX_Object::GetContent(bool bScriptModify) {
+WideString CJX_Object::GetContent(bool bScriptModify) const {
return TryContent(bScriptModify, true).value_or(WideString());
}
-Optional<WideString> CJX_Object::TryContent(bool bScriptModify, bool bProto) {
+Optional<WideString> CJX_Object::TryContent(bool bScriptModify,
+ bool bProto) const {
CXFA_Node* pNode = nullptr;
switch (GetXFANode()->GetObjectType()) {
case XFA_ObjectType::ContainerNode:
@@ -738,7 +740,7 @@
return {};
}
-Optional<WideString> CJX_Object::TryNamespace() {
+Optional<WideString> CJX_Object::TryNamespace() const {
if (GetXFANode()->IsModelNode() ||
GetXFANode()->GetElementType() == XFA_Element::Packet) {
CFX_XMLNode* pXMLNode = GetXFANode()->GetXMLMappingNode();
@@ -880,7 +882,7 @@
return pdfium::nullopt;
}
-bool CJX_Object::HasMapModuleKey(uint32_t key) {
+bool CJX_Object::HasMapModuleKey(uint32_t key) const {
CFXJSE_MapModule* pModule = GetMapModule();
return pModule && pModule->HasKey(key);
}
diff --git a/fxjs/xfa/cjx_object.h b/fxjs/xfa/cjx_object.h
index b2a7ca9..7dacd99 100644
--- a/fxjs/xfa/cjx_object.h
+++ b/fxjs/xfa/cjx_object.h
@@ -129,23 +129,24 @@
CJS_Result RunMethod(const WideString& func,
const std::vector<v8::Local<v8::Value>>& params);
- bool HasAttribute(XFA_Attribute eAttr);
+ bool HasAttribute(XFA_Attribute eAttr) const;
+ WideString GetAttributeByString(WideStringView attr) const;
+ WideString GetAttributeByEnum(XFA_Attribute attr) const;
+ Optional<WideString> TryAttribute(XFA_Attribute eAttr,
+ bool bUseDefault) const;
void SetAttributeByEnum(XFA_Attribute eAttr,
const WideString& wsValue,
bool bNotify);
void SetAttributeByString(WideStringView wsAttr, const WideString& wsValue);
void RemoveAttribute(WideStringView wsAttr);
- WideString GetAttributeByString(WideStringView attr);
- WideString GetAttributeByEnum(XFA_Attribute attr);
- Optional<WideString> TryAttribute(XFA_Attribute eAttr, bool bUseDefault);
- Optional<WideString> TryContent(bool bScriptModify, bool bProto);
+ WideString GetContent(bool bScriptModify) const;
+ Optional<WideString> TryContent(bool bScriptModify, bool bProto) const;
void SetContent(const WideString& wsContent,
const WideString& wsXMLValue,
bool bNotify,
bool bScriptModify,
bool bSyncData);
- WideString GetContent(bool bScriptModify);
template <typename T>
T* GetProperty(int32_t index, XFA_Element eType) const {
@@ -185,33 +186,33 @@
bool bSetting,
XFA_SOM_MESSAGETYPE iMessageType);
- Optional<WideString> TryNamespace();
+ Optional<WideString> TryNamespace() const;
+ int32_t GetInteger(XFA_Attribute eAttr) const;
Optional<int32_t> TryInteger(XFA_Attribute eAttr, bool bUseDefault) const;
void SetInteger(XFA_Attribute eAttr, int32_t iValue, bool bNotify);
- int32_t GetInteger(XFA_Attribute eAttr) const;
+ WideString GetCData(XFA_Attribute eAttr) const;
Optional<WideString> TryCData(XFA_Attribute eAttr, bool bUseDefault) const;
void SetCData(XFA_Attribute eAttr, const WideString& wsValue);
- WideString GetCData(XFA_Attribute eAttr) const;
+ XFA_AttributeValue GetEnum(XFA_Attribute eAttr) const;
Optional<XFA_AttributeValue> TryEnum(XFA_Attribute eAttr,
bool bUseDefault) const;
void SetEnum(XFA_Attribute eAttr, XFA_AttributeValue eValue, bool bNotify);
- XFA_AttributeValue GetEnum(XFA_Attribute eAttr) const;
- Optional<bool> TryBoolean(XFA_Attribute eAttr, bool bUseDefault);
+ bool GetBoolean(XFA_Attribute eAttr) const;
+ Optional<bool> TryBoolean(XFA_Attribute eAttr, bool bUseDefault) const;
void SetBoolean(XFA_Attribute eAttr, bool bValue, bool bNotify);
- bool GetBoolean(XFA_Attribute eAttr);
+ CXFA_Measurement GetMeasure(XFA_Attribute eAttr) const;
+ float GetMeasureInUnit(XFA_Attribute eAttr, XFA_Unit unit) const;
Optional<CXFA_Measurement> TryMeasure(XFA_Attribute eAttr,
bool bUseDefault) const;
Optional<float> TryMeasureAsFloat(XFA_Attribute attr) const;
void SetMeasure(XFA_Attribute eAttr,
const CXFA_Measurement& mValue,
bool bNotify);
- CXFA_Measurement GetMeasure(XFA_Attribute eAttr) const;
- float GetMeasureInUnit(XFA_Attribute eAttr, XFA_Unit unit) const;
void MergeAllData(CXFA_Object* pDstObj);
@@ -268,7 +269,7 @@
Optional<WideString> GetMapModuleStringFollowingChain(uint32_t key) const;
Optional<CXFA_Measurement> GetMapModuleMeasurementFollowingChain(
uint32_t key) const;
- bool HasMapModuleKey(uint32_t key);
+ bool HasMapModuleKey(uint32_t key) const;
void RemoveMapModuleKey(uint32_t key);
void MoveBufferMapData(CXFA_Object* pDstObj);