Pass UFT8 ByteStringVies as arguments to {Get,Set}ObjectProperty().

Avoids widening then narrowing in a few cases, and removes some wide
literals.

Change-Id: I5fd3fed7043ba4b9ec56a7b33a37fb1eba71e12d
Reviewed-on: https://pdfium-review.googlesource.com/c/47132
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/fxjs/cfx_v8.cpp b/fxjs/cfx_v8.cpp
index bd0e5eb..58b30e5 100644
--- a/fxjs/cfx_v8.cpp
+++ b/fxjs/cfx_v8.cpp
@@ -15,12 +15,11 @@
 
 v8::Local<v8::Value> CFX_V8::GetObjectProperty(
     v8::Local<v8::Object> pObj,
-    const WideString& wsPropertyName) {
+    const ByteStringView& bsUTF8PropertyName) {
   if (pObj.IsEmpty())
     return v8::Local<v8::Value>();
   v8::Local<v8::Value> val;
-  if (!pObj->Get(m_pIsolate->GetCurrentContext(),
-                 NewString(wsPropertyName.AsStringView()))
+  if (!pObj->Get(m_pIsolate->GetCurrentContext(), NewString(bsUTF8PropertyName))
            .ToLocal(&val))
     return v8::Local<v8::Value>();
   return val;
@@ -45,12 +44,12 @@
 }
 
 void CFX_V8::PutObjectProperty(v8::Local<v8::Object> pObj,
-                               const WideString& wsPropertyName,
+                               const ByteStringView& bsUTF8PropertyName,
                                v8::Local<v8::Value> pPut) {
   if (pObj.IsEmpty())
     return;
-  pObj->Set(m_pIsolate->GetCurrentContext(),
-            NewString(wsPropertyName.AsStringView()), pPut)
+  pObj->Set(m_pIsolate->GetCurrentContext(), NewString(bsUTF8PropertyName),
+            pPut)
       .FromJust();
 }
 
diff --git a/fxjs/cfx_v8.h b/fxjs/cfx_v8.h
index 70d3655..73fb3ac 100644
--- a/fxjs/cfx_v8.h
+++ b/fxjs/cfx_v8.h
@@ -50,10 +50,11 @@
 
   // Objects.
   std::vector<WideString> GetObjectPropertyNames(v8::Local<v8::Object> pObj);
-  v8::Local<v8::Value> GetObjectProperty(v8::Local<v8::Object> pObj,
-                                         const WideString& PropertyName);
+  v8::Local<v8::Value> GetObjectProperty(
+      v8::Local<v8::Object> pObj,
+      const ByteStringView& bsUTF8PropertyName);
   void PutObjectProperty(v8::Local<v8::Object> pObj,
-                         const WideString& PropertyName,
+                         const ByteStringView& bsUTF8PropertyName,
                          v8::Local<v8::Value> pValue);
 
  protected:
diff --git a/fxjs/cfx_v8_unittest.cpp b/fxjs/cfx_v8_unittest.cpp
index 91188c3..077abfd 100644
--- a/fxjs/cfx_v8_unittest.cpp
+++ b/fxjs/cfx_v8_unittest.cpp
@@ -187,13 +187,13 @@
   auto object = cfx_v8()->NewObject();
   ASSERT_FALSE(object.IsEmpty());
   EXPECT_EQ(0u, cfx_v8()->GetObjectPropertyNames(object).size());
-  EXPECT_FALSE(cfx_v8()->GetObjectProperty(object, L"clams").IsEmpty());
-  EXPECT_TRUE(cfx_v8()->GetObjectProperty(object, L"clams")->IsUndefined());
+  EXPECT_FALSE(cfx_v8()->GetObjectProperty(object, "clams").IsEmpty());
+  EXPECT_TRUE(cfx_v8()->GetObjectProperty(object, "clams")->IsUndefined());
   EXPECT_EQ(0u, cfx_v8()->GetObjectPropertyNames(object).size());
 
-  cfx_v8()->PutObjectProperty(object, L"clams", cfx_v8()->NewNumber(12));
-  EXPECT_FALSE(cfx_v8()->GetObjectProperty(object, L"clams").IsEmpty());
-  EXPECT_TRUE(cfx_v8()->GetObjectProperty(object, L"clams")->IsNumber());
+  cfx_v8()->PutObjectProperty(object, "clams", cfx_v8()->NewNumber(12));
+  EXPECT_FALSE(cfx_v8()->GetObjectProperty(object, "clams").IsEmpty());
+  EXPECT_TRUE(cfx_v8()->GetObjectProperty(object, "clams")->IsNumber());
   EXPECT_EQ(1u, cfx_v8()->GetObjectPropertyNames(object).size());
   EXPECT_EQ(L"clams", cfx_v8()->GetObjectPropertyNames(object)[0]);
 
diff --git a/fxjs/cfxjs_engine_embeddertest.cpp b/fxjs/cfxjs_engine_embeddertest.cpp
index a9422ec..bef0f28 100644
--- a/fxjs/cfxjs_engine_embeddertest.cpp
+++ b/fxjs/cfxjs_engine_embeddertest.cpp
@@ -25,7 +25,7 @@
                                     double expected) {
   v8::Context::Scope context_scope(current_engine->GetV8Context());
   v8::Local<v8::Object> This = current_engine->GetThisObj();
-  v8::Local<v8::Value> fred = current_engine->GetObjectProperty(This, L"fred");
+  v8::Local<v8::Value> fred = current_engine->GetObjectProperty(This, "fred");
   EXPECT_TRUE(fred->IsNumber());
   EXPECT_EQ(expected, current_engine->ToDouble(fred));
 }
