Changeset 246408 in webkit for trunk/Source/JavaScriptCore/yarr/YarrInterpreter.cpp
- Timestamp:
- Jun 13, 2019, 11:47:22 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/yarr/YarrInterpreter.cpp
r243642 r246408 1691 1691 : m_pattern(pattern) 1692 1692 { 1693 m_currentAlternativeIndex = 0; 1694 } 1695 1696 std::unique_ptr<BytecodePattern> compile(BumpPointerAllocator* allocator, ConcurrentJSLock* lock) 1693 } 1694 1695 std::unique_ptr<BytecodePattern> compile(BumpPointerAllocator* allocator, ConcurrentJSLock* lock, ErrorCode& errorCode) 1697 1696 { 1698 1697 regexBegin(m_pattern.m_numSubpatterns, m_pattern.m_body->m_callFrameSize, m_pattern.m_body->m_alternatives[0]->onceThrough()); 1699 emitDisjunction(m_pattern.m_body); 1698 if (auto error = emitDisjunction(m_pattern.m_body, 0, 0)) { 1699 errorCode = error.value(); 1700 return nullptr; 1701 } 1700 1702 regexEnd(); 1701 1703 … … 1752 1754 m_bodyDisjunction->terms.append(ByteTerm(characterClass, invert, inputPosition)); 1753 1755 1754 m_bodyDisjunction->terms [m_bodyDisjunction->terms.size() - 1].atom.quantityMaxCount = quantityMaxCount.unsafeGet();1755 m_bodyDisjunction->terms [m_bodyDisjunction->terms.size() - 1].atom.quantityType = quantityType;1756 m_bodyDisjunction->terms [m_bodyDisjunction->terms.size() - 1].frameLocation = frameLocation;1756 m_bodyDisjunction->terms.last().atom.quantityMaxCount = quantityMaxCount.unsafeGet(); 1757 m_bodyDisjunction->terms.last().atom.quantityType = quantityType; 1758 m_bodyDisjunction->terms.last().frameLocation = frameLocation; 1757 1759 } 1758 1760 … … 1763 1765 m_bodyDisjunction->terms.append(ByteTerm::BackReference(subpatternId, inputPosition)); 1764 1766 1765 m_bodyDisjunction->terms [m_bodyDisjunction->terms.size() - 1].atom.quantityMaxCount = quantityMaxCount.unsafeGet();1766 m_bodyDisjunction->terms [m_bodyDisjunction->terms.size() - 1].atom.quantityType = quantityType;1767 m_bodyDisjunction->terms [m_bodyDisjunction->terms.size() - 1].frameLocation = frameLocation;1767 m_bodyDisjunction->terms.last().atom.quantityMaxCount = quantityMaxCount.unsafeGet(); 1768 m_bodyDisjunction->terms.last().atom.quantityType = quantityType; 1769 m_bodyDisjunction->terms.last().frameLocation = frameLocation; 1768 1770 } 1769 1771 1770 1772 void atomParenthesesOnceBegin(unsigned subpatternId, bool capture, unsigned inputPosition, unsigned frameLocation, unsigned alternativeFrameLocation) 1771 1773 { 1772 intbeginTerm = m_bodyDisjunction->terms.size();1774 unsigned beginTerm = m_bodyDisjunction->terms.size(); 1773 1775 1774 1776 m_bodyDisjunction->terms.append(ByteTerm(ByteTerm::TypeParenthesesSubpatternOnceBegin, subpatternId, capture, false, inputPosition)); 1775 m_bodyDisjunction->terms [m_bodyDisjunction->terms.size() - 1].frameLocation = frameLocation;1777 m_bodyDisjunction->terms.last().frameLocation = frameLocation; 1776 1778 m_bodyDisjunction->terms.append(ByteTerm::AlternativeBegin()); 1777 m_bodyDisjunction->terms [m_bodyDisjunction->terms.size() - 1].frameLocation = alternativeFrameLocation;1779 m_bodyDisjunction->terms.last().frameLocation = alternativeFrameLocation; 1778 1780 1779 1781 m_parenthesesStack.append(ParenthesesStackEntry(beginTerm, m_currentAlternativeIndex)); … … 1783 1785 void atomParenthesesTerminalBegin(unsigned subpatternId, bool capture, unsigned inputPosition, unsigned frameLocation, unsigned alternativeFrameLocation) 1784 1786 { 1785 intbeginTerm = m_bodyDisjunction->terms.size();1787 unsigned beginTerm = m_bodyDisjunction->terms.size(); 1786 1788 1787 1789 m_bodyDisjunction->terms.append(ByteTerm(ByteTerm::TypeParenthesesSubpatternTerminalBegin, subpatternId, capture, false, inputPosition)); 1788 m_bodyDisjunction->terms [m_bodyDisjunction->terms.size() - 1].frameLocation = frameLocation;1790 m_bodyDisjunction->terms.last().frameLocation = frameLocation; 1789 1791 m_bodyDisjunction->terms.append(ByteTerm::AlternativeBegin()); 1790 m_bodyDisjunction->terms [m_bodyDisjunction->terms.size() - 1].frameLocation = alternativeFrameLocation;1792 m_bodyDisjunction->terms.last().frameLocation = alternativeFrameLocation; 1791 1793 1792 1794 m_parenthesesStack.append(ParenthesesStackEntry(beginTerm, m_currentAlternativeIndex)); … … 1800 1802 // https://bugs.webkit.org/show_bug.cgi?id=50136 1801 1803 1802 intbeginTerm = m_bodyDisjunction->terms.size();1804 unsigned beginTerm = m_bodyDisjunction->terms.size(); 1803 1805 1804 1806 m_bodyDisjunction->terms.append(ByteTerm(ByteTerm::TypeParenthesesSubpatternOnceBegin, subpatternId, capture, false, inputPosition)); 1805 m_bodyDisjunction->terms [m_bodyDisjunction->terms.size() - 1].frameLocation = frameLocation;1807 m_bodyDisjunction->terms.last().frameLocation = frameLocation; 1806 1808 m_bodyDisjunction->terms.append(ByteTerm::AlternativeBegin()); 1807 m_bodyDisjunction->terms [m_bodyDisjunction->terms.size() - 1].frameLocation = alternativeFrameLocation;1809 m_bodyDisjunction->terms.last().frameLocation = alternativeFrameLocation; 1808 1810 1809 1811 m_parenthesesStack.append(ParenthesesStackEntry(beginTerm, m_currentAlternativeIndex)); … … 1813 1815 void atomParentheticalAssertionBegin(unsigned subpatternId, bool invert, unsigned frameLocation, unsigned alternativeFrameLocation) 1814 1816 { 1815 intbeginTerm = m_bodyDisjunction->terms.size();1817 unsigned beginTerm = m_bodyDisjunction->terms.size(); 1816 1818 1817 1819 m_bodyDisjunction->terms.append(ByteTerm(ByteTerm::TypeParentheticalAssertionBegin, subpatternId, false, invert, 0)); 1818 m_bodyDisjunction->terms [m_bodyDisjunction->terms.size() - 1].frameLocation = frameLocation;1820 m_bodyDisjunction->terms.last().frameLocation = frameLocation; 1819 1821 m_bodyDisjunction->terms.append(ByteTerm::AlternativeBegin()); 1820 m_bodyDisjunction->terms [m_bodyDisjunction->terms.size() - 1].frameLocation = alternativeFrameLocation;1822 m_bodyDisjunction->terms.last().frameLocation = alternativeFrameLocation; 1821 1823 1822 1824 m_parenthesesStack.append(ParenthesesStackEntry(beginTerm, m_currentAlternativeIndex)); … … 1854 1856 { 1855 1857 ASSERT(m_parenthesesStack.size()); 1856 int stackEnd = m_parenthesesStack.size() - 1; 1857 unsigned beginTerm = m_parenthesesStack[stackEnd].beginTerm; 1858 m_currentAlternativeIndex = m_parenthesesStack[stackEnd].savedAlternativeIndex; 1859 m_parenthesesStack.shrink(stackEnd); 1858 unsigned beginTerm = m_parenthesesStack.last().beginTerm; 1859 m_currentAlternativeIndex = m_parenthesesStack.last().savedAlternativeIndex; 1860 m_parenthesesStack.removeLast(); 1860 1861 1861 1862 ASSERT(beginTerm < m_bodyDisjunction->terms.size()); … … 1865 1866 } 1866 1867 1867 void closeAlternative( intbeginTerm)1868 { 1869 intorigBeginTerm = beginTerm;1868 void closeAlternative(unsigned beginTerm) 1869 { 1870 unsigned origBeginTerm = beginTerm; 1870 1871 ASSERT(m_bodyDisjunction->terms[beginTerm].type == ByteTerm::TypeAlternativeBegin); 1871 intendIndex = m_bodyDisjunction->terms.size();1872 unsigned endIndex = m_bodyDisjunction->terms.size(); 1872 1873 1873 1874 unsigned frameLocation = m_bodyDisjunction->terms[beginTerm].frameLocation; … … 1892 1893 void closeBodyAlternative() 1893 1894 { 1894 intbeginTerm = 0;1895 intorigBeginTerm = 0;1895 unsigned beginTerm = 0; 1896 unsigned origBeginTerm = 0; 1896 1897 ASSERT(m_bodyDisjunction->terms[beginTerm].type == ByteTerm::TypeBodyAlternativeBegin); 1897 intendIndex = m_bodyDisjunction->terms.size();1898 unsigned endIndex = m_bodyDisjunction->terms.size(); 1898 1899 1899 1900 unsigned frameLocation = m_bodyDisjunction->terms[beginTerm].frameLocation; … … 2010 2011 void alternativeBodyDisjunction(bool onceThrough) 2011 2012 { 2012 intnewAlternativeIndex = m_bodyDisjunction->terms.size();2013 unsigned newAlternativeIndex = m_bodyDisjunction->terms.size(); 2013 2014 m_bodyDisjunction->terms[m_currentAlternativeIndex].alternative.next = newAlternativeIndex - m_currentAlternativeIndex; 2014 2015 m_bodyDisjunction->terms.append(ByteTerm::BodyAlternativeDisjunction(onceThrough)); … … 2019 2020 void alternativeDisjunction() 2020 2021 { 2021 intnewAlternativeIndex = m_bodyDisjunction->terms.size();2022 unsigned newAlternativeIndex = m_bodyDisjunction->terms.size(); 2022 2023 m_bodyDisjunction->terms[m_currentAlternativeIndex].alternative.next = newAlternativeIndex - m_currentAlternativeIndex; 2023 2024 m_bodyDisjunction->terms.append(ByteTerm::AlternativeDisjunction()); … … 2026 2027 } 2027 2028 2028 void emitDisjunction(PatternDisjunction* disjunction, unsigned inputCountAlreadyChecked = 0, unsigned parenthesesInputCountAlreadyChecked = 0)2029 Optional<ErrorCode> WARN_UNUSED_RETURN emitDisjunction(PatternDisjunction* disjunction, Checked<unsigned, RecordOverflow> inputCountAlreadyChecked, unsigned parenthesesInputCountAlreadyChecked) 2029 2030 { 2030 2031 for (unsigned alt = 0; alt < disjunction->m_alternatives.size(); ++alt) { 2031 unsignedcurrentCountAlreadyChecked = inputCountAlreadyChecked;2032 auto currentCountAlreadyChecked = inputCountAlreadyChecked; 2032 2033 2033 2034 PatternAlternative* alternative = disjunction->m_alternatives[alt].get(); … … 2047 2048 checkInput(countToCheck); 2048 2049 currentCountAlreadyChecked += countToCheck; 2050 if (currentCountAlreadyChecked.hasOverflowed()) 2051 return ErrorCode::OffsetTooLarge; 2049 2052 } 2050 2053 … … 2052 2055 switch (term.type) { 2053 2056 case PatternTerm::TypeAssertionBOL: 2054 assertionBOL( currentCountAlreadyChecked - term.inputPosition);2057 assertionBOL((currentCountAlreadyChecked - term.inputPosition).unsafeGet()); 2055 2058 break; 2056 2059 2057 2060 case PatternTerm::TypeAssertionEOL: 2058 assertionEOL( currentCountAlreadyChecked - term.inputPosition);2061 assertionEOL((currentCountAlreadyChecked - term.inputPosition).unsafeGet()); 2059 2062 break; 2060 2063 2061 2064 case PatternTerm::TypeAssertionWordBoundary: 2062 assertionWordBoundary(term.invert(), currentCountAlreadyChecked - term.inputPosition);2065 assertionWordBoundary(term.invert(), (currentCountAlreadyChecked - term.inputPosition).unsafeGet()); 2063 2066 break; 2064 2067 2065 2068 case PatternTerm::TypePatternCharacter: 2066 atomPatternCharacter(term.patternCharacter, currentCountAlreadyChecked - term.inputPosition, term.frameLocation, term.quantityMaxCount, term.quantityType);2069 atomPatternCharacter(term.patternCharacter, (currentCountAlreadyChecked - term.inputPosition).unsafeGet(), term.frameLocation, term.quantityMaxCount, term.quantityType); 2067 2070 break; 2068 2071 2069 2072 case PatternTerm::TypeCharacterClass: 2070 atomCharacterClass(term.characterClass, term.invert(), currentCountAlreadyChecked- term.inputPosition, term.frameLocation, term.quantityMaxCount, term.quantityType);2073 atomCharacterClass(term.characterClass, term.invert(), (currentCountAlreadyChecked - term.inputPosition).unsafeGet(), term.frameLocation, term.quantityMaxCount, term.quantityType); 2071 2074 break; 2072 2075 2073 2076 case PatternTerm::TypeBackReference: 2074 atomBackReference(term.backReferenceSubpatternId, currentCountAlreadyChecked - term.inputPosition, term.frameLocation, term.quantityMaxCount, term.quantityType);2075 2077 atomBackReference(term.backReferenceSubpatternId, (currentCountAlreadyChecked - term.inputPosition).unsafeGet(), term.frameLocation, term.quantityMaxCount, term.quantityType); 2078 break; 2076 2079 2077 2080 case PatternTerm::TypeForwardReference: … … 2087 2090 else 2088 2091 alternativeFrameLocation += YarrStackSpaceForBackTrackInfoParenthesesOnce; 2089 ASSERT(currentCountAlreadyChecked >= term.inputPosition); 2090 unsigned delegateEndInputOffset = currentCountAlreadyChecked - term.inputPosition; 2092 unsigned delegateEndInputOffset = (currentCountAlreadyChecked - term.inputPosition).unsafeGet(); 2091 2093 atomParenthesesOnceBegin(term.parentheses.subpatternId, term.capture(), disjunctionAlreadyCheckedCount + delegateEndInputOffset, term.frameLocation, alternativeFrameLocation); 2092 emitDisjunction(term.parentheses.disjunction, currentCountAlreadyChecked, disjunctionAlreadyCheckedCount); 2094 if (auto error = emitDisjunction(term.parentheses.disjunction, currentCountAlreadyChecked, disjunctionAlreadyCheckedCount)) 2095 return error; 2093 2096 atomParenthesesOnceEnd(delegateEndInputOffset, term.frameLocation, term.quantityMinCount, term.quantityMaxCount, term.quantityType); 2094 2097 } else if (term.parentheses.isTerminal) { 2095 ASSERT(currentCountAlreadyChecked >= term.inputPosition); 2096 unsigned delegateEndInputOffset = currentCountAlreadyChecked - term.inputPosition; 2098 unsigned delegateEndInputOffset = (currentCountAlreadyChecked - term.inputPosition).unsafeGet(); 2097 2099 atomParenthesesTerminalBegin(term.parentheses.subpatternId, term.capture(), disjunctionAlreadyCheckedCount + delegateEndInputOffset, term.frameLocation, term.frameLocation + YarrStackSpaceForBackTrackInfoParenthesesTerminal); 2098 emitDisjunction(term.parentheses.disjunction, currentCountAlreadyChecked, disjunctionAlreadyCheckedCount); 2100 if (auto error = emitDisjunction(term.parentheses.disjunction, currentCountAlreadyChecked, disjunctionAlreadyCheckedCount)) 2101 return error; 2099 2102 atomParenthesesTerminalEnd(delegateEndInputOffset, term.frameLocation, term.quantityMinCount, term.quantityMaxCount, term.quantityType); 2100 2103 } else { 2101 ASSERT(currentCountAlreadyChecked >= term.inputPosition); 2102 unsigned delegateEndInputOffset = currentCountAlreadyChecked - term.inputPosition; 2104 unsigned delegateEndInputOffset = (currentCountAlreadyChecked - term.inputPosition).unsafeGet(); 2103 2105 atomParenthesesSubpatternBegin(term.parentheses.subpatternId, term.capture(), disjunctionAlreadyCheckedCount + delegateEndInputOffset, term.frameLocation, 0); 2104 emitDisjunction(term.parentheses.disjunction, currentCountAlreadyChecked, 0); 2106 if (auto error = emitDisjunction(term.parentheses.disjunction, currentCountAlreadyChecked, 0)) 2107 return error; 2105 2108 atomParenthesesSubpatternEnd(term.parentheses.lastSubpatternId, delegateEndInputOffset, term.frameLocation, term.quantityMinCount, term.quantityMaxCount, term.quantityType, term.parentheses.disjunction->m_callFrameSize); 2106 2109 } … … 2110 2113 case PatternTerm::TypeParentheticalAssertion: { 2111 2114 unsigned alternativeFrameLocation = term.frameLocation + YarrStackSpaceForBackTrackInfoParentheticalAssertion; 2112 2113 ASSERT(currentCountAlreadyChecked >= term.inputPosition); 2114 unsigned positiveInputOffset = currentCountAlreadyChecked - term.inputPosition; 2115 unsigned positiveInputOffset = (currentCountAlreadyChecked - term.inputPosition).unsafeGet(); 2115 2116 unsigned uncheckAmount = 0; 2116 2117 if (positiveInputOffset > term.parentheses.disjunction->m_minimumSize) { … … 2118 2119 uncheckInput(uncheckAmount); 2119 2120 currentCountAlreadyChecked -= uncheckAmount; 2121 if (currentCountAlreadyChecked.hasOverflowed()) 2122 return ErrorCode::OffsetTooLarge; 2120 2123 } 2121 2124 2122 2125 atomParentheticalAssertionBegin(term.parentheses.subpatternId, term.invert(), term.frameLocation, alternativeFrameLocation); 2123 emitDisjunction(term.parentheses.disjunction, currentCountAlreadyChecked, positiveInputOffset - uncheckAmount); 2126 if (auto error = emitDisjunction(term.parentheses.disjunction, currentCountAlreadyChecked, positiveInputOffset - uncheckAmount)) 2127 return error; 2124 2128 atomParentheticalAssertionEnd(0, term.frameLocation, term.quantityMaxCount, term.quantityType); 2125 2129 if (uncheckAmount) { 2126 2130 checkInput(uncheckAmount); 2127 2131 currentCountAlreadyChecked += uncheckAmount; 2132 if (currentCountAlreadyChecked.hasOverflowed()) 2133 return ErrorCode::OffsetTooLarge; 2128 2134 } 2129 2135 break; … … 2136 2142 } 2137 2143 } 2144 return WTF::nullopt; 2138 2145 } 2139 2146 #ifndef NDEBUG … … 2401 2408 YarrPattern& m_pattern; 2402 2409 std::unique_ptr<ByteDisjunction> m_bodyDisjunction; 2403 unsigned m_currentAlternativeIndex ;2410 unsigned m_currentAlternativeIndex { 0 }; 2404 2411 Vector<ParenthesesStackEntry> m_parenthesesStack; 2405 2412 Vector<std::unique_ptr<ByteDisjunction>> m_allParenthesesInfo; 2406 2413 }; 2407 2414 2408 std::unique_ptr<BytecodePattern> byteCompile(YarrPattern& pattern, BumpPointerAllocator* allocator, ConcurrentJSLock* lock)2415 std::unique_ptr<BytecodePattern> byteCompile(YarrPattern& pattern, BumpPointerAllocator* allocator, ErrorCode& errorCode, ConcurrentJSLock* lock) 2409 2416 { 2410 return ByteCompiler(pattern).compile(allocator, lock );2417 return ByteCompiler(pattern).compile(allocator, lock, errorCode); 2411 2418 } 2412 2419
Note:
See TracChangeset
for help on using the changeset viewer.