Finish gutting logic from CFX_V8

Change-Id: I82d600c5a883c43bae15575e76ff672d1345c89c
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/67530
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/fxjs/cfx_v8.cpp b/fxjs/cfx_v8.cpp
index 41cd44f..3a01aa2 100644
--- a/fxjs/cfx_v8.cpp
+++ b/fxjs/cfx_v8.cpp
@@ -39,52 +39,43 @@
 }
 
 v8::Local<v8::Array> CFX_V8::NewArray() {
-  return v8::Array::New(GetIsolate());
+  return fxv8::NewArrayHelper(GetIsolate());
 }
 
 v8::Local<v8::Object> CFX_V8::NewObject() {
-  return v8::Object::New(GetIsolate());
+  return fxv8::NewObjectHelper(GetIsolate());
 }
 
 bool CFX_V8::PutArrayElement(v8::Local<v8::Array> pArray,
                              unsigned index,
                              v8::Local<v8::Value> pValue) {
-  ASSERT(!pValue.IsEmpty());
-  if (pArray.IsEmpty())
-    return false;
-  return pArray->Set(m_pIsolate->GetCurrentContext(), index, pValue).IsJust();
+  return fxv8::ReentrantPutArrayElementHelper(GetIsolate(), pArray, index,
+                                              pValue);
 }
 
 v8::Local<v8::Value> CFX_V8::GetArrayElement(v8::Local<v8::Array> pArray,
                                              unsigned index) {
-  if (pArray.IsEmpty())
-    return v8::Local<v8::Value>();
-  v8::Local<v8::Value> val;
-  if (!pArray->Get(m_pIsolate->GetCurrentContext(), index).ToLocal(&val))
-    return v8::Local<v8::Value>();
-  return val;
+  return fxv8::ReentrantGetArrayElementHelper(GetIsolate(), pArray, index);
 }
 
 unsigned CFX_V8::GetArrayLength(v8::Local<v8::Array> pArray) {
-  if (pArray.IsEmpty())
-    return 0;
-  return pArray->Length();
+  return fxv8::GetArrayLengthHelper(pArray);
 }
 
 v8::Local<v8::Number> CFX_V8::NewNumber(int number) {
-  return v8::Int32::New(GetIsolate(), number);
+  return fxv8::NewNumberHelper(GetIsolate(), number);
 }
 
 v8::Local<v8::Number> CFX_V8::NewNumber(double number) {
-  return v8::Number::New(GetIsolate(), number);
+  return fxv8::NewNumberHelper(GetIsolate(), number);
 }
 
 v8::Local<v8::Number> CFX_V8::NewNumber(float number) {
-  return v8::Number::New(GetIsolate(), number);
+  return fxv8::NewNumberHelper(GetIsolate(), number);
 }
 
 v8::Local<v8::Boolean> CFX_V8::NewBoolean(bool b) {
-  return v8::Boolean::New(GetIsolate(), b);
+  return fxv8::NewBooleanHelper(GetIsolate(), b);
 }
 
 v8::Local<v8::String> CFX_V8::NewString(ByteStringView str) {
@@ -100,17 +91,15 @@
 }
 
 v8::Local<v8::Value> CFX_V8::NewNull() {
-  return v8::Null(GetIsolate());
+  return fxv8::NewNullHelper(GetIsolate());
 }
 
 v8::Local<v8::Value> CFX_V8::NewUndefined() {
-  return v8::Undefined(GetIsolate());
+  return fxv8::NewUndefinedHelper(GetIsolate());
 }
 
 v8::Local<v8::Date> CFX_V8::NewDate(double d) {
-  return v8::Date::New(m_pIsolate->GetCurrentContext(), d)
-      .ToLocalChecked()
-      .As<v8::Date>();
+  return fxv8::NewDateHelper(GetIsolate(), d);
 }
 
 int CFX_V8::ToInt32(v8::Local<v8::Value> pValue) {
@@ -134,17 +123,11 @@
 }
 
 v8::Local<v8::Object> CFX_V8::ToObject(v8::Local<v8::Value> pValue) {
-  if (pValue.IsEmpty() || !pValue->IsObject())
-    return v8::Local<v8::Object>();
-  v8::Local<v8::Context> context = m_pIsolate->GetCurrentContext();
-  return pValue->ToObject(context).ToLocalChecked();
+  return fxv8::ReentrantToObjectHelper(GetIsolate(), pValue);
 }
 
 v8::Local<v8::Array> CFX_V8::ToArray(v8::Local<v8::Value> pValue) {
-  if (pValue.IsEmpty() || !pValue->IsArray())
-    return v8::Local<v8::Array>();
-  v8::Local<v8::Context> context = m_pIsolate->GetCurrentContext();
-  return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked());
+  return fxv8::ReentrantToArrayHelper(GetIsolate(), pValue);
 }
 
 void* CFX_V8ArrayBufferAllocator::Allocate(size_t length) {
diff --git a/fxjs/fxv8.cpp b/fxjs/fxv8.cpp
index 7b52d0b..1c7abd8 100644
--- a/fxjs/fxv8.cpp
+++ b/fxjs/fxv8.cpp
@@ -8,6 +8,30 @@
 
 namespace fxv8 {
 
+v8::Local<v8::Value> NewNullHelper(v8::Isolate* pIsolate) {
+  return v8::Null(pIsolate);
+}
+
+v8::Local<v8::Value> NewUndefinedHelper(v8::Isolate* pIsolate) {
+  return v8::Undefined(pIsolate);
+}
+
+v8::Local<v8::Number> NewNumberHelper(v8::Isolate* pIsolate, int number) {
+  return v8::Int32::New(pIsolate, number);
+}
+
+v8::Local<v8::Number> NewNumberHelper(v8::Isolate* pIsolate, double number) {
+  return v8::Number::New(pIsolate, number);
+}
+
+v8::Local<v8::Number> NewNumberHelper(v8::Isolate* pIsolate, float number) {
+  return v8::Number::New(pIsolate, number);
+}
+
+v8::Local<v8::Boolean> NewBooleanHelper(v8::Isolate* pIsolate, bool b) {
+  return v8::Boolean::New(pIsolate, b);
+}
+
 v8::Local<v8::String> NewStringHelper(v8::Isolate* pIsolate,
                                       ByteStringView str) {
   return v8::String::NewFromUtf8(pIsolate, str.unterminated_c_str(),
@@ -20,6 +44,20 @@
   return NewStringHelper(pIsolate, FX_UTF8Encode(str).AsStringView());
 }
 
+v8::Local<v8::Array> NewArrayHelper(v8::Isolate* pIsolate) {
+  return v8::Array::New(pIsolate);
+}
+
+v8::Local<v8::Object> NewObjectHelper(v8::Isolate* pIsolate) {
+  return v8::Object::New(pIsolate);
+}
+
+v8::Local<v8::Date> NewDateHelper(v8::Isolate* pIsolate, double d) {
+  return v8::Date::New(pIsolate->GetCurrentContext(), d)
+      .ToLocalChecked()
+      .As<v8::Date>();
+}
+
 int ReentrantToInt32Helper(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue) {
   if (pValue.IsEmpty())
     return 0;
@@ -68,6 +106,22 @@
   return ByteString(*s);
 }
 
+v8::Local<v8::Object> ReentrantToObjectHelper(v8::Isolate* pIsolate,
+                                              v8::Local<v8::Value> pValue) {
+  if (pValue.IsEmpty() || !pValue->IsObject())
+    return v8::Local<v8::Object>();
+  v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
+  return pValue->ToObject(context).ToLocalChecked();
+}
+
+v8::Local<v8::Array> ReentrantToArrayHelper(v8::Isolate* pIsolate,
+                                            v8::Local<v8::Value> pValue) {
+  if (pValue.IsEmpty() || !pValue->IsArray())
+    return v8::Local<v8::Array>();
+  v8::Local<v8::Context> context = pIsolate->GetCurrentContext();
+  return v8::Local<v8::Array>::Cast(pValue->ToObject(context).ToLocalChecked());
+}
+
 v8::Local<v8::Value> ReentrantGetObjectPropertyHelper(
     v8::Isolate* pIsolate,
     v8::Local<v8::Object> pObj,
@@ -115,6 +169,32 @@
   return pObj->Set(pIsolate->GetCurrentContext(), name, pPut).IsJust();
 }
 
+bool ReentrantPutArrayElementHelper(v8::Isolate* pIsolate,
+                                    v8::Local<v8::Array> pArray,
+                                    unsigned index,
+                                    v8::Local<v8::Value> pValue) {
+  if (pArray.IsEmpty())
+    return false;
+  return pArray->Set(pIsolate->GetCurrentContext(), index, pValue).IsJust();
+}
+
+v8::Local<v8::Value> ReentrantGetArrayElementHelper(v8::Isolate* pIsolate,
+                                                    v8::Local<v8::Array> pArray,
+                                                    unsigned index) {
+  if (pArray.IsEmpty())
+    return v8::Local<v8::Value>();
+  v8::Local<v8::Value> val;
+  if (!pArray->Get(pIsolate->GetCurrentContext(), index).ToLocal(&val))
+    return v8::Local<v8::Value>();
+  return val;
+}
+
+unsigned GetArrayLengthHelper(v8::Local<v8::Array> pArray) {
+  if (pArray.IsEmpty())
+    return 0;
+  return pArray->Length();
+}
+
 void ThrowExceptionHelper(v8::Isolate* pIsolate, ByteStringView str) {
   pIsolate->ThrowException(NewStringHelper(pIsolate, str));
 }
diff --git a/fxjs/fxv8.h b/fxjs/fxv8.h
index 6c05d76..f1f35ec 100644
--- a/fxjs/fxv8.h
+++ b/fxjs/fxv8.h
@@ -14,10 +14,19 @@
 
 namespace fxv8 {
 
+v8::Local<v8::Value> NewNullHelper(v8::Isolate* pIsolate);
+v8::Local<v8::Value> NewUndefinedHelper(v8::Isolate* pIsolate);
+v8::Local<v8::Number> NewNumberHelper(v8::Isolate* pIsolate, int number);
+v8::Local<v8::Number> NewNumberHelper(v8::Isolate* pIsolate, double number);
+v8::Local<v8::Number> NewNumberHelper(v8::Isolate* pIsolate, float number);
+v8::Local<v8::Boolean> NewBooleanHelper(v8::Isolate* pIsolate, bool b);
 v8::Local<v8::String> NewStringHelper(v8::Isolate* pIsolate,
                                       ByteStringView str);
 v8::Local<v8::String> NewStringHelper(v8::Isolate* pIsolate,
                                       WideStringView str);
+v8::Local<v8::Array> NewArrayHelper(v8::Isolate* pIsolate);
+v8::Local<v8::Object> NewObjectHelper(v8::Isolate* pIsolate);
+v8::Local<v8::Date> NewDateHelper(v8::Isolate* pIsolate, double d);
 
 int ReentrantToInt32Helper(v8::Isolate* pIsolate, v8::Local<v8::Value> pValue);
 bool ReentrantToBooleanHelper(v8::Isolate* pIsolate,
@@ -28,6 +37,10 @@
                                        v8::Local<v8::Value> pValue);
 ByteString ReentrantToByteStringHelper(v8::Isolate* pIsolate,
                                        v8::Local<v8::Value> pValue);
+v8::Local<v8::Object> ReentrantToObjectHelper(v8::Isolate* pIsolate,
+                                              v8::Local<v8::Value> pValue);
+v8::Local<v8::Array> ReentrantToArrayHelper(v8::Isolate* pIsolate,
+                                            v8::Local<v8::Value> pValue);
 
 v8::Local<v8::Value> ReentrantGetObjectPropertyHelper(
     v8::Isolate* pIsolate,
@@ -40,6 +53,15 @@
                                       v8::Local<v8::Object> pObj,
                                       ByteStringView bsUTF8PropertyName,
                                       v8::Local<v8::Value> pPut);
+bool ReentrantPutArrayElementHelper(v8::Isolate* pIsolate,
+                                    v8::Local<v8::Array> pArray,
+                                    unsigned index,
+                                    v8::Local<v8::Value> pValue);
+v8::Local<v8::Value> ReentrantGetArrayElementHelper(v8::Isolate* pIsolate,
+                                                    v8::Local<v8::Array> pArray,
+                                                    unsigned index);
+
+unsigned GetArrayLengthHelper(v8::Local<v8::Array> pArray);
 
 void ThrowExceptionHelper(v8::Isolate* pIsolate, ByteStringView str);
 void ThrowExceptionHelper(v8::Isolate* pIsolate, WideStringView str);