Stop using deprecated v8::ObjectTemplate::NewInstance().

Fix nits in affected files.

Change-Id: I3a0363c9b7c28359fd1c7cea305e4f7705a228c2
Reviewed-on: https://pdfium-review.googlesource.com/41355
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/fxjs/cfxjse_class.cpp b/fxjs/cfxjse_class.cpp
index 0d68147..8e49ebe 100644
--- a/fxjs/cfxjse_class.cpp
+++ b/fxjs/cfxjse_class.cpp
@@ -142,7 +142,9 @@
           v8::ObjectTemplate::New(pIsolate);
       hCallBackInfoTemplate->SetInternalFieldCount(2);
       v8::Local<v8::Object> hCallBackInfo =
-          hCallBackInfoTemplate->NewInstance();
+          hCallBackInfoTemplate
+              ->NewInstance(pValue->GetIsolate()->GetCurrentContext())
+              .ToLocalChecked();
       hCallBackInfo->SetAlignedPointerInInternalField(
           0, const_cast<FXJSE_CLASS_DESCRIPTOR*>(lpClass));
       hCallBackInfo->SetInternalField(
@@ -251,6 +253,21 @@
   info.GetReturnValue().Set(v8::Array::New(info.GetIsolate()));
 }
 
+void SetUpNamedPropHandler(v8::Isolate* pIsolate,
+                           v8::Local<v8::ObjectTemplate>* pObjectTemplate,
+                           const FXJSE_CLASS_DESCRIPTOR* lpClassDefinition) {
+  v8::NamedPropertyHandlerConfiguration configuration(
+      lpClassDefinition->dynPropGetter ? NamedPropertyGetterCallback : nullptr,
+      lpClassDefinition->dynPropSetter ? NamedPropertySetterCallback : nullptr,
+      lpClassDefinition->dynPropTypeGetter ? NamedPropertyQueryCallback
+                                           : nullptr,
+      nullptr, NamedPropertyEnumeratorCallback,
+      v8::External::New(pIsolate,
+                        const_cast<FXJSE_CLASS_DESCRIPTOR*>(lpClassDefinition)),
+      v8::PropertyHandlerFlags::kNonMasking);
+  (*pObjectTemplate)->SetHandler(configuration);
+}
+
 }  // namespace
 
 // static
@@ -280,7 +297,7 @@
   hFunctionTemplate->InstanceTemplate()->SetInternalFieldCount(2);
   v8::Local<v8::ObjectTemplate> hObjectTemplate =
       hFunctionTemplate->InstanceTemplate();
-  SetUpNamedPropHandler(pIsolate, hObjectTemplate, lpClassDefinition);
+  SetUpNamedPropHandler(pIsolate, &hObjectTemplate, lpClassDefinition);
 
   if (lpClassDefinition->methNum) {
     for (int32_t i = 0; i < lpClassDefinition->methNum; i++) {
@@ -310,23 +327,6 @@
   return pResult;
 }
 
-// static
-void CFXJSE_Class::SetUpNamedPropHandler(
-    v8::Isolate* pIsolate,
-    v8::Local<v8::ObjectTemplate>& hObjectTemplate,
-    const FXJSE_CLASS_DESCRIPTOR* lpClassDefinition) {
-  v8::NamedPropertyHandlerConfiguration configuration(
-      lpClassDefinition->dynPropGetter ? NamedPropertyGetterCallback : 0,
-      lpClassDefinition->dynPropSetter ? NamedPropertySetterCallback : 0,
-      lpClassDefinition->dynPropTypeGetter ? NamedPropertyQueryCallback : 0, 0,
-      NamedPropertyEnumeratorCallback,
-      v8::External::New(pIsolate,
-                        const_cast<FXJSE_CLASS_DESCRIPTOR*>(lpClassDefinition)),
-      v8::PropertyHandlerFlags::kNonMasking);
-  hObjectTemplate->SetHandler(configuration);
-}
-
-CFXJSE_Class::CFXJSE_Class(CFXJSE_Context* lpContext)
-    : m_lpClassDefinition(nullptr), m_pContext(lpContext) {}
+CFXJSE_Class::CFXJSE_Class(CFXJSE_Context* lpContext) : m_pContext(lpContext) {}
 
 CFXJSE_Class::~CFXJSE_Class() {}
diff --git a/fxjs/cfxjse_class.h b/fxjs/cfxjse_class.h
index 056525f..fd9786e 100644
--- a/fxjs/cfxjse_class.h
+++ b/fxjs/cfxjse_class.h
@@ -20,11 +20,6 @@
                               const FXJSE_CLASS_DESCRIPTOR* lpClassDefintion,
                               bool bIsJSGlobal);
 
-  static void SetUpNamedPropHandler(
-      v8::Isolate* pIsolate,
-      v8::Local<v8::ObjectTemplate>& hObjectTemplate,
-      const FXJSE_CLASS_DESCRIPTOR* lpClassDefinition);
-
   explicit CFXJSE_Class(CFXJSE_Context* lpContext);
   ~CFXJSE_Class();
 
@@ -32,12 +27,13 @@
   v8::Global<v8::FunctionTemplate>& GetTemplate() { return m_hTemplate; }
 
  protected:
-  ByteString m_szClassName;
-  UnownedPtr<const FXJSE_CLASS_DESCRIPTOR> m_lpClassDefinition;
-  UnownedPtr<CFXJSE_Context> m_pContext;
-  v8::Global<v8::FunctionTemplate> m_hTemplate;
   friend class CFXJSE_Context;
   friend class CFXJSE_Value;
