Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1460)

Unified Diff: fpdfsdk/javascript/JS_GlobalData.cpp

Issue 1876203002: Pass CFX_ByteStrings rather than raw ptrs to JS_GlobalData. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: fpdfsdk/javascript/JS_GlobalData.cpp
diff --git a/fpdfsdk/javascript/JS_GlobalData.cpp b/fpdfsdk/javascript/JS_GlobalData.cpp
index fe3475c2b1ebe4bbcc95b750974795aa0e33e456..731d617bcc23f3e32f6dbbc0bc7e6ebbf9e281f3 100644
--- a/fpdfsdk/javascript/JS_GlobalData.cpp
+++ b/fpdfsdk/javascript/JS_GlobalData.cpp
@@ -94,9 +94,7 @@ static const uint8_t JS_RC4KEY[] = {
0xf8, 0x77, 0xd5, 0xa3};
// Returns true if non-empty, setting sPropName
-static bool TrimPropName(const char* propname, CFX_ByteString* sPropName) {
- ASSERT(propname);
- *sPropName = propname;
+static bool TrimPropName(CFX_ByteString* sPropName) {
sPropName->TrimLeft();
Tom Sepez 2016/04/11 17:51:06 Note: these are now no-touch if possible, so TrimP
sPropName->TrimRight();
return sPropName->GetLength() != 0;
@@ -130,7 +128,7 @@ CJS_GlobalData::~CJS_GlobalData() {
}
CJS_GlobalData::iterator CJS_GlobalData::FindGlobalVariable(
- const FX_CHAR* propname) {
+ const CFX_ByteString& propname) {
for (auto it = m_arrayGlobalData.begin(); it != m_arrayGlobalData.end();
++it) {
if ((*it)->data.sKey == propname)
@@ -140,7 +138,7 @@ CJS_GlobalData::iterator CJS_GlobalData::FindGlobalVariable(
}
CJS_GlobalData::const_iterator CJS_GlobalData::FindGlobalVariable(
- const FX_CHAR* propname) const {
+ const CFX_ByteString& propname) const {
for (auto it = m_arrayGlobalData.begin(); it != m_arrayGlobalData.end();
++it) {
if ((*it)->data.sKey == propname)
@@ -150,15 +148,14 @@ CJS_GlobalData::const_iterator CJS_GlobalData::FindGlobalVariable(
}
CJS_GlobalData_Element* CJS_GlobalData::GetGlobalVariable(
- const FX_CHAR* propname) {
+ const CFX_ByteString& propname) {
auto iter = FindGlobalVariable(propname);
return iter != m_arrayGlobalData.end() ? iter->get() : nullptr;
}
-void CJS_GlobalData::SetGlobalVariableNumber(const FX_CHAR* propname,
+void CJS_GlobalData::SetGlobalVariableNumber(CFX_ByteString sPropName,
double dData) {
- CFX_ByteString sPropName;
- if (!TrimPropName(propname, &sPropName))
+ if (!TrimPropName(&sPropName))
return;
if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName)) {
@@ -173,10 +170,9 @@ void CJS_GlobalData::SetGlobalVariableNumber(const FX_CHAR* propname,
m_arrayGlobalData.push_back(std::move(pNewData));
}
-void CJS_GlobalData::SetGlobalVariableBoolean(const FX_CHAR* propname,
+void CJS_GlobalData::SetGlobalVariableBoolean(CFX_ByteString sPropName,
bool bData) {
- CFX_ByteString sPropName;
- if (!TrimPropName(propname, &sPropName))
+ if (!TrimPropName(&sPropName))
return;
if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName)) {
@@ -191,10 +187,9 @@ void CJS_GlobalData::SetGlobalVariableBoolean(const FX_CHAR* propname,
m_arrayGlobalData.push_back(std::move(pNewData));
}
-void CJS_GlobalData::SetGlobalVariableString(const FX_CHAR* propname,
+void CJS_GlobalData::SetGlobalVariableString(CFX_ByteString sPropName,
const CFX_ByteString& sData) {
- CFX_ByteString sPropName;
- if (!TrimPropName(propname, &sPropName))
+ if (!TrimPropName(&sPropName))
return;
if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName)) {
@@ -210,10 +205,9 @@ void CJS_GlobalData::SetGlobalVariableString(const FX_CHAR* propname,
}
void CJS_GlobalData::SetGlobalVariableObject(
- const FX_CHAR* propname,
+ CFX_ByteString sPropName,
const CJS_GlobalVariableArray& array) {
- CFX_ByteString sPropName;
- if (!TrimPropName(propname, &sPropName))
+ if (!TrimPropName(&sPropName))
return;
if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName)) {
@@ -228,9 +222,8 @@ void CJS_GlobalData::SetGlobalVariableObject(
m_arrayGlobalData.push_back(std::move(pNewData));
}
-void CJS_GlobalData::SetGlobalVariableNull(const FX_CHAR* propname) {
- CFX_ByteString sPropName;
- if (!TrimPropName(propname, &sPropName))
+void CJS_GlobalData::SetGlobalVariableNull(CFX_ByteString sPropName) {
+ if (!TrimPropName(&sPropName))
return;
if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName)) {
@@ -243,10 +236,9 @@ void CJS_GlobalData::SetGlobalVariableNull(const FX_CHAR* propname) {
m_arrayGlobalData.push_back(std::move(pNewData));
}
-FX_BOOL CJS_GlobalData::SetGlobalVariablePersistent(const FX_CHAR* propname,
+FX_BOOL CJS_GlobalData::SetGlobalVariablePersistent(CFX_ByteString sPropName,
FX_BOOL bPersistent) {
- CFX_ByteString sPropName;
- if (!TrimPropName(propname, &sPropName))
+ if (!TrimPropName(&sPropName))
return FALSE;
CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName);
@@ -257,9 +249,8 @@ FX_BOOL CJS_GlobalData::SetGlobalVariablePersistent(const FX_CHAR* propname,
return TRUE;
}
-FX_BOOL CJS_GlobalData::DeleteGlobalVariable(const FX_CHAR* propname) {
- CFX_ByteString sPropName;
- if (!TrimPropName(propname, &sPropName))
+FX_BOOL CJS_GlobalData::DeleteGlobalVariable(CFX_ByteString sPropName) {
+ if (!TrimPropName(&sPropName))
return FALSE;
auto iter = FindGlobalVariable(sPropName);
@@ -292,8 +283,6 @@ void CJS_GlobalData::LoadGlobalPersistentVariables() {
uint16_t wType = *((uint16_t*)p);
p += sizeof(uint16_t);
- // uint16_t wTemp = (uint16_t)(('X' << 8) | 'F');
-
if (wType == (uint16_t)(('X' << 8) | 'F')) {
uint16_t wVersion = *((uint16_t*)p);
p += sizeof(uint16_t);

Powered by Google App Engine
This is Rietveld 408576698