summaryrefslogtreecommitdiff
path: root/fpdfsdk/src/javascript/PublicMethods.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2015-10-08 12:24:19 -0700
committerTom Sepez <tsepez@chromium.org>2015-10-08 12:24:19 -0700
commit67fd5df1a378195ae3fb40c862a4e6e58731020a (patch)
tree498a4803209d78747f97ed514c45981df47de3e5 /fpdfsdk/src/javascript/PublicMethods.cpp
parent6d5649b46c73bde7de2488b5631ecbf0d4a3bb05 (diff)
downloadpdfium-67fd5df1a378195ae3fb40c862a4e6e58731020a.tar.xz
Merge to XFA: Wean CJS_Value off of v8::Isolate.
(cherry picked from commit 287b63d9ab410783d71cf37291f09fd57d3059b4) Original Review URL: https://codereview.chromium.org/1394103002 . R=thestig@chromium.org Review URL: https://codereview.chromium.org/1394053003 .
Diffstat (limited to 'fpdfsdk/src/javascript/PublicMethods.cpp')
-rw-r--r--fpdfsdk/src/javascript/PublicMethods.cpp136
1 files changed, 42 insertions, 94 deletions
diff --git a/fpdfsdk/src/javascript/PublicMethods.cpp b/fpdfsdk/src/javascript/PublicMethods.cpp
index 4e068ec568..0b3b38f8f1 100644
--- a/fpdfsdk/src/javascript/PublicMethods.cpp
+++ b/fpdfsdk/src/javascript/PublicMethods.cpp
@@ -19,19 +19,6 @@
#include "resource.h"
#include "util.h"
-static v8::Isolate* GetIsolate(IJS_Context* cc) {
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
-
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
- return pRuntime->GetIsolate();
-}
-
-/* -------------------------------- CJS_PublicMethods
- * -------------------------------- */
-
#define DOUBLE_CORRECT 0.000000000000001
BEGIN_JS_STATIC_GLOBAL_FUN(CJS_PublicMethods)
@@ -346,9 +333,9 @@ FX_BOOL CJS_PublicMethods::ConvertStringToNumber(const FX_WCHAR* swSource,
return bAllDigits;
}
-CJS_Array CJS_PublicMethods::AF_MakeArrayFromList(v8::Isolate* isolate,
+CJS_Array CJS_PublicMethods::AF_MakeArrayFromList(CJS_Runtime* pRuntime,
CJS_Value val) {
- CJS_Array StrArray(isolate);
+ CJS_Array StrArray(pRuntime);
if (val.IsArrayObject()) {
val.ConvertToArray(StrArray);
return StrArray;
@@ -363,14 +350,14 @@ CJS_Array CJS_PublicMethods::AF_MakeArrayFromList(v8::Isolate* isolate,
while (*p) {
const char* pTemp = strchr(p, ch);
if (pTemp == NULL) {
- StrArray.SetElement(nIndex, CJS_Value(isolate, StrTrim(p).c_str()));
+ StrArray.SetElement(nIndex, CJS_Value(pRuntime, StrTrim(p).c_str()));
break;
} else {
char* pSub = new char[pTemp - p + 1];
strncpy(pSub, p, pTemp - p);
*(pSub + (pTemp - p)) = '\0';
- StrArray.SetElement(nIndex, CJS_Value(isolate, StrTrim(pSub).c_str()));
+ StrArray.SetElement(nIndex, CJS_Value(pRuntime, StrTrim(pSub).c_str()));
delete[] pSub;
nIndex++;
@@ -911,21 +898,19 @@ FX_BOOL CJS_PublicMethods::AFNumber_Format(IJS_Context* cc,
CJS_Value& vRet,
CFX_WideString& sError) {
#if _FX_OS_ != _FX_ANDROID_
- v8::Isolate* isolate = ::GetIsolate(cc);
CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
if (params.size() != 6) {
sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
return FALSE;
}
+
+ CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
if (!pEvent->m_pValue)
return FALSE;
+
CFX_WideString& Value = pEvent->Value();
CFX_ByteString strValue = StrTrim(CFX_ByteString::FromUnicode(Value));
-
if (strValue.IsEmpty())
return TRUE;
@@ -1032,8 +1017,8 @@ FX_BOOL CJS_PublicMethods::AFNumber_Format(IJS_Context* cc,
}
if (iNegStyle == 1 || iNegStyle == 3) {
if (Field* fTarget = pEvent->Target_Field()) {
- CJS_Array arColor(isolate);
- CJS_Value vColElm(isolate);
+ CJS_Array arColor(pRuntime);
+ CJS_Value vColElm(pRuntime);
vColElm = L"RGB";
arColor.SetElement(0, vColElm);
vColElm = 1;
@@ -1043,7 +1028,7 @@ FX_BOOL CJS_PublicMethods::AFNumber_Format(IJS_Context* cc,
arColor.SetElement(3, vColElm);
- CJS_PropValue vProp(isolate);
+ CJS_PropValue vProp(pRuntime);
vProp.StartGetting();
vProp << arColor;
vProp.StartSetting();
@@ -1053,8 +1038,8 @@ FX_BOOL CJS_PublicMethods::AFNumber_Format(IJS_Context* cc,
} else {
if (iNegStyle == 1 || iNegStyle == 3) {
if (Field* fTarget = pEvent->Target_Field()) {
- CJS_Array arColor(isolate);
- CJS_Value vColElm(isolate);
+ CJS_Array arColor(pRuntime);
+ CJS_Value vColElm(pRuntime);
vColElm = L"RGB";
arColor.SetElement(0, vColElm);
vColElm = 0;
@@ -1062,11 +1047,11 @@ FX_BOOL CJS_PublicMethods::AFNumber_Format(IJS_Context* cc,
arColor.SetElement(2, vColElm);
arColor.SetElement(3, vColElm);
- CJS_PropValue vProp(isolate);
+ CJS_PropValue vProp(pRuntime);
vProp.StartGetting();
fTarget->textColor(cc, vProp, sError);
- CJS_Array aProp(isolate);
+ CJS_Array aProp(pRuntime);
vProp.ConvertToArray(aProp);
CPWL_Color crProp;
@@ -1075,7 +1060,7 @@ FX_BOOL CJS_PublicMethods::AFNumber_Format(IJS_Context* cc,
color::ConvertArrayToPWLColor(arColor, crColor);
if (crColor != crProp) {
- CJS_PropValue vProp2(isolate);
+ CJS_PropValue vProp2(pRuntime);
vProp2.StartGetting();
vProp2 << arColor;
vProp2.StartSetting();
@@ -1472,12 +1457,8 @@ FX_BOOL CJS_PublicMethods::AFDate_Format(IJS_Context* cc,
const CJS_Parameters& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- v8::Isolate* isolate = ::GetIsolate(cc);
-
+ CJS_Context* pContext = (CJS_Context*)cc;
if (params.size() != 1) {
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
-
sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
return FALSE;
}
@@ -1502,8 +1483,8 @@ FX_BOOL CJS_PublicMethods::AFDate_Format(IJS_Context* cc,
iIndex = 0;
CJS_Parameters newParams;
- CJS_Value val(isolate, cFormats[iIndex]);
- newParams.push_back(val);
+ newParams.push_back(
+ CJS_Value(CJS_Runtime::FromContext(cc), cFormats[iIndex]));
return AFDate_FormatEx(cc, newParams, vRet, sError);
}
@@ -1512,12 +1493,8 @@ FX_BOOL CJS_PublicMethods::AFDate_Keystroke(IJS_Context* cc,
const CJS_Parameters& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- v8::Isolate* isolate = ::GetIsolate(cc);
-
+ CJS_Context* pContext = (CJS_Context*)cc;
if (params.size() != 1) {
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
-
sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
return FALSE;
}
@@ -1542,8 +1519,8 @@ FX_BOOL CJS_PublicMethods::AFDate_Keystroke(IJS_Context* cc,
iIndex = 0;
CJS_Parameters newParams;
- CJS_Value val(isolate, cFormats[iIndex]);
- newParams.push_back(val);
+ newParams.push_back(
+ CJS_Value(CJS_Runtime::FromContext(cc), cFormats[iIndex]));
return AFDate_KeystrokeEx(cc, newParams, vRet, sError);
}
@@ -1552,11 +1529,8 @@ FX_BOOL CJS_PublicMethods::AFTime_Format(IJS_Context* cc,
const CJS_Parameters& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- v8::Isolate* isolate = ::GetIsolate(cc);
-
+ CJS_Context* pContext = (CJS_Context*)cc;
if (params.size() != 1) {
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
return FALSE;
}
@@ -1569,8 +1543,8 @@ FX_BOOL CJS_PublicMethods::AFTime_Format(IJS_Context* cc,
iIndex = 0;
CJS_Parameters newParams;
- CJS_Value val(isolate, cFormats[iIndex]);
- newParams.push_back(val);
+ newParams.push_back(
+ CJS_Value(CJS_Runtime::FromContext(cc), cFormats[iIndex]));
return AFDate_FormatEx(cc, newParams, vRet, sError);
}
@@ -1578,10 +1552,8 @@ FX_BOOL CJS_PublicMethods::AFTime_Keystroke(IJS_Context* cc,
const CJS_Parameters& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- v8::Isolate* isolate = ::GetIsolate(cc);
+ CJS_Context* pContext = (CJS_Context*)cc;
if (params.size() != 1) {
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
return FALSE;
}
@@ -1594,8 +1566,8 @@ FX_BOOL CJS_PublicMethods::AFTime_Keystroke(IJS_Context* cc,
iIndex = 0;
CJS_Parameters newParams;
- CJS_Value val(isolate, cFormats[iIndex]);
- newParams.push_back(val);
+ newParams.push_back(
+ CJS_Value(CJS_Runtime::FromContext(cc), cFormats[iIndex]));
return AFDate_KeystrokeEx(cc, newParams, vRet, sError);
}
@@ -1762,24 +1734,18 @@ FX_BOOL CJS_PublicMethods::AFSpecial_Keystroke(IJS_Context* cc,
const CJS_Parameters& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- v8::Isolate* isolate = ::GetIsolate(cc);
-
CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
if (params.size() != 1) {
sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
return FALSE;
}
- std::string cFormat;
- int iIndex = params[0].ToInt();
-
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
if (!pEvent->m_pValue)
return FALSE;
- // CJS_Value val = pEvent->Value();
+
+ std::string cFormat;
+ int iIndex = params[0].ToInt();
CFX_WideString& val = pEvent->Value();
std::string strSrc = CFX_ByteString::FromUnicode(val).c_str();
std::wstring wstrChange = pEvent->Change().c_str();
@@ -1810,9 +1776,7 @@ FX_BOOL CJS_PublicMethods::AFSpecial_Keystroke(IJS_Context* cc,
}
CJS_Parameters params2;
- CJS_Value vMask(isolate, cFormat.c_str());
- params2.push_back(vMask);
-
+ params2.push_back(CJS_Value(CJS_Runtime::FromContext(cc), cFormat.c_str()));
return AFSpecial_KeystrokeEx(cc, params2, vRet, sError);
}
@@ -1924,45 +1888,31 @@ FX_BOOL CJS_PublicMethods::AFSimple_Calculate(IJS_Context* cc,
const CJS_Parameters& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- v8::Isolate* isolate = ::GetIsolate(cc);
-
CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
-
if (params.size() != 2) {
sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
return FALSE;
}
CJS_Value params1 = params[1];
-
if (!params1.IsArrayObject() && params1.GetType() != CJS_Value::VT_string) {
sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
return FALSE;
}
CPDFSDK_Document* pReaderDoc = pContext->GetReaderDocument();
- ASSERT(pReaderDoc != NULL);
-
CPDFSDK_InterForm* pReaderInterForm = pReaderDoc->GetInterForm();
- ASSERT(pReaderInterForm != NULL);
-
CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm();
- ASSERT(pInterForm != NULL);
- double dValue;
CFX_WideString sFunction = params[0].ToCFXWideString();
- if (wcscmp(sFunction.c_str(), L"PRD") == 0)
- dValue = 1.0;
- else
- dValue = 0.0;
-
- CJS_Array FieldNameArray = AF_MakeArrayFromList(isolate, params1);
+ double dValue = wcscmp(sFunction.c_str(), L"PRD") == 0 ? 1.0 : 0.0;
+ CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
+ CJS_Array FieldNameArray = AF_MakeArrayFromList(pRuntime, params1);
int nFieldsCount = 0;
for (int i = 0, isz = FieldNameArray.GetLength(); i < isz; i++) {
- CJS_Value jsValue(isolate);
+ CJS_Value jsValue(pRuntime);
FieldNameArray.GetElement(i, jsValue);
CFX_WideString wsFieldName = jsValue.ToCFXWideString();
@@ -2024,7 +1974,7 @@ FX_BOOL CJS_PublicMethods::AFSimple_Calculate(IJS_Context* cc,
dValue = (double)floor(dValue * FXSYS_pow((double)10, (double)6) + 0.49) /
FXSYS_pow((double)10, (double)6);
- CJS_Value jsValue(isolate, dValue);
+ CJS_Value jsValue(pRuntime, dValue);
if (pContext->GetEventHandler()->m_pValue)
pContext->GetEventHandler()->Value() = jsValue.ToCFXWideString();
@@ -2085,16 +2035,14 @@ FX_BOOL CJS_PublicMethods::AFExtractNums(IJS_Context* cc,
const CJS_Parameters& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- v8::Isolate* isolate = ::GetIsolate(cc);
CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
-
if (params.size() != 1) {
sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
return FALSE;
}
- CJS_Array nums(isolate);
+ CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
+ CJS_Array nums(pRuntime);
CFX_WideString str = params[0].ToCFXWideString();
CFX_WideString sPart;
@@ -2109,7 +2057,7 @@ FX_BOOL CJS_PublicMethods::AFExtractNums(IJS_Context* cc,
sPart += wc;
} else {
if (sPart.GetLength() > 0) {
- nums.SetElement(nIndex, CJS_Value(isolate, sPart.c_str()));
+ nums.SetElement(nIndex, CJS_Value(pRuntime, sPart.c_str()));
sPart = L"";
nIndex++;
}
@@ -2117,7 +2065,7 @@ FX_BOOL CJS_PublicMethods::AFExtractNums(IJS_Context* cc,
}
if (sPart.GetLength() > 0) {
- nums.SetElement(nIndex, CJS_Value(isolate, sPart.c_str()));
+ nums.SetElement(nIndex, CJS_Value(pRuntime, sPart.c_str()));
}
if (nums.GetLength() > 0)