diff --git a/fxjs/cjs_app.cpp b/fxjs/cjs_app.cpp
index f279250..d241d03 100644
--- a/fxjs/cjs_app.cpp
+++ b/fxjs/cjs_app.cpp
@@ -224,7 +224,7 @@
 CJS_Result CJS_App::alert(CJS_Runtime* pRuntime,
                           const std::vector<v8::Local<v8::Value>>& params) {
   std::vector<v8::Local<v8::Value>> newParams = ExpandKeywordParams(
-      pRuntime, params, 4, L"cMsg", L"nIcon", L"nType", L"cTitle");
+      pRuntime, params, 4, "cMsg", "nIcon", "nType", "cTitle");
 
   if (!IsExpandedParamKnown(newParams[0]))
     return CJS_Result::Failure(JSMessage::kParamError);
@@ -433,9 +433,8 @@
 
 CJS_Result CJS_App::mailMsg(CJS_Runtime* pRuntime,
                             const std::vector<v8::Local<v8::Value>>& params) {
-  std::vector<v8::Local<v8::Value>> newParams =
-      ExpandKeywordParams(pRuntime, params, 6, L"bUI", L"cTo", L"cCc", L"cBcc",
-                          L"cSubject", L"cMsg");
+  std::vector<v8::Local<v8::Value>> newParams = ExpandKeywordParams(
+      pRuntime, params, 6, "bUI", "cTo", "cCc", "cBcc", "cSubject", "cMsg");
 
   if (!IsExpandedParamKnown(newParams[0]))
     return CJS_Result::Failure(JSMessage::kParamError);
@@ -532,8 +531,8 @@
 CJS_Result CJS_App::response(CJS_Runtime* pRuntime,
                              const std::vector<v8::Local<v8::Value>>& params) {
   std::vector<v8::Local<v8::Value>> newParams =
-      ExpandKeywordParams(pRuntime, params, 5, L"cQuestion", L"cTitle",
-                          L"cDefault", L"bPassword", L"cLabel");
+      ExpandKeywordParams(pRuntime, params, 5, "cQuestion", "cTitle",
+                          "cDefault", "bPassword", "cLabel");
 
   if (!IsExpandedParamKnown(newParams[0]))
     return CJS_Result::Failure(JSMessage::kParamError);
diff --git a/fxjs/cjs_document.cpp b/fxjs/cjs_document.cpp
index 926e731..336e9ea 100644
--- a/fxjs/cjs_document.cpp
+++ b/fxjs/cjs_document.cpp
@@ -380,9 +380,8 @@
   if (!m_pFormFillEnv)
     return CJS_Result::Failure(JSMessage::kBadObjectError);
 
-  std::vector<v8::Local<v8::Value>> newParams =
-      ExpandKeywordParams(pRuntime, params, 6, L"bUI", L"cTo", L"cCc", L"cBcc",
-                          L"cSubject", L"cMsg");
+  std::vector<v8::Local<v8::Value>> newParams = ExpandKeywordParams(
+      pRuntime, params, 6, "bUI", "cTo", "cCc", "cBcc", "cSubject", "cMsg");
 
   bool bUI = true;
   if (IsExpandedParamKnown(newParams[0]))
@@ -431,9 +430,8 @@
   if (sTextBuf.GetLength() == 0)
     return CJS_Result::Failure(L"Bad FDF format.");
 
-  std::vector<v8::Local<v8::Value>> newParams =
-      ExpandKeywordParams(pRuntime, params, 6, L"bUI", L"cTo", L"cCc", L"cBcc",
-                          L"cSubject", L"cMsg");
+  std::vector<v8::Local<v8::Value>> newParams = ExpandKeywordParams(
+      pRuntime, params, 6, "bUI", "cTo", "cCc", "cBcc", "cSubject", "cMsg");
 
   bool bUI = true;
   if (IsExpandedParamKnown(newParams[0]))
@@ -471,8 +469,8 @@
     CJS_Runtime* pRuntime,
     const std::vector<v8::Local<v8::Value>>& params) {
   std::vector<v8::Local<v8::Value>> newParams = ExpandKeywordParams(
-      pRuntime, params, 8, L"bUI", L"nStart", L"nEnd", L"bSilent",
-      L"bShrinkToFit", L"bPrintAsImage", L"bReverse", L"bAnnotations");
+      pRuntime, params, 8, "bUI", "nStart", "nEnd", "bSilent", "bShrinkToFit",
+      "bPrintAsImage", "bReverse", "bAnnotations");
 
   bool bUI = true;
   if (IsExpandedParamKnown(newParams[0]))
@@ -645,13 +643,13 @@
       aFields = pRuntime->ToArray(params[3]);
   } else if (params[0]->IsObject()) {
     v8::Local<v8::Object> pObj = pRuntime->ToObject(params[0]);
-    v8::Local<v8::Value> pValue = pRuntime->GetObjectProperty(pObj, L"cURL");
+    v8::Local<v8::Value> pValue = pRuntime->GetObjectProperty(pObj, "cURL");
     if (!pValue.IsEmpty())
       strURL = pRuntime->ToWideString(pValue);
 
-    bFDF = pRuntime->ToBoolean(pRuntime->GetObjectProperty(pObj, L"bFDF"));
-    bEmpty = pRuntime->ToBoolean(pRuntime->GetObjectProperty(pObj, L"bEmpty"));
-    aFields = pRuntime->ToArray(pRuntime->GetObjectProperty(pObj, L"aFields"));
+    bFDF = pRuntime->ToBoolean(pRuntime->GetObjectProperty(pObj, "bFDF"));
+    bEmpty = pRuntime->ToBoolean(pRuntime->GetObjectProperty(pObj, "bEmpty"));
+    aFields = pRuntime->ToArray(pRuntime->GetObjectProperty(pObj, "aFields"));
   }
 
   CPDF_InteractiveForm* pPDFForm = GetCoreInteractiveForm();
