summaryrefslogtreecommitdiff
path: root/fpdfsdk/javascript
diff options
context:
space:
mode:
Diffstat (limited to 'fpdfsdk/javascript')
-rw-r--r--fpdfsdk/javascript/Document.cpp30
-rw-r--r--fpdfsdk/javascript/JS_Value.cpp27
-rw-r--r--fpdfsdk/javascript/global.cpp52
3 files changed, 58 insertions, 51 deletions
diff --git a/fpdfsdk/javascript/Document.cpp b/fpdfsdk/javascript/Document.cpp
index 79d68ec3a7..4bf1afd5a3 100644
--- a/fpdfsdk/javascript/Document.cpp
+++ b/fpdfsdk/javascript/Document.cpp
@@ -801,15 +801,18 @@ bool Document::info(IJS_Context* cc,
CJS_Runtime* pRuntime = pContext->GetJSRuntime();
v8::Local<v8::Object> pObj = pRuntime->NewFxDynamicObj(-1);
- pRuntime->PutObjectString(pObj, L"Author", cwAuthor);
- pRuntime->PutObjectString(pObj, L"Title", cwTitle);
- pRuntime->PutObjectString(pObj, L"Subject", cwSubject);
- pRuntime->PutObjectString(pObj, L"Keywords", cwKeywords);
- pRuntime->PutObjectString(pObj, L"Creator", cwCreator);
- pRuntime->PutObjectString(pObj, L"Producer", cwProducer);
- pRuntime->PutObjectString(pObj, L"CreationDate", cwCreationDate);
- pRuntime->PutObjectString(pObj, L"ModDate", cwModDate);
- pRuntime->PutObjectString(pObj, L"Trapped", cwTrapped);
+ pRuntime->PutObjectProperty(pObj, L"Author", pRuntime->NewString(cwAuthor));
+ pRuntime->PutObjectProperty(pObj, L"Title", pRuntime->NewString(cwTitle));
+ pRuntime->PutObjectProperty(pObj, L"Subject", pRuntime->NewString(cwSubject));
+ pRuntime->PutObjectProperty(pObj, L"Keywords",
+ pRuntime->NewString(cwKeywords));
+ pRuntime->PutObjectProperty(pObj, L"Creator", pRuntime->NewString(cwCreator));
+ pRuntime->PutObjectProperty(pObj, L"Producer",
+ pRuntime->NewString(cwProducer));
+ pRuntime->PutObjectProperty(pObj, L"CreationDate",
+ pRuntime->NewString(cwCreationDate));
+ pRuntime->PutObjectProperty(pObj, L"ModDate", pRuntime->NewString(cwModDate));
+ pRuntime->PutObjectProperty(pObj, L"Trapped", pRuntime->NewString(cwTrapped));
// It's to be compatible to non-standard info dictionary.
for (const auto& it : *pDictionary) {
@@ -817,11 +820,14 @@ bool Document::info(IJS_Context* cc,
CPDF_Object* pValueObj = it.second.get();
CFX_WideString wsKey = CFX_WideString::FromUTF8(bsKey.AsStringC());
if (pValueObj->IsString() || pValueObj->IsName()) {
- pRuntime->PutObjectString(pObj, wsKey, pValueObj->GetUnicodeText());
+ pRuntime->PutObjectProperty(
+ pObj, wsKey, pRuntime->NewString(pValueObj->GetUnicodeText()));
} else if (pValueObj->IsNumber()) {
- pRuntime->PutObjectNumber(pObj, wsKey, (float)pValueObj->GetNumber());
+ pRuntime->PutObjectProperty(pObj, wsKey,
+ pRuntime->NewNumber(pValueObj->GetNumber()));
} else if (pValueObj->IsBoolean()) {
- pRuntime->PutObjectBoolean(pObj, wsKey, !!pValueObj->GetInteger());
+ pRuntime->PutObjectProperty(
+ pObj, wsKey, pRuntime->NewBoolean(!!pValueObj->GetInteger()));
}
}
vp << pObj;
diff --git a/fpdfsdk/javascript/JS_Value.cpp b/fpdfsdk/javascript/JS_Value.cpp
index c99affbede..7900914a8e 100644
--- a/fpdfsdk/javascript/JS_Value.cpp
+++ b/fpdfsdk/javascript/JS_Value.cpp
@@ -88,7 +88,7 @@ bool CJS_Value::ToBool(CJS_Runtime* pRuntime) const {
}
double CJS_Value::ToDouble(CJS_Runtime* pRuntime) const {
- return pRuntime->ToNumber(m_pValue);
+ return pRuntime->ToDouble(m_pValue);
}
float CJS_Value::ToFloat(CJS_Runtime* pRuntime) const {
@@ -105,7 +105,7 @@ v8::Local<v8::Object> CJS_Value::ToV8Object(CJS_Runtime* pRuntime) const {
}
CFX_WideString CJS_Value::ToCFXWideString(CJS_Runtime* pRuntime) const {
- return pRuntime->ToString(m_pValue);
+ return pRuntime->ToWideString(m_pValue);
}
CFX_ByteString CJS_Value::ToCFXByteString(CJS_Runtime* pRuntime) const {
@@ -117,9 +117,7 @@ v8::Local<v8::Value> CJS_Value::ToV8Value(CJS_Runtime* pRuntime) const {
}
v8::Local<v8::Array> CJS_Value::ToV8Array(CJS_Runtime* pRuntime) const {
- if (IsArrayObject())
- return v8::Local<v8::Array>::Cast(pRuntime->ToObject(m_pValue));
- return v8::Local<v8::Array>();
+ return pRuntime->ToArray(m_pValue);
}
void CJS_Value::SetNull(CJS_Runtime* pRuntime) {
@@ -360,7 +358,7 @@ CJS_Date::CJS_Date(CJS_Runtime* pRuntime,
CJS_Date::~CJS_Date() {}
bool CJS_Date::IsValidDate(CJS_Runtime* pRuntime) const {
- return !m_pDate.IsEmpty() && !JS_PortIsNan(pRuntime->ToNumber(m_pDate));
+ return !m_pDate.IsEmpty() && !JS_PortIsNan(pRuntime->ToDouble(m_pDate));
}
void CJS_Date::Attach(v8::Local<v8::Date> pDate) {
@@ -371,7 +369,7 @@ int CJS_Date::GetYear(CJS_Runtime* pRuntime) const {
if (!IsValidDate(pRuntime))
return 0;
- return JS_GetYearFromTime(JS_LocalTime(pRuntime->ToNumber(m_pDate)));
+ return JS_GetYearFromTime(JS_LocalTime(pRuntime->ToDouble(m_pDate)));
}
void CJS_Date::SetYear(CJS_Runtime* pRuntime, int iYear) {
@@ -384,7 +382,7 @@ int CJS_Date::GetMonth(CJS_Runtime* pRuntime) const {
if (!IsValidDate(pRuntime))
return 0;
- return JS_GetMonthFromTime(JS_LocalTime(pRuntime->ToNumber(m_pDate)));
+ return JS_GetMonthFromTime(JS_LocalTime(pRuntime->ToDouble(m_pDate)));
}
void CJS_Date::SetMonth(CJS_Runtime* pRuntime, int iMonth) {
@@ -397,7 +395,7 @@ int CJS_Date::GetDay(CJS_Runtime* pRuntime) const {
if (!IsValidDate(pRuntime))
return 0;
- return JS_GetDayFromTime(JS_LocalTime(pRuntime->ToNumber(m_pDate)));
+ return JS_GetDayFromTime(JS_LocalTime(pRuntime->ToDouble(m_pDate)));
}
void CJS_Date::SetDay(CJS_Runtime* pRuntime, int iDay) {
@@ -410,7 +408,7 @@ int CJS_Date::GetHours(CJS_Runtime* pRuntime) const {
if (!IsValidDate(pRuntime))
return 0;
- return JS_GetHourFromTime(JS_LocalTime(pRuntime->ToNumber(m_pDate)));
+ return JS_GetHourFromTime(JS_LocalTime(pRuntime->ToDouble(m_pDate)));
}
void CJS_Date::SetHours(CJS_Runtime* pRuntime, int iHours) {
@@ -423,7 +421,7 @@ int CJS_Date::GetMinutes(CJS_Runtime* pRuntime) const {
if (!IsValidDate(pRuntime))
return 0;
- return JS_GetMinFromTime(JS_LocalTime(pRuntime->ToNumber(m_pDate)));
+ return JS_GetMinFromTime(JS_LocalTime(pRuntime->ToDouble(m_pDate)));
}
void CJS_Date::SetMinutes(CJS_Runtime* pRuntime, int minutes) {
@@ -436,7 +434,7 @@ int CJS_Date::GetSeconds(CJS_Runtime* pRuntime) const {
if (!IsValidDate(pRuntime))
return 0;
- return JS_GetSecFromTime(JS_LocalTime(pRuntime->ToNumber(m_pDate)));
+ return JS_GetSecFromTime(JS_LocalTime(pRuntime->ToDouble(m_pDate)));
}
void CJS_Date::SetSeconds(CJS_Runtime* pRuntime, int seconds) {
@@ -446,11 +444,12 @@ void CJS_Date::SetSeconds(CJS_Runtime* pRuntime, int seconds) {
}
double CJS_Date::ToDouble(CJS_Runtime* pRuntime) const {
- return !m_pDate.IsEmpty() ? pRuntime->ToNumber(m_pDate) : 0.0;
+ return !m_pDate.IsEmpty() ? pRuntime->ToDouble(m_pDate) : 0.0;
}
CFX_WideString CJS_Date::ToString(CJS_Runtime* pRuntime) const {
- return !m_pDate.IsEmpty() ? pRuntime->ToString(m_pDate) : CFX_WideString();
+ return !m_pDate.IsEmpty() ? pRuntime->ToWideString(m_pDate)
+ : CFX_WideString();
}
v8::Local<v8::Date> CJS_Date::ToV8Date(CJS_Runtime* pRuntime) const {
diff --git a/fpdfsdk/javascript/global.cpp b/fpdfsdk/javascript/global.cpp
index c2d3586874..aca86979ae 100644
--- a/fpdfsdk/javascript/global.cpp
+++ b/fpdfsdk/javascript/global.cpp
@@ -192,41 +192,41 @@ void JSGlobalAlternate::UpdateGlobalPersistentVariables() {
SetGlobalVariables(pData->data.sKey, JS_GlobalDataType::NUMBER,
pData->data.dData, false, "",
v8::Local<v8::Object>(), pData->bPersistent == 1);
- pRuntime->PutObjectNumber(m_pJSObject->ToV8Object(),
- pData->data.sKey.UTF8Decode(),
- pData->data.dData);
+ pRuntime->PutObjectProperty(m_pJSObject->ToV8Object(),
+ pData->data.sKey.UTF8Decode(),
+ pRuntime->NewNumber(pData->data.dData));
break;
case JS_GlobalDataType::BOOLEAN:
SetGlobalVariables(pData->data.sKey, JS_GlobalDataType::BOOLEAN, 0,
- (bool)(pData->data.bData == 1), "",
- v8::Local<v8::Object>(), pData->bPersistent == 1);
- pRuntime->PutObjectBoolean(m_pJSObject->ToV8Object(),
- pData->data.sKey.UTF8Decode(),
- (bool)(pData->data.bData == 1));
+ pData->data.bData == 1, "", v8::Local<v8::Object>(),
+ pData->bPersistent == 1);
+ pRuntime->PutObjectProperty(
+ m_pJSObject->ToV8Object(), pData->data.sKey.UTF8Decode(),
+ pRuntime->NewBoolean(pData->data.bData == 1));
break;
case JS_GlobalDataType::STRING:
SetGlobalVariables(pData->data.sKey, JS_GlobalDataType::STRING, 0,
false, pData->data.sData, v8::Local<v8::Object>(),
pData->bPersistent == 1);
- pRuntime->PutObjectString(m_pJSObject->ToV8Object(),
- pData->data.sKey.UTF8Decode(),
- pData->data.sData.UTF8Decode());
+ pRuntime->PutObjectProperty(
+ m_pJSObject->ToV8Object(), pData->data.sKey.UTF8Decode(),
+ pRuntime->NewString(pData->data.sData.UTF8Decode()));
break;
case JS_GlobalDataType::OBJECT: {
v8::Local<v8::Object> pObj = pRuntime->NewFxDynamicObj(-1);
-
PutObjectProperty(pObj, &pData->data);
SetGlobalVariables(pData->data.sKey, JS_GlobalDataType::OBJECT, 0,
false, "", pObj, pData->bPersistent == 1);
- pRuntime->PutObjectObject(m_pJSObject->ToV8Object(),
- pData->data.sKey.UTF8Decode(), pObj);
+ pRuntime->PutObjectProperty(m_pJSObject->ToV8Object(),
+ pData->data.sKey.UTF8Decode(), pObj);
} break;
case JS_GlobalDataType::NULLOBJ:
SetGlobalVariables(pData->data.sKey, JS_GlobalDataType::NULLOBJ, 0,
false, "", v8::Local<v8::Object>(),
pData->bPersistent == 1);
- pRuntime->PutObjectNull(m_pJSObject->ToV8Object(),
- pData->data.sKey.UTF8Decode());
+ pRuntime->PutObjectProperty(m_pJSObject->ToV8Object(),
+ pData->data.sKey.UTF8Decode(),
+ pRuntime->NewNull());
break;
}
}
@@ -282,7 +282,7 @@ void JSGlobalAlternate::ObjectToArray(IJS_Context* cc,
CJS_KeyValue* pObjElement = new CJS_KeyValue;
pObjElement->nType = JS_GlobalDataType::NUMBER;
pObjElement->sKey = sKey;
- pObjElement->dData = pRuntime->ToNumber(v);
+ pObjElement->dData = pRuntime->ToDouble(v);
array.Add(pObjElement);
} break;
case CJS_Value::VT_boolean: {
@@ -329,24 +329,26 @@ void JSGlobalAlternate::PutObjectProperty(v8::Local<v8::Object> pObj,
CJS_KeyValue* pObjData = pData->objData.GetAt(i);
switch (pObjData->nType) {
case JS_GlobalDataType::NUMBER:
- pRuntime->PutObjectNumber(pObj, pObjData->sKey.UTF8Decode(),
- pObjData->dData);
+ pRuntime->PutObjectProperty(pObj, pObjData->sKey.UTF8Decode(),
+ pRuntime->NewNumber(pObjData->dData));
break;
case JS_GlobalDataType::BOOLEAN:
- pRuntime->PutObjectBoolean(pObj, pObjData->sKey.UTF8Decode(),
- pObjData->bData == 1);
+ pRuntime->PutObjectProperty(pObj, pObjData->sKey.UTF8Decode(),
+ pRuntime->NewBoolean(pObjData->bData == 1));
break;
case JS_GlobalDataType::STRING:
- pRuntime->PutObjectString(pObj, pObjData->sKey.UTF8Decode(),
- pObjData->sData.UTF8Decode());
+ pRuntime->PutObjectProperty(
+ pObj, pObjData->sKey.UTF8Decode(),
+ pRuntime->NewString(pObjData->sData.UTF8Decode()));
break;
case JS_GlobalDataType::OBJECT: {
v8::Local<v8::Object> pNewObj = pRuntime->NewFxDynamicObj(-1);
PutObjectProperty(pNewObj, pObjData);
- pRuntime->PutObjectObject(pObj, pObjData->sKey.UTF8Decode(), pNewObj);
+ pRuntime->PutObjectProperty(pObj, pObjData->sKey.UTF8Decode(), pNewObj);
} break;
case JS_GlobalDataType::NULLOBJ:
- pRuntime->PutObjectNull(pObj, pObjData->sKey.UTF8Decode());
+ pRuntime->PutObjectProperty(pObj, pObjData->sKey.UTF8Decode(),
+ pRuntime->NewNull());
break;
}
}