Annotation deleted while retrieving it in JS
Widgets as returned from GetWidgets() can pop out of existence
unexpectedly, so always return observed pointers. This extends
the same pattern used elsewhere in the file to all occurrences.
BUG=679642
Review-Url: https://codereview.chromium.org/2624933002
diff --git a/fpdfsdk/javascript/Document.cpp b/fpdfsdk/javascript/Document.cpp
index 29f9764..7e4dc26 100644
--- a/fpdfsdk/javascript/Document.cpp
+++ b/fpdfsdk/javascript/Document.cpp
@@ -506,12 +506,16 @@
CJS_Runtime* pRuntime = pContext->GetJSRuntime();
CFX_WideString sFieldName = params[0].ToCFXWideString(pRuntime);
CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm();
- std::vector<CPDFSDK_Widget*> widgets;
+ std::vector<CPDFSDK_Annot::ObservedPtr> widgets;
pInterForm->GetWidgets(sFieldName, &widgets);
if (widgets.empty())
return true;
- for (CPDFSDK_Widget* pWidget : widgets) {
+ for (const auto& pAnnot : widgets) {
+ CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot.Get());
+ if (!pWidget)
+ continue;
+
CFX_FloatRect rcAnnot = pWidget->GetRect();
--rcAnnot.left;
--rcAnnot.bottom;