Replace calls to v8::Isolate::GetCurrent(), part 3

Fixed: pdfium:1737
Change-Id: I3b83015078ad46a733b18e54299be592d5b164a2
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/86296
Commit-Queue: Daniel Hosseinian <dhoss@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/fxjs/cfxjs_engine.cpp b/fxjs/cfxjs_engine.cpp
index 9f15613..6335c2a 100644
--- a/fxjs/cfxjs_engine.cpp
+++ b/fxjs/cfxjs_engine.cpp
@@ -638,7 +638,8 @@
 }
 
 // static
-CJS_Object* CFXJS_Engine::GetObjectPrivate(v8::Local<v8::Object> pObj) {
+CJS_Object* CFXJS_Engine::GetObjectPrivate(v8::Isolate* pIsolate,
+                                           v8::Local<v8::Object> pObj) {
   auto* pData = CFXJS_PerObjectData::GetFromObject(pObj);
   if (pData)
     return pData->m_pPrivate.get();
@@ -656,7 +657,7 @@
   if (!pProtoData)
     return nullptr;
 
-  auto* pIsolateData = FXJS_PerIsolateData::Get(v8::Isolate::GetCurrent());
+  auto* pIsolateData = FXJS_PerIsolateData::Get(pIsolate);
   if (!pIsolateData)
     return nullptr;
 
diff --git a/fxjs/cfxjs_engine.h b/fxjs/cfxjs_engine.h
index 45dc664..7094c3f 100644
--- a/fxjs/cfxjs_engine.h
+++ b/fxjs/cfxjs_engine.h
@@ -84,7 +84,8 @@
   using Destructor = std::function<void(v8::Local<v8::Object> obj)>;
 
   static uint32_t GetObjDefnID(v8::Local<v8::Object> pObj);
-  static CJS_Object* GetObjectPrivate(v8::Local<v8::Object> pObj);
+  static CJS_Object* GetObjectPrivate(v8::Isolate* pIsolate,
+                                      v8::Local<v8::Object> pObj);
   static void SetObjectPrivate(v8::Local<v8::Object> pObj,
                                std::unique_ptr<CJS_Object> p);
   static void FreeObjectPrivate(v8::Local<v8::Object> pObj);
diff --git a/fxjs/cjs_app.cpp b/fxjs/cjs_app.cpp
index c9f1ca6..b3f2de2 100644
--- a/fxjs/cjs_app.cpp
+++ b/fxjs/cjs_app.cpp
@@ -93,7 +93,7 @@
 
 CJS_Result CJS_App::get_active_docs(CJS_Runtime* pRuntime) {
   v8::Local<v8::Object> pObj = pRuntime->GetThisObj();
-  auto pJSDocument = JSGetObject<CJS_Document>(pObj);
+  auto pJSDocument = JSGetObject<CJS_Document>(pRuntime->GetIsolate(), pObj);
   if (!pJSDocument)
     return CJS_Result::Failure(JSMessage::kObjectTypeError);
   v8::Local<v8::Array> aDocs = pRuntime->NewArray();
@@ -317,8 +317,8 @@
   if (pRetObj.IsEmpty())
     return CJS_Result::Failure(JSMessage::kBadObjectError);
 
-  auto* pJS_TimerObj =
-      static_cast<CJS_TimerObj*>(CFXJS_Engine::GetObjectPrivate(pRetObj));
+  auto* pJS_TimerObj = static_cast<CJS_TimerObj*>(
+      CFXJS_Engine::GetObjectPrivate(pRuntime->GetIsolate(), pRetObj));
 
   pJS_TimerObj->SetTimer(pTimerRef);
   return CJS_Result::Success(pRetObj);
@@ -346,8 +346,8 @@
   if (pRetObj.IsEmpty())
     return CJS_Result::Failure(JSMessage::kBadObjectError);
 
-  auto* pJS_TimerObj =
-      static_cast<CJS_TimerObj*>(CFXJS_Engine::GetObjectPrivate(pRetObj));
+  auto* pJS_TimerObj = static_cast<CJS_TimerObj*>(
+      CFXJS_Engine::GetObjectPrivate(pRuntime->GetIsolate(), pRetObj));
 
   pJS_TimerObj->SetTimer(pTimerRef);
   return CJS_Result::Success(pRetObj);
@@ -379,7 +379,7 @@
     return;
 
   v8::Local<v8::Object> pObj = pRuntime->ToObject(param);
-  auto pTimer = JSGetObject<CJS_TimerObj>(pObj);
+  auto pTimer = JSGetObject<CJS_TimerObj>(pRuntime->GetIsolate(), pObj);
   if (!pTimer)
     return;
 
diff --git a/fxjs/cjs_document.cpp b/fxjs/cjs_document.cpp
index 7520da2..3f598cd 100644
--- a/fxjs/cjs_document.cpp
+++ b/fxjs/cjs_document.cpp
@@ -260,8 +260,8 @@
   if (pFieldObj.IsEmpty())
     return CJS_Result::Failure(JSMessage::kBadObjectError);
 
-  auto* pJSField =
-      static_cast<CJS_Field*>(CFXJS_Engine::GetObjectPrivate(pFieldObj));
+  auto* pJSField = static_cast<CJS_Field*>(
+      CFXJS_Engine::GetObjectPrivate(pRuntime->GetIsolate(), pFieldObj));
   if (!pJSField)
     return CJS_Result::Failure(JSMessage::kBadObjectError);
 
@@ -1038,8 +1038,8 @@
   if (pObj.IsEmpty())
     return CJS_Result::Failure(JSMessage::kBadObjectError);
 
-  auto* pJS_Annot =
-      static_cast<CJS_Annot*>(CFXJS_Engine::GetObjectPrivate(pObj));
+  auto* pJS_Annot = static_cast<CJS_Annot*>(
+      CFXJS_Engine::GetObjectPrivate(pRuntime->GetIsolate(), pObj));
   if (!pJS_Annot)
     return CJS_Result::Failure(JSMessage::kBadObjectError);
 
@@ -1073,8 +1073,8 @@
       if (pObj.IsEmpty())
         return CJS_Result::Failure(JSMessage::kBadObjectError);
 
-      auto* pJS_Annot =
-          static_cast<CJS_Annot*>(CFXJS_Engine::GetObjectPrivate(pObj));
+      auto* pJS_Annot = static_cast<CJS_Annot*>(
+          CFXJS_Engine::GetObjectPrivate(pRuntime->GetIsolate(), pObj));
       pJS_Annot->SetSDKAnnot(pSDKAnnotCur->AsBAAnnot());
       pRuntime->PutArrayElement(
           annots, i,
@@ -1119,7 +1119,7 @@
     return CJS_Result::Failure(JSMessage::kTypeError);
 
   v8::Local<v8::Object> pObj = pRuntime->ToObject(params[1]);
-  if (!JSGetObject<CJS_Icon>(pObj))
+  if (!JSGetObject<CJS_Icon>(pRuntime->GetIsolate(), pObj))
     return CJS_Result::Failure(JSMessage::kTypeError);
 
   WideString swIconName = pRuntime->ToWideString(params[0]);
@@ -1141,8 +1141,8 @@
     if (pObj.IsEmpty())
       return CJS_Result::Failure(JSMessage::kBadObjectError);
 
-    auto* pJS_Icon =
-        static_cast<CJS_Icon*>(CFXJS_Engine::GetObjectPrivate(pObj));
+    auto* pJS_Icon = static_cast<CJS_Icon*>(
+        CFXJS_Engine::GetObjectPrivate(pRuntime->GetIsolate(), pObj));
     pJS_Icon->SetIconName(name);
     pRuntime->PutArrayElement(Icons, i++,
                               pJS_Icon
@@ -1173,7 +1173,8 @@
   if (pObj.IsEmpty())
     return CJS_Result::Failure(JSMessage::kBadObjectError);
 
-  auto* pJSIcon = static_cast<CJS_Icon*>(CFXJS_Engine::GetObjectPrivate(pObj));
+  auto* pJSIcon = static_cast<CJS_Icon*>(
+      CFXJS_Engine::GetObjectPrivate(pRuntime->GetIsolate(), pObj));
   if (!pJSIcon)
     return CJS_Result::Failure(JSMessage::kBadObjectError);
 
diff --git a/fxjs/cjs_event_context.cpp b/fxjs/cjs_event_context.cpp
index 888d429..302d011 100644
--- a/fxjs/cjs_event_context.cpp
+++ b/fxjs/cjs_event_context.cpp
@@ -65,12 +65,12 @@
     return nullptr;
 
   auto* pFormFillEnv = GetFormFillEnv();
-  auto* pJSDocument =
-      static_cast<CJS_Document*>(CFXJS_Engine::GetObjectPrivate(pDocObj));
+  auto* pJSDocument = static_cast<CJS_Document*>(
+      CFXJS_Engine::GetObjectPrivate(m_pRuntime->GetIsolate(), pDocObj));
   pJSDocument->SetFormFillEnv(pFormFillEnv);
 
-  auto* pJSField =
-      static_cast<CJS_Field*>(CFXJS_Engine::GetObjectPrivate(pFieldObj));
+  auto* pJSField = static_cast<CJS_Field*>(
+      CFXJS_Engine::GetObjectPrivate(m_pRuntime->GetIsolate(), pFieldObj));
   pJSField->AttachField(pJSDocument, SourceName());
   return pJSField;
 }
@@ -87,12 +87,12 @@
     return nullptr;
 
   auto* pFormFillEnv = GetFormFillEnv();
-  auto* pJSDocument =
-      static_cast<CJS_Document*>(CFXJS_Engine::GetObjectPrivate(pDocObj));
+  auto* pJSDocument = static_cast<CJS_Document*>(
+      CFXJS_Engine::GetObjectPrivate(m_pRuntime->GetIsolate(), pDocObj));
   pJSDocument->SetFormFillEnv(pFormFillEnv);
 
-  auto* pJSField =
-      static_cast<CJS_Field*>(CFXJS_Engine::GetObjectPrivate(pFieldObj));
+  auto* pJSField = static_cast<CJS_Field*>(
+      CFXJS_Engine::GetObjectPrivate(m_pRuntime->GetIsolate(), pFieldObj));
   pJSField->AttachField(pJSDocument, TargetName());
   return pJSField;
 }
diff --git a/fxjs/cjs_field.cpp b/fxjs/cjs_field.cpp
index 3ffae49..e6addf8 100644
--- a/fxjs/cjs_field.cpp
+++ b/fxjs/cjs_field.cpp
@@ -2264,7 +2264,8 @@
   if (pObj.IsEmpty())
     return CJS_Result::Failure(JSMessage::kBadObjectError);
 
-  auto* pJS_Icon = static_cast<CJS_Icon*>(CFXJS_Engine::GetObjectPrivate(pObj));
+  auto* pJS_Icon = static_cast<CJS_Icon*>(
+      CFXJS_Engine::GetObjectPrivate(pRuntime->GetIsolate(), pObj));
   return pJS_Icon ? CJS_Result::Success(pJS_Icon->ToV8Object())
                   : CJS_Result::Failure(JSMessage::kBadObjectError);
 }
@@ -2377,8 +2378,8 @@
     if (pObj.IsEmpty())
       return CJS_Result::Failure(JSMessage::kBadObjectError);
 
-    auto* pJSField =
-        static_cast<CJS_Field*>(CFXJS_Engine::GetObjectPrivate(pObj));
+    auto* pJSField = static_cast<CJS_Field*>(
+        CFXJS_Engine::GetObjectPrivate(pRuntime->GetIsolate(), pObj));
     pJSField->AttachField(m_pJSDoc.Get(), *pStr);
     pRuntime->PutArrayElement(FormFieldArray, j++,
                               pJSField
diff --git a/fxjs/cjs_global.cpp b/fxjs/cjs_global.cpp
index 5d10ae7..849c00f 100644
--- a/fxjs/cjs_global.cpp
+++ b/fxjs/cjs_global.cpp
@@ -25,7 +25,7 @@
 
 void JSSpecialPropQuery(v8::Local<v8::String> property,
                         const v8::PropertyCallbackInfo<v8::Integer>& info) {
-  auto pObj = JSGetObject<CJS_Global>(info.Holder());
+  auto pObj = JSGetObject<CJS_Global>(info.GetIsolate(), info.Holder());
   if (!pObj)
     return;
 
@@ -44,7 +44,7 @@
 
 void JSSpecialPropGet(v8::Local<v8::String> property,
                       const v8::PropertyCallbackInfo<v8::Value>& info) {
-  auto pObj = JSGetObject<CJS_Global>(info.Holder());
+  auto pObj = JSGetObject<CJS_Global>(info.GetIsolate(), info.Holder());
   if (!pObj)
     return;
 
@@ -66,7 +66,7 @@
 void JSSpecialPropPut(v8::Local<v8::String> property,
                       v8::Local<v8::Value> value,
                       const v8::PropertyCallbackInfo<v8::Value>& info) {
-  auto pObj = JSGetObject<CJS_Global>(info.Holder());
+  auto pObj = JSGetObject<CJS_Global>(info.GetIsolate(), info.Holder());
   if (!pObj)
     return;
 
@@ -84,7 +84,7 @@
 
 void JSSpecialPropDel(v8::Local<v8::String> property,
                       const v8::PropertyCallbackInfo<v8::Boolean>& info) {
-  auto pObj = JSGetObject<CJS_Global>(info.Holder());
+  auto pObj = JSGetObject<CJS_Global>(info.GetIsolate(), info.Holder());
   if (!pObj)
     return;
 
diff --git a/fxjs/cjs_globalarrays.cpp b/fxjs/cjs_globalarrays.cpp
index 407b620..89b2b68 100644
--- a/fxjs/cjs_globalarrays.cpp
+++ b/fxjs/cjs_globalarrays.cpp
@@ -10,21 +10,22 @@
 #include "v8/include/v8-container.h"
 #include "v8/include/v8-isolate.h"
 
-#define GLOBAL_ARRAY(rt, name, ...)                                          \
-  {                                                                          \
-    static const wchar_t* const values[] = {__VA_ARGS__};                    \
-    v8::Local<v8::Array> array = (rt)->NewArray();                           \
-    v8::Local<v8::Context> ctx = (rt)->GetIsolate()->GetCurrentContext();    \
-    for (size_t i = 0; i < pdfium::size(values); ++i)                        \
-      array->Set(ctx, i, (rt)->NewString(values[i])).FromJust();             \
-    (rt)->SetConstArray((name), array);                                      \
-    (rt)->DefineGlobalConst(                                                 \
-        (name), [](const v8::FunctionCallbackInfo<v8::Value>& info) {        \
-          CJS_Object* pObj = CFXJS_Engine::GetObjectPrivate(info.Holder());  \
-          CJS_Runtime* pCurrentRuntime = pObj->GetRuntime();                 \
-          if (pCurrentRuntime)                                               \
-            info.GetReturnValue().Set(pCurrentRuntime->GetConstArray(name)); \
-        });                                                                  \
+#define GLOBAL_ARRAY(rt, name, ...)                                            \
+  {                                                                            \
+    static const wchar_t* const values[] = {__VA_ARGS__};                      \
+    v8::Local<v8::Array> array = (rt)->NewArray();                             \
+    v8::Local<v8::Context> ctx = (rt)->GetIsolate()->GetCurrentContext();      \
+    for (size_t i = 0; i < pdfium::size(values); ++i)                          \
+      array->Set(ctx, i, (rt)->NewString(values[i])).FromJust();               \
+    (rt)->SetConstArray((name), array);                                        \
+    (rt)->DefineGlobalConst(                                                   \
+        (name), [](const v8::FunctionCallbackInfo<v8::Value>& info) {          \
+          CJS_Object* pObj = CFXJS_Engine::GetObjectPrivate(info.GetIsolate(), \
+                                                            info.Holder());    \
+          CJS_Runtime* pCurrentRuntime = pObj->GetRuntime();                   \
+          if (pCurrentRuntime)                                                 \
+            info.GetReturnValue().Set(pCurrentRuntime->GetConstArray(name));   \
+        });                                                                    \
   }
 
 // static
diff --git a/fxjs/cjs_publicmethods.cpp b/fxjs/cjs_publicmethods.cpp
index 420551d..d724f2e 100644
--- a/fxjs/cjs_publicmethods.cpp
+++ b/fxjs/cjs_publicmethods.cpp
@@ -141,7 +141,8 @@
                           const std::vector<v8::Local<v8::Value>>&)>
 void JSGlobalFunc(const char* func_name_string,
                   const v8::FunctionCallbackInfo<v8::Value>& info) {
-  CJS_Object* pObj = CFXJS_Engine::GetObjectPrivate(info.Holder());
+  CJS_Object* pObj =
+      CFXJS_Engine::GetObjectPrivate(info.GetIsolate(), info.Holder());
   if (!pObj)
     return;
 
diff --git a/fxjs/cjs_runtime.cpp b/fxjs/cjs_runtime.cpp
index 91d2499..53568c0 100644
--- a/fxjs/cjs_runtime.cpp
+++ b/fxjs/cjs_runtime.cpp
@@ -155,7 +155,7 @@
   if (pThis.IsEmpty())
     return;
 
-  auto pJSDocument = JSGetObject<CJS_Document>(pThis);
+  auto pJSDocument = JSGetObject<CJS_Document>(GetIsolate(), pThis);
   if (!pJSDocument)
     return;
 
diff --git a/fxjs/js_define.h b/fxjs/js_define.h
index a4314d7..17f4ed7 100644
--- a/fxjs/js_define.h
+++ b/fxjs/js_define.h
@@ -51,11 +51,11 @@
 void JSDestructor(v8::Local<v8::Object> obj);
 
 template <class C>
-UnownedPtr<C> JSGetObject(v8::Local<v8::Object> obj) {
+UnownedPtr<C> JSGetObject(v8::Isolate* isolate, v8::Local<v8::Object> obj) {
   if (CFXJS_Engine::GetObjDefnID(obj) != C::GetObjDefnID())
     return nullptr;
 
-  CJS_Object* pJSObj = CFXJS_Engine::GetObjectPrivate(obj);
+  CJS_Object* pJSObj = CFXJS_Engine::GetObjectPrivate(isolate, obj);
   if (!pJSObj)
     return nullptr;
 
@@ -67,7 +67,7 @@
                   const char* class_name_string,
                   v8::Local<v8::String> property,
                   const v8::PropertyCallbackInfo<v8::Value>& info) {
-  auto pObj = JSGetObject<C>(info.Holder());
+  auto pObj = JSGetObject<C>(info.GetIsolate(), info.Holder());
   if (!pObj)
     return;
 
@@ -92,7 +92,7 @@
                   v8::Local<v8::String> property,
                   v8::Local<v8::Value> value,
                   const v8::PropertyCallbackInfo<void>& info) {
-  auto pObj = JSGetObject<C>(info.Holder());
+  auto pObj = JSGetObject<C>(info.GetIsolate(), info.Holder());
   if (!pObj)
     return;
 
@@ -113,7 +113,7 @@
 void JSMethod(const char* method_name_string,
               const char* class_name_string,
               const v8::FunctionCallbackInfo<v8::Value>& info) {
-  auto pObj = JSGetObject<C>(info.Holder());
+  auto pObj = JSGetObject<C>(info.GetIsolate(), info.Holder());
   if (!pObj)
     return;