summaryrefslogtreecommitdiff
path: root/fxjs
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-08-08 17:49:02 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-08-08 17:49:02 +0000
commit34dab07ed6e826666fd0589069f2c9b5bd2ba4dc (patch)
tree0eb30bd1c76f54890a6d365258a7157ae9972748 /fxjs
parent6d9897b103aef10b369eb999a40c22011a8ae4f5 (diff)
downloadpdfium-34dab07ed6e826666fd0589069f2c9b5bd2ba4dc.tar.xz
Move ByteString::FromUnicode() to WideString::ToDefANSI()
Turns out that "FromUnicode" is misleading in that, on linux, it simply removes any characters beyond 0xFF and passes the rest unchanged, so no unicode decoding actually takes place. On Windows, it passes it into the system function specifying FX_CODEPAGE_DefANSI, converting it into the so-called "default ANSI code plane", passing some characters, converting others to '?' and still others to 'A'. Either way, nothing resembling UTF8 comes out of this, so pick a better name. These now immediately look suspicious, so a follow-up CL will see which ones should really be WideString::UTF8Encode() instead. Making this a normal method on a widestring rather than a static method on a bytestring feels more natural; this is parallel to the UTF8Encode and UTF16LE_Encode functions. Add a test that shows these conversions. Change-Id: Ia7551b47199eba61b5c328a97bfe9176ac8e583c Reviewed-on: https://pdfium-review.googlesource.com/39690 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'fxjs')
-rw-r--r--fxjs/cfxjse_class.cpp3
-rw-r--r--fxjs/cjs_field.cpp4
-rw-r--r--fxjs/cjs_global.cpp18
-rw-r--r--fxjs/cjs_publicmethods.cpp8
-rw-r--r--fxjs/cjs_runtime.cpp2
5 files changed, 16 insertions, 19 deletions
diff --git a/fxjs/cfxjse_class.cpp b/fxjs/cfxjse_class.cpp
index e7e54c8867..9207fd5094 100644
--- a/fxjs/cfxjse_class.cpp
+++ b/fxjs/cfxjse_class.cpp
@@ -112,8 +112,7 @@ void DynPropGetterAdapter_MethodCallback(
WideString err = JSFormatErrorString(pClassDescriptor->name, *szPropName,
result.Error());
v8::MaybeLocal<v8::String> str = v8::String::NewFromUtf8(
- info.GetIsolate(), ByteString::FromUnicode(err).c_str(),
- v8::NewStringType::kNormal);
+ info.GetIsolate(), err.ToDefANSI().c_str(), v8::NewStringType::kNormal);
info.GetIsolate()->ThrowException(str.ToLocalChecked());
return;
}
diff --git a/fxjs/cjs_field.cpp b/fxjs/cjs_field.cpp
index 19e6712f2a..cd97372ad0 100644
--- a/fxjs/cjs_field.cpp
+++ b/fxjs/cjs_field.cpp
@@ -731,7 +731,7 @@ CJS_Return CJS_Field::set_border_style(CJS_Runtime* pRuntime,
if (!m_bCanSet)
return CJS_Return(JSMessage::kReadOnlyError);
- ByteString byte_str = ByteString::FromUnicode(pRuntime->ToWideString(vp));
+ ByteString byte_str = pRuntime->ToWideString(vp).ToDefANSI();
if (m_bDelay) {
AddDelay_String(FP_BORDERSTYLE, byte_str);
} else {
@@ -2002,7 +2002,7 @@ CJS_Return CJS_Field::set_text_font(CJS_Runtime* pRuntime,
if (!m_bCanSet)
return CJS_Return(JSMessage::kReadOnlyError);
- if (ByteString::FromUnicode(pRuntime->ToWideString(vp)).IsEmpty())
+ if (pRuntime->ToWideString(vp).ToDefANSI().IsEmpty())
return CJS_Return(JSMessage::kValueError);
return CJS_Return();
}
diff --git a/fxjs/cjs_global.cpp b/fxjs/cjs_global.cpp
index 567d54853c..1865f57ddb 100644
--- a/fxjs/cjs_global.cpp
+++ b/fxjs/cjs_global.cpp
@@ -232,7 +232,7 @@ CJS_Return CJS_Global::QueryProperty(const wchar_t* propname) {
CJS_Return CJS_Global::DelProperty(CJS_Runtime* pRuntime,
const wchar_t* propname) {
- auto it = m_MapGlobal.find(ByteString::FromUnicode(propname));
+ auto it = m_MapGlobal.find(WideString(propname).ToDefANSI());
if (it == m_MapGlobal.end())
return CJS_Return(JSMessage::kUnknownProperty);
@@ -242,7 +242,7 @@ CJS_Return CJS_Global::DelProperty(CJS_Runtime* pRuntime,
CJS_Return CJS_Global::GetProperty(CJS_Runtime* pRuntime,
const wchar_t* propname) {
- auto it = m_MapGlobal.find(ByteString::FromUnicode(propname));
+ auto it = m_MapGlobal.find(WideString(propname).ToDefANSI());
if (it == m_MapGlobal.end())
return CJS_Return();
@@ -272,7 +272,7 @@ CJS_Return CJS_Global::GetProperty(CJS_Runtime* pRuntime,
CJS_Return CJS_Global::SetProperty(CJS_Runtime* pRuntime,
const wchar_t* propname,
v8::Local<v8::Value> vp) {
- ByteString sPropName = ByteString::FromUnicode(propname);
+ ByteString sPropName = WideString(propname).ToDefANSI();
if (vp->IsNumber()) {
return SetGlobalVariables(sPropName, JS_GlobalDataType::NUMBER,
pRuntime->ToDouble(vp), false, "",
@@ -284,10 +284,9 @@ CJS_Return CJS_Global::SetProperty(CJS_Runtime* pRuntime,
v8::Local<v8::Object>(), false);
}
if (vp->IsString()) {
- return SetGlobalVariables(
- sPropName, JS_GlobalDataType::STRING, 0, false,
- ByteString::FromUnicode(pRuntime->ToWideString(vp)),
- v8::Local<v8::Object>(), false);
+ return SetGlobalVariables(sPropName, JS_GlobalDataType::STRING, 0, false,
+ pRuntime->ToWideString(vp).ToDefANSI(),
+ v8::Local<v8::Object>(), false);
}
if (vp->IsObject()) {
return SetGlobalVariables(sPropName, JS_GlobalDataType::OBJECT, 0, false,
@@ -310,8 +309,7 @@ CJS_Return CJS_Global::setPersistent(
if (params.size() != 2)
return CJS_Return(JSMessage::kParamError);
- auto it = m_MapGlobal.find(
- ByteString::FromUnicode(pRuntime->ToWideString(params[0])));
+ auto it = m_MapGlobal.find(pRuntime->ToWideString(params[0]).ToDefANSI());
if (it == m_MapGlobal.end() || it->second->bDeleted)
return CJS_Return(JSMessage::kGlobalNotFoundError);
@@ -432,7 +430,7 @@ void CJS_Global::ObjectToArray(CJS_Runtime* pRuntime,
continue;
}
if (v->IsString()) {
- ByteString sValue = ByteString::FromUnicode(pRuntime->ToWideString(v));
+ ByteString sValue = pRuntime->ToWideString(v).ToDefANSI();
CJS_KeyValue* pObjElement = new CJS_KeyValue;
pObjElement->nType = JS_GlobalDataType::STRING;
pObjElement->sKey = sKey;
diff --git a/fxjs/cjs_publicmethods.cpp b/fxjs/cjs_publicmethods.cpp
index a86ece3461..f2cd3ff7c1 100644
--- a/fxjs/cjs_publicmethods.cpp
+++ b/fxjs/cjs_publicmethods.cpp
@@ -327,7 +327,7 @@ v8::Local<v8::Array> CJS_PublicMethods::AF_MakeArrayFromList(
return pRuntime->ToArray(val);
WideString wsStr = pRuntime->ToWideString(val);
- ByteString t = ByteString::FromUnicode(wsStr);
+ ByteString t = wsStr.ToDefANSI();
const char* p = t.c_str();
int nIndex = 0;
@@ -882,7 +882,7 @@ CJS_Return CJS_PublicMethods::AFNumber_Format(
return CJS_Return(L"No event handler");
WideString& Value = pEvent->Value();
- ByteString strValue = StrTrim(ByteString::FromUnicode(Value));
+ ByteString strValue = StrTrim(Value.ToDefANSI());
if (strValue.IsEmpty())
return CJS_Return();
@@ -1078,7 +1078,7 @@ CJS_Return CJS_PublicMethods::AFPercent_Format(
return CJS_Return(JSMessage::kBadObjectError);
WideString& Value = pEvent->Value();
- ByteString strValue = StrTrim(ByteString::FromUnicode(Value));
+ ByteString strValue = StrTrim(Value.ToDefANSI());
if (strValue.IsEmpty())
return CJS_Return();
@@ -1683,7 +1683,7 @@ CJS_Return CJS_PublicMethods::AFRange_Validate(
if (pEvent->Value().IsEmpty())
return CJS_Return();
- double dEentValue = atof(ByteString::FromUnicode(pEvent->Value()).c_str());
+ double dEentValue = atof(pEvent->Value().ToDefANSI().c_str());
bool bGreaterThan = pRuntime->ToBoolean(params[0]);
double dGreaterThan = pRuntime->ToDouble(params[1]);
bool bLessThan = pRuntime->ToBoolean(params[2]);
diff --git a/fxjs/cjs_runtime.cpp b/fxjs/cjs_runtime.cpp
index 9329a483f4..6042538e30 100644
--- a/fxjs/cjs_runtime.cpp
+++ b/fxjs/cjs_runtime.cpp
@@ -234,7 +234,7 @@ v8::Local<v8::Value> CJS_Runtime::MaybeCoerceToNumber(
v8::Local<v8::Value> value) {
bool bAllowNaN = false;
if (value->IsString()) {
- ByteString bstr = ByteString::FromUnicode(ToWideString(value));
+ ByteString bstr = ToWideString(value).ToDefANSI();
if (bstr.GetLength() == 0)
return value;
if (bstr == "NaN")