Changeset 246408 in webkit
- Timestamp:
- Jun 13, 2019, 11:47:22 AM (7 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 8 edited
-
JSTests/ChangeLog (modified) (1 diff)
-
JSTests/stress/regexp-bytecode-compilation-fail.js (added)
-
Source/JavaScriptCore/ChangeLog (modified) (1 diff)
-
Source/JavaScriptCore/inspector/ContentSearchUtilities.cpp (modified) (1 diff)
-
Source/JavaScriptCore/runtime/RegExp.cpp (modified) (4 diffs)
-
Source/JavaScriptCore/runtime/RegExpInlines.h (modified) (7 diffs)
-
Source/JavaScriptCore/yarr/RegularExpression.cpp (modified) (1 diff)
-
Source/JavaScriptCore/yarr/YarrInterpreter.cpp (modified) (19 diffs)
-
Source/JavaScriptCore/yarr/YarrInterpreter.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/JSTests/ChangeLog
r246372 r246408 1 2019-06-13 Yusuke Suzuki <ysuzuki@apple.com> 2 3 Yarr bytecode compilation failure should be gracefully handled 4 https://bugs.webkit.org/show_bug.cgi?id=198700 5 6 Reviewed by Michael Saboff. 7 8 * stress/regexp-bytecode-compilation-fail.js: Added. 9 (shouldThrow): 10 1 11 2019-06-12 Yusuke Suzuki <ysuzuki@apple.com> 2 12 -
trunk/Source/JavaScriptCore/ChangeLog
r246372 r246408 1 2019-06-13 Yusuke Suzuki <ysuzuki@apple.com> 2 3 Yarr bytecode compilation failure should be gracefully handled 4 https://bugs.webkit.org/show_bug.cgi?id=198700 5 6 Reviewed by Michael Saboff. 7 8 Currently, we assume that Yarr bytecode compilation does not fail. But in fact it can fail. 9 We should gracefully handle this failure as a runtime error, as we did for parse errors in [1]. 10 We also harden Yarr's consumed character calculation by using Checked. 11 12 [1]: https://bugs.webkit.org/show_bug.cgi?id=185755 13 14 * inspector/ContentSearchUtilities.cpp: 15 (Inspector::ContentSearchUtilities::findMagicComment): 16 * runtime/RegExp.cpp: 17 (JSC::RegExp::byteCodeCompileIfNecessary): 18 (JSC::RegExp::compile): 19 (JSC::RegExp::compileMatchOnly): 20 * runtime/RegExpInlines.h: 21 (JSC::RegExp::matchInline): 22 * yarr/YarrErrorCode.cpp: 23 (JSC::Yarr::errorMessage): 24 (JSC::Yarr::errorToThrow): 25 * yarr/YarrErrorCode.h: 26 * yarr/YarrInterpreter.cpp: 27 (JSC::Yarr::ByteCompiler::ByteCompiler): 28 (JSC::Yarr::ByteCompiler::compile): 29 (JSC::Yarr::ByteCompiler::atomCharacterClass): 30 (JSC::Yarr::ByteCompiler::atomBackReference): 31 (JSC::Yarr::ByteCompiler::atomParenthesesOnceBegin): 32 (JSC::Yarr::ByteCompiler::atomParenthesesTerminalBegin): 33 (JSC::Yarr::ByteCompiler::atomParenthesesSubpatternBegin): 34 (JSC::Yarr::ByteCompiler::atomParentheticalAssertionBegin): 35 (JSC::Yarr::ByteCompiler::popParenthesesStack): 36 (JSC::Yarr::ByteCompiler::closeAlternative): 37 (JSC::Yarr::ByteCompiler::closeBodyAlternative): 38 (JSC::Yarr::ByteCompiler::alternativeBodyDisjunction): 39 (JSC::Yarr::ByteCompiler::alternativeDisjunction): 40 (JSC::Yarr::ByteCompiler::emitDisjunction): 41 1 42 2019-06-12 Yusuke Suzuki <ysuzuki@apple.com> 2 43 -
trunk/Source/JavaScriptCore/inspector/ContentSearchUtilities.cpp
r242699 r246408 172 172 ASSERT(!hasError(error)); 173 173 BumpPointerAllocator regexAllocator; 174 auto bytecodePattern = byteCompile(pattern, ®exAllocator); 175 ASSERT(bytecodePattern); 174 JSC::Yarr::ErrorCode ignoredErrorCode = JSC::Yarr::ErrorCode::NoError; 175 auto bytecodePattern = byteCompile(pattern, ®exAllocator, ignoredErrorCode); 176 RELEASE_ASSERT(bytecodePattern); 176 177 177 178 ASSERT(pattern.m_numSubpatterns == 1); -
trunk/Source/JavaScriptCore/runtime/RegExp.cpp
r244505 r246408 218 218 219 219 220 static std::unique_ptr<Yarr::BytecodePattern> byteCodeCompilePattern(VM* vm, Yarr::YarrPattern& pattern )221 { 222 return Yarr::byteCompile(pattern, &vm->m_regExpAllocator, &vm->m_regExpAllocatorLock);220 static std::unique_ptr<Yarr::BytecodePattern> byteCodeCompilePattern(VM* vm, Yarr::YarrPattern& pattern, Yarr::ErrorCode& errorCode) 221 { 222 return Yarr::byteCompile(pattern, &vm->m_regExpAllocator, errorCode, &vm->m_regExpAllocatorLock); 223 223 } 224 224 … … 238 238 ASSERT(m_numSubpatterns == pattern.m_numSubpatterns); 239 239 240 m_regExpBytecode = byteCodeCompilePattern(vm, pattern); 240 m_regExpBytecode = byteCodeCompilePattern(vm, pattern, m_constructionErrorCode); 241 if (!m_regExpBytecode) { 242 m_state = ParseError; 243 return; 244 } 241 245 } 242 246 … … 279 283 280 284 m_state = ByteCode; 281 m_regExpBytecode = byteCodeCompilePattern(vm, pattern); 285 m_regExpBytecode = byteCodeCompilePattern(vm, pattern, m_constructionErrorCode); 286 if (!m_regExpBytecode) { 287 m_state = ParseError; 288 return; 289 } 282 290 } 283 291 … … 337 345 338 346 m_state = ByteCode; 339 m_regExpBytecode = byteCodeCompilePattern(vm, pattern); 347 m_regExpBytecode = byteCodeCompilePattern(vm, pattern, m_constructionErrorCode); 348 if (!m_regExpBytecode) { 349 m_state = ParseError; 350 return; 351 } 340 352 } 341 353 -
trunk/Source/JavaScriptCore/runtime/RegExpInlines.h
r245593 r246408 140 140 compileIfNecessary(vm, s.is8Bit() ? Yarr::Char8 : Yarr::Char16); 141 141 142 if (m_state == ParseError){142 auto throwError = [&] { 143 143 auto throwScope = DECLARE_THROW_SCOPE(vm); 144 144 ExecState* exec = vm.topCallFrame; … … 147 147 reset(); 148 148 return -1; 149 } 149 }; 150 151 if (m_state == ParseError) 152 return throwError(); 150 153 151 154 int offsetVectorSize = (m_numSubpatterns + 1) * 2; … … 169 172 // JIT'ed code couldn't handle expression, so punt back to the interpreter. 170 173 byteCodeCompileIfNecessary(&vm); 174 if (m_state == ParseError) 175 return throwError(); 171 176 result = Yarr::interpret(m_regExpBytecode.get(), s, startOffset, reinterpret_cast<unsigned*>(offsetVector)); 172 177 } … … 175 180 if (m_state == JITCode) { 176 181 byteCodeCompileIfNecessary(&vm); 182 if (m_state == ParseError) 183 return throwError(); 177 184 matchCompareWithInterpreter(s, startOffset, offsetVector, result); 178 185 } … … 261 268 compileIfNecessaryMatchOnly(vm, s.is8Bit() ? Yarr::Char8 : Yarr::Char16); 262 269 263 if (m_state == ParseError){270 auto throwError = [&] { 264 271 auto throwScope = DECLARE_THROW_SCOPE(vm); 265 272 ExecState* exec = vm.topCallFrame; … … 268 275 reset(); 269 276 return MatchResult::failed(); 270 } 277 }; 278 279 if (m_state == ParseError) 280 return throwError(); 271 281 272 282 #if ENABLE(YARR_JIT) … … 292 302 // JIT'ed code couldn't handle expression, so punt back to the interpreter. 293 303 byteCodeCompileIfNecessary(&vm); 304 if (m_state == ParseError) 305 return throwError(); 294 306 } 295 307 #endif -
trunk/Source/JavaScriptCore/yarr/RegularExpression.cpp
r244286 r246408 71 71 m_numSubpatterns = pattern.m_numSubpatterns; 72 72 73 return JSC::Yarr::byteCompile(pattern, &m_regexAllocator );73 return JSC::Yarr::byteCompile(pattern, &m_regexAllocator, m_constructionErrorCode); 74 74 } 75 75 -
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 break;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 -
trunk/Source/JavaScriptCore/yarr/YarrInterpreter.h
r244286 r246408 27 27 28 28 #include "ConcurrentJSLock.h" 29 #include "YarrErrorCode.h" 29 30 #include "YarrFlags.h" 30 31 #include "YarrPattern.h" … … 390 391 }; 391 392 392 JS_EXPORT_PRIVATE std::unique_ptr<BytecodePattern> byteCompile(YarrPattern&, BumpPointerAllocator*, ConcurrentJSLock* = nullptr);393 JS_EXPORT_PRIVATE std::unique_ptr<BytecodePattern> byteCompile(YarrPattern&, BumpPointerAllocator*, ErrorCode&, ConcurrentJSLock* = nullptr); 393 394 JS_EXPORT_PRIVATE unsigned interpret(BytecodePattern*, const String& input, unsigned start, unsigned* output); 394 395 unsigned interpret(BytecodePattern*, const LChar* input, unsigned length, unsigned start, unsigned* output);
Note:
See TracChangeset
for help on using the changeset viewer.