Remove raw wchar_t* usage from CJS_Global.
Avoid converting to c_str() format, then duplicating the string
as a WideString, as we already start with a WideString.
Change-Id: I874e34251e061f05665d210d4c3b9ac2601881df
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/86650
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/fxjs/cjs_global.cpp b/fxjs/cjs_global.cpp
index e55252b..b6e18ea 100644
--- a/fxjs/cjs_global.cpp
+++ b/fxjs/cjs_global.cpp
@@ -34,7 +34,7 @@
return;
WideString wsProp = fxv8::ToWideString(info.GetIsolate(), property);
- CJS_Result result = pObj->QueryProperty(wsProp.c_str());
+ CJS_Result result = pObj->QueryProperty(wsProp);
v8::PropertyAttribute attr = !result.HasError()
? v8::PropertyAttribute::DontDelete
: v8::PropertyAttribute::None;
@@ -53,7 +53,7 @@
return;
WideString wsProp = fxv8::ToWideString(info.GetIsolate(), property);
- CJS_Result result = pObj->GetProperty(pRuntime, wsProp.c_str());
+ CJS_Result result = pObj->GetProperty(pRuntime, wsProp);
if (result.HasError()) {
pRuntime->Error(
JSFormatErrorString("global", "GetProperty", result.Error()));
@@ -75,7 +75,7 @@
return;
WideString wsProp = fxv8::ToWideString(info.GetIsolate(), property);
- CJS_Result result = pObj->SetProperty(pRuntime, wsProp.c_str(), value);
+ CJS_Result result = pObj->SetProperty(pRuntime, wsProp, value);
if (result.HasError()) {
pRuntime->Error(
JSFormatErrorString("global", "PutProperty", result.Error()));
@@ -93,7 +93,7 @@
return;
WideString wsProp = fxv8::ToWideString(info.GetIsolate(), property);
- pObj->DelProperty(pRuntime, wsProp.c_str()); // Silently ignore error.
+ pObj->DelProperty(pRuntime, wsProp); // Silently ignore error.
}
v8::Local<v8::String> GetV8StringFromName(v8::Isolate* pIsolate,
@@ -184,16 +184,16 @@
m_pGlobalData.Release()->Release();
}
-CJS_Result CJS_Global::QueryProperty(const wchar_t* propname) {
- if (WideString(propname).EqualsASCII("setPersistent"))
+CJS_Result CJS_Global::QueryProperty(const WideString& propname) {
+ if (propname.EqualsASCII("setPersistent"))
return CJS_Result::Success();
return CJS_Result::Failure(JSMessage::kUnknownProperty);
}
CJS_Result CJS_Global::DelProperty(CJS_Runtime* pRuntime,
- const wchar_t* propname) {
- auto it = m_MapGlobal.find(WideString(propname).ToDefANSI());
+ const WideString& propname) {
+ auto it = m_MapGlobal.find(propname.ToDefANSI());
if (it == m_MapGlobal.end())
return CJS_Result::Failure(JSMessage::kUnknownProperty);
@@ -202,8 +202,8 @@
}
CJS_Result CJS_Global::GetProperty(CJS_Runtime* pRuntime,
- const wchar_t* propname) {
- auto it = m_MapGlobal.find(WideString(propname).ToDefANSI());
+ const WideString& propname) {
+ auto it = m_MapGlobal.find(propname.ToDefANSI());
if (it == m_MapGlobal.end())
return CJS_Result::Success();
@@ -231,9 +231,9 @@
}
CJS_Result CJS_Global::SetProperty(CJS_Runtime* pRuntime,
- const wchar_t* propname,
+ const WideString& propname,
v8::Local<v8::Value> vp) {
- ByteString sPropName = WideString(propname).ToDefANSI();
+ ByteString sPropName = propname.ToDefANSI();
if (vp->IsNumber()) {
return SetGlobalVariables(sPropName, CFX_Value::DataType::kNumber,
pRuntime->ToDouble(vp), false, ByteString(),
diff --git a/fxjs/cjs_global.h b/fxjs/cjs_global.h
index 5bb9e0f..994589f 100644
--- a/fxjs/cjs_global.h
+++ b/fxjs/cjs_global.h
@@ -51,14 +51,13 @@
CJS_Global(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime);
~CJS_Global() override;
- CJS_Result DelProperty(CJS_Runtime* pRuntime, const wchar_t* propname);
-
CJS_Result setPersistent(CJS_Runtime* pRuntime,
const std::vector<v8::Local<v8::Value>>& params);
- CJS_Result QueryProperty(const wchar_t* propname);
- CJS_Result GetProperty(CJS_Runtime* pRuntime, const wchar_t* propname);
+ CJS_Result QueryProperty(const WideString& propname);
+ CJS_Result DelProperty(CJS_Runtime* pRuntime, const WideString& propname);
+ CJS_Result GetProperty(CJS_Runtime* pRuntime, const WideString& propname);
CJS_Result SetProperty(CJS_Runtime* pRuntime,
- const wchar_t* propname,
+ const WideString& propname,
v8::Local<v8::Value> vp);
private: