From 701d21682af1aa3f7f449d2da9681ee01dc8990d Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Wed, 24 Jan 2018 16:01:54 +0000 Subject: Update code to assume a Value node exists. When we retrieve the first Value node from a Field or a Draw element it either must exist, or must be created. If that doesn't happen something has gone very wrong. Change-Id: I818aaf9d361336c898035fe542e5b37a33fef0ea Reviewed-on: https://pdfium-review.googlesource.com/23710 Reviewed-by: Ryan Harrison Commit-Queue: dsinclair --- xfa/fxfa/parser/cxfa_node.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp index 1fd96f427b..970459f6ed 100644 --- a/xfa/fxfa/parser/cxfa_node.cpp +++ b/xfa/fxfa/parser/cxfa_node.cpp @@ -2522,10 +2522,15 @@ std::pair CXFA_Node::CreateUIChild() { XFA_Element eWidgetType = XFA_Element::Unknown; XFA_Element eUIType = XFA_Element::Unknown; - auto* defValue = + + // Both Field and Draw nodes have a Value child. So, we should either always + // have it, or always create it. If we don't get the Value child for some + // reason something has gone really wrong. + CXFA_Value* value = JSObject()->GetOrCreateProperty(0, XFA_Element::Value); - XFA_Element eValueType = - defValue ? defValue->GetChildValueClassID() : XFA_Element::Unknown; + ASSERT(value); + + XFA_Element eValueType = value->GetChildValueClassID(); switch (eValueType) { case XFA_Element::Boolean: eUIType = XFA_Element::CheckButton; @@ -2606,10 +2611,7 @@ std::pair CXFA_Node::CreateUIChild() { if (!pUIChild) { if (eUIType == XFA_Element::Unknown) { eUIType = XFA_Element::TextEdit; - if (defValue) { - defValue->JSObject()->GetOrCreateProperty(0, - XFA_Element::Text); - } + value->JSObject()->GetOrCreateProperty(0, XFA_Element::Text); } return {eWidgetType, pUI ? pUI->JSObject()->GetOrCreateProperty(0, eUIType) @@ -2656,8 +2658,7 @@ std::pair CXFA_Node::CreateUIChild() { eValueType = XFA_Element::Text; break; } - if (defValue) - defValue->JSObject()->GetOrCreateProperty(0, eValueType); + value->JSObject()->GetOrCreateProperty(0, eValueType); return {eWidgetType, pUIChild}; } -- cgit v1.2.3