+
+  ByteString m_szClassName;
+  UnownedPtr<const FXJSE_CLASS_DESCRIPTOR> m_lpClassDefinition;
+  UnownedPtr<CFXJSE_Context> const m_pContext;
+  v8::Global<v8::FunctionTemplate> m_hTemplate;
 };
 
 #endif  // FXJS_CFXJSE_CLASS_H_
diff --git a/fxjs/cfxjse_engine.cpp b/fxjs/cfxjse_engine.cpp
index a4fc0a2..1812d02 100644
--- a/fxjs/cfxjse_engine.cpp
+++ b/fxjs/cfxjse_engine.cpp
@@ -805,7 +805,9 @@
   v8::EscapableHandleScope scope(GetIsolate());
   v8::Local<v8::FunctionTemplate> klass =
       v8::Local<v8::FunctionTemplate>::New(GetIsolate(), tmpl);
-  v8::Local<v8::Object> object = klass->InstanceTemplate()->NewInstance();
+  v8::Local<v8::Object> object = klass->InstanceTemplate()
+                                     ->NewInstance(m_JsContext->GetContext())
+                                     .ToLocalChecked();
   FXJSE_UpdateObjectBinding(object, obj);
   return scope.Escape(object);
 }
diff --git a/fxjs/cfxjse_value.cpp b/fxjs/cfxjse_value.cpp
index 6afba97..6d0f6f7 100644
--- a/fxjs/cfxjse_value.cpp
+++ b/fxjs/cfxjse_value.cpp
@@ -84,7 +84,10 @@
   CFXJSE_ScopeUtil_IsolateHandleRootContext scope(GetIsolate());
   v8::Local<v8::FunctionTemplate> hClass =
       v8::Local<v8::FunctionTemplate>::New(GetIsolate(), pClass->m_hTemplate);
-  v8::Local<v8::Object> hObject = hClass->InstanceTemplate()->NewInstance();
+  v8::Local<v8::Object> hObject =
+      hClass->InstanceTemplate()
+          ->NewInstance(GetIsolate()->GetCurrentContext())
+          .ToLocalChecked();
   FXJSE_UpdateObjectBinding(hObject, lpObject);
   m_hValue.Reset(GetIsolate(), hObject);
 }
@@ -125,11 +128,11 @@
 
   v8::Local<v8::Value> hPropValue =
       v8::Local<v8::Value>::New(GetIsolate(), lpPropValue->DirectGetValue());
-  return (bool)hObject.As<v8::Object>()->Set(
+  return static_cast<bool>(hObject.As<v8::Object>()->Set(
       v8::String::NewFromUtf8(GetIsolate(), szPropName.unterminated_c_str(),
                               v8::String::kNormalString,
                               szPropName.GetLength()),
-      hPropValue);
+      hPropValue));
 }
 
 bool CFXJSE_Value::GetObjectProperty(const ByteStringView& szPropName,
@@ -159,7 +162,7 @@
 
   v8::Local<v8::Value> hPropValue =
       v8::Local<v8::Value>::New(GetIsolate(), lpPropValue->DirectGetValue());
-  return (bool)hObject.As<v8::Object>()->Set(uPropIdx, hPropValue);
+  return static_cast<bool>(hObject.As<v8::Object>()->Set(uPropIdx, hPropValue));
 }
 
 bool CFXJSE_Value::GetObjectPropertyByIdx(uint32_t uPropIdx,
@@ -219,7 +222,7 @@
       v8::Local<v8::Value>::New(GetIsolate(), lpPropValue->m_hValue);
   return hObject.As<v8::Object>()
       ->DefineOwnProperty(
-          m_pIsolate->GetCurrentContext(),
+          GetIsolate()->GetCurrentContext(),
           v8::String::NewFromUtf8(GetIsolate(), szPropName.unterminated_c_str(),
                                   v8::String::kNormalString,
                                   szPropName.GetLength()),
@@ -249,7 +252,7 @@
       v8::String::NewFromUtf8(GetIsolate(),
                               "(function (oldfunction, newthis) { return "
                               "oldfunction.bind(newthis); })");
-  v8::Local<v8::Context> hContext = m_pIsolate->GetCurrentContext();
+  v8::Local<v8::Context> hContext = GetIsolate()->GetCurrentContext();
   v8::Local<v8::Function> hBinderFunc =
       v8::Script::Compile(hContext, hBinderFuncSource)
           .ToLocalChecked()
diff --git a/fxjs/cfxjse_value.h b/fxjs/cfxjse_value.h
index dd01843..f83ddc3 100644
--- a/fxjs/cfxjse_value.h
+++ b/fxjs/cfxjse_value.h
@@ -88,11 +88,11 @@
   friend class CFXJSE_Class;
   friend class CFXJSE_Context;
 
-  CFXJSE_Value();
-  CFXJSE_Value(const CFXJSE_Value&);
-  CFXJSE_Value& operator=(const CFXJSE_Value&);
+  CFXJSE_Value() = delete;
+  CFXJSE_Value(const CFXJSE_Value&) = delete;
+  CFXJSE_Value& operator=(const CFXJSE_Value&) = delete;
 
-  UnownedPtr<v8::Isolate> m_pIsolate;
+  UnownedPtr<v8::Isolate> const m_pIsolate;
   v8::Global<v8::Value> m_hValue;
 };