Remove unreachable null checks for CXFA_Document::GetScriptContext().
It asserts that it never returns NULL, so caller's checks are
unreachable. Also kill some needless asserts when immediately
followed by de-ref (since segvs are free).
Change-Id: I1bac6122fb3922c9547d7223c01c4611907e268e
Reviewed-on: https://pdfium-review.googlesource.com/c/49191
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/fxjs/xfa/cfxjse_formcalc_context.cpp b/fxjs/xfa/cfxjse_formcalc_context.cpp
index ae4d096..00ae76f 100644
--- a/fxjs/xfa/cfxjse_formcalc_context.cpp
+++ b/fxjs/xfa/cfxjse_formcalc_context.cpp
@@ -420,7 +420,6 @@
return pMgr->GetLocaleByName(WideString::FromUTF8(szLocale));
CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject());
- ASSERT(pThisNode);
return pThisNode->GetLocale();
}
@@ -2372,7 +2371,6 @@
LocaleIface* pLocale = nullptr;
if (localString.IsEmpty()) {
CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject());
- ASSERT(pThisNode);
pLocale = pThisNode->GetLocale();
} else {
pLocale =
@@ -3686,8 +3684,6 @@
CXFA_Document* pDoc = pContext->GetDocument();
CXFA_LocaleMgr* pMgr = pDoc->GetLocaleMgr();
CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject());
- ASSERT(pThisNode);
-
LocaleIface* pLocale = pThisNode->GetLocale();
WideString wsPattern = WideString::FromUTF8(szPattern.AsStringView());
WideString wsValue = WideString::FromUTF8(szValue.AsStringView());
@@ -3865,8 +3861,6 @@
CXFA_Document* pDoc = pContext->GetDocument();
CXFA_LocaleMgr* pMgr = pDoc->GetLocaleMgr();
CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject());
- ASSERT(pThisNode);
-
LocaleIface* pLocale = pThisNode->GetLocale();
WideString wsPattern = WideString::FromUTF8(szPattern.AsStringView());
WideString wsValue = WideString::FromUTF8(szValue.AsStringView());
diff --git a/fxjs/xfa/cjx_eventpseudomodel.cpp b/fxjs/xfa/cjx_eventpseudomodel.cpp
index 99c155e..4c744f7 100644
--- a/fxjs/xfa/cjx_eventpseudomodel.cpp
+++ b/fxjs/xfa/cjx_eventpseudomodel.cpp
@@ -109,9 +109,6 @@
return;
CFXJSE_Engine* pScriptContext = GetDocument()->GetScriptContext();
- if (!pScriptContext)
- return;
-
CXFA_EventParam* pEventParam = pScriptContext->GetEventParam();
if (!pEventParam)
return;
@@ -177,9 +174,6 @@
CFX_V8* runtime,
const std::vector<v8::Local<v8::Value>>& params) {
CFXJSE_Engine* pScriptContext = GetDocument()->GetScriptContext();
- if (!pScriptContext)
- return CJS_Result::Success();
-
CXFA_EventParam* pEventParam = pScriptContext->GetEventParam();
if (!pEventParam)
return CJS_Result::Success();
@@ -200,9 +194,6 @@
CFX_V8* runtime,
const std::vector<v8::Local<v8::Value>>& params) {
CFXJSE_Engine* pScriptContext = GetDocument()->GetScriptContext();
- if (!pScriptContext)
- return CJS_Result::Success();
-
CXFA_EventParam* pEventParam = pScriptContext->GetEventParam();
if (pEventParam)
*pEventParam = CXFA_EventParam();
@@ -221,9 +212,6 @@
}
CFXJSE_Engine* pScriptContext = GetDocument()->GetScriptContext();
- if (!pScriptContext)
- return;
-
CXFA_EventParam* pEventParam = pScriptContext->GetEventParam();
if (!pEventParam)
return;
diff --git a/fxjs/xfa/cjx_hostpseudomodel.cpp b/fxjs/xfa/cjx_hostpseudomodel.cpp
index 2e7d137..ab132b5 100644
--- a/fxjs/xfa/cjx_hostpseudomodel.cpp
+++ b/fxjs/xfa/cjx_hostpseudomodel.cpp
@@ -281,9 +281,6 @@
ToNode(static_cast<CFXJSE_Engine*>(runtime)->ToXFAObject(params[0]));
} else if (params[0]->IsString()) {
CFXJSE_Engine* pScriptContext = GetDocument()->GetScriptContext();
- if (!pScriptContext)
- return CJS_Result::Success();
-
CXFA_Object* pObject = pScriptContext->GetThisObject();
if (!pObject)
return CJS_Result::Success();
@@ -379,9 +376,6 @@
while (iStart < iExpLength) {
iStart = FilterName(expression.AsStringView(), iStart, wsName);
CFXJSE_Engine* pScriptContext = GetDocument()->GetScriptContext();
- if (!pScriptContext)
- return CJS_Result::Success();
-
CXFA_Object* pObject = pScriptContext->GetThisObject();
if (!pObject)
return CJS_Result::Success();
@@ -444,9 +438,6 @@
ToNode(static_cast<CFXJSE_Engine*>(runtime)->ToXFAObject(params[0]));
} else if (params[0]->IsString()) {
CFXJSE_Engine* pScriptContext = GetDocument()->GetScriptContext();
- if (!pScriptContext)
- return CJS_Result::Success();
-
CXFA_Object* pObject = pScriptContext->GetThisObject();
if (!pObject)
return CJS_Result::Success();
diff --git a/fxjs/xfa/cjx_object.cpp b/fxjs/xfa/cjx_object.cpp
index 654e588..08656ab 100644
--- a/fxjs/xfa/cjx_object.cpp
+++ b/fxjs/xfa/cjx_object.cpp
@@ -774,9 +774,7 @@
if (pNode) {
if (bScriptModify) {
CFXJSE_Engine* pScriptContext = GetDocument()->GetScriptContext();
- if (pScriptContext)
- GetDocument()->GetScriptContext()->AddNodesOfRunScript(
- ToNode(GetXFAObject()));
+ pScriptContext->AddNodesOfRunScript(ToNode(GetXFAObject()));
}
return TryCData(XFA_Attribute::Value, false);
}
diff --git a/fxjs/xfa/cjx_tree.cpp b/fxjs/xfa/cjx_tree.cpp
index 50c90cb..b01a147 100644
--- a/fxjs/xfa/cjx_tree.cpp
+++ b/fxjs/xfa/cjx_tree.cpp
@@ -41,9 +41,6 @@
WideString expression = runtime->ToWideString(params[0]);
CFXJSE_Engine* pScriptContext = GetDocument()->GetScriptContext();
- if (!pScriptContext)
- return CJS_Result::Success();
-
CXFA_Object* refNode = GetXFAObject();
if (refNode->GetElementType() == XFA_Element::Xfa)
refNode = pScriptContext->GetThisObject();
@@ -93,9 +90,6 @@
refNode = GetDocument()->GetScriptContext()->GetThisObject();
CFXJSE_Engine* pScriptContext = GetDocument()->GetScriptContext();
- if (!pScriptContext)
- return CJS_Result::Success();
-
auto pValue = pdfium::MakeUnique<CFXJSE_Value>(pScriptContext->GetIsolate());
ResolveNodeList(pValue.get(), runtime->ToWideString(params[0]),
XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Attributes |
@@ -136,16 +130,13 @@
void CJX_Tree::nodes(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute) {
- CFXJSE_Engine* pScriptContext = GetDocument()->GetScriptContext();
- if (!pScriptContext)
- return;
-
if (bSetting) {
WideString wsMessage = L"Unable to set ";
FXJSE_ThrowMessage(wsMessage.ToUTF8().AsStringView());
return;
}
+ CFXJSE_Engine* pScriptContext = GetDocument()->GetScriptContext();
CXFA_AttachNodeList* pNodeList =
new CXFA_AttachNodeList(GetDocument(), ToNode(GetXFAObject()));
pValue->SetObject(pNodeList, pScriptContext->GetJseNormalClass());
@@ -177,10 +168,6 @@
}
CFXJSE_Engine* pScriptContext = GetDocument()->GetScriptContext();
- if (!pScriptContext) {
- pValue->SetInteger(-1);
- return;
- }
pValue->SetInteger(pScriptContext->GetIndexByName(ToNode(GetXFAObject())));
}
@@ -193,10 +180,6 @@
}
CFXJSE_Engine* pScriptContext = GetDocument()->GetScriptContext();
- if (!pScriptContext) {
- pValue->SetInteger(-1);
- return;
- }
pValue->SetInteger(
pScriptContext->GetIndexByClassName(ToNode(GetXFAObject())));
}
@@ -217,13 +200,11 @@
WideString wsExpression,
uint32_t dwFlag,
CXFA_Node* refNode) {
- CFXJSE_Engine* pScriptContext = GetDocument()->GetScriptContext();
- if (!pScriptContext)
- return;
if (!refNode)
refNode = ToNode(GetXFAObject());
XFA_RESOLVENODE_RS resolveNodeRS;
+ CFXJSE_Engine* pScriptContext = GetDocument()->GetScriptContext();
pScriptContext->ResolveObjects(refNode, wsExpression.AsStringView(),
&resolveNodeRS, dwFlag, nullptr);
CXFA_ArrayNodeList* pNodeList = new CXFA_ArrayNodeList(GetDocument());
diff --git a/xfa/fxfa/cxfa_ffdocview.cpp b/xfa/fxfa/cxfa_ffdocview.cpp
index 985e4ce..87835bb 100644
--- a/xfa/fxfa/cxfa_ffdocview.cpp
+++ b/xfa/fxfa/cxfa_ffdocview.cpp
@@ -405,9 +405,6 @@
CXFA_FFWidget* CXFA_FFDocView::GetWidgetByName(const WideString& wsName,
CXFA_FFWidget* pRefWidget) {
CFXJSE_Engine* pScriptContext = m_pDoc->GetXFADoc()->GetScriptContext();
- if (!pScriptContext)
- return nullptr;
-
CXFA_Node* pRefNode = nullptr;
if (pRefWidget) {
CXFA_Node* node = pRefWidget->GetNode();
diff --git a/xfa/fxfa/parser/cxfa_object.cpp b/xfa/fxfa/parser/cxfa_object.cpp
index 38cc41d..e69d060 100644
--- a/xfa/fxfa/parser/cxfa_object.cpp
+++ b/xfa/fxfa/parser/cxfa_object.cpp
@@ -38,9 +38,6 @@
WideString CXFA_Object::GetSOMExpression() {
CFXJSE_Engine* pScriptContext = m_pDocument->GetScriptContext();
- if (!pScriptContext)
- return WideString();
-
return pScriptContext->GetSomExpression(ToNode(this));
}