Avoid more default ANSI strings in fxjs.

Treat everything as UTF-8/16/WideString when originated in V8.

Change-Id: Ib7beee3428f62893673dc8fa4d12ae6374e7701a
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/93790
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/fxjs/cjs_annot.cpp b/fxjs/cjs_annot.cpp
index 3c89b0d..af3d409 100644
--- a/fxjs/cjs_annot.cpp
+++ b/fxjs/cjs_annot.cpp
@@ -102,9 +102,7 @@
     return CJS_Result::Failure(JSMessage::kBadObjectError);
 
   return CJS_Result::Success(pRuntime->NewString(
-      WideString::FromDefANSI(
-          CPDF_Annot::AnnotSubtypeToString(pBAAnnot->GetAnnotSubtype())
-              .AsStringView())
+      CPDF_Annot::AnnotSubtypeToString(pBAAnnot->GetAnnotSubtype())
           .AsStringView()));
 }
 
diff --git a/fxjs/cjs_field.cpp b/fxjs/cjs_field.cpp
index 2bd3eaa..ff8f49a 100644
--- a/fxjs/cjs_field.cpp
+++ b/fxjs/cjs_field.cpp
@@ -759,7 +759,7 @@
   if (!m_bCanSet)
     return CJS_Result::Failure(JSMessage::kReadOnlyError);
 
-  ByteString byte_str = pRuntime->ToWideString(vp).ToDefANSI();
+  ByteString byte_str = pRuntime->ToByteString(vp);
   if (m_bDelay) {
     AddDelay_String(FP_BORDERSTYLE, byte_str);
   } else {
@@ -1886,8 +1886,7 @@
       csBCaption = "check";
       break;
   }
-  return CJS_Result::Success(pRuntime->NewString(
-      WideString::FromDefANSI(csBCaption.AsStringView()).AsStringView()));
+  return CJS_Result::Success(pRuntime->NewString(csBCaption.AsStringView()));
 }
 
 CJS_Result CJS_Field::set_style(CJS_Runtime* pRuntime,
@@ -1983,7 +1982,7 @@
 
   if (!m_bCanSet)
     return CJS_Result::Failure(JSMessage::kReadOnlyError);
-  if (pRuntime->ToWideString(vp).ToDefANSI().IsEmpty())
+  if (pRuntime->ToByteString(vp).IsEmpty())
     return CJS_Result::Failure(JSMessage::kValueError);
   return CJS_Result::Success();
 }
diff --git a/fxjs/cjs_publicmethods.cpp b/fxjs/cjs_publicmethods.cpp
index b55e26a..4f0dc66 100644
--- a/fxjs/cjs_publicmethods.cpp
+++ b/fxjs/cjs_publicmethods.cpp
@@ -326,9 +326,8 @@
     return pRuntime->ToArray(val);
 
   DCHECK(val->IsString());
-  WideString wsStr = pRuntime->ToWideString(val);
-  ByteString t = wsStr.ToDefANSI();
-  const char* p = t.c_str();
+  ByteString bsVal = pRuntime->ToByteString(val);
+  const char* p = bsVal.c_str();
 
   int nIndex = 0;
   v8::Local<v8::Array> StrArray = pRuntime->NewArray();
@@ -602,7 +601,7 @@
     return CJS_Result::Failure(WideString::FromASCII("No event handler"));
 
   WideString& Value = pEventContext->Value();
-  ByteString strValue = StrTrim(Value.ToDefANSI());
+  ByteString strValue = StrTrim(Value.ToUTF8());
   if (strValue.IsEmpty())
     return CJS_Result::Success();
 
@@ -648,7 +647,7 @@
   }
 
   // Processing currency string
-  Value = WideString::FromDefANSI(strValue.AsStringView());
+  Value = WideString::FromUTF8(strValue.AsStringView());
   if (bCurrencyPrepend)
     Value = wstrCurrency + Value;
   else
@@ -815,7 +814,7 @@
     return CJS_Result::Success();
   }
 
