Stop using deprecated V8 APIs in CJS_Global.

Also merge Initial() into the ctor.

Change-Id: Ib3cb9619a65a5c33d7c739051c13dfcd7f2324d7
Reviewed-on: https://pdfium-review.googlesource.com/41356
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/fxjs/cjs_global.cpp b/fxjs/cjs_global.cpp
index ea8694f..d9338ab 100644
--- a/fxjs/cjs_global.cpp
+++ b/fxjs/cjs_global.cpp
@@ -113,6 +113,13 @@
   }
 }
 
+template <class T>
+v8::Local<v8::String> GetV8StringFromProperty(v8::Local<v8::Name> property,
+                                              const T& info) {
+  return property->ToString(info.GetIsolate()->GetCurrentContext())
+      .ToLocalChecked();
+}
+
 }  // namespace
 
 CJS_Global::JSGlobalData::JSGlobalData()
@@ -147,7 +154,7 @@
   JSSpecialPropQuery<CJS_Global>(
       "global",
       v8::Local<v8::String>::New(info.GetIsolate(),
-                                 property->ToString(info.GetIsolate())),
+                                 GetV8StringFromProperty(property, info)),
       info);
 }
 
@@ -159,7 +166,7 @@
   JSSpecialPropGet<CJS_Global>(
       "global",
       v8::Local<v8::String>::New(info.GetIsolate(),
-                                 property->ToString(info.GetIsolate())),
+                                 GetV8StringFromProperty(property, info)),
       info);
 }
 
@@ -172,7 +179,7 @@
   JSSpecialPropPut<CJS_Global>(
       "global",
       v8::Local<v8::String>::New(info.GetIsolate(),
-                                 property->ToString(info.GetIsolate())),
+                                 GetV8StringFromProperty(property, info)),
       value, info);
 }
 
@@ -184,7 +191,7 @@
   JSSpecialPropDel<CJS_Global>(
       "global",
       v8::Local<v8::String>::New(info.GetIsolate(),
-                                 property->ToString(info.GetIsolate())),
+                                 GetV8StringFromProperty(property, info)),
       info);
 }
 
@@ -210,7 +217,10 @@
 
 CJS_Global::CJS_Global(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime)
     : CJS_Object(pObject, pRuntime) {
-  Initial(GetRuntime()->GetFormFillEnv());
+  CPDFSDK_FormFillEnvironment* pFormFillEnv = GetRuntime()->GetFormFillEnv();
+  m_pFormFillEnv.Reset(pFormFillEnv);
+  m_pGlobalData = CJS_GlobalData::GetRetainedInstance(pFormFillEnv);
+  UpdateGlobalPersistentVariables();
 }
 
 CJS_Global::~CJS_Global() {
@@ -218,12 +228,6 @@
   m_pGlobalData->Release();
 }
 
-void CJS_Global::Initial(CPDFSDK_FormFillEnvironment* pFormFillEnv) {
-  m_pFormFillEnv.Reset(pFormFillEnv);
-  m_pGlobalData = CJS_GlobalData::GetRetainedInstance(pFormFillEnv);
-  UpdateGlobalPersistentVariables();
-}
-
 CJS_Result CJS_Global::QueryProperty(const wchar_t* propname) {
   if (WideString(propname) != L"setPersistent")
     return CJS_Result::Failure(JSMessage::kUnknownProperty);
diff --git a/fxjs/cjs_global.h b/fxjs/cjs_global.h
index 6ecd6c0..454ddf9 100644
--- a/fxjs/cjs_global.h
+++ b/fxjs/cjs_global.h
@@ -40,7 +40,6 @@
   ~CJS_Global() override;
 
   CJS_Result DelProperty(CJS_Runtime* pRuntime, const wchar_t* propname);
-  void Initial(CPDFSDK_FormFillEnvironment* pFormFillEnv);
 
   CJS_Result setPersistent(CJS_Runtime* pRuntime,
                            const std::vector<v8::Local<v8::Value>>& params);