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

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

Issue 1290383003: Fix more sign comparison errors. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: rebase Created 5 years, 4 months 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/fpdftext_embeddertest.cpp ('k') | no next file » | 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 "../../include/javascript/JavaScript.h" 7 #include "../../include/javascript/JavaScript.h"
8 #include "../../include/javascript/IJavaScript.h" 8 #include "../../include/javascript/IJavaScript.h"
9 #include "../../include/javascript/JS_Define.h" 9 #include "../../include/javascript/JS_Define.h"
10 #include "../../include/javascript/JS_Object.h" 10 #include "../../include/javascript/JS_Object.h"
(...skipping 1478 matching lines...) Expand 10 before | Expand all | Expand 10 after
1489 L"d-mmm-yy", 1489 L"d-mmm-yy",
1490 L"dd-mmm-yy", 1490 L"dd-mmm-yy",
1491 L"yy-mm-dd", 1491 L"yy-mm-dd",
1492 L"mmm-yy", 1492 L"mmm-yy",
1493 L"mmmm-yy", 1493 L"mmmm-yy",
1494 L"mmm d, yyyy", 1494 L"mmm d, yyyy",
1495 L"mmmm d, yyyy", 1495 L"mmmm d, yyyy",
1496 L"m/d/yy h:MM tt", 1496 L"m/d/yy h:MM tt",
1497 L"m/d/yy HH:MM"}; 1497 L"m/d/yy HH:MM"};
1498 1498
1499 ASSERT(iIndex < FX_ArraySize(cFormats)); 1499 if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats)))
1500 iIndex = 0;
1500 1501
1501 if (iIndex < 0)
1502 iIndex = 0;
1503 if (iIndex >= FX_ArraySize(cFormats))
1504 iIndex = 0;
1505 CJS_Parameters newParams; 1502 CJS_Parameters newParams;
1506 CJS_Value val(isolate, cFormats[iIndex]); 1503 CJS_Value val(isolate, cFormats[iIndex]);
1507 newParams.push_back(val); 1504 newParams.push_back(val);
1508 return AFDate_FormatEx(cc, newParams, vRet, sError); 1505 return AFDate_FormatEx(cc, newParams, vRet, sError);
1509 } 1506 }
1510 1507
1511 // AFDate_KeystrokeEx(cFormat) 1508 // AFDate_KeystrokeEx(cFormat)
1512 FX_BOOL CJS_PublicMethods::AFDate_Keystroke(IFXJS_Context* cc, 1509 FX_BOOL CJS_PublicMethods::AFDate_Keystroke(IFXJS_Context* cc,
1513 const CJS_Parameters& params, 1510 const CJS_Parameters& params,
1514 CJS_Value& vRet, 1511 CJS_Value& vRet,
(...skipping 17 matching lines...) Expand all
1532 L"d-mmm-yy", 1529 L"d-mmm-yy",
1533 L"dd-mmm-yy", 1530 L"dd-mmm-yy",
1534 L"yy-mm-dd", 1531 L"yy-mm-dd",
1535 L"mmm-yy", 1532 L"mmm-yy",
1536 L"mmmm-yy", 1533 L"mmmm-yy",
1537 L"mmm d, yyyy", 1534 L"mmm d, yyyy",
1538 L"mmmm d, yyyy", 1535 L"mmmm d, yyyy",
1539 L"m/d/yy h:MM tt", 1536 L"m/d/yy h:MM tt",
1540 L"m/d/yy HH:MM"}; 1537 L"m/d/yy HH:MM"};
1541 1538
1542 ASSERT(iIndex < FX_ArraySize(cFormats)); 1539 if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats)))
1540 iIndex = 0;
1543 1541
1544 if (iIndex < 0)
1545 iIndex = 0;
1546 if (iIndex >= FX_ArraySize(cFormats))
1547 iIndex = 0;
1548 CJS_Parameters newParams; 1542 CJS_Parameters newParams;
1549 CJS_Value val(isolate, cFormats[iIndex]); 1543 CJS_Value val(isolate, cFormats[iIndex]);
1550 newParams.push_back(val); 1544 newParams.push_back(val);
1551 return AFDate_KeystrokeEx(cc, newParams, vRet, sError); 1545 return AFDate_KeystrokeEx(cc, newParams, vRet, sError);
1552 } 1546 }
1553 1547
1554 // function AFTime_Format(ptf) 1548 // function AFTime_Format(ptf)
1555 FX_BOOL CJS_PublicMethods::AFTime_Format(IFXJS_Context* cc, 1549 FX_BOOL CJS_PublicMethods::AFTime_Format(IFXJS_Context* cc,
1556 const CJS_Parameters& params, 1550 const CJS_Parameters& params,
1557 CJS_Value& vRet, 1551 CJS_Value& vRet,
1558 CFX_WideString& sError) { 1552 CFX_WideString& sError) {
1559 v8::Isolate* isolate = ::GetIsolate(cc); 1553 v8::Isolate* isolate = ::GetIsolate(cc);
1560 1554
1561 if (params.size() != 1) { 1555 if (params.size() != 1) {
1562 CJS_Context* pContext = (CJS_Context*)cc; 1556 CJS_Context* pContext = (CJS_Context*)cc;
1563 ASSERT(pContext != NULL); 1557 ASSERT(pContext != NULL);
1564 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 1558 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1565 return FALSE; 1559 return FALSE;
1566 } 1560 }
1567 1561
1568 int iIndex = params[0].ToInt(); 1562 int iIndex = params[0].ToInt();
1569 const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", 1563 const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss",
1570 L"h:MM:ss tt"}; 1564 L"h:MM:ss tt"};
1571 1565
1572 ASSERT(iIndex < FX_ArraySize(cFormats)); 1566 if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats)))
1567 iIndex = 0;
1573 1568
1574 if (iIndex < 0)
1575 iIndex = 0;
1576 if (iIndex >= FX_ArraySize(cFormats))
1577 iIndex = 0;
1578 CJS_Parameters newParams; 1569 CJS_Parameters newParams;
1579 CJS_Value val(isolate, cFormats[iIndex]); 1570 CJS_Value val(isolate, cFormats[iIndex]);
1580 newParams.push_back(val); 1571 newParams.push_back(val);
1581 return AFDate_FormatEx(cc, newParams, vRet, sError); 1572 return AFDate_FormatEx(cc, newParams, vRet, sError);
1582 } 1573 }
1583 1574
1584 FX_BOOL CJS_PublicMethods::AFTime_Keystroke(IFXJS_Context* cc, 1575 FX_BOOL CJS_PublicMethods::AFTime_Keystroke(IFXJS_Context* cc,
1585 const CJS_Parameters& params, 1576 const CJS_Parameters& params,
1586 CJS_Value& vRet, 1577 CJS_Value& vRet,
1587 CFX_WideString& sError) { 1578 CFX_WideString& sError) {
1588 v8::Isolate* isolate = ::GetIsolate(cc); 1579 v8::Isolate* isolate = ::GetIsolate(cc);
1589 if (params.size() != 1) { 1580 if (params.size() != 1) {
1590 CJS_Context* pContext = (CJS_Context*)cc; 1581 CJS_Context* pContext = (CJS_Context*)cc;
1591 ASSERT(pContext != NULL); 1582 ASSERT(pContext != NULL);
1592 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 1583 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1593 return FALSE; 1584 return FALSE;
1594 } 1585 }
1595 1586
1596 int iIndex = params[0].ToInt(); 1587 int iIndex = params[0].ToInt();
1597 const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", 1588 const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss",
1598 L"h:MM:ss tt"}; 1589 L"h:MM:ss tt"};
1599 1590
1600 ASSERT(iIndex < FX_ArraySize(cFormats)); 1591 if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats)))
1592 iIndex = 0;
1601 1593
1602 if (iIndex < 0)
1603 iIndex = 0;
1604 if (iIndex >= FX_ArraySize(cFormats))
1605 iIndex = 0;
1606 CJS_Parameters newParams; 1594 CJS_Parameters newParams;
1607 CJS_Value val(isolate, cFormats[iIndex]); 1595 CJS_Value val(isolate, cFormats[iIndex]);
1608 newParams.push_back(val); 1596 newParams.push_back(val);
1609 return AFDate_KeystrokeEx(cc, newParams, vRet, sError); 1597 return AFDate_KeystrokeEx(cc, newParams, vRet, sError);
1610 } 1598 }
1611 1599
1612 FX_BOOL CJS_PublicMethods::AFTime_FormatEx(IFXJS_Context* cc, 1600 FX_BOOL CJS_PublicMethods::AFTime_FormatEx(IFXJS_Context* cc,
1613 const CJS_Parameters& params, 1601 const CJS_Parameters& params,
1614 CJS_Value& vRet, 1602 CJS_Value& vRet,
1615 CFX_WideString& sError) { 1603 CFX_WideString& sError) {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1691 } 1679 }
1692 1680
1693 if (!pEvent->m_pValue) 1681 if (!pEvent->m_pValue)
1694 return FALSE; 1682 return FALSE;
1695 CFX_WideString& valEvent = pEvent->Value(); 1683 CFX_WideString& valEvent = pEvent->Value();
1696 1684
1697 CFX_WideString wstrMask = params[0].ToCFXWideString(); 1685 CFX_WideString wstrMask = params[0].ToCFXWideString();
1698 if (wstrMask.IsEmpty()) 1686 if (wstrMask.IsEmpty())
1699 return TRUE; 1687 return TRUE;
1700 1688
1701 std::wstring wstrValue = valEvent.c_str(); 1689 const size_t wstrMaskLen = wstrMask.GetLength();
1690 const std::wstring wstrValue = valEvent.c_str();
1702 1691
1703 if (pEvent->WillCommit()) { 1692 if (pEvent->WillCommit()) {
1704 if (wstrValue.empty()) 1693 if (wstrValue.empty())
1705 return TRUE; 1694 return TRUE;
1706 int iIndexMask = 0; 1695 size_t iIndexMask = 0;
1707 for (std::wstring::iterator it = wstrValue.begin(); it != wstrValue.end(); 1696 for (const auto& w_Value : wstrValue) {
1708 it++) {
1709 wchar_t w_Value = *it;
1710 if (!maskSatisfied(w_Value, wstrMask[iIndexMask])) 1697 if (!maskSatisfied(w_Value, wstrMask[iIndexMask]))
1711 break; 1698 break;
1712 iIndexMask++; 1699 iIndexMask++;
1713 } 1700 }
1714 1701
1715 if (iIndexMask != wstrMask.GetLength() || 1702 if (iIndexMask != wstrMaskLen ||
1716 (iIndexMask != wstrValue.size() && wstrMask.GetLength() != 0)) { 1703 (iIndexMask != wstrValue.size() && wstrMaskLen != 0)) {
1717 Alert( 1704 Alert(
1718 pContext, 1705 pContext,
1719 JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE).c_str()); 1706 JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE).c_str());
1720 pEvent->Rc() = FALSE; 1707 pEvent->Rc() = FALSE;
1721 } 1708 }
1722 return TRUE; 1709 return TRUE;
1723 } 1710 }
1724 1711
1725 CFX_WideString& wideChange = pEvent->Change(); 1712 CFX_WideString& wideChange = pEvent->Change();
1726 std::wstring wChange = wideChange.c_str(); 1713 std::wstring wChange = wideChange.c_str();
1727 if (wChange.empty()) 1714 if (wChange.empty())
1728 return TRUE; 1715 return TRUE;
1729 1716
1730 int iIndexMask = pEvent->SelStart(); 1717 int iIndexMask = pEvent->SelStart();
1731 1718
1732 if (wstrValue.length() - (pEvent->SelEnd() - pEvent->SelStart()) + 1719 size_t combined_len = wstrValue.length() + wChange.length() -
1733 wChange.length() > 1720 (pEvent->SelEnd() - pEvent->SelStart());
1734 (FX_DWORD)wstrMask.GetLength()) { 1721 if (combined_len > wstrMaskLen) {
1735 Alert(pContext, 1722 Alert(pContext,
1736 JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str()); 1723 JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str());
1737 pEvent->Rc() = FALSE; 1724 pEvent->Rc() = FALSE;
1738 return TRUE; 1725 return TRUE;
1739 } 1726 }
1740 1727
1741 if (iIndexMask >= wstrMask.GetLength() && (!wChange.empty())) { 1728 if (iIndexMask >= wstrMaskLen && (!wChange.empty())) {
1742 Alert(pContext, 1729 Alert(pContext,
1743 JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str()); 1730 JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str());
1744 pEvent->Rc() = FALSE; 1731 pEvent->Rc() = FALSE;
1745 return TRUE; 1732 return TRUE;
1746 } 1733 }
1747 1734
1748 for (std::wstring::iterator it = wChange.begin(); it != wChange.end(); it++) { 1735 for (std::wstring::iterator it = wChange.begin(); it != wChange.end(); it++) {
1749 if (iIndexMask >= wstrMask.GetLength()) { 1736 if (iIndexMask >= wstrMaskLen) {
1750 Alert(pContext, 1737 Alert(pContext,
1751 JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str()); 1738 JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str());
1752 pEvent->Rc() = FALSE; 1739 pEvent->Rc() = FALSE;
1753 return TRUE; 1740 return TRUE;
1754 } 1741 }
1755 wchar_t w_Mask = wstrMask[iIndexMask]; 1742 wchar_t w_Mask = wstrMask[iIndexMask];
1756 if (!isReservedMaskChar(w_Mask)) { 1743 if (!isReservedMaskChar(w_Mask)) {
1757 *it = w_Mask; 1744 *it = w_Mask;
1758 } 1745 }
1759 wchar_t w_Change = *it; 1746 wchar_t w_Change = *it;
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
2132 nums.SetElement(nIndex, CJS_Value(isolate, sPart.c_str())); 2119 nums.SetElement(nIndex, CJS_Value(isolate, sPart.c_str()));
2133 } 2120 }
2134 2121
2135 if (nums.GetLength() > 0) 2122 if (nums.GetLength() > 0)
2136 vRet = nums; 2123 vRet = nums;
2137 else 2124 else
2138 vRet.SetNull(); 2125 vRet.SetNull();
2139 2126
2140 return TRUE; 2127 return TRUE;
2141 } 2128 }
OLDNEW
« no previous file with comments | « fpdfsdk/src/fpdftext_embeddertest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698