From 1b2a18ec4ed99fc2ac56b5fde230bc2b348d9725 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Tue, 24 Oct 2017 13:56:29 -0400 Subject: Remove the CJS_Value To* methods. This CL removes all of the To* methods on the CJS classes except for ToV8Value. Change-Id: If01263c8cfa557ef7b00f573ddbf68b591d5ae9a Reviewed-on: https://pdfium-review.googlesource.com/16614 Reviewed-by: Tom Sepez Commit-Queue: dsinclair --- fpdfsdk/javascript/Annot.cpp | 6 +- fpdfsdk/javascript/Document.cpp | 174 ++++++++++++++++++----------------- fpdfsdk/javascript/Field.cpp | 150 +++++++++++++++++++----------- fpdfsdk/javascript/JS_Value.cpp | 68 +------------- fpdfsdk/javascript/JS_Value.h | 19 +--- fpdfsdk/javascript/PublicMethods.cpp | 110 ++++++++++++---------- fpdfsdk/javascript/app.cpp | 68 ++++++++------ fpdfsdk/javascript/color.cpp | 78 +++++++++------- fpdfsdk/javascript/event.cpp | 10 +- fpdfsdk/javascript/global.cpp | 20 ++-- fpdfsdk/javascript/util.cpp | 39 ++++---- 11 files changed, 385 insertions(+), 357 deletions(-) diff --git a/fpdfsdk/javascript/Annot.cpp b/fpdfsdk/javascript/Annot.cpp index c9fbaaf76f..d80c75525a 100644 --- a/fpdfsdk/javascript/Annot.cpp +++ b/fpdfsdk/javascript/Annot.cpp @@ -52,7 +52,8 @@ bool Annot::get_hidden(CJS_Runtime* pRuntime, bool Annot::set_hidden(CJS_Runtime* pRuntime, const CJS_Value& vp, WideString* sError) { - bool bHidden = vp.ToBool(pRuntime); // May invalidate m_pAnnot. + // May invalidate m_pAnnot. + bool bHidden = pRuntime->ToBoolean(vp.ToV8Value()); if (!m_pAnnot) { *sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return false; @@ -89,7 +90,8 @@ bool Annot::get_name(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError) { bool Annot::set_name(CJS_Runtime* pRuntime, const CJS_Value& vp, WideString* sError) { - WideString annotName = vp.ToWideString(pRuntime); // May invalidate m_pAnnot. + // May invalidate m_pAnnot. + WideString annotName = pRuntime->ToWideString(vp.ToV8Value()); if (!m_pAnnot) { *sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return false; diff --git a/fpdfsdk/javascript/Document.cpp b/fpdfsdk/javascript/Document.cpp index c406425a92..68023d02b0 100644 --- a/fpdfsdk/javascript/Document.cpp +++ b/fpdfsdk/javascript/Document.cpp @@ -204,8 +204,8 @@ bool Document::set_dirty(CJS_Runtime* pRuntime, return false; } - vp.ToBool(pRuntime) ? m_pFormFillEnv->SetChangeMark() - : m_pFormFillEnv->ClearChangeMark(); + pRuntime->ToBoolean(vp.ToV8Value()) ? m_pFormFillEnv->SetChangeMark() + : m_pFormFillEnv->ClearChangeMark(); return true; } @@ -245,7 +245,7 @@ bool Document::set_page_num(CJS_Runtime* pRuntime, } int iPageCount = m_pFormFillEnv->GetPageCount(); - int iPageNum = vp.ToInt(pRuntime); + int iPageNum = pRuntime->ToInt32(vp.ToV8Value()); if (iPageNum >= 0 && iPageNum < iPageCount) m_pFormFillEnv->JS_docgotoPage(iPageNum); else if (iPageNum >= iPageCount) @@ -308,7 +308,7 @@ bool Document::getField(CJS_Runtime* pRuntime, sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return false; } - WideString wideName = params[0].ToWideString(pRuntime); + WideString wideName = pRuntime->ToWideString(params[0].ToV8Value()); CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); if (pPDFForm->CountFields(wideName) <= 0) { @@ -344,7 +344,7 @@ bool Document::getNthFieldName(CJS_Runtime* pRuntime, sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return false; } - int nIndex = params[0].ToInt(pRuntime); + int nIndex = pRuntime->ToInt32(params[0].ToV8Value()); if (nIndex < 0) { sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR); return false; @@ -399,12 +399,17 @@ bool Document::mailForm(CJS_Runtime* pRuntime, return false; } int iLength = params.size(); - bool bUI = iLength > 0 ? params[0].ToBool(pRuntime) : true; - 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""; + bool bUI = iLength > 0 ? pRuntime->ToBoolean(params[0].ToV8Value()) : true; + WideString cTo = + iLength > 1 ? pRuntime->ToWideString(params[1].ToV8Value()) : L""; + WideString cCc = + iLength > 2 ? pRuntime->ToWideString(params[2].ToV8Value()) : L""; + WideString cBcc = + iLength > 3 ? pRuntime->ToWideString(params[3].ToV8Value()) : L""; + WideString cSubject = + iLength > 4 ? pRuntime->ToWideString(params[4].ToV8Value()) : L""; + WideString cMsg = + iLength > 5 ? pRuntime->ToWideString(params[5].ToV8Value()) : L""; CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); ByteString sTextBuf = pInterForm->ExportFormToFDFTextBuf(); if (sTextBuf.GetLength() == 0) @@ -443,10 +448,13 @@ bool Document::print(CJS_Runtime* pRuntime, int nlength = params.size(); if (nlength == 9) { if (params[8].GetType() == CJS_Value::VT_object) { - v8::Local pObj = params[8].ToV8Object(pRuntime); + v8::Local pObj = pRuntime->ToObject(params[8].ToV8Value()); if (CFXJS_Engine::GetObjDefnID(pObj) == CJS_PrintParamsObj::g_nObjDefnID) { - if (CJS_Object* pJSObj = params[8].ToObject(pRuntime)) { + v8::Local pObj = pRuntime->ToObject(params[8].ToV8Value()); + CJS_Object* pJSObj = + static_cast(pRuntime->GetObjectPrivate(pObj)); + if (pJSObj) { if (PrintParamsObj* pprintparamsObj = static_cast(pJSObj->GetEmbedObject())) { bUI = pprintparamsObj->bUI; @@ -463,21 +471,21 @@ bool Document::print(CJS_Runtime* pRuntime, } } else { if (nlength >= 1) - bUI = params[0].ToBool(pRuntime); + bUI = pRuntime->ToBoolean(params[0].ToV8Value()); if (nlength >= 2) - nStart = params[1].ToInt(pRuntime); + nStart = pRuntime->ToInt32(params[1].ToV8Value()); if (nlength >= 3) - nEnd = params[2].ToInt(pRuntime); + nEnd = pRuntime->ToInt32(params[2].ToV8Value()); if (nlength >= 4) - bSilent = params[3].ToBool(pRuntime); + bSilent = pRuntime->ToBoolean(params[3].ToV8Value()); if (nlength >= 5) - bShrinkToFit = params[4].ToBool(pRuntime); + bShrinkToFit = pRuntime->ToBoolean(params[4].ToV8Value()); if (nlength >= 6) - bPrintAsImage = params[5].ToBool(pRuntime); + bPrintAsImage = pRuntime->ToBoolean(params[5].ToV8Value()); if (nlength >= 7) - bReverse = params[6].ToBool(pRuntime); + bReverse = pRuntime->ToBoolean(params[6].ToV8Value()); if (nlength >= 8) - bAnnotations = params[7].ToBool(pRuntime); + bAnnotations = pRuntime->ToBoolean(params[7].ToV8Value()); } if (m_pFormFillEnv) { @@ -509,7 +517,7 @@ bool Document::removeField(CJS_Runtime* pRuntime, sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); return false; } - WideString sFieldName = params[0].ToWideString(pRuntime); + WideString sFieldName = pRuntime->ToWideString(params[0].ToV8Value()); CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); std::vector widgets; pInterForm->GetWidgets(sFieldName, &widgets); @@ -578,7 +586,7 @@ bool Document::resetForm(CJS_Runtime* pRuntime, switch (params[0].GetType()) { default: - aName = CJS_Array(params[0].ToV8Array(pRuntime)); + aName = CJS_Array(pRuntime->ToArray(params[0].ToV8Value())); break; case CJS_Value::VT_string: aName.SetElement(pRuntime, 0, params[0]); @@ -587,8 +595,8 @@ bool Document::resetForm(CJS_Runtime* pRuntime, std::vector aFields; for (int i = 0, isz = aName.GetLength(pRuntime); i < isz; ++i) { - CJS_Value valElement(aName.GetElement(pRuntime, i)); - WideString swVal = valElement.ToWideString(pRuntime); + WideString swVal = + pRuntime->ToWideString(aName.GetElement(pRuntime, i).ToV8Value()); for (int j = 0, jsz = pPDFForm->CountFields(swVal); j < jsz; ++j) aFields.push_back(pPDFForm->GetField(j, swVal)); } @@ -636,27 +644,23 @@ bool Document::submitForm(CJS_Runtime* pRuntime, bool bEmpty = false; CJS_Value v(params[0]); if (v.GetType() == CJS_Value::VT_string) { - strURL = params[0].ToWideString(pRuntime); + strURL = pRuntime->ToWideString(params[0].ToV8Value()); if (nSize > 1) - bFDF = params[1].ToBool(pRuntime); + bFDF = pRuntime->ToBoolean(params[1].ToV8Value()); if (nSize > 2) - bEmpty = params[2].ToBool(pRuntime); + bEmpty = pRuntime->ToBoolean(params[2].ToV8Value()); if (nSize > 3) - aFields = CJS_Array(params[3].ToV8Array(pRuntime)); + aFields = CJS_Array(pRuntime->ToArray(params[3].ToV8Value())); } else if (v.GetType() == CJS_Value::VT_object) { - v8::Local pObj = params[0].ToV8Object(pRuntime); + v8::Local pObj = pRuntime->ToObject(params[0].ToV8Value()); v8::Local pValue = pRuntime->GetObjectProperty(pObj, L"cURL"); if (!pValue.IsEmpty()) - strURL = CJS_Value(pValue).ToWideString(pRuntime); + strURL = pRuntime->ToWideString(pValue); - pValue = pRuntime->GetObjectProperty(pObj, L"bFDF"); - bFDF = CJS_Value(pValue).ToBool(pRuntime); - - pValue = pRuntime->GetObjectProperty(pObj, L"bEmpty"); - bEmpty = CJS_Value(pValue).ToBool(pRuntime); - - pValue = pRuntime->GetObjectProperty(pObj, L"aFields"); - aFields = CJS_Array(CJS_Value(pValue).ToV8Array(pRuntime)); + bFDF = pRuntime->ToBoolean(pRuntime->GetObjectProperty(pObj, L"bFDF")); + bEmpty = pRuntime->ToBoolean(pRuntime->GetObjectProperty(pObj, L"bEmpty")); + aFields = CJS_Array( + pRuntime->ToArray(pRuntime->GetObjectProperty(pObj, L"aFields"))); } CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); @@ -672,8 +676,8 @@ bool Document::submitForm(CJS_Runtime* pRuntime, std::vector fieldObjects; for (int i = 0, sz = aFields.GetLength(pRuntime); i < sz; ++i) { - CJS_Value valName(aFields.GetElement(pRuntime, i)); - WideString sName = valName.ToWideString(pRuntime); + WideString sName = + pRuntime->ToWideString(aFields.GetElement(pRuntime, i).ToV8Value()); CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); for (int j = 0, jsz = pPDFForm->CountFields(sName); j < jsz; ++j) { CPDF_FormField* pField = pPDFForm->GetField(j, sName); @@ -721,38 +725,27 @@ bool Document::mailDoc(CJS_Runtime* pRuntime, WideString cMsg = L""; if (params.size() >= 1) - bUI = params[0].ToBool(pRuntime); + bUI = pRuntime->ToBoolean(params[0].ToV8Value()); if (params.size() >= 2) - cTo = params[1].ToWideString(pRuntime); + cTo = pRuntime->ToWideString(params[1].ToV8Value()); if (params.size() >= 3) - cCc = params[2].ToWideString(pRuntime); + cCc = pRuntime->ToWideString(params[2].ToV8Value()); if (params.size() >= 4) - cBcc = params[3].ToWideString(pRuntime); + cBcc = pRuntime->ToWideString(params[3].ToV8Value()); if (params.size() >= 5) - cSubject = params[4].ToWideString(pRuntime); + cSubject = pRuntime->ToWideString(params[4].ToV8Value()); if (params.size() >= 6) - cMsg = params[5].ToWideString(pRuntime); + cMsg = pRuntime->ToWideString(params[5].ToV8Value()); if (params.size() >= 1 && params[0].GetType() == CJS_Value::VT_object) { - v8::Local pObj = params[0].ToV8Object(pRuntime); - - v8::Local pValue = pRuntime->GetObjectProperty(pObj, L"bUI"); - bUI = CJS_Value(pValue).ToBool(pRuntime); - - pValue = pRuntime->GetObjectProperty(pObj, L"cTo"); - cTo = CJS_Value(pValue).ToWideString(pRuntime); - - pValue = pRuntime->GetObjectProperty(pObj, L"cCc"); - cCc = CJS_Value(pValue).ToWideString(pRuntime); - - pValue = pRuntime->GetObjectProperty(pObj, L"cBcc"); - cBcc = CJS_Value(pValue).ToWideString(pRuntime); - - pValue = pRuntime->GetObjectProperty(pObj, L"cSubject"); - cSubject = CJS_Value(pValue).ToWideString(pRuntime); - - pValue = pRuntime->GetObjectProperty(pObj, L"cMsg"); - cMsg = CJS_Value(pValue).ToWideString(pRuntime); + v8::Local pObj = pRuntime->ToObject(params[0].ToV8Value()); + bUI = pRuntime->ToBoolean(pRuntime->GetObjectProperty(pObj, L"bUI")); + cTo = pRuntime->ToWideString(pRuntime->GetObjectProperty(pObj, L"cTo")); + cCc = pRuntime->ToWideString(pRuntime->GetObjectProperty(pObj, L"cCc")); + cBcc = pRuntime->ToWideString(pRuntime->GetObjectProperty(pObj, L"cBcc")); + cSubject = + pRuntime->ToWideString(pRuntime->GetObjectProperty(pObj, L"cSubject")); + cMsg = pRuntime->ToWideString(pRuntime->GetObjectProperty(pObj, L"cMsg")); } pRuntime->BeginBlock(); @@ -881,7 +874,7 @@ bool Document::setPropertyInternal(CJS_Runtime* pRuntime, *sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); return false; } - WideString csProperty = vp.ToWideString(pRuntime); + WideString csProperty = pRuntime->ToWideString(vp.ToV8Value()); pDictionary->SetNewFor(propName, PDF_EncodeText(csProperty), false); m_pFormFillEnv->SetChangeMark(); @@ -936,7 +929,7 @@ bool Document::set_delay(CJS_Runtime* pRuntime, return false; } - m_bDelay = vp.ToBool(pRuntime); + m_bDelay = pRuntime->ToBoolean(vp.ToV8Value()); if (m_bDelay) { m_DelayData.clear(); return true; @@ -1116,7 +1109,7 @@ bool Document::get_base_URL(CJS_Runtime* pRuntime, bool Document::set_base_URL(CJS_Runtime* pRuntime, const CJS_Value& vp, WideString* sError) { - m_cwBaseURL = vp.ToWideString(pRuntime); + m_cwBaseURL = pRuntime->ToWideString(vp.ToV8Value()); return true; } @@ -1142,7 +1135,7 @@ bool Document::set_calculate(CJS_Runtime* pRuntime, } CPDFSDK_InterForm* pInterForm = m_pFormFillEnv->GetInterForm(); - pInterForm->EnableCalculate(vp.ToBool(pRuntime)); + pInterForm->EnableCalculate(pRuntime->ToBoolean(vp.ToV8Value())); return true; } @@ -1253,8 +1246,9 @@ bool Document::getAnnot(CJS_Runtime* pRuntime, sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return false; } - int nPageNo = params[0].ToInt(pRuntime); - WideString swAnnotName = params[1].ToWideString(pRuntime); + + int nPageNo = pRuntime->ToInt32(params[0].ToV8Value()); + WideString swAnnotName = pRuntime->ToWideString(params[1].ToV8Value()); CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetPageView(nPageNo); if (!pPageView) return false; @@ -1326,7 +1320,10 @@ bool Document::getAnnots(CJS_Runtime* pRuntime, pJS_Annot ? CJS_Value(pJS_Annot->ToV8Object()) : CJS_Value()); } } - vRet = CJS_Value(annots.ToV8Array(pRuntime)); + if (annots.ToV8Value().IsEmpty()) + vRet = CJS_Value(pRuntime->NewArray()); + else + vRet = CJS_Value(annots.ToV8Value()); return true; } @@ -1373,19 +1370,21 @@ bool Document::addIcon(CJS_Runtime* pRuntime, return false; } - WideString swIconName = params[0].ToWideString(pRuntime); + WideString swIconName = pRuntime->ToWideString(params[0].ToV8Value()); if (params[1].GetType() != CJS_Value::VT_object) { sError = JSGetStringFromID(IDS_STRING_JSTYPEERROR); return false; } - v8::Local pJSIcon = params[1].ToV8Object(pRuntime); + v8::Local pJSIcon = pRuntime->ToObject(params[1].ToV8Value()); if (CFXJS_Engine::GetObjDefnID(pJSIcon) != CJS_Icon::g_nObjDefnID) { sError = JSGetStringFromID(IDS_STRING_JSTYPEERROR); return false; } - if (!params[1].ToObject(pRuntime)->GetEmbedObject()) { + v8::Local pObj = pRuntime->ToObject(params[1].ToV8Value()); + CJS_Object* obj = static_cast(pRuntime->GetObjectPrivate(pObj)); + if (!obj->GetEmbedObject()) { sError = JSGetStringFromID(IDS_STRING_JSTYPEERROR); return false; } @@ -1419,7 +1418,11 @@ bool Document::get_icons(CJS_Runtime* pRuntime, pJS_Icon ? CJS_Value(pJS_Icon->ToV8Object()) : CJS_Value()); } - vp->Set(Icons.ToV8Array(pRuntime)); + if (Icons.ToV8Value().IsEmpty()) + vp->Set(pRuntime->NewArray()); + else + vp->Set(Icons.ToV8Value()); + return true; } @@ -1439,7 +1442,7 @@ bool Document::getIcon(CJS_Runtime* pRuntime, return false; } - WideString swIconName = params[0].ToWideString(pRuntime); + WideString swIconName = pRuntime->ToWideString(params[0].ToV8Value()); auto it = std::find(m_IconNames.begin(), m_IconNames.end(), swIconName); if (it == m_IconNames.end()) return false; @@ -1531,9 +1534,12 @@ bool Document::getPageNthWord(CJS_Runtime* pRuntime, // TODO(tsepez): check maximum allowable params. - int nPageNo = params.size() > 0 ? params[0].ToInt(pRuntime) : 0; - int nWordNo = params.size() > 1 ? params[1].ToInt(pRuntime) : 0; - bool bStrip = params.size() > 2 ? params[2].ToBool(pRuntime) : true; + int nPageNo = + params.size() > 0 ? pRuntime->ToInt32(params[0].ToV8Value()) : 0; + int nWordNo = + params.size() > 1 ? pRuntime->ToInt32(params[1].ToV8Value()) : 0; + bool bStrip = + params.size() > 2 ? pRuntime->ToBoolean(params[2].ToV8Value()) : true; CPDF_Document* pDocument = m_pFormFillEnv->GetPDFDocument(); if (!pDocument) @@ -1601,7 +1607,8 @@ bool Document::getPageNumWords(CJS_Runtime* pRuntime, sError = JSGetStringFromID(IDS_STRING_JSNOPERMISSION); return false; } - int nPageNo = params.size() > 0 ? params[0].ToInt(pRuntime) : 0; + int nPageNo = + params.size() > 0 ? pRuntime->ToInt32(params[0].ToV8Value()) : 0; CPDF_Document* pDocument = m_pFormFillEnv->GetPDFDocument(); if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) { sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR); @@ -1786,7 +1793,8 @@ bool Document::gotoNamedDest(CJS_Runtime* pRuntime, sError = JSGetStringFromID(IDS_STRING_JSBADOBJECT); return false; } - WideString wideName = params[0].ToWideString(pRuntime); + + WideString wideName = pRuntime->ToWideString(params[0].ToV8Value()); CPDF_Document* pDocument = m_pFormFillEnv->GetPDFDocument(); if (!pDocument) return false; diff --git a/fpdfsdk/javascript/Field.cpp b/fpdfsdk/javascript/Field.cpp index 8979e7f8ec..5bcc66b7e9 100644 --- a/fpdfsdk/javascript/Field.cpp +++ b/fpdfsdk/javascript/Field.cpp @@ -471,11 +471,13 @@ bool Field::set_border_style(CJS_Runtime* pRuntime, if (!m_bCanSet) return false; + ByteString byte_str = + ByteString::FromUnicode(pRuntime->ToWideString(vp.ToV8Value())); if (m_bDelay) { - AddDelay_String(FP_BORDERSTYLE, vp.ToByteString(pRuntime)); + AddDelay_String(FP_BORDERSTYLE, byte_str); } else { Field::SetBorderStyle(m_pFormFillEnv.Get(), m_FieldName, - m_nFormControlIndex, vp.ToByteString(pRuntime)); + m_nFormControlIndex, byte_str); } return true; } @@ -860,7 +862,10 @@ bool Field::get_current_value_indices(CJS_Runtime* pRuntime, pRuntime, i, CJS_Value(pRuntime->NewNumber(pFormField->GetSelectedIndex(i)))); } - vp->Set(SelArray.ToV8Array(pRuntime)); + if (SelArray.ToV8Value().IsEmpty()) + vp->Set(pRuntime->NewArray()); + else + vp->Set(SelArray.ToV8Value()); return true; } @@ -873,11 +878,12 @@ bool Field::set_current_value_indices(CJS_Runtime* pRuntime, std::vector array; if (vp.GetType() == CJS_Value::VT_number) { - array.push_back(vp.ToInt(pRuntime)); + array.push_back(pRuntime->ToInt32(vp.ToV8Value())); } else if (vp.IsArrayObject()) { - CJS_Array SelArray = vp.ToArray(pRuntime); + CJS_Array SelArray(pRuntime->ToArray(vp.ToV8Value())); for (int i = 0, sz = SelArray.GetLength(pRuntime); i < sz; i++) - array.push_back(SelArray.GetElement(pRuntime, i).ToInt(pRuntime)); + array.push_back( + pRuntime->ToInt32(SelArray.GetElement(pRuntime, i).ToV8Value())); } if (m_bDelay) { @@ -1027,7 +1033,7 @@ bool Field::set_delay(CJS_Runtime* pRuntime, if (!m_bCanSet) return false; - SetDelay(vp.ToBool(pRuntime)); + SetDelay(pRuntime->ToBoolean(vp.ToV8Value())); return true; } @@ -1070,10 +1076,10 @@ bool Field::set_display(CJS_Runtime* pRuntime, return false; if (m_bDelay) { - AddDelay_Int(FP_DISPLAY, vp.ToInt(pRuntime)); + AddDelay_Int(FP_DISPLAY, pRuntime->ToInt32(vp.ToV8Value())); } else { Field::SetDisplay(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, - vp.ToInt(pRuntime)); + pRuntime->ToInt32(vp.ToV8Value())); } return true; } @@ -1160,13 +1166,14 @@ bool Field::get_export_values(CJS_Runtime* pRuntime, return false; } - CJS_Array ExportValusArray; + CJS_Array ExportValuesArray; if (m_nFormControlIndex < 0) { for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { CPDF_FormControl* pFormControl = pFormField->GetControl(i); - ExportValusArray.SetElement(pRuntime, i, - CJS_Value(pRuntime->NewString( - pFormControl->GetExportValue().c_str()))); + ExportValuesArray.SetElement( + pRuntime, i, + CJS_Value( + pRuntime->NewString(pFormControl->GetExportValue().c_str()))); } } else { if (m_nFormControlIndex >= pFormField->CountControls()) @@ -1177,12 +1184,16 @@ bool Field::get_export_values(CJS_Runtime* pRuntime, if (!pFormControl) return false; - ExportValusArray.SetElement( + ExportValuesArray.SetElement( pRuntime, 0, CJS_Value(pRuntime->NewString(pFormControl->GetExportValue().c_str()))); } - vp->Set(ExportValusArray.ToV8Array(pRuntime)); + if (ExportValuesArray.ToV8Value().IsEmpty()) + vp->Set(pRuntime->NewArray()); + else + vp->Set(ExportValuesArray.ToV8Value()); + return true; } @@ -1269,7 +1280,12 @@ bool Field::get_fill_color(CJS_Runtime* pRuntime, return false; } - vp->Set(color::ConvertPWLColorToArray(pRuntime, color).ToV8Array(pRuntime)); + CJS_Array array = color::ConvertPWLColorToArray(pRuntime, color); + if (array.ToV8Value().IsEmpty()) + vp->Set(pRuntime->NewArray()); + else + vp->Set(array.ToV8Value()); + return true; } @@ -1315,10 +1331,10 @@ bool Field::set_hidden(CJS_Runtime* pRuntime, return false; if (m_bDelay) { - AddDelay_Bool(FP_HIDDEN, vp.ToBool(pRuntime)); + AddDelay_Bool(FP_HIDDEN, pRuntime->ToBoolean(vp.ToV8Value())); } else { Field::SetHidden(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, - vp.ToBool(pRuntime)); + pRuntime->ToBoolean(vp.ToV8Value())); } return true; } @@ -1409,10 +1425,10 @@ bool Field::set_line_width(CJS_Runtime* pRuntime, return false; if (m_bDelay) { - AddDelay_Int(FP_LINEWIDTH, vp.ToInt(pRuntime)); + AddDelay_Int(FP_LINEWIDTH, pRuntime->ToInt32(vp.ToV8Value())); } else { Field::SetLineWidth(m_pFormFillEnv.Get(), m_FieldName, m_nFormControlIndex, - vp.ToInt(pRuntime)); + pRuntime->ToInt32(vp.ToV8Value())); } return true; } @@ -1578,7 +1594,11 @@ bool Field::get_page(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError) { ++i; } - vp->Set(PageArray.ToV8Array(pRuntime)); + if (PageArray.ToV8Value().IsEmpty()) + vp->Set(pRuntime->NewArray()); + else + vp->Set(PageArray.ToV8Value()); + return true; } @@ -1650,7 +1670,7 @@ bool Field::set_print(CJS_Runtime* pRuntime, if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormField->GetControl(i))) { uint32_t dwFlags = pWidget->GetFlags(); - if (vp.ToBool(pRuntime)) + if (pRuntime->ToBoolean(vp.ToV8Value())) dwFlags |= ANNOTFLAG_PRINT; else dwFlags &= ~ANNOTFLAG_PRINT; @@ -1674,7 +1694,7 @@ bool Field::set_print(CJS_Runtime* pRuntime, pFormField->GetControl(m_nFormControlIndex)) { if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) { uint32_t dwFlags = pWidget->GetFlags(); - if (vp.ToBool(pRuntime)) + if (pRuntime->ToBoolean(vp.ToV8Value())) dwFlags |= ANNOTFLAG_PRINT; else dwFlags &= ~ANNOTFLAG_PRINT; @@ -1763,7 +1783,12 @@ bool Field::get_rect(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError) { rcArray.SetElement( pRuntime, 3, CJS_Value(pRuntime->NewNumber(static_cast(crRect.bottom)))); - vp->Set(rcArray.ToV8Array(pRuntime)); + + if (rcArray.ToV8Value().IsEmpty()) + vp->Set(pRuntime->NewArray()); + else + vp->Set(rcArray.ToV8Value()); + return true; } @@ -1775,16 +1800,16 @@ bool Field::set_rect(CJS_Runtime* pRuntime, if (!vp.IsArrayObject()) return false; - CJS_Array rcArray = vp.ToArray(pRuntime); + CJS_Array rcArray(pRuntime->ToArray(vp.ToV8Value())); float pArray[4]; - pArray[0] = - static_cast(rcArray.GetElement(pRuntime, 0).ToInt(pRuntime)); - pArray[1] = - static_cast(rcArray.GetElement(pRuntime, 1).ToInt(pRuntime)); - pArray[2] = - static_cast(rcArray.GetElement(pRuntime, 2).ToInt(pRuntime)); - pArray[3] = - static_cast(rcArray.GetElement(pRuntime, 3).ToInt(pRuntime)); + pArray[0] = static_cast( + pRuntime->ToInt32(rcArray.GetElement(pRuntime, 0).ToV8Value())); + pArray[1] = static_cast( + pRuntime->ToInt32(rcArray.GetElement(pRuntime, 1).ToV8Value())); + pArray[2] = static_cast( + pRuntime->ToInt32(rcArray.GetElement(pRuntime, 2).ToV8Value())); + pArray[3] = static_cast( + pRuntime->ToInt32(rcArray.GetElement(pRuntime, 3).ToV8Value())); CFX_FloatRect crRect(pArray); if (m_bDelay) { @@ -1978,7 +2003,12 @@ bool Field::get_stroke_color(CJS_Runtime* pRuntime, return false; } - vp->Set(color::ConvertPWLColorToArray(pRuntime, color).ToV8Array(pRuntime)); + CJS_Array array = color::ConvertPWLColorToArray(pRuntime, color); + if (array.ToV8Value().IsEmpty()) + vp->Set(pRuntime->NewArray()); + else + vp->Set(array.ToV8Value()); + return true; } @@ -2087,7 +2117,12 @@ bool Field::get_text_color(CJS_Runtime* pRuntime, if (iColorType == CFX_Color::kTransparent) crRet = CFX_Color(CFX_Color::kTransparent); - vp->Set(color::ConvertPWLColorToArray(pRuntime, crRet).ToV8Array(pRuntime)); + CJS_Array array = color::ConvertPWLColorToArray(pRuntime, crRet); + if (array.ToV8Value().IsEmpty()) + vp->Set(pRuntime->NewArray()); + else + vp->Set(array.ToV8Value()); + return true; } @@ -2137,9 +2172,8 @@ bool Field::set_text_font(CJS_Runtime* pRuntime, if (!m_bCanSet) return false; - - ByteString fontName = vp.ToByteString(pRuntime); - return !fontName.IsEmpty(); + return !ByteString::FromUnicode(pRuntime->ToWideString(vp.ToV8Value())) + .IsEmpty(); } bool Field::get_text_size(CJS_Runtime* pRuntime, @@ -2259,13 +2293,19 @@ bool Field::get_value(CJS_Runtime* pRuntime, iIndex = pFormField->GetSelectedIndex(i); ElementValue = CJS_Value( pRuntime->NewString(pFormField->GetOptionValue(iIndex).c_str())); - if (wcslen(ElementValue.ToWideString(pRuntime).c_str()) == 0) { + if (wcslen( + pRuntime->ToWideString(ElementValue.ToV8Value()).c_str()) == + 0) { ElementValue = CJS_Value(pRuntime->NewString( pFormField->GetOptionLabel(iIndex).c_str())); } ValueArray.SetElement(pRuntime, i, ElementValue); } - vp->Set(ValueArray.ToV8Array(pRuntime)); + + if (ValueArray.ToV8Value().IsEmpty()) + vp->Set(pRuntime->NewArray()); + else + vp->Set(ValueArray.ToV8Value()); } else { vp->Set(pRuntime->NewString(pFormField->GetValue().c_str())); } @@ -2303,13 +2343,13 @@ bool Field::set_value(CJS_Runtime* pRuntime, std::vector strArray; if (vp.IsArrayObject()) { - CJS_Array ValueArray(vp.ToArray(pRuntime)); + CJS_Array ValueArray(pRuntime->ToArray(vp.ToV8Value())); for (int i = 0, sz = ValueArray.GetLength(pRuntime); i < sz; i++) { CJS_Value ElementValue(ValueArray.GetElement(pRuntime, i)); - strArray.push_back(ElementValue.ToWideString(pRuntime)); + strArray.push_back(pRuntime->ToWideString(ElementValue.ToV8Value())); } } else { - strArray.push_back(vp.ToWideString(pRuntime)); + strArray.push_back(pRuntime->ToWideString(vp.ToV8Value())); } if (m_bDelay) { @@ -2453,7 +2493,7 @@ bool Field::buttonGetCaption(CJS_Runtime* pRuntime, int nface = 0; int iSize = params.size(); if (iSize >= 1) - nface = params[0].ToInt(pRuntime); + nface = pRuntime->ToInt32(params[0].ToV8Value()); std::vector FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) @@ -2487,7 +2527,7 @@ bool Field::buttonGetIcon(CJS_Runtime* pRuntime, CJS_Value& vRet, WideString& sError) { if (params.size() >= 1) { - int nFace = params[0].ToInt(pRuntime); + int nFace = pRuntime->ToInt32(params[0].ToV8Value()); if (nFace < 0 || nFace > 2) return false; } @@ -2548,10 +2588,10 @@ bool Field::checkThisBox(CJS_Runtime* pRuntime, if (!m_bCanSet) return false; - int nWidget = params[0].ToInt(pRuntime); + int nWidget = pRuntime->ToInt32(params[0].ToV8Value()); bool bCheckit = true; if (iSize >= 2) - bCheckit = params[1].ToBool(pRuntime); + bCheckit = pRuntime->ToBoolean(params[1].ToV8Value()); std::vector FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) @@ -2592,7 +2632,7 @@ bool Field::defaultIsChecked(CJS_Runtime* pRuntime, if (iSize < 1) return false; - int nWidget = params[0].ToInt(pRuntime); + int nWidget = pRuntime->ToInt32(params[0].ToV8Value()); std::vector FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) return false; @@ -2651,7 +2691,11 @@ bool Field::getArray(CJS_Runtime* pRuntime, pJSField ? CJS_Value(pJSField->ToV8Object()) : CJS_Value()); } - vRet = CJS_Value(FormFieldArray.ToV8Array(pRuntime)); + if (FormFieldArray.ToV8Value().IsEmpty()) + vRet = CJS_Value(pRuntime->NewArray()); + else + vRet = CJS_Value(FormFieldArray.ToV8Value()); + return true; } @@ -2662,11 +2706,11 @@ bool Field::getItemAt(CJS_Runtime* pRuntime, int iSize = params.size(); int nIdx = -1; if (iSize >= 1) - nIdx = params[0].ToInt(pRuntime); + nIdx = pRuntime->ToInt32(params[0].ToV8Value()); bool bExport = true; if (iSize >= 2) - bExport = params[1].ToBool(pRuntime); + bExport = pRuntime->ToBoolean(params[1].ToV8Value()); std::vector FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) @@ -2715,7 +2759,7 @@ bool Field::isBoxChecked(CJS_Runtime* pRuntime, WideString& sError) { int nIndex = -1; if (params.size() >= 1) - nIndex = params[0].ToInt(pRuntime); + nIndex = pRuntime->ToInt32(params[0].ToV8Value()); std::vector FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) @@ -2738,7 +2782,7 @@ bool Field::isDefaultChecked(CJS_Runtime* pRuntime, WideString& sError) { int nIndex = -1; if (params.size() >= 1) - nIndex = params[0].ToInt(pRuntime); + nIndex = pRuntime->ToInt32(params[0].ToV8Value()); std::vector FieldArray = GetFormFields(m_FieldName); if (FieldArray.empty()) diff --git a/fpdfsdk/javascript/JS_Value.cpp b/fpdfsdk/javascript/JS_Value.cpp index fcf913a7fb..35a5b1c682 100644 --- a/fpdfsdk/javascript/JS_Value.cpp +++ b/fpdfsdk/javascript/JS_Value.cpp @@ -190,66 +190,15 @@ void CJS_Value::Set(v8::Local pValue) { m_pValue = pValue; } -int CJS_Value::ToInt(CJS_Runtime* pRuntime) const { - return pRuntime->ToInt32(m_pValue); -} - -bool CJS_Value::ToBool(CJS_Runtime* pRuntime) const { - return pRuntime->ToBoolean(m_pValue); -} - -double CJS_Value::ToDouble(CJS_Runtime* pRuntime) const { - return pRuntime->ToDouble(m_pValue); -} - -float CJS_Value::ToFloat(CJS_Runtime* pRuntime) const { - return static_cast(ToDouble(pRuntime)); -} - -CJS_Object* CJS_Value::ToObject(CJS_Runtime* pRuntime) const { - v8::Local pObj = pRuntime->ToObject(m_pValue); - return static_cast(pRuntime->GetObjectPrivate(pObj)); -} - -CJS_Document* CJS_Value::ToDocument(CJS_Runtime* pRuntime) const { - return static_cast(ToObject(pRuntime)); -} - -CJS_Array CJS_Value::ToArray(CJS_Runtime* pRuntime) const { - ASSERT(IsArrayObject()); - return CJS_Array(pRuntime->ToArray(m_pValue)); -} - -CJS_Date CJS_Value::ToDate() const { - ASSERT(IsDateObject()); - v8::Local mutable_value = m_pValue; - return CJS_Date(mutable_value.As()); -} - -v8::Local CJS_Value::ToV8Object(CJS_Runtime* pRuntime) const { - return pRuntime->ToObject(m_pValue); -} - -WideString CJS_Value::ToWideString(CJS_Runtime* pRuntime) const { - return pRuntime->ToWideString(m_pValue); -} - -ByteString CJS_Value::ToByteString(CJS_Runtime* pRuntime) const { - return ByteString::FromUnicode(ToWideString(pRuntime)); -} - v8::Local CJS_Value::ToV8Value() const { return m_pValue; } -v8::Local CJS_Value::ToV8Array(CJS_Runtime* pRuntime) const { - return pRuntime->ToArray(m_pValue); -} - void CJS_Value::MaybeCoerceToNumber(CJS_Runtime* pRuntime) { bool bAllowNaN = false; if (GetType() == VT_string) { - ByteString bstr = ToByteString(pRuntime); + ByteString bstr = + ByteString::FromUnicode(pRuntime->ToWideString(ToV8Value())); if (bstr.GetLength() == 0) return; if (bstr == "NaN") @@ -326,13 +275,6 @@ int CJS_Array::GetLength(CJS_Runtime* pRuntime) const { return pRuntime->GetArrayLength(m_pArray); } -v8::Local CJS_Array::ToV8Array(CJS_Runtime* pRuntime) const { - if (m_pArray.IsEmpty()) - m_pArray = pRuntime->NewArray(); - - return m_pArray; -} - CJS_Date::CJS_Date() {} CJS_Date::CJS_Date(v8::Local pDate) : m_pDate(pDate) {} @@ -398,10 +340,6 @@ int CJS_Date::GetSeconds(CJS_Runtime* pRuntime) const { return JS_GetSecFromTime(JS_LocalTime(pRuntime->ToDouble(m_pDate))); } -v8::Local CJS_Date::ToV8Date() const { - return m_pDate; -} - double JS_GetDateTime() { if (!FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) return 0; @@ -522,7 +460,7 @@ std::vector ExpandKeywordParams( originals[0].IsArrayObject()) { return result; } - v8::Local pObj = originals[0].ToV8Object(pRuntime); + v8::Local pObj = pRuntime->ToObject(originals[0].ToV8Value()); result[0] = CJS_Value(); // Make unknown. va_list ap; diff --git a/fpdfsdk/javascript/JS_Value.h b/fpdfsdk/javascript/JS_Value.h index c0e267a4a5..07e5986527 100644 --- a/fpdfsdk/javascript/JS_Value.h +++ b/fpdfsdk/javascript/JS_Value.h @@ -42,18 +42,6 @@ class CJS_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* ToObject(CJS_Runtime* pRuntime) const; - CJS_Document* ToDocument(CJS_Runtime* pRuntime) const; - CJS_Array ToArray(CJS_Runtime* pRuntime) const; - CJS_Date ToDate() const; - WideString ToWideString(CJS_Runtime* pRuntime) const; - ByteString ToByteString(CJS_Runtime* pRuntime) const; - v8::Local ToV8Object(CJS_Runtime* pRuntime) const; - v8::Local ToV8Array(CJS_Runtime* pRuntime) const; v8::Local ToV8Value() const; // Replace the current |m_pValue| with a v8::Number if possible @@ -82,7 +70,7 @@ class CJS_Array { unsigned index, const CJS_Value& value); - v8::Local ToV8Array(CJS_Runtime* pRuntime) const; + v8::Local ToV8Value() const { return m_pArray; } private: mutable v8::Local m_pArray; @@ -112,10 +100,9 @@ class CJS_Date { int GetMinutes(CJS_Runtime* pRuntime) const; int GetSeconds(CJS_Runtime* pRuntime) const; - v8::Local ToV8Date() const; - WideString ToWideString(int style) const; + v8::Local ToV8Value() const { return m_pDate; } - protected: + private: v8::Local m_pDate; }; diff --git a/fpdfsdk/javascript/PublicMethods.cpp b/fpdfsdk/javascript/PublicMethods.cpp index 9f336ae938..462398012d 100644 --- a/fpdfsdk/javascript/PublicMethods.cpp +++ b/fpdfsdk/javascript/PublicMethods.cpp @@ -248,9 +248,9 @@ double CJS_PublicMethods::AF_Simple(const wchar_t* sFuction, CJS_Array CJS_PublicMethods::AF_MakeArrayFromList(CJS_Runtime* pRuntime, CJS_Value val) { if (val.IsArrayObject()) - return val.ToArray(pRuntime); + return CJS_Array(pRuntime->ToArray(val.ToV8Value())); - WideString wsStr = val.ToWideString(pRuntime); + WideString wsStr = pRuntime->ToWideString(val.ToV8Value()); ByteString t = ByteString::FromUnicode(wsStr); const char* p = t.c_str(); @@ -827,12 +827,12 @@ bool CJS_PublicMethods::AFNumber_Format(CJS_Runtime* pRuntime, if (strValue.IsEmpty()) return true; - int iDec = params[0].ToInt(pRuntime); - int iSepStyle = params[1].ToInt(pRuntime); - int iNegStyle = params[2].ToInt(pRuntime); + int iDec = pRuntime->ToInt32(params[0].ToV8Value()); + int iSepStyle = pRuntime->ToInt32(params[1].ToV8Value()); + int iNegStyle = pRuntime->ToInt32(params[2].ToV8Value()); // params[3] is iCurrStyle, it's not used. - WideString wstrCurrency = params[4].ToWideString(pRuntime); - bool bCurrencyPrepend = params[5].ToBool(pRuntime); + WideString wstrCurrency = pRuntime->ToWideString(params[4].ToV8Value()); + bool bCurrencyPrepend = pRuntime->ToBoolean(params[5].ToV8Value()); if (iDec < 0) iDec = -iDec; @@ -908,7 +908,12 @@ bool CJS_PublicMethods::AFNumber_Format(CJS_Runtime* pRuntime, arColor.SetElement(pRuntime, 2, vColElm); arColor.SetElement(pRuntime, 3, vColElm); - CJS_Value vProp(arColor.ToV8Array(pRuntime)); + CJS_Value vProp; + if (arColor.ToV8Value().IsEmpty()) + vProp.Set(pRuntime->NewArray()); + else + vProp.Set(arColor.ToV8Value()); + fTarget->set_text_color(pRuntime, vProp, &sError); // red } } @@ -927,12 +932,17 @@ bool CJS_PublicMethods::AFNumber_Format(CJS_Runtime* pRuntime, CJS_Value vProp; fTarget->get_text_color(pRuntime, &vProp, &sError); - CFX_Color crProp = - color::ConvertArrayToPWLColor(pRuntime, vProp.ToArray(pRuntime)); + CFX_Color crProp = color::ConvertArrayToPWLColor( + pRuntime, CJS_Array(pRuntime->ToArray(vProp.ToV8Value()))); CFX_Color crColor = color::ConvertArrayToPWLColor(pRuntime, arColor); if (crColor != crProp) { - fTarget->set_text_color( - pRuntime, CJS_Value(arColor.ToV8Array(pRuntime)), &sError); + CJS_Value value; + if (arColor.ToV8Value().IsEmpty()) + value.Set(pRuntime->NewArray()); + else + value.Set(arColor.ToV8Value()); + + fTarget->set_text_color(pRuntime, value, &sError); } } } @@ -988,7 +998,7 @@ bool CJS_PublicMethods::AFNumber_Keystroke(CJS_Runtime* pRuntime, } } - int iSepStyle = params[1].ToInt(pRuntime); + int iSepStyle = pRuntime->ToInt32(params[1].ToV8Value()); if (iSepStyle < 0 || iSepStyle > 3) iSepStyle = 0; const wchar_t cSep = iSepStyle < 2 ? L'.' : L','; @@ -1058,11 +1068,11 @@ bool CJS_PublicMethods::AFPercent_Format(CJS_Runtime* pRuntime, if (strValue.IsEmpty()) return true; - int iDec = params[0].ToInt(pRuntime); + int iDec = pRuntime->ToInt32(params[0].ToV8Value()); if (iDec < 0) iDec = -iDec; - int iSepStyle = params[1].ToInt(pRuntime); + int iSepStyle = pRuntime->ToInt32(params[1].ToV8Value()); if (iSepStyle < 0 || iSepStyle > 3) iSepStyle = 0; @@ -1157,7 +1167,7 @@ bool CJS_PublicMethods::AFDate_FormatEx(CJS_Runtime* pRuntime, if (strValue.IsEmpty()) return true; - WideString sFormat = params[0].ToWideString(pRuntime); + WideString sFormat = pRuntime->ToWideString(params[0].ToV8Value()); double dDate = 0.0f; if (strValue.Contains(L"GMT")) { @@ -1255,7 +1265,7 @@ bool CJS_PublicMethods::AFDate_KeystrokeEx(CJS_Runtime* pRuntime, if (strValue.IsEmpty()) return true; - WideString sFormat = params[0].ToWideString(pRuntime); + WideString sFormat = pRuntime->ToWideString(params[0].ToV8Value()); bool bWrongFormat = false; double dRet = MakeRegularDate(strValue, sFormat, &bWrongFormat); if (bWrongFormat || std::isnan(dRet)) { @@ -1279,7 +1289,7 @@ bool CJS_PublicMethods::AFDate_Format(CJS_Runtime* pRuntime, return false; } - int iIndex = params[0].ToInt(pRuntime); + int iIndex = pRuntime->ToInt32(params[0].ToV8Value()); const wchar_t* cFormats[] = {L"m/d", L"m/d/yy", L"mm/dd/yy", @@ -1313,7 +1323,7 @@ bool CJS_PublicMethods::AFDate_Keystroke(CJS_Runtime* pRuntime, return false; } - int iIndex = params[0].ToInt(pRuntime); + int iIndex = pRuntime->ToInt32(params[0].ToV8Value()); const wchar_t* cFormats[] = {L"m/d", L"m/d/yy", L"mm/dd/yy", @@ -1347,7 +1357,7 @@ bool CJS_PublicMethods::AFTime_Format(CJS_Runtime* pRuntime, return false; } - int iIndex = params[0].ToInt(pRuntime); + int iIndex = pRuntime->ToInt32(params[0].ToV8Value()); const wchar_t* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", L"h:MM:ss tt"}; @@ -1368,7 +1378,7 @@ bool CJS_PublicMethods::AFTime_Keystroke(CJS_Runtime* pRuntime, return false; } - int iIndex = params[0].ToInt(pRuntime); + int iIndex = pRuntime->ToInt32(params[0].ToV8Value()); const wchar_t* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", L"h:MM:ss tt"}; @@ -1411,7 +1421,7 @@ bool CJS_PublicMethods::AFSpecial_Format(CJS_Runtime* pRuntime, WideString wsSource = pEvent->Value(); WideString wsFormat; - switch (params[0].ToInt(pRuntime)) { + switch (pRuntime->ToInt32(params[0].ToV8Value())) { case 0: wsFormat = L"99999"; break; @@ -1450,7 +1460,7 @@ bool CJS_PublicMethods::AFSpecial_KeystrokeEx( return false; WideString& valEvent = pEvent->Value(); - WideString wstrMask = params[0].ToWideString(pRuntime); + WideString wstrMask = pRuntime->ToWideString(params[0].ToV8Value()); if (wstrMask.IsEmpty()) return true; @@ -1533,7 +1543,7 @@ bool CJS_PublicMethods::AFSpecial_Keystroke( return false; const char* cFormat = ""; - switch (params[0].ToInt(pRuntime)) { + switch (pRuntime->ToInt32(params[0].ToV8Value())) { case 0: cFormat = "99999"; break; @@ -1605,8 +1615,8 @@ bool CJS_PublicMethods::AFParseDateEx(CJS_Runtime* pRuntime, return false; } - WideString sValue = params[0].ToWideString(pRuntime); - WideString sFormat = params[1].ToWideString(pRuntime); + WideString sValue = pRuntime->ToWideString(params[0].ToV8Value()); + WideString sFormat = pRuntime->ToWideString(params[1].ToV8Value()); double dDate = MakeRegularDate(sValue, sFormat, nullptr); if (std::isnan(dDate)) { WideString swMsg; @@ -1630,8 +1640,9 @@ bool CJS_PublicMethods::AFSimple(CJS_Runtime* pRuntime, } vRet = CJS_Value(pRuntime->NewNumber(static_cast( - AF_Simple(params[0].ToWideString(pRuntime).c_str(), - params[1].ToDouble(pRuntime), params[2].ToDouble(pRuntime))))); + AF_Simple(pRuntime->ToWideString(params[0].ToV8Value()).c_str(), + pRuntime->ToDouble(params[1].ToV8Value()), + pRuntime->ToDouble(params[2].ToV8Value()))))); return true; } @@ -1645,7 +1656,7 @@ bool CJS_PublicMethods::AFMakeNumber(CJS_Runtime* pRuntime, return false; } - WideString ws = params[0].ToWideString(pRuntime); + WideString ws = pRuntime->ToWideString(params[0].ToV8Value()); ws.Replace(L",", L"."); vRet = CJS_Value(pRuntime->NewString(ws.c_str())); vRet.MaybeCoerceToNumber(pRuntime); @@ -1673,15 +1684,15 @@ bool CJS_PublicMethods::AFSimple_Calculate(CJS_Runtime* pRuntime, pRuntime->GetFormFillEnv()->GetInterForm(); CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm(); - WideString sFunction = params[0].ToWideString(pRuntime); + WideString sFunction = pRuntime->ToWideString(params[0].ToV8Value()); 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(FieldNameArray.GetElement(pRuntime, i)); - WideString wsFieldName = jsValue.ToWideString(pRuntime); + WideString wsFieldName = pRuntime->ToWideString( + FieldNameArray.GetElement(pRuntime, i).ToV8Value()); for (int j = 0, jsz = pInterForm->CountFields(wsFieldName); j < jsz; j++) { if (CPDF_FormField* pFormField = pInterForm->GetField(j, wsFieldName)) { @@ -1741,10 +1752,11 @@ bool CJS_PublicMethods::AFSimple_Calculate(CJS_Runtime* pRuntime, dValue = (double)floor(dValue * FXSYS_pow((double)10, (double)6) + 0.49) / FXSYS_pow((double)10, (double)6); - CJS_Value jsValue(pRuntime->NewNumber(dValue)); CJS_EventContext* pContext = pRuntime->GetCurrentEventContext(); - if (pContext->GetEventHandler()->m_pValue) - pContext->GetEventHandler()->Value() = jsValue.ToWideString(pRuntime); + if (pContext->GetEventHandler()->m_pValue) { + pContext->GetEventHandler()->Value() = + pRuntime->ToWideString(pRuntime->NewNumber(dValue)); + } return true; } @@ -1769,25 +1781,25 @@ bool CJS_PublicMethods::AFRange_Validate(CJS_Runtime* pRuntime, return true; double dEentValue = atof(ByteString::FromUnicode(pEvent->Value()).c_str()); - bool bGreaterThan = params[0].ToBool(pRuntime); - double dGreaterThan = params[1].ToDouble(pRuntime); - bool bLessThan = params[2].ToBool(pRuntime); - double dLessThan = params[3].ToDouble(pRuntime); + bool bGreaterThan = pRuntime->ToBoolean(params[0].ToV8Value()); + double dGreaterThan = pRuntime->ToDouble(params[1].ToV8Value()); + bool bLessThan = pRuntime->ToBoolean(params[2].ToV8Value()); + double dLessThan = pRuntime->ToDouble(params[3].ToV8Value()); WideString swMsg; if (bGreaterThan && bLessThan) { if (dEentValue < dGreaterThan || dEentValue > dLessThan) swMsg.Format(JSGetStringFromID(IDS_STRING_JSRANGE1).c_str(), - params[1].ToWideString(pRuntime).c_str(), - params[3].ToWideString(pRuntime).c_str()); + pRuntime->ToWideString(params[1].ToV8Value()).c_str(), + pRuntime->ToWideString(params[3].ToV8Value()).c_str()); } else if (bGreaterThan) { if (dEentValue < dGreaterThan) swMsg.Format(JSGetStringFromID(IDS_STRING_JSRANGE2).c_str(), - params[1].ToWideString(pRuntime).c_str()); + pRuntime->ToWideString(params[1].ToV8Value()).c_str()); } else if (bLessThan) { if (dEentValue > dLessThan) swMsg.Format(JSGetStringFromID(IDS_STRING_JSRANGE3).c_str(), - params[3].ToWideString(pRuntime).c_str()); + pRuntime->ToWideString(params[3].ToV8Value()).c_str()); } if (!swMsg.IsEmpty()) { @@ -1806,7 +1818,7 @@ bool CJS_PublicMethods::AFExtractNums(CJS_Runtime* pRuntime, return false; } - WideString str = params[0].ToWideString(pRuntime); + WideString str = pRuntime->ToWideString(params[0].ToV8Value()); if (str.GetLength() > 0 && (str[0] == L'.' || str[0] == L',')) str = L"0" + str; @@ -1827,10 +1839,14 @@ bool CJS_PublicMethods::AFExtractNums(CJS_Runtime* pRuntime, nums.SetElement(pRuntime, nIndex, CJS_Value(pRuntime->NewString(sPart.c_str()))); - if (nums.GetLength(pRuntime) > 0) - vRet = CJS_Value(nums.ToV8Array(pRuntime)); - else + if (nums.GetLength(pRuntime) > 0) { + if (nums.ToV8Value().IsEmpty()) + vRet = CJS_Value(pRuntime->NewArray()); + else + vRet = CJS_Value(nums.ToV8Value()); + } else { vRet.Set(pRuntime->NewNull()); + } return true; } diff --git a/fpdfsdk/javascript/app.cpp b/fpdfsdk/javascript/app.cpp index 7203c3bfa6..5345d25334 100644 --- a/fpdfsdk/javascript/app.cpp +++ b/fpdfsdk/javascript/app.cpp @@ -220,10 +220,14 @@ bool app::get_active_docs(CJS_Runtime* pRuntime, aDocs.SetElement( pRuntime, 0, pJSDocument ? CJS_Value(pJSDocument->ToV8Object()) : CJS_Value()); - if (aDocs.GetLength(pRuntime) > 0) - vp->Set(aDocs.ToV8Array(pRuntime)); - else + if (aDocs.GetLength(pRuntime) > 0) { + if (aDocs.ToV8Value().IsEmpty()) + vp->Set(pRuntime->NewArray()); + else + vp->Set(aDocs.ToV8Value()); + } else { vp->Set(pRuntime->NewNull()); + } return true; } @@ -244,7 +248,7 @@ bool app::get_calculate(CJS_Runtime* pRuntime, bool app::set_calculate(CJS_Runtime* pRuntime, const CJS_Value& vp, WideString* sError) { - m_bCalculate = vp.ToBool(pRuntime); + m_bCalculate = pRuntime->ToBoolean(vp.ToV8Value()); pRuntime->GetFormFillEnv()->GetInterForm()->EnableCalculate(m_bCalculate); return true; } @@ -401,34 +405,34 @@ bool app::alert(CJS_Runtime* pRuntime, WideString swMsg; if (newParams[0].GetType() == CJS_Value::VT_object) { if (newParams[0].IsArrayObject()) { - CJS_Array carray = newParams[0].ToArray(pRuntime); + CJS_Array carray(pRuntime->ToArray(newParams[0].ToV8Value())); swMsg = L"["; for (int i = 0; i < carray.GetLength(pRuntime); ++i) { if (i) swMsg += L", "; CJS_Value element(carray.GetElement(pRuntime, i)); - swMsg += element.ToWideString(pRuntime); + swMsg += pRuntime->ToWideString(element.ToV8Value()); } swMsg += L"]"; } else { - swMsg = newParams[0].ToWideString(pRuntime); + swMsg = pRuntime->ToWideString(newParams[0].ToV8Value()); } } else { - swMsg = newParams[0].ToWideString(pRuntime); + swMsg = pRuntime->ToWideString(newParams[0].ToV8Value()); } int iIcon = 0; if (newParams[1].GetType() != CJS_Value::VT_unknown) - iIcon = newParams[1].ToInt(pRuntime); + iIcon = pRuntime->ToInt32(newParams[1].ToV8Value()); int iType = 0; if (newParams[2].GetType() != CJS_Value::VT_unknown) - iType = newParams[2].ToInt(pRuntime); + iType = pRuntime->ToInt32(newParams[2].ToV8Value()); WideString swTitle; if (newParams[3].GetType() != CJS_Value::VT_unknown) - swTitle = newParams[3].ToWideString(pRuntime); + swTitle = pRuntime->ToWideString(newParams[3].ToV8Value()); else swTitle = JSGetStringFromID(IDS_STRING_JSALERT); @@ -446,7 +450,8 @@ bool app::beep(CJS_Runtime* pRuntime, CJS_Value& vRet, WideString& sError) { if (params.size() == 1) { - pRuntime->GetFormFillEnv()->JS_appBeep(params[0].ToInt(pRuntime)); + pRuntime->GetFormFillEnv()->JS_appBeep( + pRuntime->ToInt32(params[0].ToV8Value())); return true; } @@ -488,13 +493,14 @@ bool app::setInterval(CJS_Runtime* pRuntime, } WideString script = - params.size() > 0 ? params[0].ToWideString(pRuntime) : L""; + params.size() > 0 ? pRuntime->ToWideString(params[0].ToV8Value()) : L""; if (script.IsEmpty()) { sError = JSGetStringFromID(IDS_STRING_JSAFNUMBER_KEYSTROKE); return true; } - uint32_t dwInterval = params.size() > 1 ? params[1].ToInt(pRuntime) : 1000; + uint32_t dwInterval = + params.size() > 1 ? pRuntime->ToInt32(params[1].ToV8Value()) : 1000; GlobalTimer* timerRef = new GlobalTimer(this, pRuntime->GetFormFillEnv(), pRuntime, 0, script, dwInterval, 0); @@ -523,13 +529,14 @@ bool app::setTimeOut(CJS_Runtime* pRuntime, return false; } - WideString script = params[0].ToWideString(pRuntime); + WideString script = pRuntime->ToWideString(params[0].ToV8Value()); if (script.IsEmpty()) { sError = JSGetStringFromID(IDS_STRING_JSAFNUMBER_KEYSTROKE); return true; } - uint32_t dwTimeOut = params.size() > 1 ? params[1].ToInt(pRuntime) : 1000; + uint32_t dwTimeOut = + params.size() > 1 ? pRuntime->ToInt32(params[1].ToV8Value()) : 1000; GlobalTimer* timerRef = new GlobalTimer(this, pRuntime->GetFormFillEnv(), pRuntime, 1, script, dwTimeOut, dwTimeOut); @@ -578,11 +585,12 @@ void app::ClearTimerCommon(CJS_Runtime* pRuntime, const CJS_Value& param) { if (param.GetType() != CJS_Value::VT_object) return; - v8::Local pObj = param.ToV8Object(pRuntime); + v8::Local pObj = pRuntime->ToObject(param.ToV8Value()); if (CFXJS_Engine::GetObjDefnID(pObj) != CJS_TimerObj::g_nObjDefnID) return; - CJS_Object* pJSObj = param.ToObject(pRuntime); + CJS_Object* pJSObj = + static_cast(pRuntime->GetObjectPrivate(pObj)); if (!pJSObj) return; @@ -648,11 +656,11 @@ bool app::mailMsg(CJS_Runtime* pRuntime, sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); return false; } - bool bUI = newParams[0].ToBool(pRuntime); + bool bUI = pRuntime->ToBoolean(newParams[0].ToV8Value()); WideString cTo; if (newParams[1].GetType() != CJS_Value::VT_unknown) { - cTo = newParams[1].ToWideString(pRuntime); + cTo = pRuntime->ToWideString(newParams[1].ToV8Value()); } else { if (!bUI) { // cTo parameter required when UI not invoked. @@ -663,19 +671,19 @@ bool app::mailMsg(CJS_Runtime* pRuntime, WideString cCc; if (newParams[2].GetType() != CJS_Value::VT_unknown) - cCc = newParams[2].ToWideString(pRuntime); + cCc = pRuntime->ToWideString(newParams[2].ToV8Value()); WideString cBcc; if (newParams[3].GetType() != CJS_Value::VT_unknown) - cBcc = newParams[3].ToWideString(pRuntime); + cBcc = pRuntime->ToWideString(newParams[3].ToV8Value()); WideString cSubject; if (newParams[4].GetType() != CJS_Value::VT_unknown) - cSubject = newParams[4].ToWideString(pRuntime); + cSubject = pRuntime->ToWideString(newParams[4].ToV8Value()); WideString cMsg; if (newParams[5].GetType() != CJS_Value::VT_unknown) - cMsg = newParams[5].ToWideString(pRuntime); + cMsg = pRuntime->ToWideString(newParams[5].ToV8Value()); pRuntime->BeginBlock(); pRuntime->GetFormFillEnv()->JS_docmailForm(nullptr, 0, bUI, cTo.c_str(), @@ -703,7 +711,7 @@ bool app::get_runtime_highlight(CJS_Runtime* pRuntime, bool app::set_runtime_highlight(CJS_Runtime* pRuntime, const CJS_Value& vp, WideString* sError) { - m_bRuntimeHighLight = vp.ToBool(pRuntime); + m_bRuntimeHighLight = pRuntime->ToBoolean(vp.ToV8Value()); return true; } @@ -769,23 +777,23 @@ bool app::response(CJS_Runtime* pRuntime, sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); return false; } - WideString swQuestion = newParams[0].ToWideString(pRuntime); + WideString swQuestion = pRuntime->ToWideString(newParams[0].ToV8Value()); WideString swTitle = L"PDF"; if (newParams[1].GetType() != CJS_Value::VT_unknown) - swTitle = newParams[1].ToWideString(pRuntime); + swTitle = pRuntime->ToWideString(newParams[1].ToV8Value()); WideString swDefault; if (newParams[2].GetType() != CJS_Value::VT_unknown) - swDefault = newParams[2].ToWideString(pRuntime); + swDefault = pRuntime->ToWideString(newParams[2].ToV8Value()); bool bPassword = false; if (newParams[3].GetType() != CJS_Value::VT_unknown) - bPassword = newParams[3].ToBool(pRuntime); + bPassword = pRuntime->ToBoolean(newParams[3].ToV8Value()); WideString swLabel; if (newParams[4].GetType() != CJS_Value::VT_unknown) - swLabel = newParams[4].ToWideString(pRuntime); + swLabel = pRuntime->ToWideString(newParams[4].ToV8Value()); const int MAX_INPUT_BYTES = 2048; std::vector pBuff(MAX_INPUT_BYTES + 2); diff --git a/fpdfsdk/javascript/color.cpp b/fpdfsdk/javascript/color.cpp index e730c31588..56baa59019 100644 --- a/fpdfsdk/javascript/color.cpp +++ b/fpdfsdk/javascript/color.cpp @@ -82,32 +82,41 @@ CFX_Color color::ConvertArrayToPWLColor(CJS_Runtime* pRuntime, if (nArrayLen < 1) return CFX_Color(); - ByteString sSpace = array.GetElement(pRuntime, 0).ToByteString(pRuntime); - if (sSpace == "T") + WideString sSpace = + pRuntime->ToWideString(array.GetElement(pRuntime, 0).ToV8Value()); + if (sSpace == L"T") return CFX_Color(CFX_Color::kTransparent); float d1 = 0; - if (nArrayLen > 1) - d1 = array.GetElement(pRuntime, 1).ToFloat(pRuntime); + if (nArrayLen > 1) { + d1 = static_cast( + pRuntime->ToDouble(array.GetElement(pRuntime, 1).ToV8Value())); + } - if (sSpace == "G") + if (sSpace == L"G") return CFX_Color(CFX_Color::kGray, d1); float d2 = 0; float d3 = 0; - if (nArrayLen > 2) - d2 = array.GetElement(pRuntime, 2).ToFloat(pRuntime); - if (nArrayLen > 3) - d3 = array.GetElement(pRuntime, 3).ToFloat(pRuntime); + if (nArrayLen > 2) { + d2 = static_cast( + pRuntime->ToDouble(array.GetElement(pRuntime, 2).ToV8Value())); + } + if (nArrayLen > 3) { + d3 = static_cast( + pRuntime->ToDouble(array.GetElement(pRuntime, 3).ToV8Value())); + } - if (sSpace == "RGB") + if (sSpace == L"RGB") return CFX_Color(CFX_Color::kRGB, d1, d2, d3); float d4 = 0; - if (nArrayLen > 4) - d4 = array.GetElement(pRuntime, 4).ToFloat(pRuntime); + if (nArrayLen > 4) { + d4 = static_cast( + pRuntime->ToDouble(array.GetElement(pRuntime, 4).ToV8Value())); + } - if (sSpace == "CMYK") + if (sSpace == L"CMYK") return CFX_Color(CFX_Color::kCMYK, d1, d2, d3, d4); return CFX_Color(); @@ -269,7 +278,11 @@ bool color::set_light_gray(CJS_Runtime* pRuntime, bool color::GetPropertyHelper(CJS_Runtime* pRuntime, CJS_Value* vp, CFX_Color* var) { - vp->Set(ConvertPWLColorToArray(pRuntime, *var).ToV8Array(pRuntime)); + CJS_Array array = ConvertPWLColorToArray(pRuntime, *var); + if (array.ToV8Value().IsEmpty()) + vp->Set(pRuntime->NewArray()); + else + vp->Set(array.ToV8Value()); return true; } @@ -279,7 +292,8 @@ bool color::SetPropertyHelper(CJS_Runtime* pRuntime, if (!vp.IsArrayObject()) return false; - *var = ConvertArrayToPWLColor(pRuntime, vp.ToArray(pRuntime)); + *var = ConvertArrayToPWLColor(pRuntime, + CJS_Array(pRuntime->ToArray(vp.ToV8Value()))); return true; } @@ -290,27 +304,29 @@ bool color::convert(CJS_Runtime* pRuntime, int iSize = params.size(); if (iSize < 2) return false; - if (!params[0].IsArrayObject()) return false; - - ByteString sDestSpace = params[1].ToByteString(pRuntime); + WideString sDestSpace = pRuntime->ToWideString(params[1].ToV8Value()); int nColorType = CFX_Color::kTransparent; - if (sDestSpace == "T") + if (sDestSpace == L"T") nColorType = CFX_Color::kTransparent; - else if (sDestSpace == "G") + else if (sDestSpace == L"G") nColorType = CFX_Color::kGray; - else if (sDestSpace == "RGB") + else if (sDestSpace == L"RGB") nColorType = CFX_Color::kRGB; - else if (sDestSpace == "CMYK") + else if (sDestSpace == L"CMYK") nColorType = CFX_Color::kCMYK; - CFX_Color color = - ConvertArrayToPWLColor(pRuntime, params[0].ToArray(pRuntime)); - vRet = CJS_Value( - ConvertPWLColorToArray(pRuntime, color.ConvertColorType(nColorType)) - .ToV8Array(pRuntime)); + CFX_Color color = ConvertArrayToPWLColor( + pRuntime, CJS_Array(pRuntime->ToArray(params[0].ToV8Value()))); + + CJS_Array array = + ConvertPWLColorToArray(pRuntime, color.ConvertColorType(nColorType)); + if (array.ToV8Value().IsEmpty()) + vRet = CJS_Value(pRuntime->NewArray()); + else + vRet = CJS_Value(array.ToV8Value()); return true; } @@ -324,10 +340,10 @@ bool color::equal(CJS_Runtime* pRuntime, if (!params[0].IsArrayObject() || !params[1].IsArrayObject()) return false; - CFX_Color color1 = - ConvertArrayToPWLColor(pRuntime, params[0].ToArray(pRuntime)); - CFX_Color color2 = - ConvertArrayToPWLColor(pRuntime, params[1].ToArray(pRuntime)); + CFX_Color color1 = ConvertArrayToPWLColor( + pRuntime, CJS_Array(pRuntime->ToArray(params[0].ToV8Value()))); + CFX_Color color2 = ConvertArrayToPWLColor( + pRuntime, CJS_Array(pRuntime->ToArray(params[1].ToV8Value()))); color1 = color1.ConvertColorType(color2.nColorType); vRet = CJS_Value(pRuntime->NewBoolean(color1 == color2)); diff --git a/fpdfsdk/javascript/event.cpp b/fpdfsdk/javascript/event.cpp index 361afa8cff..337ce40cd8 100644 --- a/fpdfsdk/javascript/event.cpp +++ b/fpdfsdk/javascript/event.cpp @@ -63,7 +63,7 @@ bool event::set_change(CJS_Runtime* pRuntime, if (vp.GetType() == CJS_Value::VT_string) { WideString& wChange = pEvent->Change(); - wChange = vp.ToWideString(pRuntime); + wChange = pRuntime->ToWideString(vp.ToV8Value()); } return true; } @@ -174,7 +174,7 @@ bool event::set_rc(CJS_Runtime* pRuntime, WideString* sError) { CJS_EventHandler* pEvent = pRuntime->GetCurrentEventContext()->GetEventHandler(); - pEvent->Rc() = vp.ToBool(pRuntime); + pEvent->Rc() = pRuntime->ToBoolean(vp.ToV8Value()); return true; } @@ -236,7 +236,7 @@ bool event::set_sel_end(CJS_Runtime* pRuntime, if (wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0) return true; - pEvent->SelEnd() = vp.ToInt(pRuntime); + pEvent->SelEnd() = pRuntime->ToInt32(vp.ToV8Value()); return true; } @@ -262,7 +262,7 @@ bool event::set_sel_start(CJS_Runtime* pRuntime, if (wcscmp((const wchar_t*)pEvent->Name(), L"Keystroke") != 0) return true; - pEvent->SelStart() = vp.ToInt(pRuntime); + pEvent->SelStart() = pRuntime->ToInt32(vp.ToV8Value()); return true; } @@ -367,7 +367,7 @@ bool event::set_value(CJS_Runtime* pRuntime, if (!pEvent->m_pValue) return false; - pEvent->Value() = vp.ToWideString(pRuntime); + pEvent->Value() = pRuntime->ToWideString(vp.ToV8Value()); return true; } diff --git a/fpdfsdk/javascript/global.cpp b/fpdfsdk/javascript/global.cpp index a226bb25cc..f095440413 100644 --- a/fpdfsdk/javascript/global.cpp +++ b/fpdfsdk/javascript/global.cpp @@ -328,19 +328,20 @@ bool JSGlobalAlternate::SetProperty(CJS_Runtime* pRuntime, switch (vp.GetType()) { case CJS_Value::VT_number: return SetGlobalVariables(sPropName, JS_GlobalDataType::NUMBER, - vp.ToDouble(pRuntime), false, "", + pRuntime->ToDouble(vp.ToV8Value()), false, "", v8::Local(), false); case CJS_Value::VT_boolean: return SetGlobalVariables(sPropName, JS_GlobalDataType::BOOLEAN, 0, - vp.ToBool(pRuntime), "", + pRuntime->ToBoolean(vp.ToV8Value()), "", v8::Local(), false); case CJS_Value::VT_string: - return SetGlobalVariables(sPropName, JS_GlobalDataType::STRING, 0, false, - vp.ToByteString(pRuntime), - v8::Local(), false); + return SetGlobalVariables( + sPropName, JS_GlobalDataType::STRING, 0, false, + ByteString::FromUnicode(pRuntime->ToWideString(vp.ToV8Value())), + v8::Local(), false); case CJS_Value::VT_object: return SetGlobalVariables(sPropName, JS_GlobalDataType::OBJECT, 0, false, - "", vp.ToV8Object(pRuntime), false); + "", pRuntime->ToObject(vp.ToV8Value()), false); case CJS_Value::VT_null: return SetGlobalVariables(sPropName, JS_GlobalDataType::NULLOBJ, 0, false, "", v8::Local(), false); @@ -361,12 +362,13 @@ bool JSGlobalAlternate::setPersistent(CJS_Runtime* pRuntime, sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); return false; } - auto it = m_MapGlobal.find(params[0].ToByteString(pRuntime)); + auto it = m_MapGlobal.find( + ByteString::FromUnicode(pRuntime->ToWideString(params[0].ToV8Value()))); if (it == m_MapGlobal.end() || it->second->bDeleted) { sError = JSGetStringFromID(IDS_STRING_JSNOGLOBAL); return false; } - it->second->bPersistent = params[1].ToBool(pRuntime); + it->second->bPersistent = pRuntime->ToBoolean(params[1].ToV8Value()); return true; } @@ -485,7 +487,7 @@ void JSGlobalAlternate::ObjectToArray(CJS_Runtime* pRuntime, array.Add(pObjElement); } break; case CJS_Value::VT_string: { - ByteString sValue = CJS_Value(v).ToByteString(pRuntime); + ByteString sValue = ByteString::FromUnicode(pRuntime->ToWideString(v)); 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 63179c84a8..96b2c8a6ef 100644 --- a/fpdfsdk/javascript/util.cpp +++ b/fpdfsdk/javascript/util.cpp @@ -81,7 +81,8 @@ bool util::printf(CJS_Runtime* pRuntime, if (iSize < 1) return false; - std::wstring unsafe_fmt_string(params[0].ToWideString(pRuntime).c_str()); + std::wstring unsafe_fmt_string( + pRuntime->ToWideString(params[0].ToV8Value()).c_str()); std::vector unsafe_conversion_specifiers; int iOffset = 0; int iOffend = 0; @@ -114,15 +115,17 @@ bool util::printf(CJS_Runtime* pRuntime, WideString strSegment; switch (ParseDataType(&c_strFormat)) { case UTIL_INT: - strSegment.Format(c_strFormat.c_str(), params[iIndex].ToInt(pRuntime)); + strSegment.Format(c_strFormat.c_str(), + pRuntime->ToInt32(params[iIndex].ToV8Value())); break; case UTIL_DOUBLE: strSegment.Format(c_strFormat.c_str(), - params[iIndex].ToDouble(pRuntime)); + pRuntime->ToDouble(params[iIndex].ToV8Value())); break; case UTIL_STRING: - strSegment.Format(c_strFormat.c_str(), - params[iIndex].ToWideString(pRuntime).c_str()); + strSegment.Format( + c_strFormat.c_str(), + pRuntime->ToWideString(params[iIndex].ToV8Value()).c_str()); break; default: strSegment.Format(L"%ls", c_strFormat.c_str()); @@ -151,7 +154,9 @@ bool util::printd(CJS_Runtime* pRuntime, return false; } - CJS_Date jsDate = p2.ToDate(); + ASSERT(p2.IsDateObject()); + v8::Local mutable_value = p2.ToV8Value(); + CJS_Date jsDate(mutable_value.As()); if (!jsDate.IsValidDate(pRuntime)) { sError = JSGetStringFromID(IDS_STRING_JSPRINT2); return false; @@ -159,7 +164,7 @@ bool util::printd(CJS_Runtime* pRuntime, if (p1.GetType() == CJS_Value::VT_number) { WideString swResult; - switch (p1.ToInt(pRuntime)) { + switch (pRuntime->ToInt32(p1.ToV8Value())) { case 0: swResult.Format(L"D:%04d%02d%02d%02d%02d%02d", jsDate.GetYear(pRuntime), jsDate.GetMonth(pRuntime) + 1, jsDate.GetDay(pRuntime), @@ -190,14 +195,15 @@ bool util::printd(CJS_Runtime* pRuntime, } if (p1.GetType() == CJS_Value::VT_string) { - if (iSize > 2 && params[2].ToBool(pRuntime)) { + if (iSize > 2 && pRuntime->ToBoolean(params[2].ToV8Value())) { sError = JSGetStringFromID(IDS_STRING_JSNOTSUPPORT); return false; // currently, it doesn't support XFAPicture. } // Convert PDF-style format specifiers to wcsftime specifiers. Remove any // pre-existing %-directives before inserting our own. - std::basic_string cFormat = p1.ToWideString(pRuntime).c_str(); + std::basic_string cFormat = + pRuntime->ToWideString(p1.ToV8Value()).c_str(); cFormat.erase(std::remove(cFormat.begin(), cFormat.end(), '%'), cFormat.end()); @@ -276,9 +282,10 @@ bool util::printx(CJS_Runtime* pRuntime, return false; } - vRet = CJS_Value(pRuntime->NewString( - printx(params[0].ToWideString(pRuntime), params[1].ToWideString(pRuntime)) - .c_str())); + vRet = CJS_Value( + pRuntime->NewString(printx(pRuntime->ToWideString(params[0].ToV8Value()), + pRuntime->ToWideString(params[1].ToV8Value())) + .c_str())); return true; } @@ -388,15 +395,15 @@ bool util::scand(CJS_Runtime* pRuntime, if (params.size() < 2) return false; - WideString sFormat = params[0].ToWideString(pRuntime); - WideString sDate = params[1].ToWideString(pRuntime); + WideString sFormat = pRuntime->ToWideString(params[0].ToV8Value()); + WideString sDate = pRuntime->ToWideString(params[1].ToV8Value()); double dDate = JS_GetDateTime(); if (sDate.GetLength() > 0) { dDate = CJS_PublicMethods::MakeRegularDate(sDate, sFormat, nullptr); } if (!std::isnan(dDate)) { - vRet = CJS_Value(CJS_Date(pRuntime, dDate).ToV8Date()); + vRet = CJS_Value(CJS_Date(pRuntime, dDate).ToV8Value()); } else { vRet.Set(pRuntime->NewNull()); } @@ -413,7 +420,7 @@ bool util::byteToChar(CJS_Runtime* pRuntime, return false; } - int arg = params[0].ToInt(pRuntime); + int arg = pRuntime->ToInt32(params[0].ToV8Value()); if (arg < 0 || arg > 255) { sError = JSGetStringFromID(IDS_STRING_JSVALUEERROR); return false; -- cgit v1.2.3