@@ -726,24 +724,23 @@
   WideString cwTrapped = pDictionary->GetUnicodeTextFor("Trapped");
 
   v8::Local<v8::Object> pObj = pRuntime->NewObject();
-  pRuntime->PutObjectProperty(pObj, L"Author",
+  pRuntime->PutObjectProperty(pObj, "Author",
                               pRuntime->NewString(cwAuthor.AsStringView()));
-  pRuntime->PutObjectProperty(pObj, L"Title",
+  pRuntime->PutObjectProperty(pObj, "Title",
                               pRuntime->NewString(cwTitle.AsStringView()));
-  pRuntime->PutObjectProperty(pObj, L"Subject",
+  pRuntime->PutObjectProperty(pObj, "Subject",
                               pRuntime->NewString(cwSubject.AsStringView()));
-  pRuntime->PutObjectProperty(pObj, L"Keywords",
+  pRuntime->PutObjectProperty(pObj, "Keywords",
                               pRuntime->NewString(cwKeywords.AsStringView()));
-  pRuntime->PutObjectProperty(pObj, L"Creator",
+  pRuntime->PutObjectProperty(pObj, "Creator",
                               pRuntime->NewString(cwCreator.AsStringView()));
-  pRuntime->PutObjectProperty(pObj, L"Producer",
+  pRuntime->PutObjectProperty(pObj, "Producer",
                               pRuntime->NewString(cwProducer.AsStringView()));
   pRuntime->PutObjectProperty(
-      pObj, L"CreationDate",
-      pRuntime->NewString(cwCreationDate.AsStringView()));
-  pRuntime->PutObjectProperty(pObj, L"ModDate",
+      pObj, "CreationDate", pRuntime->NewString(cwCreationDate.AsStringView()));
+  pRuntime->PutObjectProperty(pObj, "ModDate",
                               pRuntime->NewString(cwModDate.AsStringView()));
-  pRuntime->PutObjectProperty(pObj, L"Trapped",
+  pRuntime->PutObjectProperty(pObj, "Trapped",
                               pRuntime->NewString(cwTrapped.AsStringView()));
 
   // PutObjectProperty() calls below may re-enter JS and change info dict.
@@ -752,17 +749,17 @@
   for (const auto& it : locker) {
     const ByteString& bsKey = it.first;
     CPDF_Object* pValueObj = it.second.get();
-    WideString wsKey = WideString::FromUTF8(bsKey.AsStringView());
     if (pValueObj->IsString() || pValueObj->IsName()) {
       pRuntime->PutObjectProperty(
-          pObj, wsKey,
+          pObj, bsKey.AsStringView(),
           pRuntime->NewString(pValueObj->GetUnicodeText().AsStringView()));
     } else if (pValueObj->IsNumber()) {
-      pRuntime->PutObjectProperty(pObj, wsKey,
+      pRuntime->PutObjectProperty(pObj, bsKey.AsStringView(),
                                   pRuntime->NewNumber(pValueObj->GetNumber()));
     } else if (pValueObj->IsBoolean()) {
       pRuntime->PutObjectProperty(
-          pObj, wsKey, pRuntime->NewBoolean(!!pValueObj->GetInteger()));
+          pObj, bsKey.AsStringView(),
+          pRuntime->NewBoolean(!!pValueObj->GetInteger()));
     }
   }
   return CJS_Result::Success(pObj);
diff --git a/fxjs/cjs_global.cpp b/fxjs/cjs_global.cpp
index 8f67887..28d2214 100644
--- a/fxjs/cjs_global.cpp
+++ b/fxjs/cjs_global.cpp
@@ -327,16 +327,16 @@
         SetGlobalVariables(pData->data.sKey, CFX_Value::DataType::NUMBER,
                            pData->data.dData, false, ByteString(),
                            v8::Local<v8::Object>(), pData->bPersistent == 1);
-        pRuntime->PutObjectProperty(
-            ToV8Object(), WideString::FromUTF8(pData->data.sKey.AsStringView()),
-            pRuntime->NewNumber(pData->data.dData));
+        pRuntime->PutObjectProperty(ToV8Object(),
+                                    pData->data.sKey.AsStringView(),
+                                    pRuntime->NewNumber(pData->data.dData));
         break;
       case CFX_Value::DataType::BOOLEAN:
         SetGlobalVariables(pData->data.sKey, CFX_Value::DataType::BOOLEAN, 0,
                            pData->data.bData == 1, ByteString(),
                            v8::Local<v8::Object>(), pData->bPersistent == 1);
         pRuntime->PutObjectProperty(
-            ToV8Object(), WideString::FromUTF8(pData->data.sKey.AsStringView()),
+            ToV8Object(), pData->data.sKey.AsStringView(),
             pRuntime->NewBoolean(pData->data.bData == 1));
         break;
       case CFX_Value::DataType::STRING:
@@ -344,7 +344,7 @@
                            false, pData->data.sData, v8::Local<v8::Object>(),
                            pData->bPersistent == 1);
         pRuntime->PutObjectProperty(
-            ToV8Object(), WideString::FromUTF8(pData->data.sKey.AsStringView()),
+            ToV8Object(), pData->data.sKey.AsStringView(),
             pRuntime->NewString(
                 WideString::FromUTF8(pData->data.sData.AsStringView())
                     .AsStringView()));
@@ -356,9 +356,8 @@
           SetGlobalVariables(pData->data.sKey, CFX_Value::DataType::OBJECT, 0,
                              false, ByteString(), pObj,
                              pData->bPersistent == 1);
-          pRuntime->PutObjectProperty(
-              ToV8Object(),
-              WideString::FromUTF8(pData->data.sKey.AsStringView()), pObj);
+          pRuntime->PutObjectProperty(ToV8Object(),
+                                      pData->data.sKey.AsStringView(), pObj);
         }
       } break;
       case CFX_Value::DataType::NULLOBJ:
@@ -366,8 +365,7 @@
                            false, ByteString(), v8::Local<v8::Object>(),
                            pData->bPersistent == 1);
         pRuntime->PutObjectProperty(
-            ToV8Object(), WideString::FromUTF8(pData->data.sKey.AsStringView()),
-            pRuntime->NewNull());
+            ToV8Object(), pData->data.sKey.AsStringView(), pRuntime->NewNull());
         break;
     }
   }
