OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "fpdfsdk/javascript/PublicMethods.h" | 7 #include "fpdfsdk/javascript/PublicMethods.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <vector> | 10 #include <vector> |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 if (FXSYS_wcsicmp(sFuction, L"MAX") == 0) { | 156 if (FXSYS_wcsicmp(sFuction, L"MAX") == 0) { |
157 return std::max(dValue1, dValue2); | 157 return std::max(dValue1, dValue2); |
158 } | 158 } |
159 return dValue1; | 159 return dValue1; |
160 } | 160 } |
161 | 161 |
162 CJS_Array CJS_PublicMethods::AF_MakeArrayFromList(CJS_Runtime* pRuntime, | 162 CJS_Array CJS_PublicMethods::AF_MakeArrayFromList(CJS_Runtime* pRuntime, |
163 CJS_Value val) { | 163 CJS_Value val) { |
164 CJS_Array StrArray; | 164 CJS_Array StrArray; |
165 if (val.IsArrayObject()) { | 165 if (val.IsArrayObject()) { |
166 val.ConvertToArray(StrArray); | 166 val.ConvertToArray(pRuntime->GetIsolate(), StrArray); |
167 return StrArray; | 167 return StrArray; |
168 } | 168 } |
169 CFX_WideString wsStr = val.ToCFXWideString(); | 169 CFX_WideString wsStr = val.ToCFXWideString(pRuntime->GetIsolate()); |
170 CFX_ByteString t = CFX_ByteString::FromUnicode(wsStr); | 170 CFX_ByteString t = CFX_ByteString::FromUnicode(wsStr); |
171 const char* p = t.c_str(); | 171 const char* p = t.c_str(); |
172 | 172 |
173 int ch = ','; | 173 int ch = ','; |
174 int nIndex = 0; | 174 int nIndex = 0; |
175 | 175 |
176 while (*p) { | 176 while (*p) { |
177 const char* pTemp = strchr(p, ch); | 177 const char* pTemp = strchr(p, ch); |
178 if (!pTemp) { | 178 if (!pTemp) { |
179 StrArray.SetElement( | 179 StrArray.SetElement( |
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
736 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 736 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
737 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 737 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
738 if (!pEvent->m_pValue) | 738 if (!pEvent->m_pValue) |
739 return FALSE; | 739 return FALSE; |
740 | 740 |
741 CFX_WideString& Value = pEvent->Value(); | 741 CFX_WideString& Value = pEvent->Value(); |
742 CFX_ByteString strValue = StrTrim(CFX_ByteString::FromUnicode(Value)); | 742 CFX_ByteString strValue = StrTrim(CFX_ByteString::FromUnicode(Value)); |
743 if (strValue.IsEmpty()) | 743 if (strValue.IsEmpty()) |
744 return TRUE; | 744 return TRUE; |
745 | 745 |
746 int iDec = params[0].ToInt(); | 746 int iDec = params[0].ToInt(pRuntime->GetIsolate()); |
747 int iSepStyle = params[1].ToInt(); | 747 int iSepStyle = params[1].ToInt(pRuntime->GetIsolate()); |
748 int iNegStyle = params[2].ToInt(); | 748 int iNegStyle = params[2].ToInt(pRuntime->GetIsolate()); |
749 // params[3] is iCurrStyle, it's not used. | 749 // params[3] is iCurrStyle, it's not used. |
750 CFX_WideString wstrCurrency = params[4].ToCFXWideString(); | 750 CFX_WideString wstrCurrency = |
751 FX_BOOL bCurrencyPrepend = params[5].ToBool(); | 751 params[4].ToCFXWideString(pRuntime->GetIsolate()); |
| 752 FX_BOOL bCurrencyPrepend = params[5].ToBool(pRuntime->GetIsolate()); |
752 | 753 |
753 if (iDec < 0) | 754 if (iDec < 0) |
754 iDec = -iDec; | 755 iDec = -iDec; |
755 | 756 |
756 if (iSepStyle < 0 || iSepStyle > 3) | 757 if (iSepStyle < 0 || iSepStyle > 3) |
757 iSepStyle = 0; | 758 iSepStyle = 0; |
758 | 759 |
759 if (iNegStyle < 0 || iNegStyle > 3) | 760 if (iNegStyle < 0 || iNegStyle > 3) |
760 iNegStyle = 0; | 761 iNegStyle = 0; |
761 | 762 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
830 if (iNegative) { | 831 if (iNegative) { |
831 if (iNegStyle == 0) { | 832 if (iNegStyle == 0) { |
832 Value = L"-" + Value; | 833 Value = L"-" + Value; |
833 } else if (iNegStyle == 2 || iNegStyle == 3) { | 834 } else if (iNegStyle == 2 || iNegStyle == 3) { |
834 Value = L"(" + Value + L")"; | 835 Value = L"(" + Value + L")"; |
835 } | 836 } |
836 if (iNegStyle == 1 || iNegStyle == 3) { | 837 if (iNegStyle == 1 || iNegStyle == 3) { |
837 if (Field* fTarget = pEvent->Target_Field()) { | 838 if (Field* fTarget = pEvent->Target_Field()) { |
838 CJS_Array arColor; | 839 CJS_Array arColor; |
839 CJS_Value vColElm(pRuntime); | 840 CJS_Value vColElm(pRuntime); |
840 vColElm = L"RGB"; | 841 vColElm = CJS_Value(pRuntime, L"RGB"); |
841 arColor.SetElement(pRuntime->GetIsolate(), 0, vColElm); | 842 arColor.SetElement(pRuntime->GetIsolate(), 0, vColElm); |
842 vColElm = 1; | 843 vColElm = CJS_Value(pRuntime, 1); |
843 arColor.SetElement(pRuntime->GetIsolate(), 1, vColElm); | 844 arColor.SetElement(pRuntime->GetIsolate(), 1, vColElm); |
844 vColElm = 0; | 845 vColElm = CJS_Value(pRuntime, 0); |
845 arColor.SetElement(pRuntime->GetIsolate(), 2, vColElm); | 846 arColor.SetElement(pRuntime->GetIsolate(), 2, vColElm); |
846 arColor.SetElement(pRuntime->GetIsolate(), 3, vColElm); | 847 arColor.SetElement(pRuntime->GetIsolate(), 3, vColElm); |
847 | 848 |
848 CJS_PropValue vProp(pRuntime); | 849 CJS_PropValue vProp(pRuntime); |
849 vProp.StartGetting(); | 850 vProp.StartGetting(); |
850 vProp << arColor; | 851 vProp << arColor; |
851 vProp.StartSetting(); | 852 vProp.StartSetting(); |
852 fTarget->textColor(cc, vProp, sError); // red | 853 fTarget->textColor(cc, vProp, sError); // red |
853 } | 854 } |
854 } | 855 } |
855 } else { | 856 } else { |
856 if (iNegStyle == 1 || iNegStyle == 3) { | 857 if (iNegStyle == 1 || iNegStyle == 3) { |
857 if (Field* fTarget = pEvent->Target_Field()) { | 858 if (Field* fTarget = pEvent->Target_Field()) { |
858 CJS_Array arColor; | 859 CJS_Array arColor; |
859 CJS_Value vColElm(pRuntime); | 860 CJS_Value vColElm(pRuntime); |
860 vColElm = L"RGB"; | 861 vColElm = CJS_Value(pRuntime, L"RGB"); |
861 arColor.SetElement(pRuntime->GetIsolate(), 0, vColElm); | 862 arColor.SetElement(pRuntime->GetIsolate(), 0, vColElm); |
862 vColElm = 0; | 863 vColElm = CJS_Value(pRuntime, 0); |
863 arColor.SetElement(pRuntime->GetIsolate(), 1, vColElm); | 864 arColor.SetElement(pRuntime->GetIsolate(), 1, vColElm); |
864 arColor.SetElement(pRuntime->GetIsolate(), 2, vColElm); | 865 arColor.SetElement(pRuntime->GetIsolate(), 2, vColElm); |
865 arColor.SetElement(pRuntime->GetIsolate(), 3, vColElm); | 866 arColor.SetElement(pRuntime->GetIsolate(), 3, vColElm); |
866 | 867 |
867 CJS_PropValue vProp(pRuntime); | 868 CJS_PropValue vProp(pRuntime); |
868 vProp.StartGetting(); | 869 vProp.StartGetting(); |
869 fTarget->textColor(cc, vProp, sError); | 870 fTarget->textColor(cc, vProp, sError); |
870 | 871 |
871 CJS_Array aProp; | 872 CJS_Array aProp; |
872 vProp.ConvertToArray(aProp); | 873 vProp.GetJSValue()->ConvertToArray(pRuntime->GetIsolate(), aProp); |
873 | 874 |
874 CPWL_Color crProp; | 875 CPWL_Color crProp; |
875 CPWL_Color crColor; | 876 CPWL_Color crColor; |
876 color::ConvertArrayToPWLColor(pRuntime, aProp, &crProp); | 877 color::ConvertArrayToPWLColor(pRuntime, aProp, &crProp); |
877 color::ConvertArrayToPWLColor(pRuntime, arColor, &crColor); | 878 color::ConvertArrayToPWLColor(pRuntime, arColor, &crColor); |
878 | 879 |
879 if (crColor != crProp) { | 880 if (crColor != crProp) { |
880 CJS_PropValue vProp2(pRuntime); | 881 CJS_PropValue vProp2(pRuntime); |
881 vProp2.StartGetting(); | 882 vProp2.StartGetting(); |
882 vProp2 << arColor; | 883 vProp2 << arColor; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
933 bool bHasSign = wstrValue.Find(L'-') != -1 && wstrSelected.Find(L'-') == -1; | 934 bool bHasSign = wstrValue.Find(L'-') != -1 && wstrSelected.Find(L'-') == -1; |
934 if (bHasSign) { | 935 if (bHasSign) { |
935 // can't insert "change" in front to sign postion. | 936 // can't insert "change" in front to sign postion. |
936 if (pEvent->SelStart() == 0) { | 937 if (pEvent->SelStart() == 0) { |
937 FX_BOOL& bRc = pEvent->Rc(); | 938 FX_BOOL& bRc = pEvent->Rc(); |
938 bRc = FALSE; | 939 bRc = FALSE; |
939 return TRUE; | 940 return TRUE; |
940 } | 941 } |
941 } | 942 } |
942 | 943 |
943 int iSepStyle = params[1].ToInt(); | 944 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 945 int iSepStyle = params[1].ToInt(pRuntime->GetIsolate()); |
944 if (iSepStyle < 0 || iSepStyle > 3) | 946 if (iSepStyle < 0 || iSepStyle > 3) |
945 iSepStyle = 0; | 947 iSepStyle = 0; |
946 const FX_WCHAR cSep = iSepStyle < 2 ? L'.' : L','; | 948 const FX_WCHAR cSep = iSepStyle < 2 ? L'.' : L','; |
947 | 949 |
948 bool bHasSep = wstrValue.Find(cSep) != -1; | 950 bool bHasSep = wstrValue.Find(cSep) != -1; |
949 for (FX_STRSIZE i = 0; i < wstrChange.GetLength(); ++i) { | 951 for (FX_STRSIZE i = 0; i < wstrChange.GetLength(); ++i) { |
950 if (wstrChange[i] == cSep) { | 952 if (wstrChange[i] == cSep) { |
951 if (bHasSep) { | 953 if (bHasSep) { |
952 FX_BOOL& bRc = pEvent->Rc(); | 954 FX_BOOL& bRc = pEvent->Rc(); |
953 bRc = FALSE; | 955 bRc = FALSE; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
993 } | 995 } |
994 | 996 |
995 // function AFPercent_Format(nDec, sepStyle) | 997 // function AFPercent_Format(nDec, sepStyle) |
996 FX_BOOL CJS_PublicMethods::AFPercent_Format( | 998 FX_BOOL CJS_PublicMethods::AFPercent_Format( |
997 IJS_Context* cc, | 999 IJS_Context* cc, |
998 const std::vector<CJS_Value>& params, | 1000 const std::vector<CJS_Value>& params, |
999 CJS_Value& vRet, | 1001 CJS_Value& vRet, |
1000 CFX_WideString& sError) { | 1002 CFX_WideString& sError) { |
1001 #if _FX_OS_ != _FX_ANDROID_ | 1003 #if _FX_OS_ != _FX_ANDROID_ |
1002 CJS_Context* pContext = (CJS_Context*)cc; | 1004 CJS_Context* pContext = (CJS_Context*)cc; |
| 1005 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
1003 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 1006 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
1004 | 1007 |
1005 if (params.size() != 2) { | 1008 if (params.size() != 2) { |
1006 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1009 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
1007 return FALSE; | 1010 return FALSE; |
1008 } | 1011 } |
1009 if (!pEvent->m_pValue) | 1012 if (!pEvent->m_pValue) |
1010 return FALSE; | 1013 return FALSE; |
1011 | 1014 |
1012 CFX_WideString& Value = pEvent->Value(); | 1015 CFX_WideString& Value = pEvent->Value(); |
1013 CFX_ByteString strValue = StrTrim(CFX_ByteString::FromUnicode(Value)); | 1016 CFX_ByteString strValue = StrTrim(CFX_ByteString::FromUnicode(Value)); |
1014 if (strValue.IsEmpty()) | 1017 if (strValue.IsEmpty()) |
1015 return TRUE; | 1018 return TRUE; |
1016 | 1019 |
1017 int iDec = params[0].ToInt(); | 1020 int iDec = params[0].ToInt(pRuntime->GetIsolate()); |
1018 if (iDec < 0) | 1021 if (iDec < 0) |
1019 iDec = -iDec; | 1022 iDec = -iDec; |
1020 | 1023 |
1021 int iSepStyle = params[1].ToInt(); | 1024 int iSepStyle = params[1].ToInt(pRuntime->GetIsolate()); |
1022 if (iSepStyle < 0 || iSepStyle > 3) | 1025 if (iSepStyle < 0 || iSepStyle > 3) |
1023 iSepStyle = 0; | 1026 iSepStyle = 0; |
1024 | 1027 |
1025 // for processing decimal places | 1028 // for processing decimal places |
1026 double dValue = atof(strValue.c_str()); | 1029 double dValue = atof(strValue.c_str()); |
1027 dValue *= 100; | 1030 dValue *= 100; |
1028 if (iDec > 0) | 1031 if (iDec > 0) |
1029 dValue += DOUBLE_CORRECT; | 1032 dValue += DOUBLE_CORRECT; |
1030 | 1033 |
1031 int iDec2; | 1034 int iDec2; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1092 CFX_WideString& sError) { | 1095 CFX_WideString& sError) { |
1093 return AFNumber_Keystroke(cc, params, vRet, sError); | 1096 return AFNumber_Keystroke(cc, params, vRet, sError); |
1094 } | 1097 } |
1095 | 1098 |
1096 // function AFDate_FormatEx(cFormat) | 1099 // function AFDate_FormatEx(cFormat) |
1097 FX_BOOL CJS_PublicMethods::AFDate_FormatEx(IJS_Context* cc, | 1100 FX_BOOL CJS_PublicMethods::AFDate_FormatEx(IJS_Context* cc, |
1098 const std::vector<CJS_Value>& params, | 1101 const std::vector<CJS_Value>& params, |
1099 CJS_Value& vRet, | 1102 CJS_Value& vRet, |
1100 CFX_WideString& sError) { | 1103 CFX_WideString& sError) { |
1101 CJS_Context* pContext = (CJS_Context*)cc; | 1104 CJS_Context* pContext = (CJS_Context*)cc; |
| 1105 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
1102 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 1106 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
1103 | 1107 |
1104 if (params.size() != 1) { | 1108 if (params.size() != 1) { |
1105 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1109 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
1106 return FALSE; | 1110 return FALSE; |
1107 } | 1111 } |
1108 if (!pEvent->m_pValue) | 1112 if (!pEvent->m_pValue) |
1109 return FALSE; | 1113 return FALSE; |
1110 | 1114 |
1111 CFX_WideString& val = pEvent->Value(); | 1115 CFX_WideString& val = pEvent->Value(); |
1112 CFX_WideString strValue = val; | 1116 CFX_WideString strValue = val; |
1113 if (strValue.IsEmpty()) | 1117 if (strValue.IsEmpty()) |
1114 return TRUE; | 1118 return TRUE; |
1115 | 1119 |
1116 CFX_WideString sFormat = params[0].ToCFXWideString(); | 1120 CFX_WideString sFormat = params[0].ToCFXWideString(pRuntime->GetIsolate()); |
1117 double dDate = 0.0f; | 1121 double dDate = 0.0f; |
1118 | 1122 |
1119 if (strValue.Find(L"GMT") != -1) { | 1123 if (strValue.Find(L"GMT") != -1) { |
1120 // for GMT format time | 1124 // for GMT format time |
1121 // such as "Tue Aug 11 14:24:16 GMT+08002009" | 1125 // such as "Tue Aug 11 14:24:16 GMT+08002009" |
1122 dDate = MakeInterDate(strValue); | 1126 dDate = MakeInterDate(strValue); |
1123 } else { | 1127 } else { |
1124 dDate = MakeRegularDate(strValue, sFormat, nullptr); | 1128 dDate = MakeRegularDate(strValue, sFormat, nullptr); |
1125 } | 1129 } |
1126 | 1130 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1192 return dRet; | 1196 return dRet; |
1193 } | 1197 } |
1194 | 1198 |
1195 // AFDate_KeystrokeEx(cFormat) | 1199 // AFDate_KeystrokeEx(cFormat) |
1196 FX_BOOL CJS_PublicMethods::AFDate_KeystrokeEx( | 1200 FX_BOOL CJS_PublicMethods::AFDate_KeystrokeEx( |
1197 IJS_Context* cc, | 1201 IJS_Context* cc, |
1198 const std::vector<CJS_Value>& params, | 1202 const std::vector<CJS_Value>& params, |
1199 CJS_Value& vRet, | 1203 CJS_Value& vRet, |
1200 CFX_WideString& sError) { | 1204 CFX_WideString& sError) { |
1201 CJS_Context* pContext = (CJS_Context*)cc; | 1205 CJS_Context* pContext = (CJS_Context*)cc; |
| 1206 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
1202 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 1207 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
1203 | 1208 |
1204 if (params.size() != 1) { | 1209 if (params.size() != 1) { |
1205 sError = L"AFDate_KeystrokeEx's parameters' size r not correct"; | 1210 sError = L"AFDate_KeystrokeEx's parameters' size r not correct"; |
1206 return FALSE; | 1211 return FALSE; |
1207 } | 1212 } |
1208 | 1213 |
1209 if (pEvent->WillCommit()) { | 1214 if (pEvent->WillCommit()) { |
1210 if (!pEvent->m_pValue) | 1215 if (!pEvent->m_pValue) |
1211 return FALSE; | 1216 return FALSE; |
1212 CFX_WideString strValue = pEvent->Value(); | 1217 CFX_WideString strValue = pEvent->Value(); |
1213 if (strValue.IsEmpty()) | 1218 if (strValue.IsEmpty()) |
1214 return TRUE; | 1219 return TRUE; |
1215 | 1220 |
1216 CFX_WideString sFormat = params[0].ToCFXWideString(); | 1221 CFX_WideString sFormat = params[0].ToCFXWideString(pRuntime->GetIsolate()); |
1217 bool bWrongFormat = FALSE; | 1222 bool bWrongFormat = FALSE; |
1218 double dRet = MakeRegularDate(strValue, sFormat, &bWrongFormat); | 1223 double dRet = MakeRegularDate(strValue, sFormat, &bWrongFormat); |
1219 if (bWrongFormat || JS_PortIsNan(dRet)) { | 1224 if (bWrongFormat || JS_PortIsNan(dRet)) { |
1220 CFX_WideString swMsg; | 1225 CFX_WideString swMsg; |
1221 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE).c_str(), | 1226 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE).c_str(), |
1222 sFormat.c_str()); | 1227 sFormat.c_str()); |
1223 AlertIfPossible(pContext, swMsg.c_str()); | 1228 AlertIfPossible(pContext, swMsg.c_str()); |
1224 pEvent->Rc() = FALSE; | 1229 pEvent->Rc() = FALSE; |
1225 return TRUE; | 1230 return TRUE; |
1226 } | 1231 } |
1227 } | 1232 } |
1228 return TRUE; | 1233 return TRUE; |
1229 } | 1234 } |
1230 | 1235 |
1231 FX_BOOL CJS_PublicMethods::AFDate_Format(IJS_Context* cc, | 1236 FX_BOOL CJS_PublicMethods::AFDate_Format(IJS_Context* cc, |
1232 const std::vector<CJS_Value>& params, | 1237 const std::vector<CJS_Value>& params, |
1233 CJS_Value& vRet, | 1238 CJS_Value& vRet, |
1234 CFX_WideString& sError) { | 1239 CFX_WideString& sError) { |
1235 CJS_Context* pContext = (CJS_Context*)cc; | 1240 CJS_Context* pContext = (CJS_Context*)cc; |
1236 if (params.size() != 1) { | 1241 if (params.size() != 1) { |
1237 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1242 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
1238 return FALSE; | 1243 return FALSE; |
1239 } | 1244 } |
1240 | 1245 |
1241 int iIndex = params[0].ToInt(); | 1246 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1247 int iIndex = params[0].ToInt(pRuntime->GetIsolate()); |
1242 const FX_WCHAR* cFormats[] = {L"m/d", | 1248 const FX_WCHAR* cFormats[] = {L"m/d", |
1243 L"m/d/yy", | 1249 L"m/d/yy", |
1244 L"mm/dd/yy", | 1250 L"mm/dd/yy", |
1245 L"mm/yy", | 1251 L"mm/yy", |
1246 L"d-mmm", | 1252 L"d-mmm", |
1247 L"d-mmm-yy", | 1253 L"d-mmm-yy", |
1248 L"dd-mmm-yy", | 1254 L"dd-mmm-yy", |
1249 L"yy-mm-dd", | 1255 L"yy-mm-dd", |
1250 L"mmm-yy", | 1256 L"mmm-yy", |
1251 L"mmmm-yy", | 1257 L"mmmm-yy", |
(...skipping 16 matching lines...) Expand all Loading... |
1268 IJS_Context* cc, | 1274 IJS_Context* cc, |
1269 const std::vector<CJS_Value>& params, | 1275 const std::vector<CJS_Value>& params, |
1270 CJS_Value& vRet, | 1276 CJS_Value& vRet, |
1271 CFX_WideString& sError) { | 1277 CFX_WideString& sError) { |
1272 CJS_Context* pContext = (CJS_Context*)cc; | 1278 CJS_Context* pContext = (CJS_Context*)cc; |
1273 if (params.size() != 1) { | 1279 if (params.size() != 1) { |
1274 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1280 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
1275 return FALSE; | 1281 return FALSE; |
1276 } | 1282 } |
1277 | 1283 |
1278 int iIndex = params[0].ToInt(); | 1284 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1285 int iIndex = params[0].ToInt(pRuntime->GetIsolate()); |
1279 const FX_WCHAR* cFormats[] = {L"m/d", | 1286 const FX_WCHAR* cFormats[] = {L"m/d", |
1280 L"m/d/yy", | 1287 L"m/d/yy", |
1281 L"mm/dd/yy", | 1288 L"mm/dd/yy", |
1282 L"mm/yy", | 1289 L"mm/yy", |
1283 L"d-mmm", | 1290 L"d-mmm", |
1284 L"d-mmm-yy", | 1291 L"d-mmm-yy", |
1285 L"dd-mmm-yy", | 1292 L"dd-mmm-yy", |
1286 L"yy-mm-dd", | 1293 L"yy-mm-dd", |
1287 L"mmm-yy", | 1294 L"mmm-yy", |
1288 L"mmmm-yy", | 1295 L"mmmm-yy", |
(...skipping 15 matching lines...) Expand all Loading... |
1304 FX_BOOL CJS_PublicMethods::AFTime_Format(IJS_Context* cc, | 1311 FX_BOOL CJS_PublicMethods::AFTime_Format(IJS_Context* cc, |
1305 const std::vector<CJS_Value>& params, | 1312 const std::vector<CJS_Value>& params, |
1306 CJS_Value& vRet, | 1313 CJS_Value& vRet, |
1307 CFX_WideString& sError) { | 1314 CFX_WideString& sError) { |
1308 CJS_Context* pContext = (CJS_Context*)cc; | 1315 CJS_Context* pContext = (CJS_Context*)cc; |
1309 if (params.size() != 1) { | 1316 if (params.size() != 1) { |
1310 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1317 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
1311 return FALSE; | 1318 return FALSE; |
1312 } | 1319 } |
1313 | 1320 |
1314 int iIndex = params[0].ToInt(); | 1321 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1322 int iIndex = params[0].ToInt(pRuntime->GetIsolate()); |
1315 const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", | 1323 const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", |
1316 L"h:MM:ss tt"}; | 1324 L"h:MM:ss tt"}; |
1317 | 1325 |
1318 if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats))) | 1326 if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats))) |
1319 iIndex = 0; | 1327 iIndex = 0; |
1320 | 1328 |
1321 std::vector<CJS_Value> newParams; | 1329 std::vector<CJS_Value> newParams; |
1322 newParams.push_back( | 1330 newParams.push_back( |
1323 CJS_Value(CJS_Runtime::FromContext(cc), cFormats[iIndex])); | 1331 CJS_Value(CJS_Runtime::FromContext(cc), cFormats[iIndex])); |
1324 return AFDate_FormatEx(cc, newParams, vRet, sError); | 1332 return AFDate_FormatEx(cc, newParams, vRet, sError); |
1325 } | 1333 } |
1326 | 1334 |
1327 FX_BOOL CJS_PublicMethods::AFTime_Keystroke( | 1335 FX_BOOL CJS_PublicMethods::AFTime_Keystroke( |
1328 IJS_Context* cc, | 1336 IJS_Context* cc, |
1329 const std::vector<CJS_Value>& params, | 1337 const std::vector<CJS_Value>& params, |
1330 CJS_Value& vRet, | 1338 CJS_Value& vRet, |
1331 CFX_WideString& sError) { | 1339 CFX_WideString& sError) { |
1332 CJS_Context* pContext = (CJS_Context*)cc; | 1340 CJS_Context* pContext = (CJS_Context*)cc; |
1333 if (params.size() != 1) { | 1341 if (params.size() != 1) { |
1334 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1342 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
1335 return FALSE; | 1343 return FALSE; |
1336 } | 1344 } |
1337 | 1345 |
1338 int iIndex = params[0].ToInt(); | 1346 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1347 int iIndex = params[0].ToInt(pRuntime->GetIsolate()); |
1339 const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", | 1348 const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", |
1340 L"h:MM:ss tt"}; | 1349 L"h:MM:ss tt"}; |
1341 | 1350 |
1342 if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats))) | 1351 if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats))) |
1343 iIndex = 0; | 1352 iIndex = 0; |
1344 | 1353 |
1345 std::vector<CJS_Value> newParams; | 1354 std::vector<CJS_Value> newParams; |
1346 newParams.push_back( | 1355 newParams.push_back( |
1347 CJS_Value(CJS_Runtime::FromContext(cc), cFormats[iIndex])); | 1356 CJS_Value(CJS_Runtime::FromContext(cc), cFormats[iIndex])); |
1348 return AFDate_KeystrokeEx(cc, newParams, vRet, sError); | 1357 return AFDate_KeystrokeEx(cc, newParams, vRet, sError); |
(...skipping 14 matching lines...) Expand all Loading... |
1363 return AFDate_KeystrokeEx(cc, params, vRet, sError); | 1372 return AFDate_KeystrokeEx(cc, params, vRet, sError); |
1364 } | 1373 } |
1365 | 1374 |
1366 // function AFSpecial_Format(psf) | 1375 // function AFSpecial_Format(psf) |
1367 FX_BOOL CJS_PublicMethods::AFSpecial_Format( | 1376 FX_BOOL CJS_PublicMethods::AFSpecial_Format( |
1368 IJS_Context* cc, | 1377 IJS_Context* cc, |
1369 const std::vector<CJS_Value>& params, | 1378 const std::vector<CJS_Value>& params, |
1370 CJS_Value& vRet, | 1379 CJS_Value& vRet, |
1371 CFX_WideString& sError) { | 1380 CFX_WideString& sError) { |
1372 CJS_Context* pContext = (CJS_Context*)cc; | 1381 CJS_Context* pContext = (CJS_Context*)cc; |
1373 | |
1374 if (params.size() != 1) { | 1382 if (params.size() != 1) { |
1375 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1383 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
1376 return FALSE; | 1384 return FALSE; |
1377 } | 1385 } |
1378 | 1386 |
1379 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 1387 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
1380 if (!pEvent->m_pValue) | 1388 if (!pEvent->m_pValue) |
1381 return FALSE; | 1389 return FALSE; |
1382 | 1390 |
| 1391 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
1383 CFX_WideString wsSource = pEvent->Value(); | 1392 CFX_WideString wsSource = pEvent->Value(); |
1384 CFX_WideString wsFormat; | 1393 CFX_WideString wsFormat; |
1385 switch (params[0].ToInt()) { | 1394 switch (params[0].ToInt(pRuntime->GetIsolate())) { |
1386 case 0: | 1395 case 0: |
1387 wsFormat = L"99999"; | 1396 wsFormat = L"99999"; |
1388 break; | 1397 break; |
1389 case 1: | 1398 case 1: |
1390 wsFormat = L"99999-9999"; | 1399 wsFormat = L"99999-9999"; |
1391 break; | 1400 break; |
1392 case 2: | 1401 case 2: |
1393 if (util::printx(L"9999999999", wsSource).GetLength() >= 10) | 1402 if (util::printx(L"9999999999", wsSource).GetLength() >= 10) |
1394 wsFormat = L"(999) 999-9999"; | 1403 wsFormat = L"(999) 999-9999"; |
1395 else | 1404 else |
1396 wsFormat = L"999-9999"; | 1405 wsFormat = L"999-9999"; |
1397 break; | 1406 break; |
1398 case 3: | 1407 case 3: |
1399 wsFormat = L"999-99-9999"; | 1408 wsFormat = L"999-99-9999"; |
1400 break; | 1409 break; |
1401 } | 1410 } |
1402 | 1411 |
1403 pEvent->Value() = util::printx(wsFormat, wsSource); | 1412 pEvent->Value() = util::printx(wsFormat, wsSource); |
1404 return TRUE; | 1413 return TRUE; |
1405 } | 1414 } |
1406 | 1415 |
1407 // function AFSpecial_KeystrokeEx(mask) | 1416 // function AFSpecial_KeystrokeEx(mask) |
1408 FX_BOOL CJS_PublicMethods::AFSpecial_KeystrokeEx( | 1417 FX_BOOL CJS_PublicMethods::AFSpecial_KeystrokeEx( |
1409 IJS_Context* cc, | 1418 IJS_Context* cc, |
1410 const std::vector<CJS_Value>& params, | 1419 const std::vector<CJS_Value>& params, |
1411 CJS_Value& vRet, | 1420 CJS_Value& vRet, |
1412 CFX_WideString& sError) { | 1421 CFX_WideString& sError) { |
1413 CJS_Context* pContext = (CJS_Context*)cc; | 1422 CJS_Context* pContext = (CJS_Context*)cc; |
| 1423 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
1414 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 1424 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
1415 | 1425 |
1416 if (params.size() < 1) { | 1426 if (params.size() < 1) { |
1417 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1427 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
1418 return FALSE; | 1428 return FALSE; |
1419 } | 1429 } |
1420 | 1430 |
1421 if (!pEvent->m_pValue) | 1431 if (!pEvent->m_pValue) |
1422 return FALSE; | 1432 return FALSE; |
1423 CFX_WideString& valEvent = pEvent->Value(); | 1433 CFX_WideString& valEvent = pEvent->Value(); |
1424 | 1434 |
1425 CFX_WideString wstrMask = params[0].ToCFXWideString(); | 1435 CFX_WideString wstrMask = params[0].ToCFXWideString(pRuntime->GetIsolate()); |
1426 if (wstrMask.IsEmpty()) | 1436 if (wstrMask.IsEmpty()) |
1427 return TRUE; | 1437 return TRUE; |
1428 | 1438 |
1429 if (pEvent->WillCommit()) { | 1439 if (pEvent->WillCommit()) { |
1430 if (valEvent.IsEmpty()) | 1440 if (valEvent.IsEmpty()) |
1431 return TRUE; | 1441 return TRUE; |
1432 | 1442 |
1433 FX_STRSIZE iIndexMask = 0; | 1443 FX_STRSIZE iIndexMask = 0; |
1434 for (; iIndexMask < valEvent.GetLength(); ++iIndexMask) { | 1444 for (; iIndexMask < valEvent.GetLength(); ++iIndexMask) { |
1435 if (!maskSatisfied(valEvent[iIndexMask], wstrMask[iIndexMask])) | 1445 if (!maskSatisfied(valEvent[iIndexMask], wstrMask[iIndexMask])) |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1502 if (params.size() != 1) { | 1512 if (params.size() != 1) { |
1503 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1513 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
1504 return FALSE; | 1514 return FALSE; |
1505 } | 1515 } |
1506 | 1516 |
1507 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 1517 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
1508 if (!pEvent->m_pValue) | 1518 if (!pEvent->m_pValue) |
1509 return FALSE; | 1519 return FALSE; |
1510 | 1520 |
1511 const char* cFormat = ""; | 1521 const char* cFormat = ""; |
1512 switch (params[0].ToInt()) { | 1522 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1523 switch (params[0].ToInt(pRuntime->GetIsolate())) { |
1513 case 0: | 1524 case 0: |
1514 cFormat = "99999"; | 1525 cFormat = "99999"; |
1515 break; | 1526 break; |
1516 case 1: | 1527 case 1: |
1517 cFormat = "999999999"; | 1528 cFormat = "999999999"; |
1518 break; | 1529 break; |
1519 case 2: | 1530 case 2: |
1520 if (pEvent->Value().GetLength() + pEvent->Change().GetLength() > 7) | 1531 if (pEvent->Value().GetLength() + pEvent->Change().GetLength() > 7) |
1521 cFormat = "9999999999"; | 1532 cFormat = "9999999999"; |
1522 else | 1533 else |
1523 cFormat = "9999999"; | 1534 cFormat = "9999999"; |
1524 break; | 1535 break; |
1525 case 3: | 1536 case 3: |
1526 cFormat = "999999999"; | 1537 cFormat = "999999999"; |
1527 break; | 1538 break; |
1528 } | 1539 } |
1529 | 1540 |
1530 std::vector<CJS_Value> params2; | 1541 std::vector<CJS_Value> params2; |
1531 params2.push_back(CJS_Value(CJS_Runtime::FromContext(cc), cFormat)); | 1542 params2.push_back(CJS_Value(CJS_Runtime::FromContext(cc), cFormat)); |
1532 return AFSpecial_KeystrokeEx(cc, params2, vRet, sError); | 1543 return AFSpecial_KeystrokeEx(cc, params2, vRet, sError); |
1533 } | 1544 } |
1534 | 1545 |
1535 FX_BOOL CJS_PublicMethods::AFMergeChange(IJS_Context* cc, | 1546 FX_BOOL CJS_PublicMethods::AFMergeChange(IJS_Context* cc, |
1536 const std::vector<CJS_Value>& params, | 1547 const std::vector<CJS_Value>& params, |
1537 CJS_Value& vRet, | 1548 CJS_Value& vRet, |
1538 CFX_WideString& sError) { | 1549 CFX_WideString& sError) { |
1539 CJS_Context* pContext = (CJS_Context*)cc; | 1550 CJS_Context* pContext = (CJS_Context*)cc; |
| 1551 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
1540 CJS_EventHandler* pEventHandler = pContext->GetEventHandler(); | 1552 CJS_EventHandler* pEventHandler = pContext->GetEventHandler(); |
1541 | 1553 |
1542 if (params.size() != 1) { | 1554 if (params.size() != 1) { |
1543 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1555 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
1544 return FALSE; | 1556 return FALSE; |
1545 } | 1557 } |
1546 | 1558 |
1547 CFX_WideString swValue; | 1559 CFX_WideString swValue; |
1548 if (pEventHandler->m_pValue) | 1560 if (pEventHandler->m_pValue) |
1549 swValue = pEventHandler->Value(); | 1561 swValue = pEventHandler->Value(); |
1550 | 1562 |
1551 if (pEventHandler->WillCommit()) { | 1563 if (pEventHandler->WillCommit()) { |
1552 vRet = swValue.c_str(); | 1564 vRet = CJS_Value(pRuntime, swValue.c_str()); |
1553 return TRUE; | 1565 return TRUE; |
1554 } | 1566 } |
1555 | 1567 |
1556 CFX_WideString prefix, postfix; | 1568 CFX_WideString prefix, postfix; |
1557 | 1569 |
1558 if (pEventHandler->SelStart() >= 0) | 1570 if (pEventHandler->SelStart() >= 0) |
1559 prefix = swValue.Mid(0, pEventHandler->SelStart()); | 1571 prefix = swValue.Mid(0, pEventHandler->SelStart()); |
1560 else | 1572 else |
1561 prefix = L""; | 1573 prefix = L""; |
1562 | 1574 |
1563 if (pEventHandler->SelEnd() >= 0 && | 1575 if (pEventHandler->SelEnd() >= 0 && |
1564 pEventHandler->SelEnd() <= swValue.GetLength()) | 1576 pEventHandler->SelEnd() <= swValue.GetLength()) |
1565 postfix = swValue.Mid(pEventHandler->SelEnd(), | 1577 postfix = swValue.Mid(pEventHandler->SelEnd(), |
1566 swValue.GetLength() - pEventHandler->SelEnd()); | 1578 swValue.GetLength() - pEventHandler->SelEnd()); |
1567 else | 1579 else |
1568 postfix = L""; | 1580 postfix = L""; |
1569 | 1581 |
1570 vRet = (prefix + pEventHandler->Change() + postfix).c_str(); | 1582 vRet = |
1571 | 1583 CJS_Value(pRuntime, (prefix + pEventHandler->Change() + postfix).c_str()); |
1572 return TRUE; | 1584 return TRUE; |
1573 } | 1585 } |
1574 | 1586 |
1575 FX_BOOL CJS_PublicMethods::AFParseDateEx(IJS_Context* cc, | 1587 FX_BOOL CJS_PublicMethods::AFParseDateEx(IJS_Context* cc, |
1576 const std::vector<CJS_Value>& params, | 1588 const std::vector<CJS_Value>& params, |
1577 CJS_Value& vRet, | 1589 CJS_Value& vRet, |
1578 CFX_WideString& sError) { | 1590 CFX_WideString& sError) { |
1579 CJS_Context* pContext = (CJS_Context*)cc; | 1591 CJS_Context* pContext = (CJS_Context*)cc; |
1580 ASSERT(pContext); | 1592 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
1581 | 1593 |
1582 if (params.size() != 2) { | 1594 if (params.size() != 2) { |
1583 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1595 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
1584 return FALSE; | 1596 return FALSE; |
1585 } | 1597 } |
1586 | 1598 |
1587 CFX_WideString sValue = params[0].ToCFXWideString(); | 1599 CFX_WideString sValue = params[0].ToCFXWideString(pRuntime->GetIsolate()); |
1588 CFX_WideString sFormat = params[1].ToCFXWideString(); | 1600 CFX_WideString sFormat = params[1].ToCFXWideString(pRuntime->GetIsolate()); |
1589 | 1601 |
1590 double dDate = MakeRegularDate(sValue, sFormat, nullptr); | 1602 double dDate = MakeRegularDate(sValue, sFormat, nullptr); |
1591 | 1603 |
1592 if (JS_PortIsNan(dDate)) { | 1604 if (JS_PortIsNan(dDate)) { |
1593 CFX_WideString swMsg; | 1605 CFX_WideString swMsg; |
1594 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE).c_str(), | 1606 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE).c_str(), |
1595 sFormat.c_str()); | 1607 sFormat.c_str()); |
1596 AlertIfPossible((CJS_Context*)cc, swMsg.c_str()); | 1608 AlertIfPossible((CJS_Context*)cc, swMsg.c_str()); |
1597 return FALSE; | 1609 return FALSE; |
1598 } | 1610 } |
1599 | 1611 |
1600 vRet = dDate; | 1612 vRet = CJS_Value(pRuntime, dDate); |
1601 return TRUE; | 1613 return TRUE; |
1602 } | 1614 } |
1603 | 1615 |
1604 FX_BOOL CJS_PublicMethods::AFSimple(IJS_Context* cc, | 1616 FX_BOOL CJS_PublicMethods::AFSimple(IJS_Context* cc, |
1605 const std::vector<CJS_Value>& params, | 1617 const std::vector<CJS_Value>& params, |
1606 CJS_Value& vRet, | 1618 CJS_Value& vRet, |
1607 CFX_WideString& sError) { | 1619 CFX_WideString& sError) { |
| 1620 CJS_Context* pContext = (CJS_Context*)cc; |
| 1621 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1622 |
1608 if (params.size() != 3) { | 1623 if (params.size() != 3) { |
1609 CJS_Context* pContext = (CJS_Context*)cc; | |
1610 ASSERT(pContext); | |
1611 | |
1612 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1624 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
1613 return FALSE; | 1625 return FALSE; |
1614 } | 1626 } |
1615 | 1627 |
1616 vRet = (double)AF_Simple(params[0].ToCFXWideString().c_str(), | 1628 vRet = CJS_Value( |
1617 params[1].ToDouble(), params[2].ToDouble()); | 1629 pRuntime, static_cast<double>(AF_Simple( |
| 1630 params[0].ToCFXWideString(pRuntime->GetIsolate()).c_str(), |
| 1631 params[1].ToDouble(pRuntime->GetIsolate()), |
| 1632 params[2].ToDouble(pRuntime->GetIsolate())))); |
| 1633 |
1618 return TRUE; | 1634 return TRUE; |
1619 } | 1635 } |
1620 | 1636 |
1621 FX_BOOL CJS_PublicMethods::AFMakeNumber(IJS_Context* cc, | 1637 FX_BOOL CJS_PublicMethods::AFMakeNumber(IJS_Context* cc, |
1622 const std::vector<CJS_Value>& params, | 1638 const std::vector<CJS_Value>& params, |
1623 CJS_Value& vRet, | 1639 CJS_Value& vRet, |
1624 CFX_WideString& sError) { | 1640 CFX_WideString& sError) { |
1625 CJS_Context* pContext = (CJS_Context*)cc; | 1641 CJS_Context* pContext = (CJS_Context*)cc; |
| 1642 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1643 |
1626 if (params.size() != 1) { | 1644 if (params.size() != 1) { |
1627 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1645 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
1628 return FALSE; | 1646 return FALSE; |
1629 } | 1647 } |
1630 CFX_WideString ws = params[0].ToCFXWideString(); | 1648 |
| 1649 CFX_WideString ws = params[0].ToCFXWideString(pRuntime->GetIsolate()); |
1631 ws.Replace(L",", L"."); | 1650 ws.Replace(L",", L"."); |
1632 vRet = ws.c_str(); | 1651 vRet = CJS_Value(pRuntime, ws.c_str()); |
1633 vRet.MaybeCoerceToNumber(); | 1652 vRet.MaybeCoerceToNumber(pRuntime->GetIsolate()); |
1634 if (vRet.GetType() != CJS_Value::VT_number) | 1653 if (vRet.GetType() != CJS_Value::VT_number) |
1635 vRet = 0; | 1654 vRet = CJS_Value(pRuntime, 0); |
1636 return TRUE; | 1655 return TRUE; |
1637 } | 1656 } |
1638 | 1657 |
1639 FX_BOOL CJS_PublicMethods::AFSimple_Calculate( | 1658 FX_BOOL CJS_PublicMethods::AFSimple_Calculate( |
1640 IJS_Context* cc, | 1659 IJS_Context* cc, |
1641 const std::vector<CJS_Value>& params, | 1660 const std::vector<CJS_Value>& params, |
1642 CJS_Value& vRet, | 1661 CJS_Value& vRet, |
1643 CFX_WideString& sError) { | 1662 CFX_WideString& sError) { |
1644 CJS_Context* pContext = (CJS_Context*)cc; | 1663 CJS_Context* pContext = (CJS_Context*)cc; |
| 1664 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1665 |
1645 if (params.size() != 2) { | 1666 if (params.size() != 2) { |
1646 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1667 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
1647 return FALSE; | 1668 return FALSE; |
1648 } | 1669 } |
1649 | 1670 |
1650 CJS_Value params1 = params[1]; | 1671 CJS_Value params1 = params[1]; |
1651 if (!params1.IsArrayObject() && params1.GetType() != CJS_Value::VT_string) { | 1672 if (!params1.IsArrayObject() && params1.GetType() != CJS_Value::VT_string) { |
1652 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1673 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
1653 return FALSE; | 1674 return FALSE; |
1654 } | 1675 } |
1655 | 1676 |
1656 CPDFSDK_Document* pReaderDoc = pContext->GetReaderDocument(); | 1677 CPDFSDK_Document* pReaderDoc = pContext->GetReaderDocument(); |
1657 CPDFSDK_InterForm* pReaderInterForm = pReaderDoc->GetInterForm(); | 1678 CPDFSDK_InterForm* pReaderInterForm = pReaderDoc->GetInterForm(); |
1658 CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm(); | 1679 CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm(); |
1659 | 1680 |
1660 CFX_WideString sFunction = params[0].ToCFXWideString(); | 1681 CFX_WideString sFunction = params[0].ToCFXWideString(pRuntime->GetIsolate()); |
1661 double dValue = wcscmp(sFunction.c_str(), L"PRD") == 0 ? 1.0 : 0.0; | 1682 double dValue = wcscmp(sFunction.c_str(), L"PRD") == 0 ? 1.0 : 0.0; |
1662 | 1683 |
1663 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | |
1664 CJS_Array FieldNameArray = AF_MakeArrayFromList(pRuntime, params1); | 1684 CJS_Array FieldNameArray = AF_MakeArrayFromList(pRuntime, params1); |
1665 int nFieldsCount = 0; | 1685 int nFieldsCount = 0; |
1666 | 1686 |
1667 for (int i = 0, isz = FieldNameArray.GetLength(); i < isz; i++) { | 1687 for (int i = 0, isz = FieldNameArray.GetLength(); i < isz; i++) { |
1668 CJS_Value jsValue(pRuntime); | 1688 CJS_Value jsValue(pRuntime); |
1669 FieldNameArray.GetElement(pRuntime->GetIsolate(), i, jsValue); | 1689 FieldNameArray.GetElement(pRuntime->GetIsolate(), i, jsValue); |
1670 CFX_WideString wsFieldName = jsValue.ToCFXWideString(); | 1690 CFX_WideString wsFieldName = |
| 1691 jsValue.ToCFXWideString(pRuntime->GetIsolate()); |
1671 | 1692 |
1672 for (int j = 0, jsz = pInterForm->CountFields(wsFieldName); j < jsz; j++) { | 1693 for (int j = 0, jsz = pInterForm->CountFields(wsFieldName); j < jsz; j++) { |
1673 if (CPDF_FormField* pFormField = pInterForm->GetField(j, wsFieldName)) { | 1694 if (CPDF_FormField* pFormField = pInterForm->GetField(j, wsFieldName)) { |
1674 double dTemp = 0.0; | 1695 double dTemp = 0.0; |
1675 switch (pFormField->GetFieldType()) { | 1696 switch (pFormField->GetFieldType()) { |
1676 case FIELDTYPE_TEXTFIELD: | 1697 case FIELDTYPE_TEXTFIELD: |
1677 case FIELDTYPE_COMBOBOX: { | 1698 case FIELDTYPE_COMBOBOX: { |
1678 CFX_WideString trimmed = pFormField->GetValue(); | 1699 CFX_WideString trimmed = pFormField->GetValue(); |
1679 trimmed.TrimRight(); | 1700 trimmed.TrimRight(); |
1680 trimmed.TrimLeft(); | 1701 trimmed.TrimLeft(); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1721 } | 1742 } |
1722 } | 1743 } |
1723 | 1744 |
1724 if (wcscmp(sFunction.c_str(), L"AVG") == 0 && nFieldsCount > 0) | 1745 if (wcscmp(sFunction.c_str(), L"AVG") == 0 && nFieldsCount > 0) |
1725 dValue /= nFieldsCount; | 1746 dValue /= nFieldsCount; |
1726 | 1747 |
1727 dValue = (double)floor(dValue * FXSYS_pow((double)10, (double)6) + 0.49) / | 1748 dValue = (double)floor(dValue * FXSYS_pow((double)10, (double)6) + 0.49) / |
1728 FXSYS_pow((double)10, (double)6); | 1749 FXSYS_pow((double)10, (double)6); |
1729 CJS_Value jsValue(pRuntime, dValue); | 1750 CJS_Value jsValue(pRuntime, dValue); |
1730 if (pContext->GetEventHandler()->m_pValue) | 1751 if (pContext->GetEventHandler()->m_pValue) |
1731 pContext->GetEventHandler()->Value() = jsValue.ToCFXWideString(); | 1752 pContext->GetEventHandler()->Value() = |
| 1753 jsValue.ToCFXWideString(pRuntime->GetIsolate()); |
1732 | 1754 |
1733 return TRUE; | 1755 return TRUE; |
1734 } | 1756 } |
1735 | 1757 |
1736 /* This function validates the current event to ensure that its value is | 1758 /* This function validates the current event to ensure that its value is |
1737 ** within the specified range. */ | 1759 ** within the specified range. */ |
1738 | 1760 |
1739 FX_BOOL CJS_PublicMethods::AFRange_Validate( | 1761 FX_BOOL CJS_PublicMethods::AFRange_Validate( |
1740 IJS_Context* cc, | 1762 IJS_Context* cc, |
1741 const std::vector<CJS_Value>& params, | 1763 const std::vector<CJS_Value>& params, |
1742 CJS_Value& vRet, | 1764 CJS_Value& vRet, |
1743 CFX_WideString& sError) { | 1765 CFX_WideString& sError) { |
1744 CJS_Context* pContext = (CJS_Context*)cc; | 1766 CJS_Context* pContext = (CJS_Context*)cc; |
| 1767 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
1745 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 1768 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
1746 | 1769 |
1747 if (params.size() != 4) { | 1770 if (params.size() != 4) { |
1748 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1771 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
1749 return FALSE; | 1772 return FALSE; |
1750 } | 1773 } |
1751 | 1774 |
1752 if (!pEvent->m_pValue) | 1775 if (!pEvent->m_pValue) |
1753 return FALSE; | 1776 return FALSE; |
1754 if (pEvent->Value().IsEmpty()) | 1777 if (pEvent->Value().IsEmpty()) |
1755 return TRUE; | 1778 return TRUE; |
1756 double dEentValue = | 1779 double dEentValue = |
1757 atof(CFX_ByteString::FromUnicode(pEvent->Value()).c_str()); | 1780 atof(CFX_ByteString::FromUnicode(pEvent->Value()).c_str()); |
1758 FX_BOOL bGreaterThan = params[0].ToBool(); | 1781 FX_BOOL bGreaterThan = params[0].ToBool(pRuntime->GetIsolate()); |
1759 double dGreaterThan = params[1].ToDouble(); | 1782 double dGreaterThan = params[1].ToDouble(pRuntime->GetIsolate()); |
1760 FX_BOOL bLessThan = params[2].ToBool(); | 1783 FX_BOOL bLessThan = params[2].ToBool(pRuntime->GetIsolate()); |
1761 double dLessThan = params[3].ToDouble(); | 1784 double dLessThan = params[3].ToDouble(pRuntime->GetIsolate()); |
1762 CFX_WideString swMsg; | 1785 CFX_WideString swMsg; |
1763 | 1786 |
1764 if (bGreaterThan && bLessThan) { | 1787 if (bGreaterThan && bLessThan) { |
1765 if (dEentValue < dGreaterThan || dEentValue > dLessThan) | 1788 if (dEentValue < dGreaterThan || dEentValue > dLessThan) |
1766 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE1).c_str(), | 1789 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE1).c_str(), |
1767 params[1].ToCFXWideString().c_str(), | 1790 params[1].ToCFXWideString(pRuntime->GetIsolate()).c_str(), |
1768 params[3].ToCFXWideString().c_str()); | 1791 params[3].ToCFXWideString(pRuntime->GetIsolate()).c_str()); |
1769 } else if (bGreaterThan) { | 1792 } else if (bGreaterThan) { |
1770 if (dEentValue < dGreaterThan) | 1793 if (dEentValue < dGreaterThan) |
1771 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE2).c_str(), | 1794 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE2).c_str(), |
1772 params[1].ToCFXWideString().c_str()); | 1795 params[1].ToCFXWideString(pRuntime->GetIsolate()).c_str()); |
1773 } else if (bLessThan) { | 1796 } else if (bLessThan) { |
1774 if (dEentValue > dLessThan) | 1797 if (dEentValue > dLessThan) |
1775 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE3).c_str(), | 1798 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE3).c_str(), |
1776 params[3].ToCFXWideString().c_str()); | 1799 params[3].ToCFXWideString(pRuntime->GetIsolate()).c_str()); |
1777 } | 1800 } |
1778 | 1801 |
1779 if (!swMsg.IsEmpty()) { | 1802 if (!swMsg.IsEmpty()) { |
1780 AlertIfPossible(pContext, swMsg.c_str()); | 1803 AlertIfPossible(pContext, swMsg.c_str()); |
1781 pEvent->Rc() = FALSE; | 1804 pEvent->Rc() = FALSE; |
1782 } | 1805 } |
1783 return TRUE; | 1806 return TRUE; |
1784 } | 1807 } |
1785 | 1808 |
1786 FX_BOOL CJS_PublicMethods::AFExtractNums(IJS_Context* cc, | 1809 FX_BOOL CJS_PublicMethods::AFExtractNums(IJS_Context* cc, |
1787 const std::vector<CJS_Value>& params, | 1810 const std::vector<CJS_Value>& params, |
1788 CJS_Value& vRet, | 1811 CJS_Value& vRet, |
1789 CFX_WideString& sError) { | 1812 CFX_WideString& sError) { |
1790 CJS_Context* pContext = (CJS_Context*)cc; | 1813 CJS_Context* pContext = (CJS_Context*)cc; |
| 1814 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1815 |
1791 if (params.size() != 1) { | 1816 if (params.size() != 1) { |
1792 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1817 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
1793 return FALSE; | 1818 return FALSE; |
1794 } | 1819 } |
1795 | 1820 |
1796 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | |
1797 CJS_Array nums; | 1821 CJS_Array nums; |
1798 | 1822 CFX_WideString str = params[0].ToCFXWideString(pRuntime->GetIsolate()); |
1799 CFX_WideString str = params[0].ToCFXWideString(); | |
1800 CFX_WideString sPart; | 1823 CFX_WideString sPart; |
1801 | 1824 |
1802 if (str.GetAt(0) == L'.' || str.GetAt(0) == L',') | 1825 if (str.GetAt(0) == L'.' || str.GetAt(0) == L',') |
1803 str = L"0" + str; | 1826 str = L"0" + str; |
1804 | 1827 |
1805 int nIndex = 0; | 1828 int nIndex = 0; |
1806 for (int i = 0, sz = str.GetLength(); i < sz; i++) { | 1829 for (int i = 0, sz = str.GetLength(); i < sz; i++) { |
1807 FX_WCHAR wc = str.GetAt(i); | 1830 FX_WCHAR wc = str.GetAt(i); |
1808 if (FXSYS_iswdigit(wc)) { | 1831 if (FXSYS_iswdigit(wc)) { |
1809 sPart += wc; | 1832 sPart += wc; |
1810 } else { | 1833 } else { |
1811 if (sPart.GetLength() > 0) { | 1834 if (sPart.GetLength() > 0) { |
1812 nums.SetElement(pRuntime->GetIsolate(), nIndex, | 1835 nums.SetElement(pRuntime->GetIsolate(), nIndex, |
1813 CJS_Value(pRuntime, sPart.c_str())); | 1836 CJS_Value(pRuntime, sPart.c_str())); |
1814 sPart = L""; | 1837 sPart = L""; |
1815 nIndex++; | 1838 nIndex++; |
1816 } | 1839 } |
1817 } | 1840 } |
1818 } | 1841 } |
1819 | 1842 |
1820 if (sPart.GetLength() > 0) { | 1843 if (sPart.GetLength() > 0) { |
1821 nums.SetElement(pRuntime->GetIsolate(), nIndex, | 1844 nums.SetElement(pRuntime->GetIsolate(), nIndex, |
1822 CJS_Value(pRuntime, sPart.c_str())); | 1845 CJS_Value(pRuntime, sPart.c_str())); |
1823 } | 1846 } |
1824 | 1847 |
1825 if (nums.GetLength() > 0) | 1848 if (nums.GetLength() > 0) |
1826 vRet = CJS_Value(pRuntime, nums); | 1849 vRet = CJS_Value(pRuntime, nums); |
1827 else | 1850 else |
1828 vRet.SetNull(); | 1851 vRet.SetNull(pRuntime); |
1829 | 1852 |
1830 return TRUE; | 1853 return TRUE; |
1831 } | 1854 } |
OLD | NEW |