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 "../../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 Loading... | |
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 ASSERT(iIndex < FX_ArraySize(cFormats)); |
Tom Sepez
2015/08/17 19:18:03
Nit: do we need to assert if we handle it cleanly
Lei Zhang
2015/08/17 19:19:28
nope.
| |
1500 if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats))) | |
1501 iIndex = 0; | |
1500 | 1502 |
1501 if (iIndex < 0) | |
1502 iIndex = 0; | |
1503 if (iIndex >= FX_ArraySize(cFormats)) | |
1504 iIndex = 0; | |
1505 CJS_Parameters newParams; | 1503 CJS_Parameters newParams; |
1506 CJS_Value val(isolate, cFormats[iIndex]); | 1504 CJS_Value val(isolate, cFormats[iIndex]); |
1507 newParams.push_back(val); | 1505 newParams.push_back(val); |
1508 return AFDate_FormatEx(cc, newParams, vRet, sError); | 1506 return AFDate_FormatEx(cc, newParams, vRet, sError); |
1509 } | 1507 } |
1510 | 1508 |
1511 // AFDate_KeystrokeEx(cFormat) | 1509 // AFDate_KeystrokeEx(cFormat) |
1512 FX_BOOL CJS_PublicMethods::AFDate_Keystroke(IFXJS_Context* cc, | 1510 FX_BOOL CJS_PublicMethods::AFDate_Keystroke(IFXJS_Context* cc, |
1513 const CJS_Parameters& params, | 1511 const CJS_Parameters& params, |
1514 CJS_Value& vRet, | 1512 CJS_Value& vRet, |
(...skipping 18 matching lines...) Expand all Loading... | |
1533 L"dd-mmm-yy", | 1531 L"dd-mmm-yy", |
1534 L"yy-mm-dd", | 1532 L"yy-mm-dd", |
1535 L"mmm-yy", | 1533 L"mmm-yy", |
1536 L"mmmm-yy", | 1534 L"mmmm-yy", |
1537 L"mmm d, yyyy", | 1535 L"mmm d, yyyy", |
1538 L"mmmm d, yyyy", | 1536 L"mmmm d, yyyy", |
1539 L"m/d/yy h:MM tt", | 1537 L"m/d/yy h:MM tt", |
1540 L"m/d/yy HH:MM"}; | 1538 L"m/d/yy HH:MM"}; |
1541 | 1539 |
1542 ASSERT(iIndex < FX_ArraySize(cFormats)); | 1540 ASSERT(iIndex < FX_ArraySize(cFormats)); |
1541 if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats))) | |
1542 iIndex = 0; | |
1543 | 1543 |
1544 if (iIndex < 0) | |
1545 iIndex = 0; | |
1546 if (iIndex >= FX_ArraySize(cFormats)) | |
1547 iIndex = 0; | |
1548 CJS_Parameters newParams; | 1544 CJS_Parameters newParams; |
1549 CJS_Value val(isolate, cFormats[iIndex]); | 1545 CJS_Value val(isolate, cFormats[iIndex]); |
1550 newParams.push_back(val); | 1546 newParams.push_back(val); |
1551 return AFDate_KeystrokeEx(cc, newParams, vRet, sError); | 1547 return AFDate_KeystrokeEx(cc, newParams, vRet, sError); |
1552 } | 1548 } |
1553 | 1549 |
1554 // function AFTime_Format(ptf) | 1550 // function AFTime_Format(ptf) |
1555 FX_BOOL CJS_PublicMethods::AFTime_Format(IFXJS_Context* cc, | 1551 FX_BOOL CJS_PublicMethods::AFTime_Format(IFXJS_Context* cc, |
1556 const CJS_Parameters& params, | 1552 const CJS_Parameters& params, |
1557 CJS_Value& vRet, | 1553 CJS_Value& vRet, |
1558 CFX_WideString& sError) { | 1554 CFX_WideString& sError) { |
1559 v8::Isolate* isolate = ::GetIsolate(cc); | 1555 v8::Isolate* isolate = ::GetIsolate(cc); |
1560 | 1556 |
1561 if (params.size() != 1) { | 1557 if (params.size() != 1) { |
1562 CJS_Context* pContext = (CJS_Context*)cc; | 1558 CJS_Context* pContext = (CJS_Context*)cc; |
1563 ASSERT(pContext != NULL); | 1559 ASSERT(pContext != NULL); |
1564 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1560 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
1565 return FALSE; | 1561 return FALSE; |
1566 } | 1562 } |
1567 | 1563 |
1568 int iIndex = params[0].ToInt(); | 1564 int iIndex = params[0].ToInt(); |
1569 const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", | 1565 const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", |
1570 L"h:MM:ss tt"}; | 1566 L"h:MM:ss tt"}; |
1571 | 1567 |
1572 ASSERT(iIndex < FX_ArraySize(cFormats)); | 1568 ASSERT(iIndex < FX_ArraySize(cFormats)); |
1569 if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats))) | |
1570 iIndex = 0; | |
1573 | 1571 |
1574 if (iIndex < 0) | |
1575 iIndex = 0; | |
1576 if (iIndex >= FX_ArraySize(cFormats)) | |
1577 iIndex = 0; | |
1578 CJS_Parameters newParams; | 1572 CJS_Parameters newParams; |
1579 CJS_Value val(isolate, cFormats[iIndex]); | 1573 CJS_Value val(isolate, cFormats[iIndex]); |
1580 newParams.push_back(val); | 1574 newParams.push_back(val); |
1581 return AFDate_FormatEx(cc, newParams, vRet, sError); | 1575 return AFDate_FormatEx(cc, newParams, vRet, sError); |
1582 } | 1576 } |
1583 | 1577 |
1584 FX_BOOL CJS_PublicMethods::AFTime_Keystroke(IFXJS_Context* cc, | 1578 FX_BOOL CJS_PublicMethods::AFTime_Keystroke(IFXJS_Context* cc, |
1585 const CJS_Parameters& params, | 1579 const CJS_Parameters& params, |
1586 CJS_Value& vRet, | 1580 CJS_Value& vRet, |
1587 CFX_WideString& sError) { | 1581 CFX_WideString& sError) { |
1588 v8::Isolate* isolate = ::GetIsolate(cc); | 1582 v8::Isolate* isolate = ::GetIsolate(cc); |
1589 if (params.size() != 1) { | 1583 if (params.size() != 1) { |
1590 CJS_Context* pContext = (CJS_Context*)cc; | 1584 CJS_Context* pContext = (CJS_Context*)cc; |
1591 ASSERT(pContext != NULL); | 1585 ASSERT(pContext != NULL); |
1592 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1586 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
1593 return FALSE; | 1587 return FALSE; |
1594 } | 1588 } |
1595 | 1589 |
1596 int iIndex = params[0].ToInt(); | 1590 int iIndex = params[0].ToInt(); |
1597 const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", | 1591 const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", |
1598 L"h:MM:ss tt"}; | 1592 L"h:MM:ss tt"}; |
1599 | 1593 |
1600 ASSERT(iIndex < FX_ArraySize(cFormats)); | 1594 ASSERT(iIndex < FX_ArraySize(cFormats)); |
1595 if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats))) | |
1596 iIndex = 0; | |
1601 | 1597 |
1602 if (iIndex < 0) | |
1603 iIndex = 0; | |
1604 if (iIndex >= FX_ArraySize(cFormats)) | |
1605 iIndex = 0; | |
1606 CJS_Parameters newParams; | 1598 CJS_Parameters newParams; |
1607 CJS_Value val(isolate, cFormats[iIndex]); | 1599 CJS_Value val(isolate, cFormats[iIndex]); |
1608 newParams.push_back(val); | 1600 newParams.push_back(val); |
1609 return AFDate_KeystrokeEx(cc, newParams, vRet, sError); | 1601 return AFDate_KeystrokeEx(cc, newParams, vRet, sError); |
1610 } | 1602 } |
1611 | 1603 |
1612 FX_BOOL CJS_PublicMethods::AFTime_FormatEx(IFXJS_Context* cc, | 1604 FX_BOOL CJS_PublicMethods::AFTime_FormatEx(IFXJS_Context* cc, |
1613 const CJS_Parameters& params, | 1605 const CJS_Parameters& params, |
1614 CJS_Value& vRet, | 1606 CJS_Value& vRet, |
1615 CFX_WideString& sError) { | 1607 CFX_WideString& sError) { |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1691 } | 1683 } |
1692 | 1684 |
1693 if (!pEvent->m_pValue) | 1685 if (!pEvent->m_pValue) |
1694 return FALSE; | 1686 return FALSE; |
1695 CFX_WideString& valEvent = pEvent->Value(); | 1687 CFX_WideString& valEvent = pEvent->Value(); |
1696 | 1688 |
1697 CFX_WideString wstrMask = params[0].ToCFXWideString(); | 1689 CFX_WideString wstrMask = params[0].ToCFXWideString(); |
1698 if (wstrMask.IsEmpty()) | 1690 if (wstrMask.IsEmpty()) |
1699 return TRUE; | 1691 return TRUE; |
1700 | 1692 |
1701 std::wstring wstrValue = valEvent.c_str(); | 1693 const size_t wstrMaskLen = wstrMask.GetLength(); |
1694 const std::wstring wstrValue = valEvent.c_str(); | |
1702 | 1695 |
1703 if (pEvent->WillCommit()) { | 1696 if (pEvent->WillCommit()) { |
1704 if (wstrValue.empty()) | 1697 if (wstrValue.empty()) |
1705 return TRUE; | 1698 return TRUE; |
1706 int iIndexMask = 0; | 1699 size_t iIndexMask = 0; |
1707 for (std::wstring::iterator it = wstrValue.begin(); it != wstrValue.end(); | 1700 for (const auto& w_Value : wstrValue) { |
1708 it++) { | |
1709 wchar_t w_Value = *it; | |
1710 if (!maskSatisfied(w_Value, wstrMask[iIndexMask])) | 1701 if (!maskSatisfied(w_Value, wstrMask[iIndexMask])) |
1711 break; | 1702 break; |
1712 iIndexMask++; | 1703 iIndexMask++; |
1713 } | 1704 } |
1714 | 1705 |
1715 if (iIndexMask != wstrMask.GetLength() || | 1706 if (iIndexMask != wstrMaskLen || |
1716 (iIndexMask != wstrValue.size() && wstrMask.GetLength() != 0)) { | 1707 (iIndexMask != wstrValue.size() && wstrMaskLen != 0)) { |
1717 Alert( | 1708 Alert( |
1718 pContext, | 1709 pContext, |
1719 JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE).c_str()); | 1710 JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE).c_str()); |
1720 pEvent->Rc() = FALSE; | 1711 pEvent->Rc() = FALSE; |
1721 } | 1712 } |
1722 return TRUE; | 1713 return TRUE; |
1723 } | 1714 } |
1724 | 1715 |
1725 CFX_WideString& wideChange = pEvent->Change(); | 1716 CFX_WideString& wideChange = pEvent->Change(); |
1726 std::wstring wChange = wideChange.c_str(); | 1717 std::wstring wChange = wideChange.c_str(); |
1727 if (wChange.empty()) | 1718 if (wChange.empty()) |
1728 return TRUE; | 1719 return TRUE; |
1729 | 1720 |
1730 int iIndexMask = pEvent->SelStart(); | 1721 int iIndexMask = pEvent->SelStart(); |
1731 | 1722 |
1732 if (wstrValue.length() - (pEvent->SelEnd() - pEvent->SelStart()) + | 1723 size_t combined_len = wstrValue.length() + wChange.length() - |
1733 wChange.length() > | 1724 (pEvent->SelEnd() - pEvent->SelStart()); |
1734 (FX_DWORD)wstrMask.GetLength()) { | 1725 if (combined_len > wstrMaskLen) { |
1735 Alert(pContext, | 1726 Alert(pContext, |
1736 JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str()); | 1727 JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str()); |
1737 pEvent->Rc() = FALSE; | 1728 pEvent->Rc() = FALSE; |
1738 return TRUE; | 1729 return TRUE; |
1739 } | 1730 } |
1740 | 1731 |
1741 if (iIndexMask >= wstrMask.GetLength() && (!wChange.empty())) { | 1732 if (iIndexMask >= wstrMaskLen && (!wChange.empty())) { |
1742 Alert(pContext, | 1733 Alert(pContext, |
1743 JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str()); | 1734 JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str()); |
1744 pEvent->Rc() = FALSE; | 1735 pEvent->Rc() = FALSE; |
1745 return TRUE; | 1736 return TRUE; |
1746 } | 1737 } |
1747 | 1738 |
1748 for (std::wstring::iterator it = wChange.begin(); it != wChange.end(); it++) { | 1739 for (std::wstring::iterator it = wChange.begin(); it != wChange.end(); it++) { |
1749 if (iIndexMask >= wstrMask.GetLength()) { | 1740 if (iIndexMask >= wstrMaskLen) { |
1750 Alert(pContext, | 1741 Alert(pContext, |
1751 JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str()); | 1742 JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str()); |
1752 pEvent->Rc() = FALSE; | 1743 pEvent->Rc() = FALSE; |
1753 return TRUE; | 1744 return TRUE; |
1754 } | 1745 } |
1755 wchar_t w_Mask = wstrMask[iIndexMask]; | 1746 wchar_t w_Mask = wstrMask[iIndexMask]; |
1756 if (!isReservedMaskChar(w_Mask)) { | 1747 if (!isReservedMaskChar(w_Mask)) { |
1757 *it = w_Mask; | 1748 *it = w_Mask; |
1758 } | 1749 } |
1759 wchar_t w_Change = *it; | 1750 wchar_t w_Change = *it; |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2132 nums.SetElement(nIndex, CJS_Value(isolate, sPart.c_str())); | 2123 nums.SetElement(nIndex, CJS_Value(isolate, sPart.c_str())); |
2133 } | 2124 } |
2134 | 2125 |
2135 if (nums.GetLength() > 0) | 2126 if (nums.GetLength() > 0) |
2136 vRet = nums; | 2127 vRet = nums; |
2137 else | 2128 else |
2138 vRet.SetNull(); | 2129 vRet.SetNull(); |
2139 | 2130 |
2140 return TRUE; | 2131 return TRUE; |
2141 } | 2132 } |
OLD | NEW |