summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/javascript/Document.cpp28
-rw-r--r--fpdfsdk/javascript/Field.cpp95
-rw-r--r--fpdfsdk/javascript/JS_Value.cpp25
-rw-r--r--fpdfsdk/javascript/JS_Value.h9
-rw-r--r--fpdfsdk/javascript/PublicMethods.cpp70
-rw-r--r--fpdfsdk/javascript/app.cpp18
-rw-r--r--fpdfsdk/javascript/color.cpp39
-rw-r--r--fpdfsdk/javascript/util.cpp16
8 files changed, 153 insertions, 147 deletions
diff --git a/fpdfsdk/javascript/Document.cpp b/fpdfsdk/javascript/Document.cpp
index a47deea790..c406425a92 100644
--- a/fpdfsdk/javascript/Document.cpp
+++ b/fpdfsdk/javascript/Document.cpp
@@ -325,7 +325,9 @@ bool Document::getField(CJS_Runtime* pRuntime,
static_cast<CJS_Field*>(pRuntime->GetObjectPrivate(pFieldObj));
Field* pField = static_cast<Field*>(pJSField->GetEmbedObject());
pField->AttachField(this, wideName);
- vRet = CJS_Value(pJSField);
+
+ if (pJSField)
+ vRet = CJS_Value(pJSField->ToV8Object());
return true;
}
@@ -353,7 +355,7 @@ bool Document::getNthFieldName(CJS_Runtime* pRuntime,
if (!pField)
return false;
- vRet = CJS_Value(pRuntime, pField->GetFullName().c_str());
+ vRet = CJS_Value(pRuntime->NewString(pField->GetFullName().c_str()));
return true;
}
@@ -1279,7 +1281,9 @@ bool Document::getAnnot(CJS_Runtime* pRuntime,
static_cast<CJS_Annot*>(pRuntime->GetObjectPrivate(pObj));
Annot* pAnnot = static_cast<Annot*>(pJS_Annot->GetEmbedObject());
pAnnot->SetSDKAnnot(pSDKBAAnnot);
- vRet = CJS_Value(pJS_Annot);
+ if (pJS_Annot)
+ vRet = CJS_Value(pJS_Annot->ToV8Object());
+
return true;
}
@@ -1317,10 +1321,12 @@ bool Document::getAnnots(CJS_Runtime* pRuntime,
static_cast<CJS_Annot*>(pRuntime->GetObjectPrivate(pObj));
Annot* pAnnot = static_cast<Annot*>(pJS_Annot->GetEmbedObject());
pAnnot->SetSDKAnnot(static_cast<CPDFSDK_BAAnnot*>(pSDKAnnotCur.Get()));
- annots.SetElement(pRuntime, i, CJS_Value(pJS_Annot));
+ annots.SetElement(
+ pRuntime, i,
+ pJS_Annot ? CJS_Value(pJS_Annot->ToV8Object()) : CJS_Value());
}
}
- vRet = CJS_Value(pRuntime, annots);
+ vRet = CJS_Value(annots.ToV8Array(pRuntime));
return true;
}
@@ -1408,7 +1414,9 @@ bool Document::get_icons(CJS_Runtime* pRuntime,
static_cast<CJS_Icon*>(pRuntime->GetObjectPrivate(pObj));
Icon* pIcon = static_cast<Icon*>(pJS_Icon->GetEmbedObject());
pIcon->SetIconName(name);
- Icons.SetElement(pRuntime, i++, CJS_Value(pJS_Icon));
+ Icons.SetElement(
+ pRuntime, i++,
+ pJS_Icon ? CJS_Value(pJS_Icon->ToV8Object()) : CJS_Value());
}
vp->Set(Icons.ToV8Array(pRuntime));
@@ -1444,7 +1452,9 @@ bool Document::getIcon(CJS_Runtime* pRuntime,
CJS_Icon* pJS_Icon = static_cast<CJS_Icon*>(pRuntime->GetObjectPrivate(pObj));
Icon* pIcon = static_cast<Icon*>(pJS_Icon->GetEmbedObject());
pIcon->SetIconName(*it);
- vRet = CJS_Value(pJS_Icon);
+ if (pJS_Icon)
+ vRet = CJS_Value(pJS_Icon->ToV8Object());
+
return true;
}
@@ -1560,7 +1570,7 @@ bool Document::getPageNthWord(CJS_Runtime* pRuntime,
swRet.TrimRight();
}
- vRet = CJS_Value(pRuntime, swRet.c_str());
+ vRet = CJS_Value(pRuntime->NewString(swRet.c_str()));
return true;
}
@@ -1611,7 +1621,7 @@ bool Document::getPageNumWords(CJS_Runtime* pRuntime,
nWords += CountWords(pPageObj->AsText());
}
- vRet = CJS_Value(pRuntime, nWords);
+ vRet = CJS_Value(pRuntime->NewNumber(nWords));
return true;
}
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<int32_t>(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<int32_t>(crRect.left)));
- rcArray.SetElement(pRuntime, 1,
- CJS_Value(pRuntime, static_cast<int32_t>(crRect.top)));
- rcArray.SetElement(pRuntime, 2,
- CJS_Value(pRuntime, static_cast<int32_t>(crRect.right)));
- rcArray.SetElement(pRuntime, 3,
- CJS_Value(pRuntime, static_cast<int32_t>(crRect.bottom)));
+ rcArray.SetElement(
+ pRuntime, 0,
+ CJS_Value(pRuntime->NewNumber(static_cast<int32_t>(crRect.left))));
+ rcArray.SetElement(
+ pRuntime, 1,
+ CJS_Value(pRuntime->NewNumber(static_cast<int32_t>(crRect.top))));
+ rcArray.SetElement(
+ pRuntime, 2,
+ CJS_Value(pRuntime->NewNumber(static_cast<int32_t>(crRect.right))));
+ rcArray.SetElement(
+ pRuntime, 3,
+ CJS_Value(pRuntime->NewNumber(static_cast<int32_t>(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<CJS_Icon*>(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<CJS_Field*>(pRuntime->GetObjectPrivate(pObj));
Field* pField = static_cast<Field*>(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;
}
diff --git a/fpdfsdk/javascript/JS_Value.cpp b/fpdfsdk/javascript/JS_Value.cpp
index 7de267eaf3..fcf913a7fb 100644
--- a/fpdfsdk/javascript/JS_Value.cpp
+++ b/fpdfsdk/javascript/JS_Value.cpp
@@ -182,31 +182,6 @@ CJS_Value::CJS_Value() {}
CJS_Value::CJS_Value(v8::Local<v8::Value> pValue) : m_pValue(pValue) {}
-CJS_Value::CJS_Value(CJS_Runtime* pRuntime, int iValue)
- : CJS_Value(pRuntime->NewNumber(iValue)) {}
-
-CJS_Value::CJS_Value(CJS_Runtime* pRuntime, bool bValue)
- : CJS_Value(pRuntime->NewBoolean(bValue)) {}
-
-CJS_Value::CJS_Value(CJS_Runtime* pRuntime, double dValue)
- : CJS_Value(pRuntime->NewNumber(dValue)) {}
-
-CJS_Value::CJS_Value(CJS_Object* pObj) {
- if (pObj)
- m_pValue = pObj->ToV8Object();
-}
-
-CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const wchar_t* pWstr)
- : CJS_Value(pRuntime->NewString(pWstr)) {}
-
-CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const char* pStr)
- : CJS_Value(pRuntime->NewString(WideString::FromLocal(pStr).c_str())) {}
-
-CJS_Value::CJS_Value(CJS_Runtime* pRuntime, const CJS_Array& array)
- : CJS_Value(array.ToV8Array(pRuntime)) {}
-
-CJS_Value::CJS_Value(const CJS_Date& date) : CJS_Value(date.ToV8Date()) {}
-
CJS_Value::~CJS_Value() {}
CJS_Value::CJS_Value(const CJS_Value& other) = default;
diff --git a/fpdfsdk/javascript/JS_Value.h b/fpdfsdk/javascript/JS_Value.h
index 72d381e188..c0e267a4a5 100644
--- a/fpdfsdk/javascript/JS_Value.h
+++ b/fpdfsdk/javascript/JS_Value.h
@@ -34,16 +34,7 @@ class CJS_Value {
CJS_Value();
explicit CJS_Value(v8::Local<v8::Value> pValue);
- CJS_Value(CJS_Runtime* pRuntime, int iValue);
- CJS_Value(CJS_Runtime* pRuntime, double dValue);
- CJS_Value(CJS_Runtime* pRuntime, bool bValue);
- explicit CJS_Value(CJS_Object* pObj);
- CJS_Value(CJS_Runtime* pRuntime, const char* pStr);
- CJS_Value(CJS_Runtime* pRuntime, const wchar_t* pWstr);
- CJS_Value(CJS_Runtime* pRuntime, const CJS_Array& array);
- explicit CJS_Value(const CJS_Date& date);
CJS_Value(const CJS_Value& other);
-
~CJS_Value();
// These calls may re-enter JS (and hence invalidate objects).
diff --git a/fpdfsdk/javascript/PublicMethods.cpp b/fpdfsdk/javascript/PublicMethods.cpp
index ccd2cfc885..9f336ae938 100644
--- a/fpdfsdk/javascript/PublicMethods.cpp
+++ b/fpdfsdk/javascript/PublicMethods.cpp
@@ -261,8 +261,9 @@ CJS_Array CJS_PublicMethods::AF_MakeArrayFromList(CJS_Runtime* pRuntime,
while (*p) {
const char* pTemp = strchr(p, ch);
if (!pTemp) {
- StrArray.SetElement(pRuntime, nIndex,
- CJS_Value(pRuntime, StrTrim(ByteString(p)).c_str()));
+ StrArray.SetElement(
+ pRuntime, nIndex,
+ CJS_Value(pRuntime->NewString(StrTrim(ByteString(p)).c_str())));
break;
}
@@ -270,8 +271,9 @@ CJS_Array CJS_PublicMethods::AF_MakeArrayFromList(CJS_Runtime* pRuntime,
strncpy(pSub, p, pTemp - p);
*(pSub + (pTemp - p)) = '\0';
- StrArray.SetElement(pRuntime, nIndex,
- CJS_Value(pRuntime, StrTrim(ByteString(pSub)).c_str()));
+ StrArray.SetElement(
+ pRuntime, nIndex,
+ CJS_Value(pRuntime->NewString(StrTrim(ByteString(pSub)).c_str())));
delete[] pSub;
nIndex++;
@@ -896,16 +898,17 @@ bool CJS_PublicMethods::AFNumber_Format(CJS_Runtime* pRuntime,
if (iNegStyle == 1 || iNegStyle == 3) {
if (Field* fTarget = pEvent->Target_Field()) {
CJS_Array arColor;
- CJS_Value vColElm;
- vColElm = CJS_Value(pRuntime, L"RGB");
+ CJS_Value vColElm(pRuntime->NewString(L"RGB"));
arColor.SetElement(pRuntime, 0, vColElm);
- vColElm = CJS_Value(pRuntime, 1);
+
+ vColElm = CJS_Value(pRuntime->NewNumber(1));
arColor.SetElement(pRuntime, 1, vColElm);
- vColElm = CJS_Value(pRuntime, 0);
+
+ vColElm = CJS_Value(pRuntime->NewNumber(0));
arColor.SetElement(pRuntime, 2, vColElm);
arColor.SetElement(pRuntime, 3, vColElm);
- CJS_Value vProp(pRuntime, arColor);
+ CJS_Value vProp(arColor.ToV8Array(pRuntime));
fTarget->set_text_color(pRuntime, vProp, &sError); // red
}
}
@@ -913,10 +916,10 @@ bool CJS_PublicMethods::AFNumber_Format(CJS_Runtime* pRuntime,
if (iNegStyle == 1 || iNegStyle == 3) {
if (Field* fTarget = pEvent->Target_Field()) {
CJS_Array arColor;
- CJS_Value vColElm;
- vColElm = CJS_Value(pRuntime, L"RGB");
+ CJS_Value vColElm(pRuntime->NewString(L"RGB"));
arColor.SetElement(pRuntime, 0, vColElm);
- vColElm = CJS_Value(pRuntime, 0);
+
+ vColElm = CJS_Value(pRuntime->NewNumber(0));
arColor.SetElement(pRuntime, 1, vColElm);
arColor.SetElement(pRuntime, 2, vColElm);
arColor.SetElement(pRuntime, 3, vColElm);
@@ -928,8 +931,8 @@ bool CJS_PublicMethods::AFNumber_Format(CJS_Runtime* pRuntime,
color::ConvertArrayToPWLColor(pRuntime, vProp.ToArray(pRuntime));
CFX_Color crColor = color::ConvertArrayToPWLColor(pRuntime, arColor);
if (crColor != crProp) {
- fTarget->set_text_color(pRuntime, CJS_Value(pRuntime, arColor),
- &sError);
+ fTarget->set_text_color(
+ pRuntime, CJS_Value(arColor.ToV8Array(pRuntime)), &sError);
}
}
}
@@ -1296,7 +1299,7 @@ bool CJS_PublicMethods::AFDate_Format(CJS_Runtime* pRuntime,
iIndex = 0;
std::vector<CJS_Value> newParams;
- newParams.push_back(CJS_Value(pRuntime, cFormats[iIndex]));
+ newParams.push_back(CJS_Value(pRuntime->NewString(cFormats[iIndex])));
return AFDate_FormatEx(pRuntime, newParams, vRet, sError);
}
@@ -1330,7 +1333,7 @@ bool CJS_PublicMethods::AFDate_Keystroke(CJS_Runtime* pRuntime,
iIndex = 0;
std::vector<CJS_Value> newParams;
- newParams.push_back(CJS_Value(pRuntime, cFormats[iIndex]));
+ newParams.push_back(CJS_Value(pRuntime->NewString(cFormats[iIndex])));
return AFDate_KeystrokeEx(pRuntime, newParams, vRet, sError);
}
@@ -1352,7 +1355,7 @@ bool CJS_PublicMethods::AFTime_Format(CJS_Runtime* pRuntime,
iIndex = 0;
std::vector<CJS_Value> newParams;
- newParams.push_back(CJS_Value(pRuntime, cFormats[iIndex]));
+ newParams.push_back(CJS_Value(pRuntime->NewString(cFormats[iIndex])));
return AFDate_FormatEx(pRuntime, newParams, vRet, sError);
}
@@ -1373,7 +1376,7 @@ bool CJS_PublicMethods::AFTime_Keystroke(CJS_Runtime* pRuntime,
iIndex = 0;
std::vector<CJS_Value> newParams;
- newParams.push_back(CJS_Value(pRuntime, cFormats[iIndex]));
+ newParams.push_back(CJS_Value(pRuntime->NewString(cFormats[iIndex])));
return AFDate_KeystrokeEx(pRuntime, newParams, vRet, sError);
}
@@ -1549,7 +1552,7 @@ bool CJS_PublicMethods::AFSpecial_Keystroke(
}
std::vector<CJS_Value> params2;
- params2.push_back(CJS_Value(pRuntime, cFormat));
+ params2.push_back(CJS_Value(pRuntime->NewString(cFormat)));
return AFSpecial_KeystrokeEx(pRuntime, params2, vRet, sError);
}
@@ -1570,7 +1573,7 @@ bool CJS_PublicMethods::AFMergeChange(CJS_Runtime* pRuntime,
swValue = pEventHandler->Value();
if (pEventHandler->WillCommit()) {
- vRet = CJS_Value(pRuntime, swValue.c_str());
+ vRet = CJS_Value(pRuntime->NewString(swValue.c_str()));
return true;
}
@@ -1588,8 +1591,8 @@ bool CJS_PublicMethods::AFMergeChange(CJS_Runtime* pRuntime,
else
postfix = L"";
- vRet =
- CJS_Value(pRuntime, (prefix + pEventHandler->Change() + postfix).c_str());
+ vRet = CJS_Value(pRuntime->NewString(
+ (prefix + pEventHandler->Change() + postfix).c_str()));
return true;
}
@@ -1613,7 +1616,7 @@ bool CJS_PublicMethods::AFParseDateEx(CJS_Runtime* pRuntime,
return false;
}
- vRet = CJS_Value(pRuntime, dDate);
+ vRet = CJS_Value(pRuntime->NewNumber(dDate));
return true;
}
@@ -1626,10 +1629,9 @@ bool CJS_PublicMethods::AFSimple(CJS_Runtime* pRuntime,
return false;
}
- vRet = CJS_Value(pRuntime, static_cast<double>(AF_Simple(
- params[0].ToWideString(pRuntime).c_str(),
- params[1].ToDouble(pRuntime),
- params[2].ToDouble(pRuntime))));
+ vRet = CJS_Value(pRuntime->NewNumber(static_cast<double>(
+ AF_Simple(params[0].ToWideString(pRuntime).c_str(),
+ params[1].ToDouble(pRuntime), params[2].ToDouble(pRuntime)))));
return true;
}
@@ -1645,10 +1647,10 @@ bool CJS_PublicMethods::AFMakeNumber(CJS_Runtime* pRuntime,
WideString ws = params[0].ToWideString(pRuntime);
ws.Replace(L",", L".");
- vRet = CJS_Value(pRuntime, ws.c_str());
+ vRet = CJS_Value(pRuntime->NewString(ws.c_str()));
vRet.MaybeCoerceToNumber(pRuntime);
if (vRet.GetType() != CJS_Value::VT_number)
- vRet = CJS_Value(pRuntime, 0);
+ vRet = CJS_Value(pRuntime->NewNumber(0));
return true;
}
@@ -1739,7 +1741,7 @@ 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, dValue);
+ CJS_Value jsValue(pRuntime->NewNumber(dValue));
CJS_EventContext* pContext = pRuntime->GetCurrentEventContext();
if (pContext->GetEventHandler()->m_pValue)
pContext->GetEventHandler()->Value() = jsValue.ToWideString(pRuntime);
@@ -1815,16 +1817,18 @@ bool CJS_PublicMethods::AFExtractNums(CJS_Runtime* pRuntime,
if (std::iswdigit(wc)) {
sPart += wc;
} else if (sPart.GetLength() > 0) {
- nums.SetElement(pRuntime, nIndex, CJS_Value(pRuntime, sPart.c_str()));
+ nums.SetElement(pRuntime, nIndex,
+ CJS_Value(pRuntime->NewString(sPart.c_str())));
sPart = L"";
nIndex++;
}
}
if (sPart.GetLength() > 0)
- nums.SetElement(pRuntime, nIndex, CJS_Value(pRuntime, sPart.c_str()));
+ nums.SetElement(pRuntime, nIndex,
+ CJS_Value(pRuntime->NewString(sPart.c_str())));
if (nums.GetLength(pRuntime) > 0)
- vRet = CJS_Value(pRuntime, nums);
+ vRet = CJS_Value(nums.ToV8Array(pRuntime));
else
vRet.Set(pRuntime->NewNull());
diff --git a/fpdfsdk/javascript/app.cpp b/fpdfsdk/javascript/app.cpp
index 1c822df1d7..7203c3bfa6 100644
--- a/fpdfsdk/javascript/app.cpp
+++ b/fpdfsdk/javascript/app.cpp
@@ -217,7 +217,9 @@ bool app::get_active_docs(CJS_Runtime* pRuntime,
pJSDocument = static_cast<CJS_Document*>(pRuntime->GetObjectPrivate(pObj));
CJS_Array aDocs;
- aDocs.SetElement(pRuntime, 0, CJS_Value(pJSDocument));
+ aDocs.SetElement(
+ pRuntime, 0,
+ pJSDocument ? CJS_Value(pJSDocument->ToV8Object()) : CJS_Value());
if (aDocs.GetLength(pRuntime) > 0)
vp->Set(aDocs.ToV8Array(pRuntime));
else
@@ -392,7 +394,7 @@ bool app::alert(CJS_Runtime* pRuntime,
CPDFSDK_FormFillEnvironment* pFormFillEnv = pRuntime->GetFormFillEnv();
if (!pFormFillEnv) {
- vRet = CJS_Value(pRuntime, 0);
+ vRet = CJS_Value(pRuntime->NewNumber(0));
return true;
}
@@ -433,8 +435,8 @@ bool app::alert(CJS_Runtime* pRuntime,
pRuntime->BeginBlock();
pFormFillEnv->KillFocusAnnot(0);
- vRet = CJS_Value(pRuntime, pFormFillEnv->JS_appAlert(
- swMsg.c_str(), swTitle.c_str(), iType, iIcon));
+ vRet = CJS_Value(pRuntime->NewNumber(
+ pFormFillEnv->JS_appAlert(swMsg.c_str(), swTitle.c_str(), iType, iIcon)));
pRuntime->EndBlock();
return true;
}
@@ -796,10 +798,10 @@ bool app::response(CJS_Runtime* pRuntime,
return false;
}
- vRet = CJS_Value(pRuntime, WideString::FromUTF16LE(
- reinterpret_cast<uint16_t*>(pBuff.data()),
- nLengthBytes / sizeof(uint16_t))
- .c_str());
+ vRet = CJS_Value(pRuntime->NewString(
+ WideString::FromUTF16LE(reinterpret_cast<uint16_t*>(pBuff.data()),
+ nLengthBytes / sizeof(uint16_t))
+ .c_str()));
return true;
}
diff --git a/fpdfsdk/javascript/color.cpp b/fpdfsdk/javascript/color.cpp
index 37ab1cc4fe..e730c31588 100644
--- a/fpdfsdk/javascript/color.cpp
+++ b/fpdfsdk/javascript/color.cpp
@@ -44,24 +44,32 @@ CJS_Array color::ConvertPWLColorToArray(CJS_Runtime* pRuntime,
CJS_Array array;
switch (color.nColorType) {
case CFX_Color::kTransparent:
- array.SetElement(pRuntime, 0, CJS_Value(pRuntime, "T"));
+ array.SetElement(pRuntime, 0, CJS_Value(pRuntime->NewString(L"T")));
break;
case CFX_Color::kGray:
- array.SetElement(pRuntime, 0, CJS_Value(pRuntime, "G"));
- array.SetElement(pRuntime, 1, CJS_Value(pRuntime, color.fColor1));
+ array.SetElement(pRuntime, 0, CJS_Value(pRuntime->NewString(L"G")));
+ array.SetElement(pRuntime, 1,
+ CJS_Value(pRuntime->NewNumber(color.fColor1)));
break;
case CFX_Color::kRGB:
- array.SetElement(pRuntime, 0, CJS_Value(pRuntime, "RGB"));
- array.SetElement(pRuntime, 1, CJS_Value(pRuntime, color.fColor1));
- array.SetElement(pRuntime, 2, CJS_Value(pRuntime, color.fColor2));
- array.SetElement(pRuntime, 3, CJS_Value(pRuntime, color.fColor3));
+ array.SetElement(pRuntime, 0, CJS_Value(pRuntime->NewString(L"RGB")));
+ array.SetElement(pRuntime, 1,
+ CJS_Value(pRuntime->NewNumber(color.fColor1)));
+ array.SetElement(pRuntime, 2,
+ CJS_Value(pRuntime->NewNumber(color.fColor2)));
+ array.SetElement(pRuntime, 3,
+ CJS_Value(pRuntime->NewNumber(color.fColor3)));
break;
case CFX_Color::kCMYK:
- array.SetElement(pRuntime, 0, CJS_Value(pRuntime, "CMYK"));
- array.SetElement(pRuntime, 1, CJS_Value(pRuntime, color.fColor1));
- array.SetElement(pRuntime, 2, CJS_Value(pRuntime, color.fColor2));
- array.SetElement(pRuntime, 3, CJS_Value(pRuntime, color.fColor3));
- array.SetElement(pRuntime, 4, CJS_Value(pRuntime, color.fColor4));
+ array.SetElement(pRuntime, 0, CJS_Value(pRuntime->NewString(L"CMYK")));
+ array.SetElement(pRuntime, 1,
+ CJS_Value(pRuntime->NewNumber(color.fColor1)));
+ array.SetElement(pRuntime, 2,
+ CJS_Value(pRuntime->NewNumber(color.fColor2)));
+ array.SetElement(pRuntime, 3,
+ CJS_Value(pRuntime->NewNumber(color.fColor3)));
+ array.SetElement(pRuntime, 4,
+ CJS_Value(pRuntime->NewNumber(color.fColor4)));
break;
}
return array;
@@ -300,8 +308,9 @@ bool color::convert(CJS_Runtime* pRuntime,
CFX_Color color =
ConvertArrayToPWLColor(pRuntime, params[0].ToArray(pRuntime));
- vRet = CJS_Value(pRuntime, ConvertPWLColorToArray(
- pRuntime, color.ConvertColorType(nColorType)));
+ vRet = CJS_Value(
+ ConvertPWLColorToArray(pRuntime, color.ConvertColorType(nColorType))
+ .ToV8Array(pRuntime));
return true;
}
@@ -321,6 +330,6 @@ bool color::equal(CJS_Runtime* pRuntime,
ConvertArrayToPWLColor(pRuntime, params[1].ToArray(pRuntime));
color1 = color1.ConvertColorType(color2.nColorType);
- vRet = CJS_Value(pRuntime, color1 == color2);
+ vRet = CJS_Value(pRuntime->NewBoolean(color1 == color2));
return true;
}
diff --git a/fpdfsdk/javascript/util.cpp b/fpdfsdk/javascript/util.cpp
index 3d669b30ca..63179c84a8 100644
--- a/fpdfsdk/javascript/util.cpp
+++ b/fpdfsdk/javascript/util.cpp
@@ -132,7 +132,7 @@ bool util::printf(CJS_Runtime* pRuntime,
}
c_strResult.erase(c_strResult.begin());
- vRet = CJS_Value(pRuntime, c_strResult.c_str());
+ vRet = CJS_Value(pRuntime->NewString(c_strResult.c_str()));
return true;
}
@@ -185,7 +185,7 @@ bool util::printd(CJS_Runtime* pRuntime,
return false;
}
- vRet = CJS_Value(pRuntime, swResult.c_str());
+ vRet = CJS_Value(pRuntime->NewString(swResult.c_str()));
return true;
}
@@ -259,7 +259,7 @@ bool util::printd(CJS_Runtime* pRuntime,
wchar_t buf[64] = {};
FXSYS_wcsftime(buf, 64, cFormat.c_str(), &time);
cFormat = buf;
- vRet = CJS_Value(pRuntime, cFormat.c_str());
+ vRet = CJS_Value(pRuntime->NewString(cFormat.c_str()));
return true;
}
@@ -276,9 +276,9 @@ bool util::printx(CJS_Runtime* pRuntime,
return false;
}
- vRet = CJS_Value(pRuntime, printx(params[0].ToWideString(pRuntime),
- params[1].ToWideString(pRuntime))
- .c_str());
+ vRet = CJS_Value(pRuntime->NewString(
+ printx(params[0].ToWideString(pRuntime), params[1].ToWideString(pRuntime))
+ .c_str()));
return true;
}
@@ -396,7 +396,7 @@ bool util::scand(CJS_Runtime* pRuntime,
}
if (!std::isnan(dDate)) {
- vRet = CJS_Value(CJS_Date(pRuntime, dDate));
+ vRet = CJS_Value(CJS_Date(pRuntime, dDate).ToV8Date());
} else {
vRet.Set(pRuntime->NewNull());
}
@@ -420,7 +420,7 @@ bool util::byteToChar(CJS_Runtime* pRuntime,
}
WideString wStr(static_cast<wchar_t>(arg));
- vRet = CJS_Value(pRuntime, wStr.c_str());
+ vRet = CJS_Value(pRuntime->NewString(wStr.c_str()));
return true;
}