diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-10-23 09:40:59 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-10-23 17:56:28 +0000 |
commit | c970895f94cf76eb738d0a583ae139fecdd85268 (patch) | |
tree | 85a46f604e7294cf4402aff67d3338fe031611f4 | |
parent | 97dab80731a15a6bd74cdc3caf11f97c3a3be5ed (diff) | |
download | pdfium-chromium/3248.tar.xz |
Cleanup CJS_Valuechromium/3248
This CL removes unused methods; renames Attach to Set and generally cleans up
the CJS_Value classes.
Change-Id: I858082100908f3bc51f4b58c11ceda3357fadc70
Reviewed-on: https://pdfium-review.googlesource.com/16430
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
-rw-r--r-- | fpdfsdk/javascript/Document.cpp | 67 | ||||
-rw-r--r-- | fpdfsdk/javascript/Field.cpp | 27 | ||||
-rw-r--r-- | fpdfsdk/javascript/JS_Value.cpp | 149 | ||||
-rw-r--r-- | fpdfsdk/javascript/JS_Value.h | 52 | ||||
-rw-r--r-- | fpdfsdk/javascript/PublicMethods.cpp | 50 | ||||
-rw-r--r-- | fpdfsdk/javascript/app.cpp | 50 | ||||
-rw-r--r-- | fpdfsdk/javascript/color.cpp | 84 | ||||
-rw-r--r-- | fpdfsdk/javascript/global.cpp | 4 | ||||
-rw-r--r-- | fpdfsdk/javascript/util.cpp | 18 |
9 files changed, 195 insertions, 306 deletions
diff --git a/fpdfsdk/javascript/Document.cpp b/fpdfsdk/javascript/Document.cpp index 10947c8032..5d8f5528f7 100644 --- a/fpdfsdk/javascript/Document.cpp +++ b/fpdfsdk/javascript/Document.cpp @@ -307,7 +307,7 @@ bool Document::getField(CJS_Runtime* pRuntime, sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return false; } - WideString wideName = params[0].ToCFXWideString(pRuntime); + WideString wideName = params[0].ToWideString(pRuntime); CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); if (pPDFForm->CountFields(wideName) <= 0) { @@ -397,11 +397,11 @@ bool Document::mailForm(CJS_Runtime* pRuntime, } int iLength = params.size(); bool bUI = iLength > 0 ? params[0].ToBool(pRuntime) : true; - WideString cTo = iLength > 1 ? params[1].ToCFXWideString(pRuntime) : L""; - WideString cCc = iLength > 2 ? params[2].ToCFXWideString(pRuntime) : L""; - WideString cBcc = iLength > 3 ? params[3].ToCFXWideString(pRuntime) : L""; - WideString cSubject = iLength > 4 ? params[4].ToCFXWideString(pRuntime) : L""; - WideString cMsg = iLength > 5 ? params[5].ToCFXWideString(pRuntime) : L""; + WideString cTo = iLength > 1 ? params[1].ToWideString(pRuntime) : L""; + WideString cCc = iLength > 2 ? params[2].ToWideString(pRuntime) : L""; + WideString cBcc = iLength > 3 ? params[3].ToWideString(pRuntime) : L""; + WideString cSubject = iLength > 4 ? params[4].ToWideString(pRuntime) : L""; + WideString cMsg = iLength > 5 ? params[5].ToWideString(pRuntime) : L""; CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); ByteString sTextBuf = pInterForm->ExportFormToFDFTextBuf(); if (sTextBuf.GetLength() == 0) @@ -443,7 +443,7 @@ bool Document::print(CJS_Runtime* pRuntime, v8::Local<v8::Object> pObj = params[8].ToV8Object(pRuntime); if (CFXJS_Engine::GetObjDefnID(pObj) == CJS_PrintParamsObj::g_nObjDefnID) { - if (CJS_Object* pJSObj = params[8].ToCJSObject(pRuntime)) { + if (CJS_Object* pJSObj = params[8].ToObject(pRuntime)) { if (PrintParamsObj* pprintparamsObj = static_cast<PrintParamsObj*>(pJSObj->GetEmbedObject())) { bUI = pprintparamsObj->bUI; @@ -506,7 +506,7 @@ bool Document::removeField(CJS_Runtime* pRuntime, sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); return false; } - WideString sFieldName = params[0].ToCFXWideString(pRuntime); + WideString sFieldName = params[0].ToWideString(pRuntime); CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); std::vector<CPDFSDK_Annot::ObservedPtr> widgets; pInterForm->GetWidgets(sFieldName, &widgets); @@ -575,7 +575,7 @@ bool Document::resetForm(CJS_Runtime* pRuntime, switch (params[0].GetType()) { default: - aName.Attach(params[0].ToV8Array(pRuntime)); + aName = CJS_Array(params[0].ToV8Array(pRuntime)); break; case CJS_Value::VT_string: aName.SetElement(pRuntime, 0, params[0]); @@ -584,9 +584,8 @@ bool Document::resetForm(CJS_Runtime* pRuntime, std::vector<CPDF_FormField*> aFields; for (int i = 0, isz = aName.GetLength(pRuntime); i < isz; ++i) { - CJS_Value valElement(pRuntime); - aName.GetElement(pRuntime, i, valElement); - WideString swVal = valElement.ToCFXWideString(pRuntime); + CJS_Value valElement = aName.GetElement(pRuntime, i); + WideString swVal = valElement.ToWideString(pRuntime); for (int j = 0, jsz = pPDFForm->CountFields(swVal); j < jsz; ++j) aFields.push_back(pPDFForm->GetField(j, swVal)); } @@ -634,18 +633,18 @@ bool Document::submitForm(CJS_Runtime* pRuntime, bool bEmpty = false; CJS_Value v = params[0]; if (v.GetType() == CJS_Value::VT_string) { - strURL = params[0].ToCFXWideString(pRuntime); + strURL = params[0].ToWideString(pRuntime); if (nSize > 1) bFDF = params[1].ToBool(pRuntime); if (nSize > 2) bEmpty = params[2].ToBool(pRuntime); if (nSize > 3) - aFields.Attach(params[3].ToV8Array(pRuntime)); + aFields = CJS_Array(params[3].ToV8Array(pRuntime)); } else if (v.GetType() == CJS_Value::VT_object) { v8::Local<v8::Object> pObj = params[0].ToV8Object(pRuntime); v8::Local<v8::Value> pValue = pRuntime->GetObjectProperty(pObj, L"cURL"); if (!pValue.IsEmpty()) - strURL = CJS_Value(pRuntime, pValue).ToCFXWideString(pRuntime); + strURL = CJS_Value(pRuntime, pValue).ToWideString(pRuntime); pValue = pRuntime->GetObjectProperty(pObj, L"bFDF"); bFDF = CJS_Value(pRuntime, pValue).ToBool(pRuntime); @@ -654,7 +653,7 @@ bool Document::submitForm(CJS_Runtime* pRuntime, bEmpty = CJS_Value(pRuntime, pValue).ToBool(pRuntime); pValue = pRuntime->GetObjectProperty(pObj, L"aFields"); - aFields.Attach(CJS_Value(pRuntime, pValue).ToV8Array(pRuntime)); + aFields = CJS_Array(CJS_Value(pRuntime, pValue).ToV8Array(pRuntime)); } CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); @@ -670,10 +669,8 @@ bool Document::submitForm(CJS_Runtime* pRuntime, std::vector<CPDF_FormField*> fieldObjects; for (int i = 0, sz = aFields.GetLength(pRuntime); i < sz; ++i) { - CJS_Value valName(pRuntime); - aFields.GetElement(pRuntime, i, valName); - - WideString sName = valName.ToCFXWideString(pRuntime); + CJS_Value valName = aFields.GetElement(pRuntime, i); + WideString sName = valName.ToWideString(pRuntime); CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); for (int j = 0, jsz = pPDFForm->CountFields(sName); j < jsz; ++j) { CPDF_FormField* pField = pPDFForm->GetField(j, sName); @@ -723,15 +720,15 @@ bool Document::mailDoc(CJS_Runtime* pRuntime, if (params.size() >= 1) bUI = params[0].ToBool(pRuntime); if (params.size() >= 2) - cTo = params[1].ToCFXWideString(pRuntime); + cTo = params[1].ToWideString(pRuntime); if (params.size() >= 3) - cCc = params[2].ToCFXWideString(pRuntime); + cCc = params[2].ToWideString(pRuntime); if (params.size() >= 4) - cBcc = params[3].ToCFXWideString(pRuntime); + cBcc = params[3].ToWideString(pRuntime); if (params.size() >= 5) - cSubject = params[4].ToCFXWideString(pRuntime); + cSubject = params[4].ToWideString(pRuntime); if (params.size() >= 6) - cMsg = params[5].ToCFXWideString(pRuntime); + cMsg = params[5].ToWideString(pRuntime); if (params.size() >= 1 && params[0].GetType() == CJS_Value::VT_object) { v8::Local<v8::Object> pObj = params[0].ToV8Object(pRuntime); @@ -740,19 +737,19 @@ bool Document::mailDoc(CJS_Runtime* pRuntime, bUI = CJS_Value(pRuntime, pValue).ToBool(pRuntime); pValue = pRuntime->GetObjectProperty(pObj, L"cTo"); - cTo = CJS_Value(pRuntime, pValue).ToCFXWideString(pRuntime); + cTo = CJS_Value(pRuntime, pValue).ToWideString(pRuntime); pValue = pRuntime->GetObjectProperty(pObj, L"cCc"); - cCc = CJS_Value(pRuntime, pValue).ToCFXWideString(pRuntime); + cCc = CJS_Value(pRuntime, pValue).ToWideString(pRuntime); pValue = pRuntime->GetObjectProperty(pObj, L"cBcc"); - cBcc = CJS_Value(pRuntime, pValue).ToCFXWideString(pRuntime); + cBcc = CJS_Value(pRuntime, pValue).ToWideString(pRuntime); pValue = pRuntime->GetObjectProperty(pObj, L"cSubject"); - cSubject = CJS_Value(pRuntime, pValue).ToCFXWideString(pRuntime); + cSubject = CJS_Value(pRuntime, pValue).ToWideString(pRuntime); pValue = pRuntime->GetObjectProperty(pObj, L"cMsg"); - cMsg = CJS_Value(pRuntime, pValue).ToCFXWideString(pRuntime); + cMsg = CJS_Value(pRuntime, pValue).ToWideString(pRuntime); } pRuntime->BeginBlock(); @@ -1251,7 +1248,7 @@ bool Document::getAnnot(CJS_Runtime* pRuntime, return false; } int nPageNo = params[0].ToInt(pRuntime); - WideString swAnnotName = params[1].ToCFXWideString(pRuntime); + WideString swAnnotName = params[1].ToWideString(pRuntime); CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetPageView(nPageNo); if (!pPageView) return false; @@ -1366,7 +1363,7 @@ bool Document::addIcon(CJS_Runtime* pRuntime, return false; } - WideString swIconName = params[0].ToCFXWideString(pRuntime); + WideString swIconName = params[0].ToWideString(pRuntime); if (params[1].GetType() != CJS_Value::VT_object) { sError = JSGetStringFromID(IDS_STRING_JSTYPEERROR); return false; @@ -1378,7 +1375,7 @@ bool Document::addIcon(CJS_Runtime* pRuntime, return false; } - if (!params[1].ToCJSObject(pRuntime)->GetEmbedObject()) { + if (!params[1].ToObject(pRuntime)->GetEmbedObject()) { sError = JSGetStringFromID(IDS_STRING_JSTYPEERROR); return false; } @@ -1430,7 +1427,7 @@ bool Document::getIcon(CJS_Runtime* pRuntime, return false; } - WideString swIconName = params[0].ToCFXWideString(pRuntime); + WideString swIconName = params[0].ToWideString(pRuntime); auto it = std::find(m_IconNames.begin(), m_IconNames.end(), swIconName); if (it == m_IconNames.end()) return false; @@ -1775,7 +1772,7 @@ bool Document::gotoNamedDest(CJS_Runtime* pRuntime, sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return false; } - WideString wideName = params[0].ToCFXWideString(pRuntime); + WideString wideName = params[0].ToWideString(pRuntime); CPDF_Document* pDocument = m_pFormFillEnv->GetPDFDocument(); if (!pDocument) return false; diff --git a/fpdfsdk/javascript/Field.cpp b/fpdfsdk/javascript/Field.cpp index 0eaad73346..d3923141da 100644 --- a/fpdfsdk/javascript/Field.cpp +++ b/fpdfsdk/javascript/Field.cpp @@ -874,11 +874,8 @@ bool Field::set_current_value_indices(CJS_Runtime* pRuntime, array.push_back(vp.ToInt()); } else if (vp.GetJSValue()->IsArrayObject()) { CJS_Array SelArray = vp.ToArray(); - CJS_Value SelValue(pRuntime); - for (int i = 0, sz = SelArray.GetLength(pRuntime); i < sz; i++) { - SelArray.GetElement(pRuntime, i, SelValue); - array.push_back(SelValue.ToInt(pRuntime)); - } + for (int i = 0, sz = SelArray.GetLength(pRuntime); i < sz; i++) + array.push_back(SelArray.GetElement(pRuntime, i).ToInt(pRuntime)); } if (m_bDelay) { @@ -1771,16 +1768,11 @@ bool Field::set_rect(CJS_Runtime* pRuntime, if (!vp.GetJSValue()->IsArrayObject()) return false; - CJS_Value Upper_Leftx(pRuntime); - CJS_Value Upper_Lefty(pRuntime); - CJS_Value Lower_Rightx(pRuntime); - CJS_Value Lower_Righty(pRuntime); - CJS_Array rcArray = vp.ToArray(); - rcArray.GetElement(pRuntime, 0, Upper_Leftx); - rcArray.GetElement(pRuntime, 1, Upper_Lefty); - rcArray.GetElement(pRuntime, 2, Lower_Rightx); - rcArray.GetElement(pRuntime, 3, Lower_Righty); + CJS_Value Upper_Leftx = rcArray.GetElement(pRuntime, 0); + CJS_Value Upper_Lefty = rcArray.GetElement(pRuntime, 1); + CJS_Value Lower_Rightx = rcArray.GetElement(pRuntime, 2); + CJS_Value Lower_Righty = rcArray.GetElement(pRuntime, 3); float pArray[4]; pArray[0] = static_cast<float>(Upper_Leftx.ToInt(pRuntime)); @@ -2263,7 +2255,7 @@ bool Field::get_value(CJS_Runtime* pRuntime, iIndex = pFormField->GetSelectedIndex(i); ElementValue = CJS_Value(pRuntime, pFormField->GetOptionValue(iIndex).c_str()); - if (wcslen(ElementValue.ToCFXWideString(pRuntime).c_str()) == 0) { + if (wcslen(ElementValue.ToWideString(pRuntime).c_str()) == 0) { ElementValue = CJS_Value(pRuntime, pFormField->GetOptionLabel(iIndex).c_str()); } @@ -2308,9 +2300,8 @@ bool Field::set_value(CJS_Runtime* pRuntime, if (vp.GetJSValue()->IsArrayObject()) { CJS_Array ValueArray = vp.ToArray(); for (int i = 0, sz = ValueArray.GetLength(pRuntime); i < sz; i++) { - CJS_Value ElementValue(pRuntime); - ValueArray.GetElement(pRuntime, i, ElementValue); - strArray.push_back(ElementValue.ToCFXWideString(pRuntime)); + CJS_Value ElementValue = ValueArray.GetElement(pRuntime, i); + strArray.push_back(ElementValue.ToWideString(pRuntime)); } } else { strArray.push_back(vp.ToWideString()); diff --git a/fpdfsdk/javascript/JS_Value.cpp b/fpdfsdk/javascript/JS_Value.cpp index 6529a9d604..6205b48e6f 100644 --- a/fpdfsdk/javascript/JS_Value.cpp +++ b/fpdfsdk/javascript/JS_Value.cpp @@ -172,6 +172,10 @@ int DateFromTime(double t) { } } +double JS_LocalTime(double d) { + return d + GetLocalTZA() + GetDaylightSavingTA(d); +} + } // namespace CJS_Value::CJS_Value(CJS_Runtime* pRuntime) {} @@ -179,16 +183,16 @@ CJS_Value::CJS_Value(CJS_Runtime* pRuntime) {} CJS_Value::CJS_Value(CJS_Runtime* pRuntime, v8::Local<v8::Value> pValue) : m_pValue(pValue) {} -CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const int& iValue) +CJS_Value::CJS_Value(CJS_Runtime* pRuntime, int iValue) : m_pValue(pRuntime->NewNumber(iValue)) {} -CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const bool& bValue) +CJS_Value::CJS_Value(CJS_Runtime* pRuntime, bool bValue) : m_pValue(pRuntime->NewBoolean(bValue)) {} -CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const float& fValue) +CJS_Value::CJS_Value(CJS_Runtime* pRuntime, float fValue) : m_pValue(pRuntime->NewNumber(fValue)) {} -CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const double& dValue) +CJS_Value::CJS_Value(CJS_Runtime* pRuntime, double dValue) : m_pValue(pRuntime->NewNumber(dValue)) {} CJS_Value::CJS_Value(CJS_Runtime* pRuntime, CJS_Object* pObj) { @@ -212,14 +216,10 @@ CJS_Value::~CJS_Value() {} CJS_Value::CJS_Value(const CJS_Value& other) = default; -void CJS_Value::Attach(v8::Local<v8::Value> pValue) { +void CJS_Value::Set(v8::Local<v8::Value> pValue) { m_pValue = pValue; } -void CJS_Value::Detach() { - m_pValue = v8::Local<v8::Value>(); -} - int CJS_Value::ToInt(CJS_Runtime* pRuntime) const { return pRuntime->ToInt32(m_pValue); } @@ -233,24 +233,35 @@ double CJS_Value::ToDouble(CJS_Runtime* pRuntime) const { } float CJS_Value::ToFloat(CJS_Runtime* pRuntime) const { - return (float)ToDouble(pRuntime); + return static_cast<float>(ToDouble(pRuntime)); } -CJS_Object* CJS_Value::ToCJSObject(CJS_Runtime* pRuntime) const { +CJS_Object* CJS_Value::ToObject(CJS_Runtime* pRuntime) const { v8::Local<v8::Object> pObj = pRuntime->ToObject(m_pValue); return static_cast<CJS_Object*>(pRuntime->GetObjectPrivate(pObj)); } +CJS_Array CJS_Value::ToArray(CJS_Runtime* pRuntime) const { + ASSERT(IsArrayObject()); + return CJS_Array(pRuntime->ToArray(m_pValue)); +} + +CJS_Date CJS_Value::ToDate(CJS_Runtime* pRuntime) const { + ASSERT(IsDateObject()); + v8::Local<v8::Value> mutable_value = m_pValue; + return CJS_Date(mutable_value.As<v8::Date>()); +} + v8::Local<v8::Object> CJS_Value::ToV8Object(CJS_Runtime* pRuntime) const { return pRuntime->ToObject(m_pValue); } -WideString CJS_Value::ToCFXWideString(CJS_Runtime* pRuntime) const { +WideString CJS_Value::ToWideString(CJS_Runtime* pRuntime) const { return pRuntime->ToWideString(m_pValue); } -ByteString CJS_Value::ToCFXByteString(CJS_Runtime* pRuntime) const { - return ByteString::FromUnicode(ToCFXWideString(pRuntime)); +ByteString CJS_Value::ToByteString(CJS_Runtime* pRuntime) const { + return ByteString::FromUnicode(ToWideString(pRuntime)); } v8::Local<v8::Value> CJS_Value::ToV8Value(CJS_Runtime* pRuntime) const { @@ -268,7 +279,7 @@ void CJS_Value::SetNull(CJS_Runtime* pRuntime) { void CJS_Value::MaybeCoerceToNumber(CJS_Runtime* pRuntime) { bool bAllowNaN = false; if (GetType() == VT_string) { - ByteString bstr = ToCFXByteString(pRuntime); + ByteString bstr = ToByteString(pRuntime); if (bstr.GetLength() == 0) return; if (bstr == "NaN") @@ -315,21 +326,6 @@ bool CJS_Value::IsDateObject() const { return !m_pValue.IsEmpty() && m_pValue->IsDate(); } -bool CJS_Value::ConvertToArray(CJS_Runtime* pRuntime, CJS_Array& array) const { - if (!IsArrayObject()) - return false; - array.Attach(pRuntime->ToArray(m_pValue)); - return true; -} - -bool CJS_Value::ConvertToDate(CJS_Runtime* pRuntime, CJS_Date& date) const { - if (!IsDateObject()) - return false; - v8::Local<v8::Value> mutable_value = m_pValue; - date.Attach(mutable_value.As<v8::Date>()); - return true; -} - CJS_PropValue::CJS_PropValue(CJS_Runtime* pRuntime) : m_bIsSetting(0), m_Value(pRuntime), m_pJSRuntime(pRuntime) {} @@ -375,7 +371,7 @@ void CJS_PropValue::Set(CJS_Object* pObj) { CJS_Object* CJS_PropValue::ToObject() const { ASSERT(m_bIsSetting); - return m_Value.ToCJSObject(m_pJSRuntime.Get()); + return m_Value.ToObject(m_pJSRuntime.Get()); } void CJS_PropValue::Set(CJS_Document* pJsDoc) { @@ -385,7 +381,7 @@ void CJS_PropValue::Set(CJS_Document* pJsDoc) { CJS_Document* CJS_PropValue::ToDocument() const { ASSERT(m_bIsSetting); - return static_cast<CJS_Document*>(m_Value.ToCJSObject(m_pJSRuntime.Get())); + return static_cast<CJS_Document*>(m_Value.ToObject(m_pJSRuntime.Get())); } void CJS_PropValue::Set(v8::Local<v8::Object> pObj) { @@ -405,7 +401,7 @@ void CJS_PropValue::Set(const ByteString& str) { ByteString CJS_PropValue::ToByteString() const { ASSERT(m_bIsSetting); - return m_Value.ToCFXByteString(m_pJSRuntime.Get()); + return m_Value.ToByteString(m_pJSRuntime.Get()); } void CJS_PropValue::Set(const wchar_t* str) { @@ -415,7 +411,7 @@ void CJS_PropValue::Set(const wchar_t* str) { WideString CJS_PropValue::ToWideString() const { ASSERT(m_bIsSetting); - return m_Value.ToCFXWideString(m_pJSRuntime.Get()); + return m_Value.ToWideString(m_pJSRuntime.Get()); } void CJS_PropValue::Set(const WideString& wide_string) { @@ -425,21 +421,21 @@ void CJS_PropValue::Set(const WideString& wide_string) { CJS_Array CJS_PropValue::ToArray() const { ASSERT(m_bIsSetting); - CJS_Array ary; - m_Value.ConvertToArray(m_pJSRuntime.Get(), ary); - return ary; + if (!m_Value.IsArrayObject()) + return CJS_Array(); + return m_Value.ToArray(m_pJSRuntime.Get()); } void CJS_PropValue::Set(const CJS_Array& array) { ASSERT(!m_bIsSetting); - m_Value = CJS_Value(m_pJSRuntime.Get(), array.ToV8Array(m_pJSRuntime.Get())); + m_Value = CJS_Value(m_pJSRuntime.Get(), array); } CJS_Date CJS_PropValue::ToDate() const { ASSERT(m_bIsSetting); - CJS_Date date; - m_Value.ConvertToDate(m_pJSRuntime.Get(), date); - return date; + if (!m_Value.IsDateObject()) + return CJS_Date(); + return m_Value.ToDate(m_pJSRuntime.Get()); } void CJS_PropValue::Set(const CJS_Date& date) { @@ -449,19 +445,17 @@ void CJS_PropValue::Set(const CJS_Date& date) { CJS_Array::CJS_Array() {} +CJS_Array::CJS_Array(v8::Local<v8::Array> pArray) : m_pArray(pArray) {} + CJS_Array::CJS_Array(const CJS_Array& other) = default; CJS_Array::~CJS_Array() {} -void CJS_Array::Attach(v8::Local<v8::Array> pArray) { - m_pArray = pArray; -} - -void CJS_Array::GetElement(CJS_Runtime* pRuntime, - unsigned index, - CJS_Value& value) const { +CJS_Value CJS_Array::GetElement(CJS_Runtime* pRuntime, unsigned index) const { if (!m_pArray.IsEmpty()) - value.Attach(pRuntime->GetArrayElement(m_pArray, index)); + return CJS_Value(pRuntime, pRuntime->GetArrayElement(m_pArray, index)); + + return CJS_Value(pRuntime); } void CJS_Array::SetElement(CJS_Runtime* pRuntime, @@ -488,6 +482,8 @@ v8::Local<v8::Array> CJS_Array::ToV8Array(CJS_Runtime* pRuntime) const { CJS_Date::CJS_Date() {} +CJS_Date::CJS_Date(v8::Local<v8::Date> pDate) : m_pDate(pDate) {} + CJS_Date::CJS_Date(CJS_Runtime* pRuntime, double dMsecTime) : m_pDate(pRuntime->NewDate(dMsecTime)) {} @@ -508,10 +504,6 @@ bool CJS_Date::IsValidDate(CJS_Runtime* pRuntime) const { return !m_pDate.IsEmpty() && !std::isnan(pRuntime->ToDouble(m_pDate)); } -void CJS_Date::Attach(v8::Local<v8::Date> pDate) { - m_pDate = pDate; -} - int CJS_Date::GetYear(CJS_Runtime* pRuntime) const { if (!IsValidDate(pRuntime)) return 0; @@ -519,25 +511,12 @@ int CJS_Date::GetYear(CJS_Runtime* pRuntime) const { return JS_GetYearFromTime(JS_LocalTime(pRuntime->ToDouble(m_pDate))); } -void CJS_Date::SetYear(CJS_Runtime* pRuntime, int iYear) { - m_pDate = pRuntime->NewDate( - MakeDate(iYear, GetMonth(pRuntime), GetDay(pRuntime), GetHours(pRuntime), - GetMinutes(pRuntime), GetSeconds(pRuntime), 0)); -} - int CJS_Date::GetMonth(CJS_Runtime* pRuntime) const { if (!IsValidDate(pRuntime)) return 0; - return JS_GetMonthFromTime(JS_LocalTime(pRuntime->ToDouble(m_pDate))); } -void CJS_Date::SetMonth(CJS_Runtime* pRuntime, int iMonth) { - m_pDate = pRuntime->NewDate( - MakeDate(GetYear(pRuntime), iMonth, GetDay(pRuntime), GetHours(pRuntime), - GetMinutes(pRuntime), GetSeconds(pRuntime), 0)); -} - int CJS_Date::GetDay(CJS_Runtime* pRuntime) const { if (!IsValidDate(pRuntime)) return 0; @@ -545,12 +524,6 @@ int CJS_Date::GetDay(CJS_Runtime* pRuntime) const { return JS_GetDayFromTime(JS_LocalTime(pRuntime->ToDouble(m_pDate))); } -void CJS_Date::SetDay(CJS_Runtime* pRuntime, int iDay) { - m_pDate = pRuntime->NewDate( - MakeDate(GetYear(pRuntime), GetMonth(pRuntime), iDay, GetHours(pRuntime), - GetMinutes(pRuntime), GetSeconds(pRuntime), 0)); -} - int CJS_Date::GetHours(CJS_Runtime* pRuntime) const { if (!IsValidDate(pRuntime)) return 0; @@ -558,12 +531,6 @@ int CJS_Date::GetHours(CJS_Runtime* pRuntime) const { return JS_GetHourFromTime(JS_LocalTime(pRuntime->ToDouble(m_pDate))); } -void CJS_Date::SetHours(CJS_Runtime* pRuntime, int iHours) { - m_pDate = pRuntime->NewDate( - MakeDate(GetYear(pRuntime), GetMonth(pRuntime), GetDay(pRuntime), iHours, - GetMinutes(pRuntime), GetSeconds(pRuntime), 0)); -} - int CJS_Date::GetMinutes(CJS_Runtime* pRuntime) const { if (!IsValidDate(pRuntime)) return 0; @@ -571,12 +538,6 @@ int CJS_Date::GetMinutes(CJS_Runtime* pRuntime) const { return JS_GetMinFromTime(JS_LocalTime(pRuntime->ToDouble(m_pDate))); } -void CJS_Date::SetMinutes(CJS_Runtime* pRuntime, int minutes) { - m_pDate = pRuntime->NewDate(MakeDate(GetYear(pRuntime), GetMonth(pRuntime), - GetDay(pRuntime), GetHours(pRuntime), - minutes, GetSeconds(pRuntime), 0)); -} - int CJS_Date::GetSeconds(CJS_Runtime* pRuntime) const { if (!IsValidDate(pRuntime)) return 0; @@ -584,20 +545,6 @@ int CJS_Date::GetSeconds(CJS_Runtime* pRuntime) const { return JS_GetSecFromTime(JS_LocalTime(pRuntime->ToDouble(m_pDate))); } -void CJS_Date::SetSeconds(CJS_Runtime* pRuntime, int seconds) { - m_pDate = pRuntime->NewDate(MakeDate(GetYear(pRuntime), GetMonth(pRuntime), - GetDay(pRuntime), GetHours(pRuntime), - GetMinutes(pRuntime), seconds, 0)); -} - -double CJS_Date::ToDouble(CJS_Runtime* pRuntime) const { - return !m_pDate.IsEmpty() ? pRuntime->ToDouble(m_pDate) : 0.0; -} - -WideString CJS_Date::ToString(CJS_Runtime* pRuntime) const { - return !m_pDate.IsEmpty() ? pRuntime->ToWideString(m_pDate) : WideString(); -} - v8::Local<v8::Date> CJS_Date::ToV8Date(CJS_Runtime* pRuntime) const { return m_pDate; } @@ -706,11 +653,7 @@ double JS_MakeDate(double day, double time) { return day * 86400000 + time; } -double JS_LocalTime(double d) { - return d + GetLocalTZA() + GetDaylightSavingTA(d); -} - -std::vector<CJS_Value> JS_ExpandKeywordParams( +std::vector<CJS_Value> ExpandKeywordParams( CJS_Runtime* pRuntime, const std::vector<CJS_Value>& originals, size_t nKeywords, diff --git a/fpdfsdk/javascript/JS_Value.h b/fpdfsdk/javascript/JS_Value.h index 47e8cce98a..3631dbe6a1 100644 --- a/fpdfsdk/javascript/JS_Value.h +++ b/fpdfsdk/javascript/JS_Value.h @@ -30,12 +30,14 @@ class CJS_Value { VT_undefined }; + static Type GetValueType(v8::Local<v8::Value> value); + explicit CJS_Value(CJS_Runtime* pRuntime); CJS_Value(CJS_Runtime* pRuntime, v8::Local<v8::Value> pValue); - CJS_Value(CJS_Runtime* pRuntime, const int& iValue); - CJS_Value(CJS_Runtime* pRuntime, const double& dValue); - CJS_Value(CJS_Runtime* pRuntime, const float& fValue); - CJS_Value(CJS_Runtime* pRuntime, const bool& bValue); + CJS_Value(CJS_Runtime* pRuntime, int iValue); + CJS_Value(CJS_Runtime* pRuntime, double dValue); + CJS_Value(CJS_Runtime* pRuntime, float fValue); + CJS_Value(CJS_Runtime* pRuntime, bool bValue); CJS_Value(CJS_Runtime* pRuntime, CJS_Object* pObj); CJS_Value(CJS_Runtime* pRuntime, const char* pStr); CJS_Value(CJS_Runtime* pRuntime, const wchar_t* pWstr); @@ -47,20 +49,19 @@ class CJS_Value { ~CJS_Value(); void SetNull(CJS_Runtime* pRuntime); - void SetValue(const CJS_Value& other); - void Attach(v8::Local<v8::Value> pValue); - void Detach(); + void Set(v8::Local<v8::Value> pValue); - static Type GetValueType(v8::Local<v8::Value> value); Type GetType() const { return GetValueType(m_pValue); } int ToInt(CJS_Runtime* pRuntime) const; bool ToBool(CJS_Runtime* pRuntime) const; double ToDouble(CJS_Runtime* pRuntime) const; float ToFloat(CJS_Runtime* pRuntime) const; - CJS_Object* ToCJSObject(CJS_Runtime* pRuntime) const; - WideString ToCFXWideString(CJS_Runtime* pRuntime) const; - ByteString ToCFXByteString(CJS_Runtime* pRuntime) const; + CJS_Object* ToObject(CJS_Runtime* pRuntime) const; + CJS_Array ToArray(CJS_Runtime* pRuntime) const; + CJS_Date ToDate(CJS_Runtime* pRuntime) const; + WideString ToWideString(CJS_Runtime* pRuntime) const; + ByteString ToByteString(CJS_Runtime* pRuntime) const; v8::Local<v8::Object> ToV8Object(CJS_Runtime* pRuntime) const; v8::Local<v8::Array> ToV8Array(CJS_Runtime* pRuntime) const; v8::Local<v8::Value> ToV8Value(CJS_Runtime* pRuntime) const; @@ -71,10 +72,8 @@ class CJS_Value { bool IsArrayObject() const; bool IsDateObject() const; - bool ConvertToArray(CJS_Runtime* pRuntime, CJS_Array&) const; - bool ConvertToDate(CJS_Runtime* pRuntime, CJS_Date&) const; - protected: + private: v8::Local<v8::Value> m_pValue; }; @@ -133,16 +132,14 @@ class CJS_PropValue { class CJS_Array { public: CJS_Array(); + explicit CJS_Array(v8::Local<v8::Array> pArray); CJS_Array(const CJS_Array& other); virtual ~CJS_Array(); - void Attach(v8::Local<v8::Array> pArray); int GetLength(CJS_Runtime* pRuntime) const; // These two calls may re-enter JS (and hence invalidate objects). - void GetElement(CJS_Runtime* pRuntime, - unsigned index, - CJS_Value& value) const; + CJS_Value GetElement(CJS_Runtime* pRuntime, unsigned index) const; void SetElement(CJS_Runtime* pRuntime, unsigned index, const CJS_Value& value); @@ -156,6 +153,7 @@ class CJS_Array { class CJS_Date { public: CJS_Date(); + explicit CJS_Date(v8::Local<v8::Date> pDate); CJS_Date(CJS_Runtime* pRuntime, double dMsec_time); CJS_Date(CJS_Runtime* pRuntime, int year, @@ -167,30 +165,17 @@ class CJS_Date { CJS_Date(const CJS_Date&); virtual ~CJS_Date(); - void Attach(v8::Local<v8::Date> pDate); bool IsValidDate(CJS_Runtime* pRuntime) const; int GetYear(CJS_Runtime* pRuntime) const; - void SetYear(CJS_Runtime* pRuntime, int iYear); - int GetMonth(CJS_Runtime* pRuntime) const; - void SetMonth(CJS_Runtime* pRuntime, int iMonth); - int GetDay(CJS_Runtime* pRuntime) const; - void SetDay(CJS_Runtime* pRuntime, int iDay); - int GetHours(CJS_Runtime* pRuntime) const; - void SetHours(CJS_Runtime* pRuntime, int iHours); - int GetMinutes(CJS_Runtime* pRuntime) const; - void SetMinutes(CJS_Runtime* pRuntime, int minutes); - int GetSeconds(CJS_Runtime* pRuntime) const; - void SetSeconds(CJS_Runtime* pRuntime, int seconds); v8::Local<v8::Date> ToV8Date(CJS_Runtime* pRuntime) const; - double ToDouble(CJS_Runtime* pRuntime) const; - WideString ToString(CJS_Runtime* pRuntime) const; + WideString ToWideString(int style) const; protected: v8::Local<v8::Date> m_pDate; @@ -207,7 +192,6 @@ double JS_DateParse(const 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); -double JS_LocalTime(double d); // Some JS methods have the bizarre convention that they may also be called // with a single argument which is an object containing the actual arguments @@ -215,7 +199,7 @@ double JS_LocalTime(double d); // names as wchar_t string literals corresponding to each positional argument. // The result will always contain |nKeywords| value, with unspecified ones // being set to type VT_unknown. -std::vector<CJS_Value> JS_ExpandKeywordParams( +std::vector<CJS_Value> ExpandKeywordParams( CJS_Runtime* pRuntime, const std::vector<CJS_Value>& originals, size_t nKeywords, diff --git a/fpdfsdk/javascript/PublicMethods.cpp b/fpdfsdk/javascript/PublicMethods.cpp index 775877100e..6e0ebef0e8 100644 --- a/fpdfsdk/javascript/PublicMethods.cpp +++ b/fpdfsdk/javascript/PublicMethods.cpp @@ -189,18 +189,17 @@ double CJS_PublicMethods::AF_Simple(const wchar_t* sFuction, CJS_Array CJS_PublicMethods::AF_MakeArrayFromList(CJS_Runtime* pRuntime, CJS_Value val) { - CJS_Array StrArray; - if (val.IsArrayObject()) { - val.ConvertToArray(pRuntime, StrArray); - return StrArray; - } - WideString wsStr = val.ToCFXWideString(pRuntime); + if (val.IsArrayObject()) + return val.ToArray(pRuntime); + + WideString wsStr = val.ToWideString(pRuntime); ByteString t = ByteString::FromUnicode(wsStr); const char* p = t.c_str(); int ch = ','; int nIndex = 0; + CJS_Array StrArray; while (*p) { const char* pTemp = strchr(p, ch); if (!pTemp) { @@ -772,7 +771,7 @@ bool CJS_PublicMethods::AFNumber_Format(CJS_Runtime* pRuntime, int iSepStyle = params[1].ToInt(pRuntime); int iNegStyle = params[2].ToInt(pRuntime); // params[3] is iCurrStyle, it's not used. - WideString wstrCurrency = params[4].ToCFXWideString(pRuntime); + WideString wstrCurrency = params[4].ToWideString(pRuntime); bool bCurrencyPrepend = params[5].ToBool(pRuntime); if (iDec < 0) @@ -871,9 +870,7 @@ bool CJS_PublicMethods::AFNumber_Format(CJS_Runtime* pRuntime, vProp.StartGetting(); fTarget->get_text_color(pRuntime, &vProp, &sError); - CJS_Array aProp; - vProp.GetJSValue()->ConvertToArray(pRuntime, aProp); - + CJS_Array aProp = vProp.GetJSValue()->ToArray(pRuntime); CFX_Color crProp; CFX_Color crColor; color::ConvertArrayToPWLColor(pRuntime, aProp, &crProp); @@ -1109,7 +1106,7 @@ bool CJS_PublicMethods::AFDate_FormatEx(CJS_Runtime* pRuntime, if (strValue.IsEmpty()) return true; - WideString sFormat = params[0].ToCFXWideString(pRuntime); + WideString sFormat = params[0].ToWideString(pRuntime); double dDate = 0.0f; if (strValue.Contains(L"GMT")) { @@ -1207,7 +1204,7 @@ bool CJS_PublicMethods::AFDate_KeystrokeEx(CJS_Runtime* pRuntime, if (strValue.IsEmpty()) return true; - WideString sFormat = params[0].ToCFXWideString(pRuntime); + WideString sFormat = params[0].ToWideString(pRuntime); bool bWrongFormat = false; double dRet = MakeRegularDate(strValue, sFormat, &bWrongFormat); if (bWrongFormat || std::isnan(dRet)) { @@ -1402,7 +1399,7 @@ bool CJS_PublicMethods::AFSpecial_KeystrokeEx( return false; WideString& valEvent = pEvent->Value(); - WideString wstrMask = params[0].ToCFXWideString(pRuntime); + WideString wstrMask = params[0].ToWideString(pRuntime); if (wstrMask.IsEmpty()) return true; @@ -1557,8 +1554,8 @@ bool CJS_PublicMethods::AFParseDateEx(CJS_Runtime* pRuntime, return false; } - WideString sValue = params[0].ToCFXWideString(pRuntime); - WideString sFormat = params[1].ToCFXWideString(pRuntime); + WideString sValue = params[0].ToWideString(pRuntime); + WideString sFormat = params[1].ToWideString(pRuntime); double dDate = MakeRegularDate(sValue, sFormat, nullptr); if (std::isnan(dDate)) { WideString swMsg; @@ -1582,7 +1579,7 @@ bool CJS_PublicMethods::AFSimple(CJS_Runtime* pRuntime, } vRet = CJS_Value(pRuntime, static_cast<double>(AF_Simple( - params[0].ToCFXWideString(pRuntime).c_str(), + params[0].ToWideString(pRuntime).c_str(), params[1].ToDouble(pRuntime), params[2].ToDouble(pRuntime)))); @@ -1598,7 +1595,7 @@ bool CJS_PublicMethods::AFMakeNumber(CJS_Runtime* pRuntime, return false; } - WideString ws = params[0].ToCFXWideString(pRuntime); + WideString ws = params[0].ToWideString(pRuntime); ws.Replace(L",", L"."); vRet = CJS_Value(pRuntime, ws.c_str()); vRet.MaybeCoerceToNumber(pRuntime); @@ -1626,16 +1623,15 @@ bool CJS_PublicMethods::AFSimple_Calculate(CJS_Runtime* pRuntime, pRuntime->GetFormFillEnv()->GetInterForm(); CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm(); - WideString sFunction = params[0].ToCFXWideString(pRuntime); + WideString sFunction = params[0].ToWideString(pRuntime); double dValue = wcscmp(sFunction.c_str(), L"PRD") == 0 ? 1.0 : 0.0; CJS_Array FieldNameArray = AF_MakeArrayFromList(pRuntime, params1); int nFieldsCount = 0; for (int i = 0, isz = FieldNameArray.GetLength(pRuntime); i < isz; i++) { - CJS_Value jsValue(pRuntime); - FieldNameArray.GetElement(pRuntime, i, jsValue); - WideString wsFieldName = jsValue.ToCFXWideString(pRuntime); + CJS_Value jsValue(FieldNameArray.GetElement(pRuntime, i)); + WideString wsFieldName = jsValue.ToWideString(pRuntime); for (int j = 0, jsz = pInterForm->CountFields(wsFieldName); j < jsz; j++) { if (CPDF_FormField* pFormField = pInterForm->GetField(j, wsFieldName)) { @@ -1698,7 +1694,7 @@ bool CJS_PublicMethods::AFSimple_Calculate(CJS_Runtime* pRuntime, CJS_Value jsValue(pRuntime, dValue); CJS_EventContext* pContext = pRuntime->GetCurrentEventContext(); if (pContext->GetEventHandler()->m_pValue) - pContext->GetEventHandler()->Value() = jsValue.ToCFXWideString(pRuntime); + pContext->GetEventHandler()->Value() = jsValue.ToWideString(pRuntime); return true; } @@ -1732,16 +1728,16 @@ bool CJS_PublicMethods::AFRange_Validate(CJS_Runtime* pRuntime, if (bGreaterThan && bLessThan) { if (dEentValue < dGreaterThan || dEentValue > dLessThan) swMsg.Format(JSGetStringFromID(IDS_STRING_JSRANGE1).c_str(), - params[1].ToCFXWideString(pRuntime).c_str(), - params[3].ToCFXWideString(pRuntime).c_str()); + params[1].ToWideString(pRuntime).c_str(), + params[3].ToWideString(pRuntime).c_str()); } else if (bGreaterThan) { if (dEentValue < dGreaterThan) swMsg.Format(JSGetStringFromID(IDS_STRING_JSRANGE2).c_str(), - params[1].ToCFXWideString(pRuntime).c_str()); + params[1].ToWideString(pRuntime).c_str()); } else if (bLessThan) { if (dEentValue > dLessThan) swMsg.Format(JSGetStringFromID(IDS_STRING_JSRANGE3).c_str(), - params[3].ToCFXWideString(pRuntime).c_str()); + params[3].ToWideString(pRuntime).c_str()); } if (!swMsg.IsEmpty()) { @@ -1760,7 +1756,7 @@ bool CJS_PublicMethods::AFExtractNums(CJS_Runtime* pRuntime, return false; } - WideString str = params[0].ToCFXWideString(pRuntime); + WideString str = params[0].ToWideString(pRuntime); if (str.GetLength() > 0 && (str[0] == L'.' || str[0] == L',')) str = L"0" + str; diff --git a/fpdfsdk/javascript/app.cpp b/fpdfsdk/javascript/app.cpp index 9fac4611a6..86dc7c5673 100644 --- a/fpdfsdk/javascript/app.cpp +++ b/fpdfsdk/javascript/app.cpp @@ -382,7 +382,7 @@ bool app::alert(CJS_Runtime* pRuntime, const std::vector<CJS_Value>& params, CJS_Value& vRet, WideString& sError) { - std::vector<CJS_Value> newParams = JS_ExpandKeywordParams( + std::vector<CJS_Value> newParams = ExpandKeywordParams( pRuntime, params, 4, L"cMsg", L"nIcon", L"nType", L"cTitle"); if (newParams[0].GetType() == CJS_Value::VT_unknown) { @@ -398,22 +398,22 @@ bool app::alert(CJS_Runtime* pRuntime, WideString swMsg; if (newParams[0].GetType() == CJS_Value::VT_object) { - CJS_Array carray; - if (newParams[0].ConvertToArray(pRuntime, carray)) { + if (newParams[0].IsArrayObject()) { + CJS_Array carray = newParams[0].ToArray(pRuntime); swMsg = L"["; - CJS_Value element(pRuntime); for (int i = 0; i < carray.GetLength(pRuntime); ++i) { if (i) swMsg += L", "; - carray.GetElement(pRuntime, i, element); - swMsg += element.ToCFXWideString(pRuntime); + + CJS_Value element(carray.GetElement(pRuntime, i)); + swMsg += element.ToWideString(pRuntime); } swMsg += L"]"; } else { - swMsg = newParams[0].ToCFXWideString(pRuntime); + swMsg = newParams[0].ToWideString(pRuntime); } } else { - swMsg = newParams[0].ToCFXWideString(pRuntime); + swMsg = newParams[0].ToWideString(pRuntime); } int iIcon = 0; @@ -426,7 +426,7 @@ bool app::alert(CJS_Runtime* pRuntime, WideString swTitle; if (newParams[3].GetType() != CJS_Value::VT_unknown) - swTitle = newParams[3].ToCFXWideString(pRuntime); + swTitle = newParams[3].ToWideString(pRuntime); else swTitle = JSGetStringFromID(IDS_STRING_JSALERT); @@ -486,7 +486,7 @@ bool app::setInterval(CJS_Runtime* pRuntime, } WideString script = - params.size() > 0 ? params[0].ToCFXWideString(pRuntime) : L""; + params.size() > 0 ? params[0].ToWideString(pRuntime) : L""; if (script.IsEmpty()) { sError = JSGetStringFromID(IDS_STRING_JSAFNUMBER_KEYSTROKE); return true; @@ -521,7 +521,7 @@ bool app::setTimeOut(CJS_Runtime* pRuntime, return false; } - WideString script = params[0].ToCFXWideString(pRuntime); + WideString script = params[0].ToWideString(pRuntime); if (script.IsEmpty()) { sError = JSGetStringFromID(IDS_STRING_JSAFNUMBER_KEYSTROKE); return true; @@ -580,7 +580,7 @@ void app::ClearTimerCommon(CJS_Runtime* pRuntime, const CJS_Value& param) { if (CFXJS_Engine::GetObjDefnID(pObj) != CJS_TimerObj::g_nObjDefnID) return; - CJS_Object* pJSObj = param.ToCJSObject(pRuntime); + CJS_Object* pJSObj = param.ToObject(pRuntime); if (!pJSObj) return; @@ -639,8 +639,8 @@ bool app::mailMsg(CJS_Runtime* pRuntime, CJS_Value& vRet, WideString& sError) { std::vector<CJS_Value> newParams = - JS_ExpandKeywordParams(pRuntime, params, 6, L"bUI", L"cTo", L"cCc", - L"cBcc", L"cSubject", L"cMsg"); + ExpandKeywordParams(pRuntime, params, 6, L"bUI", L"cTo", L"cCc", L"cBcc", + L"cSubject", L"cMsg"); if (newParams[0].GetType() == CJS_Value::VT_unknown) { sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); @@ -650,7 +650,7 @@ bool app::mailMsg(CJS_Runtime* pRuntime, WideString cTo; if (newParams[1].GetType() != CJS_Value::VT_unknown) { - cTo = newParams[1].ToCFXWideString(pRuntime); + cTo = newParams[1].ToWideString(pRuntime); } else { if (!bUI) { // cTo parameter required when UI not invoked. @@ -661,19 +661,19 @@ bool app::mailMsg(CJS_Runtime* pRuntime, WideString cCc; if (newParams[2].GetType() != CJS_Value::VT_unknown) - cCc = newParams[2].ToCFXWideString(pRuntime); + cCc = newParams[2].ToWideString(pRuntime); WideString cBcc; if (newParams[3].GetType() != CJS_Value::VT_unknown) - cBcc = newParams[3].ToCFXWideString(pRuntime); + cBcc = newParams[3].ToWideString(pRuntime); WideString cSubject; if (newParams[4].GetType() != CJS_Value::VT_unknown) - cSubject = newParams[4].ToCFXWideString(pRuntime); + cSubject = newParams[4].ToWideString(pRuntime); WideString cMsg; if (newParams[5].GetType() != CJS_Value::VT_unknown) - cMsg = newParams[5].ToCFXWideString(pRuntime); + cMsg = newParams[5].ToWideString(pRuntime); pRuntime->BeginBlock(); pRuntime->GetFormFillEnv()->JS_docmailForm(nullptr, 0, bUI, cTo.c_str(), @@ -760,22 +760,22 @@ bool app::response(CJS_Runtime* pRuntime, CJS_Value& vRet, WideString& sError) { std::vector<CJS_Value> newParams = - JS_ExpandKeywordParams(pRuntime, params, 5, L"cQuestion", L"cTitle", - L"cDefault", L"bPassword", L"cLabel"); + ExpandKeywordParams(pRuntime, params, 5, L"cQuestion", L"cTitle", + L"cDefault", L"bPassword", L"cLabel"); if (newParams[0].GetType() == CJS_Value::VT_unknown) { sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); return false; } - WideString swQuestion = newParams[0].ToCFXWideString(pRuntime); + WideString swQuestion = newParams[0].ToWideString(pRuntime); WideString swTitle = L"PDF"; if (newParams[1].GetType() != CJS_Value::VT_unknown) - swTitle = newParams[1].ToCFXWideString(pRuntime); + swTitle = newParams[1].ToWideString(pRuntime); WideString swDefault; if (newParams[2].GetType() != CJS_Value::VT_unknown) - swDefault = newParams[2].ToCFXWideString(pRuntime); + swDefault = newParams[2].ToWideString(pRuntime); bool bPassword = false; if (newParams[3].GetType() != CJS_Value::VT_unknown) @@ -783,7 +783,7 @@ bool app::response(CJS_Runtime* pRuntime, WideString swLabel; if (newParams[4].GetType() != CJS_Value::VT_unknown) - swLabel = newParams[4].ToCFXWideString(pRuntime); + swLabel = newParams[4].ToWideString(pRuntime); const int MAX_INPUT_BYTES = 2048; std::vector<uint8_t> pBuff(MAX_INPUT_BYTES + 2); diff --git a/fpdfsdk/javascript/color.cpp b/fpdfsdk/javascript/color.cpp index f1dc26efec..575a86c4e6 100644 --- a/fpdfsdk/javascript/color.cpp +++ b/fpdfsdk/javascript/color.cpp @@ -89,45 +89,29 @@ void color::ConvertArrayToPWLColor(CJS_Runtime* pRuntime, if (nArrayLen < 1) return; - CJS_Value value(pRuntime); - array.GetElement(pRuntime, 0, value); - ByteString sSpace = value.ToCFXByteString(pRuntime); - - double d1 = 0; - double d2 = 0; - double d3 = 0; - double d4 = 0; - - if (nArrayLen > 1) { - array.GetElement(pRuntime, 1, value); - d1 = value.ToDouble(pRuntime); - } - - if (nArrayLen > 2) { - array.GetElement(pRuntime, 2, value); - d2 = value.ToDouble(pRuntime); - } - - if (nArrayLen > 3) { - array.GetElement(pRuntime, 3, value); - d3 = value.ToDouble(pRuntime); - } - - if (nArrayLen > 4) { - array.GetElement(pRuntime, 4, value); - d4 = value.ToDouble(pRuntime); - } - - if (sSpace == "T") { + float d1 = 0; + float d2 = 0; + float d3 = 0; + float d4 = 0; + + if (nArrayLen > 1) + d1 = array.GetElement(pRuntime, 1).ToFloat(pRuntime); + if (nArrayLen > 2) + d2 = array.GetElement(pRuntime, 2).ToFloat(pRuntime); + if (nArrayLen > 3) + d3 = array.GetElement(pRuntime, 3).ToFloat(pRuntime); + if (nArrayLen > 4) + d4 = array.GetElement(pRuntime, 4).ToFloat(pRuntime); + + ByteString sSpace = array.GetElement(pRuntime, 0).ToByteString(pRuntime); + if (sSpace == "T") *color = CFX_Color(CFX_Color::kTransparent); - } else if (sSpace == "G") { - *color = CFX_Color(CFX_Color::kGray, (float)d1); - } else if (sSpace == "RGB") { - *color = CFX_Color(CFX_Color::kRGB, (float)d1, (float)d2, (float)d3); - } else if (sSpace == "CMYK") { - *color = - CFX_Color(CFX_Color::kCMYK, (float)d1, (float)d2, (float)d3, (float)d4); - } + else if (sSpace == "G") + *color = CFX_Color(CFX_Color::kGray, d1); + else if (sSpace == "RGB") + *color = CFX_Color(CFX_Color::kRGB, d1, d2, d3); + else if (sSpace == "CMYK") + *color = CFX_Color(CFX_Color::kCMYK, d1, d2, d3, d4); } bool color::get_transparent(CJS_Runtime* pRuntime, @@ -286,11 +270,10 @@ bool color::GetPropertyHelper(CJS_Runtime* pRuntime, bool color::SetPropertyHelper(CJS_Runtime* pRuntime, const CJS_PropValue& vp, CFX_Color* var) { - CJS_Array array; - if (!vp.GetJSValue()->ConvertToArray(pRuntime, array)) + if (!vp.GetJSValue()->IsArrayObject()) return false; - ConvertArrayToPWLColor(pRuntime, array, var); + ConvertArrayToPWLColor(pRuntime, vp.GetJSValue()->ToArray(pRuntime), var); return true; } @@ -302,14 +285,13 @@ bool color::convert(CJS_Runtime* pRuntime, if (iSize < 2) return false; - CJS_Array aSource; - if (!params[0].ConvertToArray(pRuntime, aSource)) + if (!params[0].IsArrayObject()) return false; CFX_Color crSource; - ConvertArrayToPWLColor(pRuntime, aSource, &crSource); + ConvertArrayToPWLColor(pRuntime, params[0].ToArray(pRuntime), &crSource); - ByteString sDestSpace = params[1].ToCFXByteString(pRuntime); + ByteString sDestSpace = params[1].ToByteString(pRuntime); int nColorType = CFX_Color::kTransparent; if (sDestSpace == "T") { @@ -336,18 +318,14 @@ bool color::equal(CJS_Runtime* pRuntime, WideString& sError) { if (params.size() < 2) return false; - - CJS_Array array1; - CJS_Array array2; - if (!params[0].ConvertToArray(pRuntime, array1)) - return false; - if (!params[1].ConvertToArray(pRuntime, array2)) + if (!params[0].IsArrayObject() || !params[1].IsArrayObject()) return false; CFX_Color color1; CFX_Color color2; - ConvertArrayToPWLColor(pRuntime, array1, &color1); - ConvertArrayToPWLColor(pRuntime, array2, &color2); + ConvertArrayToPWLColor(pRuntime, params[0].ToArray(pRuntime), &color1); + ConvertArrayToPWLColor(pRuntime, params[1].ToArray(pRuntime), &color2); + color1 = color1.ConvertColorType(color2.nColorType); vRet = CJS_Value(pRuntime, color1 == color2); return true; diff --git a/fpdfsdk/javascript/global.cpp b/fpdfsdk/javascript/global.cpp index 43c461c497..4635f1c84c 100644 --- a/fpdfsdk/javascript/global.cpp +++ b/fpdfsdk/javascript/global.cpp @@ -154,7 +154,7 @@ bool JSGlobalAlternate::setPersistent(CJS_Runtime* pRuntime, sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); return false; } - auto it = m_MapGlobal.find(params[0].ToCFXByteString(pRuntime)); + auto it = m_MapGlobal.find(params[0].ToByteString(pRuntime)); if (it == m_MapGlobal.end() || it->second->bDeleted) { sError = JSGetStringFromID(IDS_STRING_JSNOGLOBAL); return false; @@ -278,7 +278,7 @@ void JSGlobalAlternate::ObjectToArray(CJS_Runtime* pRuntime, array.Add(pObjElement); } break; case CJS_Value::VT_string: { - ByteString sValue = CJS_Value(pRuntime, v).ToCFXByteString(pRuntime); + ByteString sValue = CJS_Value(pRuntime, v).ToByteString(pRuntime); CJS_KeyValue* pObjElement = new CJS_KeyValue; pObjElement->nType = JS_GlobalDataType::STRING; pObjElement->sKey = sKey; diff --git a/fpdfsdk/javascript/util.cpp b/fpdfsdk/javascript/util.cpp index b82020d874..109c0ece4b 100644 --- a/fpdfsdk/javascript/util.cpp +++ b/fpdfsdk/javascript/util.cpp @@ -81,7 +81,7 @@ bool util::printf(CJS_Runtime* pRuntime, if (iSize < 1) return false; - std::wstring unsafe_fmt_string(params[0].ToCFXWideString(pRuntime).c_str()); + std::wstring unsafe_fmt_string(params[0].ToWideString(pRuntime).c_str()); std::vector<std::wstring> unsafe_conversion_specifiers; int iOffset = 0; int iOffend = 0; @@ -122,7 +122,7 @@ bool util::printf(CJS_Runtime* pRuntime, break; case UTIL_STRING: strSegment.Format(c_strFormat.c_str(), - params[iIndex].ToCFXWideString(pRuntime).c_str()); + params[iIndex].ToWideString(pRuntime).c_str()); break; default: strSegment.Format(L"%ls", c_strFormat.c_str()); @@ -146,12 +146,12 @@ bool util::printd(CJS_Runtime* pRuntime, const CJS_Value& p1 = params[0]; const CJS_Value& p2 = params[1]; - CJS_Date jsDate; - if (!p2.ConvertToDate(pRuntime, jsDate)) { + if (!p2.IsDateObject()) { sError = JSGetStringFromID(IDS_STRING_JSPRINT1); return false; } + CJS_Date jsDate = p2.ToDate(pRuntime); if (!jsDate.IsValidDate(pRuntime)) { sError = JSGetStringFromID(IDS_STRING_JSPRINT2); return false; @@ -197,7 +197,7 @@ bool util::printd(CJS_Runtime* pRuntime, // Convert PDF-style format specifiers to wcsftime specifiers. Remove any // pre-existing %-directives before inserting our own. - std::basic_string<wchar_t> cFormat = p1.ToCFXWideString(pRuntime).c_str(); + std::basic_string<wchar_t> cFormat = p1.ToWideString(pRuntime).c_str(); cFormat.erase(std::remove(cFormat.begin(), cFormat.end(), '%'), cFormat.end()); @@ -276,8 +276,8 @@ bool util::printx(CJS_Runtime* pRuntime, return false; } - vRet = CJS_Value(pRuntime, printx(params[0].ToCFXWideString(pRuntime), - params[1].ToCFXWideString(pRuntime)) + vRet = CJS_Value(pRuntime, printx(params[0].ToWideString(pRuntime), + params[1].ToWideString(pRuntime)) .c_str()); return true; @@ -388,8 +388,8 @@ bool util::scand(CJS_Runtime* pRuntime, if (params.size() < 2) return false; - WideString sFormat = params[0].ToCFXWideString(pRuntime); - WideString sDate = params[1].ToCFXWideString(pRuntime); + WideString sFormat = params[0].ToWideString(pRuntime); + WideString sDate = params[1].ToWideString(pRuntime); double dDate = JS_GetDateTime(); if (sDate.GetLength() > 0) { dDate = CJS_PublicMethods::MakeRegularDate(sDate, sFormat, nullptr); |