From 1d8d9ac983fa9c7b6dfc3df736cfd3eae6908a60 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Tue, 24 Oct 2017 11:23:25 -0400 Subject: Remove CJS_Value constructors This CL removes most of the CJS_Value constructors and leaves the v8::Local constructor as the only non-default construtor. Change-Id: Ie98260d10eff645d0ca688b353e7d40ba1aac157 Reviewed-on: https://pdfium-review.googlesource.com/16611 Reviewed-by: Tom Sepez Commit-Queue: dsinclair --- fpdfsdk/javascript/Field.cpp | 95 +++++++++++++++++++++++++------------------- 1 file changed, 55 insertions(+), 40 deletions(-) (limited to 'fpdfsdk/javascript/Field.cpp') diff --git a/fpdfsdk/javascript/Field.cpp b/fpdfsdk/javascript/Field.cpp index ce94fd869a..8979e7f8ec 100644 --- a/fpdfsdk/javascript/Field.cpp +++ b/fpdfsdk/javascript/Field.cpp @@ -856,8 +856,9 @@ bool Field::get_current_value_indices(CJS_Runtime* pRuntime, CJS_Array SelArray; for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) { - SelArray.SetElement(pRuntime, i, - CJS_Value(pRuntime, pFormField->GetSelectedIndex(i))); + SelArray.SetElement( + pRuntime, i, + CJS_Value(pRuntime->NewNumber(pFormField->GetSelectedIndex(i)))); } vp->Set(SelArray.ToV8Array(pRuntime)); @@ -1163,9 +1164,9 @@ bool Field::get_export_values(CJS_Runtime* pRuntime, 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, pFormControl->GetExportValue().c_str())); + ExportValusArray.SetElement(pRuntime, i, + CJS_Value(pRuntime->NewString( + pFormControl->GetExportValue().c_str()))); } } else { if (m_nFormControlIndex >= pFormField->CountControls()) @@ -1178,7 +1179,7 @@ bool Field::get_export_values(CJS_Runtime* pRuntime, ExportValusArray.SetElement( pRuntime, 0, - CJS_Value(pRuntime, pFormControl->GetExportValue().c_str())); + CJS_Value(pRuntime->NewString(pFormControl->GetExportValue().c_str()))); } vp->Set(ExportValusArray.ToV8Array(pRuntime)); @@ -1571,8 +1572,9 @@ bool Field::get_page(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError) { if (!pPageView) return false; - PageArray.SetElement( - pRuntime, i, CJS_Value(pRuntime, (int32_t)pPageView->GetPageIndex())); + PageArray.SetElement(pRuntime, i, + CJS_Value(pRuntime->NewNumber( + static_cast(pPageView->GetPageIndex())))); ++i; } @@ -1749,14 +1751,18 @@ bool Field::get_rect(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError) { CFX_FloatRect crRect = pWidget->GetRect(); CJS_Array rcArray; - rcArray.SetElement(pRuntime, 0, - CJS_Value(pRuntime, static_cast(crRect.left))); - rcArray.SetElement(pRuntime, 1, - CJS_Value(pRuntime, static_cast(crRect.top))); - rcArray.SetElement(pRuntime, 2, - CJS_Value(pRuntime, static_cast(crRect.right))); - rcArray.SetElement(pRuntime, 3, - CJS_Value(pRuntime, static_cast(crRect.bottom))); + rcArray.SetElement( + pRuntime, 0, + CJS_Value(pRuntime->NewNumber(static_cast(crRect.left)))); + rcArray.SetElement( + pRuntime, 1, + CJS_Value(pRuntime->NewNumber(static_cast(crRect.top)))); + rcArray.SetElement( + pRuntime, 2, + CJS_Value(pRuntime->NewNumber(static_cast(crRect.right)))); + rcArray.SetElement( + pRuntime, 3, + CJS_Value(pRuntime->NewNumber(static_cast(crRect.bottom)))); vp->Set(rcArray.ToV8Array(pRuntime)); return true; } @@ -2251,11 +2257,11 @@ bool Field::get_value(CJS_Runtime* pRuntime, int iIndex; for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) { iIndex = pFormField->GetSelectedIndex(i); - ElementValue = - CJS_Value(pRuntime, pFormField->GetOptionValue(iIndex).c_str()); + ElementValue = CJS_Value( + pRuntime->NewString(pFormField->GetOptionValue(iIndex).c_str())); if (wcslen(ElementValue.ToWideString(pRuntime).c_str()) == 0) { - ElementValue = - CJS_Value(pRuntime, pFormField->GetOptionLabel(iIndex).c_str()); + ElementValue = CJS_Value(pRuntime->NewString( + pFormField->GetOptionLabel(iIndex).c_str())); } ValueArray.SetElement(pRuntime, i, ElementValue); } @@ -2462,11 +2468,14 @@ bool Field::buttonGetCaption(CJS_Runtime* pRuntime, return false; if (nface == 0) - vRet = CJS_Value(pRuntime, pFormControl->GetNormalCaption().c_str()); + vRet = CJS_Value( + pRuntime->NewString(pFormControl->GetNormalCaption().c_str())); else if (nface == 1) - vRet = CJS_Value(pRuntime, pFormControl->GetDownCaption().c_str()); + vRet = + CJS_Value(pRuntime->NewString(pFormControl->GetDownCaption().c_str())); else if (nface == 2) - vRet = CJS_Value(pRuntime, pFormControl->GetRolloverCaption().c_str()); + vRet = CJS_Value( + pRuntime->NewString(pFormControl->GetRolloverCaption().c_str())); else return false; @@ -2501,7 +2510,9 @@ bool Field::buttonGetIcon(CJS_Runtime* pRuntime, return false; CJS_Icon* pJS_Icon = static_cast(pRuntime->GetObjectPrivate(pObj)); - vRet = CJS_Value(pJS_Icon); + if (pJS_Icon) + vRet = CJS_Value(pJS_Icon->ToV8Object()); + return true; } @@ -2590,9 +2601,9 @@ bool Field::defaultIsChecked(CJS_Runtime* pRuntime, if (nWidget < 0 || nWidget >= pFormField->CountControls()) return false; - vRet = CJS_Value(pRuntime, - pFormField->GetFieldType() == FIELDTYPE_CHECKBOX || - pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON); + vRet = CJS_Value(pRuntime->NewBoolean( + pFormField->GetFieldType() == FIELDTYPE_CHECKBOX || + pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON)); return true; } @@ -2635,10 +2646,12 @@ bool Field::getArray(CJS_Runtime* pRuntime, static_cast(pRuntime->GetObjectPrivate(pObj)); Field* pField = static_cast(pJSField->GetEmbedObject()); pField->AttachField(m_pJSDoc, *pStr); - FormFieldArray.SetElement(pRuntime, j++, CJS_Value(pJSField)); + FormFieldArray.SetElement( + pRuntime, j++, + pJSField ? CJS_Value(pJSField->ToV8Object()) : CJS_Value()); } - vRet = CJS_Value(pRuntime, FormFieldArray); + vRet = CJS_Value(FormFieldArray.ToV8Array(pRuntime)); return true; } @@ -2667,11 +2680,13 @@ bool Field::getItemAt(CJS_Runtime* pRuntime, if (bExport) { WideString strval = pFormField->GetOptionValue(nIdx); if (strval.IsEmpty()) - vRet = CJS_Value(pRuntime, pFormField->GetOptionLabel(nIdx).c_str()); + vRet = CJS_Value( + pRuntime->NewString(pFormField->GetOptionLabel(nIdx).c_str())); else - vRet = CJS_Value(pRuntime, strval.c_str()); + vRet = CJS_Value(pRuntime->NewString(strval.c_str())); } else { - vRet = CJS_Value(pRuntime, pFormField->GetOptionLabel(nIdx).c_str()); + vRet = CJS_Value( + pRuntime->NewString(pFormField->GetOptionLabel(nIdx).c_str())); } } else { return false; @@ -2710,10 +2725,10 @@ bool Field::isBoxChecked(CJS_Runtime* pRuntime, if (nIndex < 0 || nIndex >= pFormField->CountControls()) return false; - vRet = CJS_Value(pRuntime, - ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX || - pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON) && - pFormField->GetControl(nIndex)->IsChecked() != 0)); + vRet = CJS_Value(pRuntime->NewBoolean( + ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX || + pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON) && + pFormField->GetControl(nIndex)->IsChecked() != 0))); return true; } @@ -2733,10 +2748,10 @@ bool Field::isDefaultChecked(CJS_Runtime* pRuntime, if (nIndex < 0 || nIndex >= pFormField->CountControls()) return false; - vRet = CJS_Value(pRuntime, - ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX || - pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON) && - pFormField->GetControl(nIndex)->IsDefaultChecked() != 0)); + vRet = CJS_Value(pRuntime->NewBoolean( + ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX || + pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON) && + pFormField->GetControl(nIndex)->IsDefaultChecked() != 0))); return true; } -- cgit v1.2.3