Chromium Code Reviews| Index: fpdfsdk/javascript/PublicMethods.cpp |
| diff --git a/fpdfsdk/javascript/PublicMethods.cpp b/fpdfsdk/javascript/PublicMethods.cpp |
| index aa0efb1fa65d6d8b8e45b7c3de0e9f45460215a5..6e7f799af1af0b6d39a9b32c75b2a5280cc34c3e 100644 |
| --- a/fpdfsdk/javascript/PublicMethods.cpp |
| +++ b/fpdfsdk/javascript/PublicMethods.cpp |
| @@ -163,10 +163,10 @@ CJS_Array CJS_PublicMethods::AF_MakeArrayFromList(CJS_Runtime* pRuntime, |
| CJS_Value val) { |
| CJS_Array StrArray; |
| if (val.IsArrayObject()) { |
| - val.ConvertToArray(StrArray); |
| + val.ConvertToArray(pRuntime->GetIsolate(), StrArray); |
| return StrArray; |
| } |
| - CFX_WideString wsStr = val.ToCFXWideString(); |
| + CFX_WideString wsStr = val.ToCFXWideString(pRuntime->GetIsolate()); |
| CFX_ByteString t = CFX_ByteString::FromUnicode(wsStr); |
| const char* p = t.c_str(); |
| @@ -743,12 +743,13 @@ FX_BOOL CJS_PublicMethods::AFNumber_Format(IJS_Context* cc, |
| if (strValue.IsEmpty()) |
| return TRUE; |
| - int iDec = params[0].ToInt(); |
| - int iSepStyle = params[1].ToInt(); |
| - int iNegStyle = params[2].ToInt(); |
| + int iDec = params[0].ToInt(pRuntime->GetIsolate()); |
| + int iSepStyle = params[1].ToInt(pRuntime->GetIsolate()); |
| + int iNegStyle = params[2].ToInt(pRuntime->GetIsolate()); |
| // params[3] is iCurrStyle, it's not used. |
| - CFX_WideString wstrCurrency = params[4].ToCFXWideString(); |
| - FX_BOOL bCurrencyPrepend = params[5].ToBool(); |
| + CFX_WideString wstrCurrency = |
| + params[4].ToCFXWideString(pRuntime->GetIsolate()); |
| + FX_BOOL bCurrencyPrepend = params[5].ToBool(pRuntime->GetIsolate()); |
| if (iDec < 0) |
| iDec = -iDec; |
| @@ -837,11 +838,11 @@ FX_BOOL CJS_PublicMethods::AFNumber_Format(IJS_Context* cc, |
| if (Field* fTarget = pEvent->Target_Field()) { |
| CJS_Array arColor; |
| CJS_Value vColElm(pRuntime); |
| - vColElm = L"RGB"; |
| + vColElm = CJS_Value(pRuntime, L"RGB"); |
| arColor.SetElement(pRuntime->GetIsolate(), 0, vColElm); |
| - vColElm = 1; |
| + vColElm = CJS_Value(pRuntime, 1); |
| arColor.SetElement(pRuntime->GetIsolate(), 1, vColElm); |
| - vColElm = 0; |
| + vColElm = CJS_Value(pRuntime, 0); |
| arColor.SetElement(pRuntime->GetIsolate(), 2, vColElm); |
| arColor.SetElement(pRuntime->GetIsolate(), 3, vColElm); |
| @@ -857,9 +858,9 @@ FX_BOOL CJS_PublicMethods::AFNumber_Format(IJS_Context* cc, |
| if (Field* fTarget = pEvent->Target_Field()) { |
| CJS_Array arColor; |
| CJS_Value vColElm(pRuntime); |
| - vColElm = L"RGB"; |
| + vColElm = CJS_Value(pRuntime, L"RGB"); |
| arColor.SetElement(pRuntime->GetIsolate(), 0, vColElm); |
| - vColElm = 0; |
| + vColElm = CJS_Value(pRuntime, 0); |
| arColor.SetElement(pRuntime->GetIsolate(), 1, vColElm); |
| arColor.SetElement(pRuntime->GetIsolate(), 2, vColElm); |
| arColor.SetElement(pRuntime->GetIsolate(), 3, vColElm); |
| @@ -869,7 +870,7 @@ FX_BOOL CJS_PublicMethods::AFNumber_Format(IJS_Context* cc, |
| fTarget->textColor(cc, vProp, sError); |
| CJS_Array aProp; |
| - vProp.ConvertToArray(aProp); |
| + vProp.GetJSValue()->ConvertToArray(pRuntime->GetIsolate(), aProp); |
| CPWL_Color crProp; |
| CPWL_Color crColor; |
| @@ -940,7 +941,8 @@ FX_BOOL CJS_PublicMethods::AFNumber_Keystroke( |
| } |
| } |
| - int iSepStyle = params[1].ToInt(); |
| + CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| + int iSepStyle = params[1].ToInt(pRuntime->GetIsolate()); |
| if (iSepStyle < 0 || iSepStyle > 3) |
| iSepStyle = 0; |
| const FX_WCHAR cSep = iSepStyle < 2 ? L'.' : L','; |
| @@ -1000,6 +1002,7 @@ FX_BOOL CJS_PublicMethods::AFPercent_Format( |
| CFX_WideString& sError) { |
| #if _FX_OS_ != _FX_ANDROID_ |
| CJS_Context* pContext = (CJS_Context*)cc; |
| + CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
| if (params.size() != 2) { |
| @@ -1014,11 +1017,11 @@ FX_BOOL CJS_PublicMethods::AFPercent_Format( |
| if (strValue.IsEmpty()) |
| return TRUE; |
| - int iDec = params[0].ToInt(); |
| + int iDec = params[0].ToInt(pRuntime->GetIsolate()); |
| if (iDec < 0) |
| iDec = -iDec; |
| - int iSepStyle = params[1].ToInt(); |
| + int iSepStyle = params[1].ToInt(pRuntime->GetIsolate()); |
| if (iSepStyle < 0 || iSepStyle > 3) |
| iSepStyle = 0; |
| @@ -1099,6 +1102,7 @@ FX_BOOL CJS_PublicMethods::AFDate_FormatEx(IJS_Context* cc, |
| CJS_Value& vRet, |
| CFX_WideString& sError) { |
| CJS_Context* pContext = (CJS_Context*)cc; |
| + CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
| if (params.size() != 1) { |
| @@ -1113,7 +1117,7 @@ FX_BOOL CJS_PublicMethods::AFDate_FormatEx(IJS_Context* cc, |
| if (strValue.IsEmpty()) |
| return TRUE; |
| - CFX_WideString sFormat = params[0].ToCFXWideString(); |
| + CFX_WideString sFormat = params[0].ToCFXWideString(pRuntime->GetIsolate()); |
| double dDate = 0.0f; |
| if (strValue.Find(L"GMT") != -1) { |
| @@ -1199,6 +1203,7 @@ FX_BOOL CJS_PublicMethods::AFDate_KeystrokeEx( |
| CJS_Value& vRet, |
| CFX_WideString& sError) { |
| CJS_Context* pContext = (CJS_Context*)cc; |
| + CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
| if (params.size() != 1) { |
| @@ -1213,7 +1218,7 @@ FX_BOOL CJS_PublicMethods::AFDate_KeystrokeEx( |
| if (strValue.IsEmpty()) |
| return TRUE; |
| - CFX_WideString sFormat = params[0].ToCFXWideString(); |
| + CFX_WideString sFormat = params[0].ToCFXWideString(pRuntime->GetIsolate()); |
| bool bWrongFormat = FALSE; |
| double dRet = MakeRegularDate(strValue, sFormat, &bWrongFormat); |
| if (bWrongFormat || JS_PortIsNan(dRet)) { |
| @@ -1238,7 +1243,8 @@ FX_BOOL CJS_PublicMethods::AFDate_Format(IJS_Context* cc, |
| return FALSE; |
| } |
| - int iIndex = params[0].ToInt(); |
| + CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| + int iIndex = params[0].ToInt(pRuntime->GetIsolate()); |
| const FX_WCHAR* cFormats[] = {L"m/d", |
| L"m/d/yy", |
| L"mm/dd/yy", |
| @@ -1275,7 +1281,8 @@ FX_BOOL CJS_PublicMethods::AFDate_Keystroke( |
| return FALSE; |
| } |
| - int iIndex = params[0].ToInt(); |
| + CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| + int iIndex = params[0].ToInt(pRuntime->GetIsolate()); |
| const FX_WCHAR* cFormats[] = {L"m/d", |
| L"m/d/yy", |
| L"mm/dd/yy", |
| @@ -1311,7 +1318,8 @@ FX_BOOL CJS_PublicMethods::AFTime_Format(IJS_Context* cc, |
| return FALSE; |
| } |
| - int iIndex = params[0].ToInt(); |
| + CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| + int iIndex = params[0].ToInt(pRuntime->GetIsolate()); |
| const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", |
| L"h:MM:ss tt"}; |
| @@ -1335,7 +1343,8 @@ FX_BOOL CJS_PublicMethods::AFTime_Keystroke( |
| return FALSE; |
| } |
| - int iIndex = params[0].ToInt(); |
| + CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| + int iIndex = params[0].ToInt(pRuntime->GetIsolate()); |
| const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", |
| L"h:MM:ss tt"}; |
| @@ -1370,7 +1379,6 @@ FX_BOOL CJS_PublicMethods::AFSpecial_Format( |
| CJS_Value& vRet, |
| CFX_WideString& sError) { |
| CJS_Context* pContext = (CJS_Context*)cc; |
| - |
| if (params.size() != 1) { |
| sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| return FALSE; |
| @@ -1380,9 +1388,10 @@ FX_BOOL CJS_PublicMethods::AFSpecial_Format( |
| if (!pEvent->m_pValue) |
| return FALSE; |
| + CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| CFX_WideString wsSource = pEvent->Value(); |
| CFX_WideString wsFormat; |
| - switch (params[0].ToInt()) { |
| + switch (params[0].ToInt(pRuntime->GetIsolate())) { |
| case 0: |
| wsFormat = L"99999"; |
| break; |
| @@ -1411,6 +1420,7 @@ FX_BOOL CJS_PublicMethods::AFSpecial_KeystrokeEx( |
| CJS_Value& vRet, |
| CFX_WideString& sError) { |
| CJS_Context* pContext = (CJS_Context*)cc; |
| + CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
| if (params.size() < 1) { |
| @@ -1422,7 +1432,7 @@ FX_BOOL CJS_PublicMethods::AFSpecial_KeystrokeEx( |
| return FALSE; |
| CFX_WideString& valEvent = pEvent->Value(); |
| - CFX_WideString wstrMask = params[0].ToCFXWideString(); |
| + CFX_WideString wstrMask = params[0].ToCFXWideString(pRuntime->GetIsolate()); |
| if (wstrMask.IsEmpty()) |
| return TRUE; |
| @@ -1509,7 +1519,8 @@ FX_BOOL CJS_PublicMethods::AFSpecial_Keystroke( |
| return FALSE; |
| const char* cFormat = ""; |
| - switch (params[0].ToInt()) { |
| + CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| + switch (params[0].ToInt(pRuntime->GetIsolate())) { |
| case 0: |
| cFormat = "99999"; |
| break; |
| @@ -1537,6 +1548,7 @@ FX_BOOL CJS_PublicMethods::AFMergeChange(IJS_Context* cc, |
| CJS_Value& vRet, |
| CFX_WideString& sError) { |
| CJS_Context* pContext = (CJS_Context*)cc; |
| + CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| CJS_EventHandler* pEventHandler = pContext->GetEventHandler(); |
| if (params.size() != 1) { |
| @@ -1549,7 +1561,7 @@ FX_BOOL CJS_PublicMethods::AFMergeChange(IJS_Context* cc, |
| swValue = pEventHandler->Value(); |
| if (pEventHandler->WillCommit()) { |
| - vRet = swValue.c_str(); |
| + vRet = CJS_Value(pRuntime, swValue.c_str()); |
| return TRUE; |
| } |
| @@ -1567,8 +1579,8 @@ FX_BOOL CJS_PublicMethods::AFMergeChange(IJS_Context* cc, |
| else |
| postfix = L""; |
| - vRet = (prefix + pEventHandler->Change() + postfix).c_str(); |
| - |
| + vRet = |
| + CJS_Value(pRuntime, (prefix + pEventHandler->Change() + postfix).c_str()); |
| return TRUE; |
| } |
| @@ -1577,15 +1589,15 @@ FX_BOOL CJS_PublicMethods::AFParseDateEx(IJS_Context* cc, |
| CJS_Value& vRet, |
| CFX_WideString& sError) { |
| CJS_Context* pContext = (CJS_Context*)cc; |
| - ASSERT(pContext); |
| + CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| if (params.size() != 2) { |
| sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| return FALSE; |
| } |
| - CFX_WideString sValue = params[0].ToCFXWideString(); |
| - CFX_WideString sFormat = params[1].ToCFXWideString(); |
| + CFX_WideString sValue = params[0].ToCFXWideString(pRuntime->GetIsolate()); |
| + CFX_WideString sFormat = params[1].ToCFXWideString(pRuntime->GetIsolate()); |
| double dDate = MakeRegularDate(sValue, sFormat, nullptr); |
| @@ -1597,7 +1609,7 @@ FX_BOOL CJS_PublicMethods::AFParseDateEx(IJS_Context* cc, |
| return FALSE; |
| } |
| - vRet = dDate; |
| + vRet = CJS_Value(pRuntime, dDate); |
| return TRUE; |
| } |
| @@ -1605,16 +1617,20 @@ FX_BOOL CJS_PublicMethods::AFSimple(IJS_Context* cc, |
| const std::vector<CJS_Value>& params, |
| CJS_Value& vRet, |
| CFX_WideString& sError) { |
| - if (params.size() != 3) { |
| - CJS_Context* pContext = (CJS_Context*)cc; |
| - ASSERT(pContext); |
| + CJS_Context* pContext = (CJS_Context*)cc; |
| + CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| + if (params.size() != 3) { |
| sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| return FALSE; |
| } |
| - vRet = (double)AF_Simple(params[0].ToCFXWideString().c_str(), |
| - params[1].ToDouble(), params[2].ToDouble()); |
| + vRet = CJS_Value( |
| + pRuntime, (double)AF_Simple( |
|
dsinclair
2016/08/09 19:25:33
static_cast
Tom Sepez
2016/08/09 20:33:24
Done.
|
| + params[0].ToCFXWideString(pRuntime->GetIsolate()).c_str(), |
| + params[1].ToDouble(pRuntime->GetIsolate()), |
| + params[2].ToDouble(pRuntime->GetIsolate()))); |
| + |
| return TRUE; |
| } |
| @@ -1623,16 +1639,19 @@ FX_BOOL CJS_PublicMethods::AFMakeNumber(IJS_Context* cc, |
| CJS_Value& vRet, |
| CFX_WideString& sError) { |
| CJS_Context* pContext = (CJS_Context*)cc; |
| + CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| + |
| if (params.size() != 1) { |
| sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| return FALSE; |
| } |
| - CFX_WideString ws = params[0].ToCFXWideString(); |
| + |
| + CFX_WideString ws = params[0].ToCFXWideString(pRuntime->GetIsolate()); |
| ws.Replace(L",", L"."); |
| - vRet = ws.c_str(); |
| - vRet.MaybeCoerceToNumber(); |
| + vRet = CJS_Value(pRuntime, ws.c_str()); |
| + vRet.MaybeCoerceToNumber(pRuntime->GetIsolate()); |
| if (vRet.GetType() != CJS_Value::VT_number) |
| - vRet = 0; |
| + vRet = CJS_Value(pRuntime, 0); |
| return TRUE; |
| } |
| @@ -1642,6 +1661,8 @@ FX_BOOL CJS_PublicMethods::AFSimple_Calculate( |
| CJS_Value& vRet, |
| CFX_WideString& sError) { |
| CJS_Context* pContext = (CJS_Context*)cc; |
| + CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| + |
| if (params.size() != 2) { |
| sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| return FALSE; |
| @@ -1657,17 +1678,17 @@ FX_BOOL CJS_PublicMethods::AFSimple_Calculate( |
| CPDFSDK_InterForm* pReaderInterForm = pReaderDoc->GetInterForm(); |
| CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm(); |
| - CFX_WideString sFunction = params[0].ToCFXWideString(); |
| + CFX_WideString sFunction = params[0].ToCFXWideString(pRuntime->GetIsolate()); |
| 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(pRuntime); |
| FieldNameArray.GetElement(pRuntime->GetIsolate(), i, jsValue); |
| - CFX_WideString wsFieldName = jsValue.ToCFXWideString(); |
| + CFX_WideString wsFieldName = |
| + jsValue.ToCFXWideString(pRuntime->GetIsolate()); |
| for (int j = 0, jsz = pInterForm->CountFields(wsFieldName); j < jsz; j++) { |
| if (CPDF_FormField* pFormField = pInterForm->GetField(j, wsFieldName)) { |
| @@ -1728,7 +1749,8 @@ FX_BOOL CJS_PublicMethods::AFSimple_Calculate( |
| FXSYS_pow((double)10, (double)6); |
| CJS_Value jsValue(pRuntime, dValue); |
| if (pContext->GetEventHandler()->m_pValue) |
| - pContext->GetEventHandler()->Value() = jsValue.ToCFXWideString(); |
| + pContext->GetEventHandler()->Value() = |
| + jsValue.ToCFXWideString(pRuntime->GetIsolate()); |
| return TRUE; |
| } |
| @@ -1742,6 +1764,7 @@ FX_BOOL CJS_PublicMethods::AFRange_Validate( |
| CJS_Value& vRet, |
| CFX_WideString& sError) { |
| CJS_Context* pContext = (CJS_Context*)cc; |
| + CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
| if (params.size() != 4) { |
| @@ -1755,25 +1778,25 @@ FX_BOOL CJS_PublicMethods::AFRange_Validate( |
| return TRUE; |
| double dEentValue = |
| atof(CFX_ByteString::FromUnicode(pEvent->Value()).c_str()); |
| - FX_BOOL bGreaterThan = params[0].ToBool(); |
| - double dGreaterThan = params[1].ToDouble(); |
| - FX_BOOL bLessThan = params[2].ToBool(); |
| - double dLessThan = params[3].ToDouble(); |
| + FX_BOOL bGreaterThan = params[0].ToBool(pRuntime->GetIsolate()); |
| + double dGreaterThan = params[1].ToDouble(pRuntime->GetIsolate()); |
| + FX_BOOL bLessThan = params[2].ToBool(pRuntime->GetIsolate()); |
| + double dLessThan = params[3].ToDouble(pRuntime->GetIsolate()); |
| CFX_WideString swMsg; |
| if (bGreaterThan && bLessThan) { |
| if (dEentValue < dGreaterThan || dEentValue > dLessThan) |
| swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE1).c_str(), |
| - params[1].ToCFXWideString().c_str(), |
| - params[3].ToCFXWideString().c_str()); |
| + params[1].ToCFXWideString(pRuntime->GetIsolate()).c_str(), |
| + params[3].ToCFXWideString(pRuntime->GetIsolate()).c_str()); |
| } else if (bGreaterThan) { |
| if (dEentValue < dGreaterThan) |
| swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE2).c_str(), |
| - params[1].ToCFXWideString().c_str()); |
| + params[1].ToCFXWideString(pRuntime->GetIsolate()).c_str()); |
| } else if (bLessThan) { |
| if (dEentValue > dLessThan) |
| swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE3).c_str(), |
| - params[3].ToCFXWideString().c_str()); |
| + params[3].ToCFXWideString(pRuntime->GetIsolate()).c_str()); |
| } |
| if (!swMsg.IsEmpty()) { |
| @@ -1788,15 +1811,15 @@ FX_BOOL CJS_PublicMethods::AFExtractNums(IJS_Context* cc, |
| CJS_Value& vRet, |
| CFX_WideString& sError) { |
| CJS_Context* pContext = (CJS_Context*)cc; |
| + CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| + |
| if (params.size() != 1) { |
| sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| return FALSE; |
| } |
| - CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| CJS_Array nums; |
| - |
| - CFX_WideString str = params[0].ToCFXWideString(); |
| + CFX_WideString str = params[0].ToCFXWideString(pRuntime->GetIsolate()); |
| CFX_WideString sPart; |
| if (str.GetAt(0) == L'.' || str.GetAt(0) == L',') |
| @@ -1825,7 +1848,7 @@ FX_BOOL CJS_PublicMethods::AFExtractNums(IJS_Context* cc, |
| if (nums.GetLength() > 0) |
| vRet = CJS_Value(pRuntime, nums); |
| else |
| - vRet.SetNull(); |
| + vRet.SetNull(pRuntime); |
| return TRUE; |
| } |