summaryrefslogtreecommitdiff
path: root/fpdfsdk/javascript
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-04-15 13:15:12 -0700
committerCommit bot <commit-bot@chromium.org>2016-04-15 13:15:12 -0700
commit018935c9304bebf13fbad20b124d775ccae87fae (patch)
treea8db5b909a5cef43317d924919e7c1be77c505c3 /fpdfsdk/javascript
parentc3b26b1479824aa5ce745c220a82de7528bc26a9 (diff)
downloadpdfium-018935c9304bebf13fbad20b124d775ccae87fae.tar.xz
Pass WideStrings without narrowing to c_str in javascript/
Avoid string duplication when the caller already has one. Review URL: https://codereview.chromium.org/1883273003
Diffstat (limited to 'fpdfsdk/javascript')
-rw-r--r--fpdfsdk/javascript/Document.cpp27
-rw-r--r--fpdfsdk/javascript/JS_Value.cpp3
-rw-r--r--fpdfsdk/javascript/JS_Value.h2
-rw-r--r--fpdfsdk/javascript/PublicMethods.cpp15
-rw-r--r--fpdfsdk/javascript/global.cpp28
5 files changed, 33 insertions, 42 deletions
diff --git a/fpdfsdk/javascript/Document.cpp b/fpdfsdk/javascript/Document.cpp
index 4c361b197e..551d649830 100644
--- a/fpdfsdk/javascript/Document.cpp
+++ b/fpdfsdk/javascript/Document.cpp
@@ -769,16 +769,15 @@ FX_BOOL Document::info(IJS_Context* cc,
CJS_Runtime* pRuntime = pContext->GetJSRuntime();
v8::Local<v8::Object> pObj =
FXJS_NewFxDynamicObj(pRuntime->GetIsolate(), pRuntime, -1);
- FXJS_PutObjectString(isolate, pObj, L"Author", cwAuthor.c_str());
- FXJS_PutObjectString(isolate, pObj, L"Title", cwTitle.c_str());
- FXJS_PutObjectString(isolate, pObj, L"Subject", cwSubject.c_str());
- FXJS_PutObjectString(isolate, pObj, L"Keywords", cwKeywords.c_str());
- FXJS_PutObjectString(isolate, pObj, L"Creator", cwCreator.c_str());
- FXJS_PutObjectString(isolate, pObj, L"Producer", cwProducer.c_str());
- FXJS_PutObjectString(isolate, pObj, L"CreationDate",
- cwCreationDate.c_str());
- FXJS_PutObjectString(isolate, pObj, L"ModDate", cwModDate.c_str());
- FXJS_PutObjectString(isolate, pObj, L"Trapped", cwTrapped.c_str());
+ FXJS_PutObjectString(isolate, pObj, L"Author", cwAuthor);
+ FXJS_PutObjectString(isolate, pObj, L"Title", cwTitle);
+ FXJS_PutObjectString(isolate, pObj, L"Subject", cwSubject);
+ FXJS_PutObjectString(isolate, pObj, L"Keywords", cwKeywords);
+ FXJS_PutObjectString(isolate, pObj, L"Creator", cwCreator);
+ FXJS_PutObjectString(isolate, pObj, L"Producer", cwProducer);
+ FXJS_PutObjectString(isolate, pObj, L"CreationDate", cwCreationDate);
+ FXJS_PutObjectString(isolate, pObj, L"ModDate", cwModDate);
+ FXJS_PutObjectString(isolate, pObj, L"Trapped", cwTrapped);
// It's to be compatible to non-standard info dictionary.
for (const auto& it : *pDictionary) {
@@ -786,14 +785,12 @@ FX_BOOL Document::info(IJS_Context* cc,
CPDF_Object* pValueObj = it.second;
CFX_WideString wsKey = CFX_WideString::FromUTF8(bsKey.AsStringC());
if (pValueObj->IsString() || pValueObj->IsName()) {
- FXJS_PutObjectString(isolate, pObj, wsKey.c_str(),
- pValueObj->GetUnicodeText().c_str());
+ FXJS_PutObjectString(isolate, pObj, wsKey, pValueObj->GetUnicodeText());
} else if (pValueObj->IsNumber()) {
- FXJS_PutObjectNumber(isolate, pObj, wsKey.c_str(),
+ FXJS_PutObjectNumber(isolate, pObj, wsKey,
(float)pValueObj->GetNumber());
} else if (pValueObj->IsBoolean()) {
- FXJS_PutObjectBoolean(isolate, pObj, wsKey.c_str(),
- !!pValueObj->GetInteger());
+ FXJS_PutObjectBoolean(isolate, pObj, wsKey, !!pValueObj->GetInteger());
}
}
vp << pObj;
diff --git a/fpdfsdk/javascript/JS_Value.cpp b/fpdfsdk/javascript/JS_Value.cpp
index 0b31494b75..e2c990c51c 100644
--- a/fpdfsdk/javascript/JS_Value.cpp
+++ b/fpdfsdk/javascript/JS_Value.cpp
@@ -787,7 +787,7 @@ int JS_GetSecFromTime(double dt) {
return (int)_Mod(floor(dt / 1000), 60);
}
-double JS_DateParse(const wchar_t* str) {
+double JS_DateParse(const CFX_WideString& str) {
v8::Isolate* pIsolate = v8::Isolate::GetCurrent();
v8::Isolate::Scope isolate_scope(pIsolate);
v8::HandleScope scope(pIsolate);
@@ -809,7 +809,6 @@ double JS_DateParse(const wchar_t* str) {
.ToLocalChecked();
if (v->IsFunction()) {
v8::Local<v8::Function> funC = v8::Local<v8::Function>::Cast(v);
-
const int argc = 1;
v8::Local<v8::String> timeStr = FXJS_WSToJSString(pIsolate, str);
v8::Local<v8::Value> argv[argc] = {timeStr};
diff --git a/fpdfsdk/javascript/JS_Value.h b/fpdfsdk/javascript/JS_Value.h
index 423d7f62e1..8adec4b1d1 100644
--- a/fpdfsdk/javascript/JS_Value.h
+++ b/fpdfsdk/javascript/JS_Value.h
@@ -208,7 +208,7 @@ int JS_GetDayFromTime(double dt);
int JS_GetHourFromTime(double dt);
int JS_GetMinFromTime(double dt);
int JS_GetSecFromTime(double dt);
-double JS_DateParse(const wchar_t* str);
+double JS_DateParse(const CFX_WideString& str);
double JS_MakeDay(int nYear, int nMonth, int nDay);
double JS_MakeTime(int nHour, int nMin, int nSec, int nMs);
double JS_MakeDate(double day, double time);
diff --git a/fpdfsdk/javascript/PublicMethods.cpp b/fpdfsdk/javascript/PublicMethods.cpp
index 9f7b60f70d..a84c0935bc 100644
--- a/fpdfsdk/javascript/PublicMethods.cpp
+++ b/fpdfsdk/javascript/PublicMethods.cpp
@@ -306,7 +306,7 @@ double CJS_PublicMethods::ParseNormalDate(const CFX_WideString& value,
CFX_WideString swTemp;
swTemp.Format(L"%d/%d/%d %d:%d:%d", nMonth, nDay, nYear, nHour, nMin, nSec);
- return JS_DateParse(swTemp.c_str());
+ return JS_DateParse(swTemp);
}
double CJS_PublicMethods::MakeRegularDate(const CFX_WideString& value,
@@ -563,24 +563,21 @@ double CJS_PublicMethods::MakeRegularDate(const CFX_WideString& value,
bBadFormat = true;
double dRet = 0;
-
if (bBadFormat) {
dRet = ParseNormalDate(value, &bBadFormat);
} else {
dRet = JS_MakeDate(JS_MakeDay(nYear, nMonth - 1, nDay),
JS_MakeTime(nHour, nMin, nSec, 0));
-
- if (JS_PortIsNan(dRet)) {
- dRet = JS_DateParse(value.c_str());
- }
+ if (JS_PortIsNan(dRet))
+ dRet = JS_DateParse(value);
}
- if (JS_PortIsNan(dRet)) {
+ if (JS_PortIsNan(dRet))
dRet = ParseNormalDate(value, &bBadFormat);
- }
if (bWrongFormat)
*bWrongFormat = bBadFormat;
+
return dRet;
}
@@ -1204,7 +1201,7 @@ double CJS_PublicMethods::MakeInterDate(const CFX_WideString& strValue) {
double dRet = JS_MakeDate(JS_MakeDay(nYear, nMonth - 1, nDay),
JS_MakeTime(nHour, nMin, nSec, 0));
if (JS_PortIsNan(dRet))
- dRet = JS_DateParse(strValue.c_str());
+ dRet = JS_DateParse(strValue);
return dRet;
}
diff --git a/fpdfsdk/javascript/global.cpp b/fpdfsdk/javascript/global.cpp
index 7242a144c9..380713b425 100644
--- a/fpdfsdk/javascript/global.cpp
+++ b/fpdfsdk/javascript/global.cpp
@@ -233,15 +233,14 @@ void JSGlobalAlternate::UpdateGlobalPersistentVariables() {
pData->data.dData, false, "",
v8::Local<v8::Object>(), pData->bPersistent == 1);
FXJS_PutObjectNumber(NULL, m_pJSObject->ToV8Object(),
- pData->data.sKey.UTF8Decode().c_str(),
- pData->data.dData);
+ pData->data.sKey.UTF8Decode(), pData->data.dData);
break;
case JS_GLOBALDATA_TYPE_BOOLEAN:
SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_BOOLEAN, 0,
(bool)(pData->data.bData == 1), "",
v8::Local<v8::Object>(), pData->bPersistent == 1);
FXJS_PutObjectBoolean(NULL, m_pJSObject->ToV8Object(),
- pData->data.sKey.UTF8Decode().c_str(),
+ pData->data.sKey.UTF8Decode(),
(bool)(pData->data.bData == 1));
break;
case JS_GLOBALDATA_TYPE_STRING:
@@ -249,8 +248,8 @@ void JSGlobalAlternate::UpdateGlobalPersistentVariables() {
false, pData->data.sData, v8::Local<v8::Object>(),
pData->bPersistent == 1);
FXJS_PutObjectString(NULL, m_pJSObject->ToV8Object(),
- pData->data.sKey.UTF8Decode().c_str(),
- pData->data.sData.UTF8Decode().c_str());
+ pData->data.sKey.UTF8Decode(),
+ pData->data.sData.UTF8Decode());
break;
case JS_GLOBALDATA_TYPE_OBJECT: {
v8::Isolate* pRuntime = m_pJSObject->ToV8Object()->GetIsolate();
@@ -261,14 +260,14 @@ void JSGlobalAlternate::UpdateGlobalPersistentVariables() {
SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_OBJECT, 0,
false, "", pObj, pData->bPersistent == 1);
FXJS_PutObjectObject(NULL, m_pJSObject->ToV8Object(),
- pData->data.sKey.UTF8Decode().c_str(), pObj);
+ pData->data.sKey.UTF8Decode(), pObj);
} break;
case JS_GLOBALDATA_TYPE_NULL:
SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_NULL, 0, false,
"", v8::Local<v8::Object>(),
pData->bPersistent == 1);
FXJS_PutObjectNull(NULL, m_pJSObject->ToV8Object(),
- pData->data.sKey.UTF8Decode().c_str());
+ pData->data.sKey.UTF8Decode());
break;
}
}
@@ -324,7 +323,7 @@ void JSGlobalAlternate::ObjectToArray(IJS_Context* cc,
FXJS_ToString(isolate, FXJS_GetArrayElement(isolate, pKeyList, i));
CFX_ByteString sKey = ws.UTF8Encode();
- v8::Local<v8::Value> v = FXJS_GetObjectElement(isolate, pObj, ws.c_str());
+ v8::Local<v8::Value> v = FXJS_GetObjectElement(isolate, pObj, ws);
switch (GET_VALUE_TYPE(v)) {
case CJS_Value::VT_number: {
CJS_KeyValue* pObjElement = new CJS_KeyValue;
@@ -374,27 +373,26 @@ void JSGlobalAlternate::PutObjectProperty(v8::Local<v8::Object> pObj,
CJS_KeyValue* pObjData = pData->objData.GetAt(i);
switch (pObjData->nType) {
case JS_GLOBALDATA_TYPE_NUMBER:
- FXJS_PutObjectNumber(NULL, pObj, pObjData->sKey.UTF8Decode().c_str(),
+ FXJS_PutObjectNumber(NULL, pObj, pObjData->sKey.UTF8Decode(),
pObjData->dData);
break;
case JS_GLOBALDATA_TYPE_BOOLEAN:
- FXJS_PutObjectBoolean(NULL, pObj, pObjData->sKey.UTF8Decode().c_str(),
+ FXJS_PutObjectBoolean(NULL, pObj, pObjData->sKey.UTF8Decode(),
pObjData->bData == 1);
break;
case JS_GLOBALDATA_TYPE_STRING:
- FXJS_PutObjectString(NULL, pObj, pObjData->sKey.UTF8Decode().c_str(),
- pObjData->sData.UTF8Decode().c_str());
+ FXJS_PutObjectString(NULL, pObj, pObjData->sKey.UTF8Decode(),
+ pObjData->sData.UTF8Decode());
break;
case JS_GLOBALDATA_TYPE_OBJECT: {
v8::Isolate* pRuntime = m_pJSObject->ToV8Object()->GetIsolate();
v8::Local<v8::Object> pNewObj =
FXJS_NewFxDynamicObj(pRuntime, NULL, -1);
PutObjectProperty(pNewObj, pObjData);
- FXJS_PutObjectObject(NULL, pObj, pObjData->sKey.UTF8Decode().c_str(),
- pNewObj);
+ FXJS_PutObjectObject(NULL, pObj, pObjData->sKey.UTF8Decode(), pNewObj);
} break;
case JS_GLOBALDATA_TYPE_NULL:
- FXJS_PutObjectNull(NULL, pObj, pObjData->sKey.UTF8Decode().c_str());
+ FXJS_PutObjectNull(NULL, pObj, pObjData->sKey.UTF8Decode());
break;
}
}