Catch more exceptions from reentrant V8 conversions.

Avoid tripping a check in debug builds.

- Move these down to a lower level to cover all possible callers
- Update one test that no longer sees the caught exception.
- Use GetIsolate() more consistently while we're at it.

Bug: chromium:1112206
Change-Id: Idd3cd4ecb68b929740f564fd780cde4b5623e630
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/72671
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/fxjs/fxv8.cpp b/fxjs/fxv8.cpp
index b655d2d..4d5804c 100644
--- a/fxjs/fxv8.cpp
+++ b/fxjs/fxv8.cpp
@@ -61,6 +61,7 @@
 int ReentrantToInt32Helper(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue) {
   if (pValue.IsEmpty())
     return 0;
+  v8::TryCatch squash_exceptions(pIsolate);
   return pValue->Int32Value(pIsolate->GetCurrentContext()).FromMaybe(0);
 }
 
@@ -68,6 +69,7 @@
                               v8::Local<v8::Value> pValue) {
   if (pValue.IsEmpty())
     return false;
+  v8::TryCatch squash_exceptions(pIsolate);
   return pValue->BooleanValue(pIsolate);
 }
 
@@ -75,6 +77,7 @@
                                v8::Local<v8::Value> pValue) {
   if (pValue.IsEmpty())
     return 0.0;
+  v8::TryCatch squash_exceptions(pIsolate);
   return pValue->NumberValue(pIsolate->GetCurrentContext()).FromMaybe(0.0);
 }
 
@@ -83,6 +86,7 @@
   if (pValue.IsEmpty())
     return WideString();
 
+  v8::TryCatch squash_exceptions(pIsolate);
   v8::MaybeLocal<v8::String> maybe_string =
       pValue->ToString(pIsolate->GetCurrentContext());
   if (maybe_string.IsEmpty())
@@ -97,6 +101,7 @@
   if (pValue.IsEmpty())
     return ByteString();
 
+  v8::TryCatch squash_exceptions(pIsolate);
   v8::MaybeLocal<v8::String> maybe_string =
       pValue->ToString(pIsolate->GetCurrentContext());
   if (maybe_string.IsEmpty())
@@ -110,6 +115,8 @@
                                               v8::Local<v8::Value> pValue) {
   if (pValue.IsEmpty() || !pValue->IsObject())
     return v8::Local<v8::Object>();
+
+  v8::TryCatch squash_exceptions(pIsolate);
   v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
   return pValue->ToObject(context).ToLocalChecked();
 }
@@ -118,6 +125,8 @@
                                             v8::Local<v8::Value> pValue) {
   if (pValue.IsEmpty() || !pValue->IsArray())
     return v8::Local<v8::Array>();
+
+  v8::TryCatch squash_exceptions(pIsolate);
   v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
   return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked());
 }
@@ -129,6 +138,7 @@
   if (pObj.IsEmpty())
     return v8::Local<v8::Value>();
 
+  v8::TryCatch squash_exceptions(pIsolate);
   v8::Local<v8::Value> val;
   if (!pObj->Get(pIsolate->GetCurrentContext(),
                  NewStringHelper(pIsolate, bsUTF8PropertyName))
@@ -144,6 +154,7 @@
   if (pObj.IsEmpty())
     return std::vector<WideString>();
 
+  v8::TryCatch squash_exceptions(pIsolate);
   v8::Local<v8::Array> val;
   v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
   if (!pObj->GetPropertyNames(context).ToLocal(&val))
@@ -165,6 +176,7 @@
   if (pObj.IsEmpty())
     return false;
 
+  v8::TryCatch squash_exceptions(pIsolate);
   v8::Local<v8::String> name = NewStringHelper(pIsolate, bsUTF8PropertyName);
   v8::Maybe<bool> result = pObj->Set(pIsolate->GetCurrentContext(), name, pPut);
   return result.IsJust() && result.FromJust();
@@ -177,6 +189,7 @@
   if (pArray.IsEmpty())
     return false;
 
+  v8::TryCatch squash_exceptions(pIsolate);
   v8::Maybe<bool> result =
       pArray->Set(pIsolate->GetCurrentContext(), index, pValue);
   return result.IsJust() && result.FromJust();
@@ -187,6 +200,8 @@
                                                     unsigned index) {
   if (pArray.IsEmpty())
     return v8::Local<v8::Value>();
+
+  v8::TryCatch squash_exceptions(pIsolate);
   v8::Local<v8::Value> val;
   if (!pArray->Get(pIsolate->GetCurrentContext(), index).ToLocal(&val))
     return v8::Local<v8::Value>();