-  ByteString strValue = StrTrim(Value.ToDefANSI());
+  ByteString strValue = StrTrim(Value.ToUTF8());
   if (strValue.IsEmpty())
     strValue = "0";
 
@@ -866,7 +865,7 @@
     strValue.InsertAtFront('%');
   else
     strValue.InsertAtBack('%');
-  Value = WideString::FromDefANSI(strValue.AsStringView());
+  Value = WideString::FromUTF8(strValue.AsStringView());
 #endif
   return CJS_Result::Success();
 }
@@ -1391,7 +1390,7 @@
   if (pEvent->Value().IsEmpty())
     return CJS_Result::Success();
 
-  double dEentValue = atof(pEvent->Value().ToDefANSI().c_str());
+  double dEventValue = atof(pEvent->Value().ToUTF8().c_str());
   bool bGreaterThan = pRuntime->ToBoolean(params[0]);
   double dGreaterThan = pRuntime->ToDouble(params[1]);
   bool bLessThan = pRuntime->ToBoolean(params[2]);
@@ -1399,18 +1398,18 @@
   WideString swMsg;
 
   if (bGreaterThan && bLessThan) {
-    if (dEentValue < dGreaterThan || dEentValue > dLessThan)
+    if (dEventValue < dGreaterThan || dEventValue > dLessThan)
       swMsg = WideString::Format(
           JSGetStringFromID(JSMessage::kRangeBetweenError).c_str(),
           pRuntime->ToWideString(params[1]).c_str(),
           pRuntime->ToWideString(params[3]).c_str());
   } else if (bGreaterThan) {
-    if (dEentValue < dGreaterThan)
+    if (dEventValue < dGreaterThan)
       swMsg = WideString::Format(
           JSGetStringFromID(JSMessage::kRangeGreaterError).c_str(),
           pRuntime->ToWideString(params[1]).c_str());
   } else if (bLessThan) {
-    if (dEentValue > dLessThan)
+    if (dEventValue > dLessThan)
       swMsg = WideString::Format(
           JSGetStringFromID(JSMessage::kRangeLessError).c_str(),
           pRuntime->ToWideString(params[3]).c_str());
diff --git a/fxjs/cjs_runtime.cpp b/fxjs/cjs_runtime.cpp
index 53568c0..ceea14d 100644
--- a/fxjs/cjs_runtime.cpp
+++ b/fxjs/cjs_runtime.cpp
@@ -213,17 +213,16 @@
     v8::Local<v8::Value> value) {
   bool bAllowNaN = false;
   if (value->IsString()) {
-    ByteString bstr = ToWideString(value).ToDefANSI();
+    ByteString bstr = fxv8::ToByteString(GetIsolate(), value.As<v8::String>());
     if (bstr.IsEmpty())
       return value;
     if (bstr == "NaN")
       bAllowNaN = true;
   }
 
-  v8::Isolate* pIsolate = GetIsolate();
-  v8::TryCatch try_catch(pIsolate);
+  v8::TryCatch try_catch(GetIsolate());
   v8::MaybeLocal<v8::Number> maybeNum =
-      value->ToNumber(pIsolate->GetCurrentContext());
+      value->ToNumber(GetIsolate()->GetCurrentContext());
   if (maybeNum.IsEmpty())
     return value;
 
diff --git a/fxjs/js_resources.cpp b/fxjs/js_resources.cpp
index 8fb88a4..4f11e27 100644
--- a/fxjs/js_resources.cpp
+++ b/fxjs/js_resources.cpp
@@ -102,10 +102,10 @@
 WideString JSFormatErrorString(const char* class_name,
                                const char* property_name,
                                const WideString& details) {
-  WideString result = WideString::FromDefANSI(class_name);
+  WideString result = WideString::FromUTF8(class_name);
   if (property_name) {
     result += L".";
-    result += WideString::FromDefANSI(property_name);
+    result += WideString::FromUTF8(property_name);
   }
   result += L": ";
   result += details;