summaryrefslogtreecommitdiff
path: root/fxjs
diff options
context:
space:
mode:
Diffstat (limited to 'fxjs')
-rw-r--r--fxjs/xfa/cjx_object.cpp17
-rw-r--r--fxjs/xfa/cjx_packet.cpp50
2 files changed, 32 insertions, 35 deletions
diff --git a/fxjs/xfa/cjx_object.cpp b/fxjs/xfa/cjx_object.cpp
index 1c0454d425..6984c3a998 100644
--- a/fxjs/xfa/cjx_object.cpp
+++ b/fxjs/xfa/cjx_object.cpp
@@ -806,30 +806,31 @@ Optional<WideString> CJX_Object::TryNamespace() {
if (ToNode(GetXFAObject())->IsModelNode() ||
ToNode(GetXFAObject())->GetElementType() == XFA_Element::Packet) {
CFX_XMLNode* pXMLNode = ToNode(GetXFAObject())->GetXMLMappingNode();
- if (!pXMLNode || pXMLNode->GetType() != FX_XMLNODE_Element)
+ CFX_XMLElement* element = ToXMLElement(pXMLNode);
+ if (!element)
return {};
- return {static_cast<CFX_XMLElement*>(pXMLNode)->GetNamespaceURI()};
+ return {element->GetNamespaceURI()};
}
if (ToNode(GetXFAObject())->GetPacketType() != XFA_PacketType::Datasets)
return ToNode(GetXFAObject())->GetModelNode()->JSObject()->TryNamespace();
CFX_XMLNode* pXMLNode = ToNode(GetXFAObject())->GetXMLMappingNode();
- if (!pXMLNode || pXMLNode->GetType() != FX_XMLNODE_Element)
+ CFX_XMLElement* element = ToXMLElement(pXMLNode);
+ if (!element)
return {};
if (ToNode(GetXFAObject())->GetElementType() == XFA_Element::DataValue &&
GetEnum(XFA_Attribute::Contains) == XFA_AttributeEnum::MetaData) {
WideString wsNamespace;
- bool ret = XFA_FDEExtension_ResolveNamespaceQualifier(
- static_cast<CFX_XMLElement*>(pXMLNode),
- GetCData(XFA_Attribute::QualifiedName), &wsNamespace);
- if (!ret)
+ if (!XFA_FDEExtension_ResolveNamespaceQualifier(
+ element, GetCData(XFA_Attribute::QualifiedName), &wsNamespace)) {
return {};
+ }
return {wsNamespace};
}
- return {static_cast<CFX_XMLElement*>(pXMLNode)->GetNamespaceURI()};
+ return {element->GetNamespaceURI()};
}
std::pair<CXFA_Node*, int32_t> CJX_Object::GetPropertyInternal(
diff --git a/fxjs/xfa/cjx_packet.cpp b/fxjs/xfa/cjx_packet.cpp
index b27cfbadfb..2288de4c8d 100644
--- a/fxjs/xfa/cjx_packet.cpp
+++ b/fxjs/xfa/cjx_packet.cpp
@@ -35,11 +35,10 @@ CJS_Return CJX_Packet::getAttribute(
return CJS_Return(JSGetStringFromID(JSMessage::kParamError));
WideString attributeValue;
- CFX_XMLNode* pXMLNode = GetXFANode()->GetXMLMappingNode();
- if (pXMLNode && pXMLNode->GetType() == FX_XMLNODE_Element) {
- attributeValue = static_cast<CFX_XMLElement*>(pXMLNode)->GetAttribute(
- runtime->ToWideString(params[0]));
- }
+ CFX_XMLElement* element = ToXMLElement(GetXFANode()->GetXMLMappingNode());
+ if (element)
+ attributeValue = element->GetAttribute(runtime->ToWideString(params[0]));
+
return CJS_Return(
runtime->NewString(attributeValue.UTF8Encode().AsStringView()));
}
@@ -50,10 +49,10 @@ CJS_Return CJX_Packet::setAttribute(
if (params.size() != 2)
return CJS_Return(JSGetStringFromID(JSMessage::kParamError));
- CFX_XMLNode* pXMLNode = GetXFANode()->GetXMLMappingNode();
- if (pXMLNode && pXMLNode->GetType() == FX_XMLNODE_Element) {
- static_cast<CFX_XMLElement*>(pXMLNode)->SetAttribute(
- runtime->ToWideString(params[1]), runtime->ToWideString(params[0]));
+ CFX_XMLElement* element = ToXMLElement(GetXFANode()->GetXMLMappingNode());
+ if (element) {
+ element->SetAttribute(runtime->ToWideString(params[1]),
+ runtime->ToWideString(params[0]));
}
return CJS_Return(runtime->NewNull());
}
@@ -64,12 +63,11 @@ CJS_Return CJX_Packet::removeAttribute(
if (params.size() != 1)
return CJS_Return(JSGetStringFromID(JSMessage::kParamError));
- CFX_XMLNode* pXMLNode = GetXFANode()->GetXMLMappingNode();
- if (pXMLNode && pXMLNode->GetType() == FX_XMLNODE_Element) {
+ CFX_XMLElement* pElement = ToXMLElement(GetXFANode()->GetXMLMappingNode());
+ if (pElement) {
WideString name = runtime->ToWideString(params[0]);
- CFX_XMLElement* pXMLElement = static_cast<CFX_XMLElement*>(pXMLNode);
- if (pXMLElement->HasAttribute(name))
- pXMLElement->RemoveAttribute(name);
+ if (pElement->HasAttribute(name))
+ pElement->RemoveAttribute(name);
}
return CJS_Return(runtime->NewNull());
}
@@ -77,25 +75,23 @@ CJS_Return CJX_Packet::removeAttribute(
void CJX_Packet::content(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute) {
- CFX_XMLNode* pXMLNode = GetXFANode()->GetXMLMappingNode();
+ CFX_XMLElement* element = ToXMLElement(GetXFANode()->GetXMLMappingNode());
if (bSetting) {
- if (pXMLNode && pXMLNode->GetType() == FX_XMLNODE_Element) {
- auto* text = GetXFANode()
- ->GetDocument()
- ->GetNotify()
- ->GetHDOC()
- ->GetXMLDocument()
- ->CreateNode<CFX_XMLText>(pValue->ToWideString());
- pXMLNode->AppendChild(text);
+ if (element) {
+ element->AppendChild(
+ GetXFANode()
+ ->GetDocument()
+ ->GetNotify()
+ ->GetHDOC()
+ ->GetXMLDocument()
+ ->CreateNode<CFX_XMLText>(pValue->ToWideString()));
}
return;
}
WideString wsTextData;
- if (pXMLNode && pXMLNode->GetType() == FX_XMLNODE_Element) {
- CFX_XMLElement* pXMLElement = static_cast<CFX_XMLElement*>(pXMLNode);
- wsTextData = pXMLElement->GetTextData();
- }
+ if (element)
+ wsTextData = element->GetTextData();
pValue->SetString(wsTextData.UTF8Encode().AsStringView());
}