int RegExp::match(JSGlobalData& globalData, const UString& s, unsigned startOffset, Vector<int, 32>* ovector) { #if ENABLE(REGEXP_TRACING) m_rtMatchCallCount++; #endif ASSERT(m_state != ParseError); compileIfNecessary(globalData, s.is8Bit() ? Yarr::Char8 : Yarr::Char16); int offsetVectorSize = (m_numSubpatterns + 1) * 2; int* offsetVector; Vector<int, 32> nonReturnedOvector; if (ovector) { ovector->resize(offsetVectorSize); offsetVector = ovector->data(); } else { nonReturnedOvector.resize(offsetVectorSize); offsetVector = nonReturnedOvector.data(); } ASSERT(offsetVector); int result; #if ENABLE(YARR_JIT) if (m_state == JITCode) { if (s.is8Bit()) result = Yarr::execute(m_representation->m_regExpJITCode, s.characters8(), startOffset, s.length(), offsetVector); else result = Yarr::execute(m_representation->m_regExpJITCode, s.characters16(), startOffset, s.length(), offsetVector); #if ENABLE(YARR_JIT_DEBUG) matchCompareWithInterpreter(s, startOffset, offsetVector, result); #endif } else #endif result = Yarr::interpret(m_representation->m_regExpBytecode.get(), s, startOffset, s.length(), offsetVector); ASSERT(result >= -1); #if REGEXP_FUNC_TEST_DATA_GEN RegExpFunctionalTestCollector::get()->outputOneTest(this, s, startOffset, offsetVector, result); #endif #if ENABLE(REGEXP_TRACING) if (result != -1) m_rtMatchFoundCount++; #endif return result; }
int RegExp::match(VM& vm, const String& s, unsigned startOffset, Vector<int, 32>& ovector) { #if ENABLE(REGEXP_TRACING) m_rtMatchCallCount++; m_rtMatchTotalSubjectStringLen += (double)(s.length() - startOffset); #endif ASSERT(m_state != ParseError); compileIfNecessary(vm, s.is8Bit() ? Yarr::Char8 : Yarr::Char16); int offsetVectorSize = (m_numSubpatterns + 1) * 2; ovector.resize(offsetVectorSize); int* offsetVector = ovector.data(); int result; #if ENABLE(YARR_JIT) if (m_state == JITCode) { if (s.is8Bit()) result = m_regExpJITCode.execute(s.characters8(), startOffset, s.length(), offsetVector).start; else result = m_regExpJITCode.execute(s.characters16(), startOffset, s.length(), offsetVector).start; #if ENABLE(YARR_JIT_DEBUG) matchCompareWithInterpreter(s, startOffset, offsetVector, result); #endif } else #endif result = Yarr::interpret(m_regExpBytecode.get(), s, startOffset, reinterpret_cast<unsigned*>(offsetVector)); // FIXME: The YARR engine should handle unsigned or size_t length matches. // The YARR Interpreter is "unsigned" clean, while the YARR JIT hasn't been addressed. // The offset vector handling needs to change as well. // Right now we convert a match where the offsets overflowed into match failure. // There are two places in WebCore that call the interpreter directly that need to // have their offsets changed to int as well. They are yarr/RegularExpression.cpp // and inspector/ContentSearchUtilities.cpp if (s.length() > INT_MAX) { bool overflowed = false; if (result < -1) overflowed = true; for (unsigned i = 0; i <= m_numSubpatterns; i++) { if ((offsetVector[i*2] < -1) || ((offsetVector[i*2] >= 0) && (offsetVector[i*2+1] < -1))) { overflowed = true; offsetVector[i*2] = -1; offsetVector[i*2+1] = -1; } } if (overflowed) result = -1; } ASSERT(result >= -1); #if REGEXP_FUNC_TEST_DATA_GEN RegExpFunctionalTestCollector::get()->outputOneTest(this, s, startOffset, offsetVector, result); #endif #if ENABLE(REGEXP_TRACING) if (result != -1) m_rtMatchFoundCount++; #endif return result; }
int RegExp::match(JSGlobalData& globalData, const UString& s, int startOffset, Vector<int, 32>* ovector) { if (startOffset < 0) startOffset = 0; #if ENABLE(REGEXP_TRACING) m_rtMatchCallCount++; #endif if (static_cast<unsigned>(startOffset) > s.length() || s.isNull()) return -1; if (m_state != ParseError) { compileIfNecessary(globalData, s.is8Bit() ? Yarr::Char8 : Yarr::Char16); int offsetVectorSize = (m_numSubpatterns + 1) * 2; int* offsetVector; Vector<int, 32> nonReturnedOvector; if (ovector) { ovector->resize(offsetVectorSize); offsetVector = ovector->data(); } else { nonReturnedOvector.resize(offsetVectorSize); offsetVector = nonReturnedOvector.data(); } ASSERT(offsetVector); // Initialize offsetVector with the return value (index 0) and the // first subpattern start indicies (even index values) set to -1. // No need to init the subpattern end indicies. for (unsigned j = 0, i = 0; i < m_numSubpatterns + 1; j += 2, i++) offsetVector[j] = -1; int result; #if ENABLE(YARR_JIT) if (m_state == JITCode) { if (s.is8Bit()) result = Yarr::execute(m_representation->m_regExpJITCode, s.latin1().data(), startOffset, s.length(), offsetVector); else result = Yarr::execute(m_representation->m_regExpJITCode, s.characters(), startOffset, s.length(), offsetVector); #if ENABLE(YARR_JIT_DEBUG) matchCompareWithInterpreter(s, startOffset, offsetVector, result); #endif } else #endif result = Yarr::interpret(m_representation->m_regExpBytecode.get(), s, startOffset, s.length(), offsetVector); ASSERT(result >= -1); #if REGEXP_FUNC_TEST_DATA_GEN RegExpFunctionalTestCollector::get()->outputOneTest(this, s, startOffset, offsetVector, result); #endif #if ENABLE(REGEXP_TRACING) if (result != -1) m_rtMatchFoundCount++; #endif return result; } return -1; }