Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(537)

Side by Side Diff: fpdfsdk/src/javascript/PublicMethods.cpp

Issue 1512763013: Get rid of most instance of 'foo != NULL' (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: nits Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fpdfsdk/src/javascript/JS_Object.cpp ('k') | fpdfsdk/src/javascript/app.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "PublicMethods.h" 7 #include "PublicMethods.h"
8 8
9 #include "Field.h" 9 #include "Field.h"
10 #include "JS_Context.h" 10 #include "JS_Context.h"
(...skipping 1078 matching lines...) Expand 10 before | Expand all | Expand 10 after
1089 } 1089 }
1090 1090
1091 // function AFNumber_Keystroke(nDec, sepStyle, negStyle, currStyle, strCurrency, 1091 // function AFNumber_Keystroke(nDec, sepStyle, negStyle, currStyle, strCurrency,
1092 // bCurrencyPrepend) 1092 // bCurrencyPrepend)
1093 FX_BOOL CJS_PublicMethods::AFNumber_Keystroke( 1093 FX_BOOL CJS_PublicMethods::AFNumber_Keystroke(
1094 IJS_Context* cc, 1094 IJS_Context* cc,
1095 const std::vector<CJS_Value>& params, 1095 const std::vector<CJS_Value>& params,
1096 CJS_Value& vRet, 1096 CJS_Value& vRet,
1097 CFX_WideString& sError) { 1097 CFX_WideString& sError) {
1098 CJS_Context* pContext = (CJS_Context*)cc; 1098 CJS_Context* pContext = (CJS_Context*)cc;
1099 ASSERT(pContext != NULL);
1100 CJS_EventHandler* pEvent = pContext->GetEventHandler(); 1099 CJS_EventHandler* pEvent = pContext->GetEventHandler();
1101 ASSERT(pEvent != NULL);
1102 1100
1103 if (params.size() < 2) 1101 if (params.size() < 2)
1104 return FALSE; 1102 return FALSE;
1105 int iSepStyle = params[1].ToInt(); 1103 int iSepStyle = params[1].ToInt();
1106 1104
1107 if (iSepStyle < 0 || iSepStyle > 3) 1105 if (iSepStyle < 0 || iSepStyle > 3)
1108 iSepStyle = 0; 1106 iSepStyle = 0;
1109 if (!pEvent->m_pValue) 1107 if (!pEvent->m_pValue)
1110 return FALSE; 1108 return FALSE;
1111 CFX_WideString& val = pEvent->Value(); 1109 CFX_WideString& val = pEvent->Value();
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1210 } 1208 }
1211 1209
1212 // function AFPercent_Format(nDec, sepStyle) 1210 // function AFPercent_Format(nDec, sepStyle)
1213 FX_BOOL CJS_PublicMethods::AFPercent_Format( 1211 FX_BOOL CJS_PublicMethods::AFPercent_Format(
1214 IJS_Context* cc, 1212 IJS_Context* cc,
1215 const std::vector<CJS_Value>& params, 1213 const std::vector<CJS_Value>& params,
1216 CJS_Value& vRet, 1214 CJS_Value& vRet,
1217 CFX_WideString& sError) { 1215 CFX_WideString& sError) {
1218 #if _FX_OS_ != _FX_ANDROID_ 1216 #if _FX_OS_ != _FX_ANDROID_
1219 CJS_Context* pContext = (CJS_Context*)cc; 1217 CJS_Context* pContext = (CJS_Context*)cc;
1220 ASSERT(pContext != NULL);
1221 CJS_EventHandler* pEvent = pContext->GetEventHandler(); 1218 CJS_EventHandler* pEvent = pContext->GetEventHandler();
1222 ASSERT(pEvent != NULL);
1223 1219
1224 if (params.size() != 2) { 1220 if (params.size() != 2) {
1225 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 1221 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1226 return FALSE; 1222 return FALSE;
1227 } 1223 }
1228 if (!pEvent->m_pValue) 1224 if (!pEvent->m_pValue)
1229 return FALSE; 1225 return FALSE;
1230 1226
1231 CFX_WideString& Value = pEvent->Value(); 1227 CFX_WideString& Value = pEvent->Value();
1232 CFX_ByteString strValue = StrTrim(CFX_ByteString::FromUnicode(Value)); 1228 CFX_ByteString strValue = StrTrim(CFX_ByteString::FromUnicode(Value));
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1312 CFX_WideString& sError) { 1308 CFX_WideString& sError) {
1313 return AFNumber_Keystroke(cc, params, vRet, sError); 1309 return AFNumber_Keystroke(cc, params, vRet, sError);
1314 } 1310 }
1315 1311
1316 // function AFDate_FormatEx(cFormat) 1312 // function AFDate_FormatEx(cFormat)
1317 FX_BOOL CJS_PublicMethods::AFDate_FormatEx(IJS_Context* cc, 1313 FX_BOOL CJS_PublicMethods::AFDate_FormatEx(IJS_Context* cc,
1318 const std::vector<CJS_Value>& params, 1314 const std::vector<CJS_Value>& params,
1319 CJS_Value& vRet, 1315 CJS_Value& vRet,
1320 CFX_WideString& sError) { 1316 CFX_WideString& sError) {
1321 CJS_Context* pContext = (CJS_Context*)cc; 1317 CJS_Context* pContext = (CJS_Context*)cc;
1322 ASSERT(pContext != NULL);
1323 CJS_EventHandler* pEvent = pContext->GetEventHandler(); 1318 CJS_EventHandler* pEvent = pContext->GetEventHandler();
1324 ASSERT(pEvent != NULL);
1325 1319
1326 if (params.size() != 1) { 1320 if (params.size() != 1) {
1327 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 1321 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1328 return FALSE; 1322 return FALSE;
1329 } 1323 }
1330 if (!pEvent->m_pValue) 1324 if (!pEvent->m_pValue)
1331 return FALSE; 1325 return FALSE;
1332 1326
1333 CFX_WideString& val = pEvent->Value(); 1327 CFX_WideString& val = pEvent->Value();
1334 CFX_WideString strValue = val; 1328 CFX_WideString strValue = val;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1429 return dRet; 1423 return dRet;
1430 } 1424 }
1431 1425
1432 // AFDate_KeystrokeEx(cFormat) 1426 // AFDate_KeystrokeEx(cFormat)
1433 FX_BOOL CJS_PublicMethods::AFDate_KeystrokeEx( 1427 FX_BOOL CJS_PublicMethods::AFDate_KeystrokeEx(
1434 IJS_Context* cc, 1428 IJS_Context* cc,
1435 const std::vector<CJS_Value>& params, 1429 const std::vector<CJS_Value>& params,
1436 CJS_Value& vRet, 1430 CJS_Value& vRet,
1437 CFX_WideString& sError) { 1431 CFX_WideString& sError) {
1438 CJS_Context* pContext = (CJS_Context*)cc; 1432 CJS_Context* pContext = (CJS_Context*)cc;
1439 ASSERT(pContext != NULL);
1440 CJS_EventHandler* pEvent = pContext->GetEventHandler(); 1433 CJS_EventHandler* pEvent = pContext->GetEventHandler();
1441 ASSERT(pEvent != NULL);
1442 1434
1443 if (params.size() != 1) { 1435 if (params.size() != 1) {
1444 sError = L"AFDate_KeystrokeEx's parameters' size r not correct"; 1436 sError = L"AFDate_KeystrokeEx's parameters' size r not correct";
1445 return FALSE; 1437 return FALSE;
1446 } 1438 }
1447 1439
1448 if (pEvent->WillCommit()) { 1440 if (pEvent->WillCommit()) {
1449 if (!pEvent->m_pValue) 1441 if (!pEvent->m_pValue)
1450 return FALSE; 1442 return FALSE;
1451 CFX_WideString strValue = pEvent->Value(); 1443 CFX_WideString strValue = pEvent->Value();
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
1602 return AFDate_KeystrokeEx(cc, params, vRet, sError); 1594 return AFDate_KeystrokeEx(cc, params, vRet, sError);
1603 } 1595 }
1604 1596
1605 // function AFSpecial_Format(psf) 1597 // function AFSpecial_Format(psf)
1606 FX_BOOL CJS_PublicMethods::AFSpecial_Format( 1598 FX_BOOL CJS_PublicMethods::AFSpecial_Format(
1607 IJS_Context* cc, 1599 IJS_Context* cc,
1608 const std::vector<CJS_Value>& params, 1600 const std::vector<CJS_Value>& params,
1609 CJS_Value& vRet, 1601 CJS_Value& vRet,
1610 CFX_WideString& sError) { 1602 CFX_WideString& sError) {
1611 CJS_Context* pContext = (CJS_Context*)cc; 1603 CJS_Context* pContext = (CJS_Context*)cc;
1612 ASSERT(pContext != NULL);
1613 1604
1614 if (params.size() != 1) { 1605 if (params.size() != 1) {
1615 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 1606 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1616 return FALSE; 1607 return FALSE;
1617 } 1608 }
1618 1609
1619 std::string cFormat; 1610 std::string cFormat;
1620 int iIndex = params[0].ToInt(); 1611 int iIndex = params[0].ToInt();
1621 1612
1622 CJS_EventHandler* pEvent = pContext->GetEventHandler(); 1613 CJS_EventHandler* pEvent = pContext->GetEventHandler();
1623 ASSERT(pEvent != NULL);
1624
1625 if (!pEvent->m_pValue) 1614 if (!pEvent->m_pValue)
1626 return FALSE; 1615 return FALSE;
1627 CFX_WideString& Value = pEvent->Value(); 1616 CFX_WideString& Value = pEvent->Value();
1628 std::string strSrc = CFX_ByteString::FromUnicode(Value).c_str(); 1617 std::string strSrc = CFX_ByteString::FromUnicode(Value).c_str();
1629 1618
1630 switch (iIndex) { 1619 switch (iIndex) {
1631 case 0: 1620 case 0:
1632 cFormat = "99999"; 1621 cFormat = "99999";
1633 break; 1622 break;
1634 case 1: 1623 case 1:
(...skipping 19 matching lines...) Expand all
1654 return TRUE; 1643 return TRUE;
1655 } 1644 }
1656 1645
1657 // function AFSpecial_KeystrokeEx(mask) 1646 // function AFSpecial_KeystrokeEx(mask)
1658 FX_BOOL CJS_PublicMethods::AFSpecial_KeystrokeEx( 1647 FX_BOOL CJS_PublicMethods::AFSpecial_KeystrokeEx(
1659 IJS_Context* cc, 1648 IJS_Context* cc,
1660 const std::vector<CJS_Value>& params, 1649 const std::vector<CJS_Value>& params,
1661 CJS_Value& vRet, 1650 CJS_Value& vRet,
1662 CFX_WideString& sError) { 1651 CFX_WideString& sError) {
1663 CJS_Context* pContext = (CJS_Context*)cc; 1652 CJS_Context* pContext = (CJS_Context*)cc;
1664 ASSERT(pContext != NULL);
1665 CJS_EventHandler* pEvent = pContext->GetEventHandler(); 1653 CJS_EventHandler* pEvent = pContext->GetEventHandler();
1666 1654
1667 ASSERT(pEvent != NULL);
1668
1669 if (params.size() < 1) { 1655 if (params.size() < 1) {
1670 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 1656 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1671 return FALSE; 1657 return FALSE;
1672 } 1658 }
1673 1659
1674 if (!pEvent->m_pValue) 1660 if (!pEvent->m_pValue)
1675 return FALSE; 1661 return FALSE;
1676 CFX_WideString& valEvent = pEvent->Value(); 1662 CFX_WideString& valEvent = pEvent->Value();
1677 1663
1678 CFX_WideString wstrMask = params[0].ToCFXWideString(); 1664 CFX_WideString wstrMask = params[0].ToCFXWideString();
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
1798 std::vector<CJS_Value> params2; 1784 std::vector<CJS_Value> params2;
1799 params2.push_back(CJS_Value(CJS_Runtime::FromContext(cc), cFormat.c_str())); 1785 params2.push_back(CJS_Value(CJS_Runtime::FromContext(cc), cFormat.c_str()));
1800 return AFSpecial_KeystrokeEx(cc, params2, vRet, sError); 1786 return AFSpecial_KeystrokeEx(cc, params2, vRet, sError);
1801 } 1787 }
1802 1788
1803 FX_BOOL CJS_PublicMethods::AFMergeChange(IJS_Context* cc, 1789 FX_BOOL CJS_PublicMethods::AFMergeChange(IJS_Context* cc,
1804 const std::vector<CJS_Value>& params, 1790 const std::vector<CJS_Value>& params,
1805 CJS_Value& vRet, 1791 CJS_Value& vRet,
1806 CFX_WideString& sError) { 1792 CFX_WideString& sError) {
1807 CJS_Context* pContext = (CJS_Context*)cc; 1793 CJS_Context* pContext = (CJS_Context*)cc;
1808 ASSERT(pContext != NULL);
1809 CJS_EventHandler* pEventHandler = pContext->GetEventHandler(); 1794 CJS_EventHandler* pEventHandler = pContext->GetEventHandler();
1810 ASSERT(pEventHandler != NULL);
1811 1795
1812 if (params.size() != 1) { 1796 if (params.size() != 1) {
1813 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 1797 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1814 return FALSE; 1798 return FALSE;
1815 } 1799 }
1816 1800
1817 CFX_WideString swValue; 1801 CFX_WideString swValue;
1818 if (pEventHandler->m_pValue) 1802 if (pEventHandler->m_pValue)
1819 swValue = pEventHandler->Value(); 1803 swValue = pEventHandler->Value();
1820 1804
(...skipping 19 matching lines...) Expand all
1840 vRet = (prefix + pEventHandler->Change() + postfix).c_str(); 1824 vRet = (prefix + pEventHandler->Change() + postfix).c_str();
1841 1825
1842 return TRUE; 1826 return TRUE;
1843 } 1827 }
1844 1828
1845 FX_BOOL CJS_PublicMethods::AFParseDateEx(IJS_Context* cc, 1829 FX_BOOL CJS_PublicMethods::AFParseDateEx(IJS_Context* cc,
1846 const std::vector<CJS_Value>& params, 1830 const std::vector<CJS_Value>& params,
1847 CJS_Value& vRet, 1831 CJS_Value& vRet,
1848 CFX_WideString& sError) { 1832 CFX_WideString& sError) {
1849 CJS_Context* pContext = (CJS_Context*)cc; 1833 CJS_Context* pContext = (CJS_Context*)cc;
1850 ASSERT(pContext != NULL); 1834 ASSERT(pContext);
1851 1835
1852 if (params.size() != 2) { 1836 if (params.size() != 2) {
1853 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 1837 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1854 return FALSE; 1838 return FALSE;
1855 } 1839 }
1856 1840
1857 CFX_WideString sValue = params[0].ToCFXWideString(); 1841 CFX_WideString sValue = params[0].ToCFXWideString();
1858 CFX_WideString sFormat = params[1].ToCFXWideString(); 1842 CFX_WideString sFormat = params[1].ToCFXWideString();
1859 1843
1860 FX_BOOL bWrongFormat = FALSE; 1844 FX_BOOL bWrongFormat = FALSE;
(...skipping 10 matching lines...) Expand all
1871 vRet = dDate; 1855 vRet = dDate;
1872 return TRUE; 1856 return TRUE;
1873 } 1857 }
1874 1858
1875 FX_BOOL CJS_PublicMethods::AFSimple(IJS_Context* cc, 1859 FX_BOOL CJS_PublicMethods::AFSimple(IJS_Context* cc,
1876 const std::vector<CJS_Value>& params, 1860 const std::vector<CJS_Value>& params,
1877 CJS_Value& vRet, 1861 CJS_Value& vRet,
1878 CFX_WideString& sError) { 1862 CFX_WideString& sError) {
1879 if (params.size() != 3) { 1863 if (params.size() != 3) {
1880 CJS_Context* pContext = (CJS_Context*)cc; 1864 CJS_Context* pContext = (CJS_Context*)cc;
1881 ASSERT(pContext != NULL); 1865 ASSERT(pContext);
1882 1866
1883 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 1867 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1884 return FALSE; 1868 return FALSE;
1885 } 1869 }
1886 1870
1887 vRet = (double)AF_Simple(params[0].ToCFXWideString().c_str(), 1871 vRet = (double)AF_Simple(params[0].ToCFXWideString().c_str(),
1888 params[1].ToDouble(), params[2].ToDouble()); 1872 params[1].ToDouble(), params[2].ToDouble());
1889 return TRUE; 1873 return TRUE;
1890 } 1874 }
1891 1875
1892 FX_BOOL CJS_PublicMethods::AFMakeNumber(IJS_Context* cc, 1876 FX_BOOL CJS_PublicMethods::AFMakeNumber(IJS_Context* cc,
1893 const std::vector<CJS_Value>& params, 1877 const std::vector<CJS_Value>& params,
1894 CJS_Value& vRet, 1878 CJS_Value& vRet,
1895 CFX_WideString& sError) { 1879 CFX_WideString& sError) {
1896 if (params.size() != 1) { 1880 if (params.size() != 1) {
1897 CJS_Context* pContext = (CJS_Context*)cc; 1881 CJS_Context* pContext = (CJS_Context*)cc;
1898 ASSERT(pContext != NULL); 1882 ASSERT(pContext);
1899 1883
1900 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 1884 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1901 return FALSE; 1885 return FALSE;
1902 } 1886 }
1903 vRet = ParseStringToNumber(params[0].ToCFXWideString().c_str()); 1887 vRet = ParseStringToNumber(params[0].ToCFXWideString().c_str());
1904 return TRUE; 1888 return TRUE;
1905 } 1889 }
1906 1890
1907 FX_BOOL CJS_PublicMethods::AFSimple_Calculate( 1891 FX_BOOL CJS_PublicMethods::AFSimple_Calculate(
1908 IJS_Context* cc, 1892 IJS_Context* cc,
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
2004 1988
2005 /* This function validates the current event to ensure that its value is 1989 /* This function validates the current event to ensure that its value is
2006 ** within the specified range. */ 1990 ** within the specified range. */
2007 1991
2008 FX_BOOL CJS_PublicMethods::AFRange_Validate( 1992 FX_BOOL CJS_PublicMethods::AFRange_Validate(
2009 IJS_Context* cc, 1993 IJS_Context* cc,
2010 const std::vector<CJS_Value>& params, 1994 const std::vector<CJS_Value>& params,
2011 CJS_Value& vRet, 1995 CJS_Value& vRet,
2012 CFX_WideString& sError) { 1996 CFX_WideString& sError) {
2013 CJS_Context* pContext = (CJS_Context*)cc; 1997 CJS_Context* pContext = (CJS_Context*)cc;
2014 ASSERT(pContext != NULL);
2015 CJS_EventHandler* pEvent = pContext->GetEventHandler(); 1998 CJS_EventHandler* pEvent = pContext->GetEventHandler();
2016 ASSERT(pEvent != NULL);
2017 1999
2018 if (params.size() != 4) { 2000 if (params.size() != 4) {
2019 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 2001 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
2020 return FALSE; 2002 return FALSE;
2021 } 2003 }
2022 2004
2023 if (!pEvent->m_pValue) 2005 if (!pEvent->m_pValue)
2024 return FALSE; 2006 return FALSE;
2025 if (pEvent->Value().IsEmpty()) 2007 if (pEvent->Value().IsEmpty())
2026 return TRUE; 2008 return TRUE;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
2090 nums.SetElement(nIndex, CJS_Value(pRuntime, sPart.c_str())); 2072 nums.SetElement(nIndex, CJS_Value(pRuntime, sPart.c_str()));
2091 } 2073 }
2092 2074
2093 if (nums.GetLength() > 0) 2075 if (nums.GetLength() > 0)
2094 vRet = nums; 2076 vRet = nums;
2095 else 2077 else
2096 vRet.SetNull(); 2078 vRet.SetNull();
2097 2079
2098 return TRUE; 2080 return TRUE;
2099 } 2081 }
OLDNEW
« no previous file with comments | « fpdfsdk/src/javascript/JS_Object.cpp ('k') | fpdfsdk/src/javascript/app.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698