@@ -416,7 +414,8 @@
   std::vector<WideString> pKeyList = pRuntime->GetObjectPropertyNames(pObj);
   for (const auto& ws : pKeyList) {
     ByteString sKey = ws.ToUTF8();
-    v8::Local<v8::Value> v = pRuntime->GetObjectProperty(pObj, ws);
+    v8::Local<v8::Value> v =
+        pRuntime->GetObjectProperty(pObj, sKey.AsStringView());
     if (v->IsNumber()) {
       auto pObjElement = pdfium::MakeUnique<CFX_KeyValue>();
       pObjElement->nType = CFX_Value::DataType::NUMBER;
@@ -469,18 +468,16 @@
     CFX_KeyValue* pObjData = pData->objData.GetAt(i);
     switch (pObjData->nType) {
       case CFX_Value::DataType::NUMBER:
-        pRuntime->PutObjectProperty(
-            pObj, WideString::FromUTF8(pObjData->sKey.AsStringView()),
-            pRuntime->NewNumber(pObjData->dData));
+        pRuntime->PutObjectProperty(pObj, pObjData->sKey.AsStringView(),
+                                    pRuntime->NewNumber(pObjData->dData));
         break;
       case CFX_Value::DataType::BOOLEAN:
-        pRuntime->PutObjectProperty(
-            pObj, WideString::FromUTF8(pObjData->sKey.AsStringView()),
-            pRuntime->NewBoolean(pObjData->bData == 1));
+        pRuntime->PutObjectProperty(pObj, pObjData->sKey.AsStringView(),
+                                    pRuntime->NewBoolean(pObjData->bData == 1));
         break;
       case CFX_Value::DataType::STRING:
         pRuntime->PutObjectProperty(
-            pObj, WideString::FromUTF8(pObjData->sKey.AsStringView()),
+            pObj, pObjData->sKey.AsStringView(),
             pRuntime->NewString(
                 WideString::FromUTF8(pObjData->sData.AsStringView())
                     .AsStringView()));
@@ -489,15 +486,13 @@
         v8::Local<v8::Object> pNewObj = pRuntime->NewObject();
         if (!pNewObj.IsEmpty()) {
           PutObjectProperty(pNewObj, pObjData);
-          pRuntime->PutObjectProperty(
-              pObj, WideString::FromUTF8(pObjData->sKey.AsStringView()),
-              pNewObj);
+          pRuntime->PutObjectProperty(pObj, pObjData->sKey.AsStringView(),
+                                      pNewObj);
         }
       } break;
       case CFX_Value::DataType::NULLOBJ:
-        pRuntime->PutObjectProperty(
-            pObj, WideString::FromUTF8(pObjData->sKey.AsStringView()),
-            pRuntime->NewNull());
+        pRuntime->PutObjectProperty(pObj, pObjData->sKey.AsStringView(),
+                                    pRuntime->NewNull());
         break;
     }
   }
diff --git a/fxjs/js_define.cpp b/fxjs/js_define.cpp
index 6089132..0c0c02c 100644
--- a/fxjs/js_define.cpp
+++ b/fxjs/js_define.cpp
@@ -83,7 +83,7 @@
   va_list ap;
   va_start(ap, nKeywords);
   for (size_t i = 0; i < nKeywords; ++i) {
-    const wchar_t* property = va_arg(ap, const wchar_t*);
+    const char* property = va_arg(ap, const char*);
     v8::Local<v8::Value> v8Value = pRuntime->GetObjectProperty(pObj, property);
     if (!v8Value->IsUndefined())
       result[i] = v8Value;