diff --git a/ecmascript/builtins/builtins_regexp.cpp b/ecmascript/builtins/builtins_regexp.cpp index 8b4007b09acb12f0a56db39cfe262bd3cca44850..82f411e150da1dbadb92ca6ea4840f70d3d80e98 100644 --- a/ecmascript/builtins/builtins_regexp.cpp +++ b/ecmascript/builtins/builtins_regexp.cpp @@ -2624,16 +2624,17 @@ void RegExpExecResultCache::AddResultInCache(JSThread *thread, JSHandle(CACHE_TABLE_HEADER_SIZE) + static_cast(entry) * static_cast(ENTRY_SIZE)) <= static_cast(UINT32_MAX)); uint32_t index = CACHE_TABLE_HEADER_SIZE + entry * ENTRY_SIZE; + cache->SetUseLastMatch(thread, true); // fast path if (cache->Get(thread, index).IsUndefined()) { cache->SetCacheCount(thread, cache->GetCacheCount() + 1); - cache->SetLastMatchGlobalTableIndex(thread, index); // update last match index - cache->SetUseLastMatch(thread, true); // fast path cache->SetEntry(thread, entry, patternValue, flagsValue, inputValue, lastIndexInputValue, lastIndexValue, extendValue, resTableArrayValue); cache->UpdateResultArray(thread, entry, resultArrayCopy.GetTaggedValue(), type); + cache->SetLastMatchGlobalTableIndex(thread, index); // update last match index } else if (cache->Match(thread, entry, patternValue, flagsValue, inputValue, lastIndexInputValue, extendValue, type)) { cache->UpdateResultArray(thread, entry, resultArrayCopy.GetTaggedValue(), type); + cache->SetLastMatchGlobalTableIndex(thread, index); // update last match index } else { uint32_t entry2 = (entry + 1) & static_cast(cache->GetCacheLength() - 1); ASSERT((static_cast(CACHE_TABLE_HEADER_SIZE) + @@ -2652,10 +2653,9 @@ void RegExpExecResultCache::AddResultInCache(JSThread *thread, JSHandleSetLastMatchGlobalTableIndex(thread, index2); // update last match index if (cache->Get(thread, index2).IsUndefined()) { cache->SetCacheCount(thread, cache->GetCacheCount() + 1); - cache->SetLastMatchGlobalTableIndex(thread, index2); // update last match index - cache->SetUseLastMatch(thread, true); // fast path cache->SetEntry(thread, entry2, patternValue, flagsValue, inputValue, lastIndexInputValue, lastIndexValue, extendValue, resTableArrayValue); cache->UpdateResultArray(thread, entry2, resultArrayCopy.GetTaggedValue(), type); @@ -2666,8 +2666,6 @@ void RegExpExecResultCache::AddResultInCache(JSThread *thread, JSHandleSetConflictCount(thread, cache->GetConflictCount() > 1 ? (cache->GetConflictCount() - 1) : 0); cache->SetCacheCount(thread, cache->GetCacheCount() - 1); cache->ClearEntry(thread, entry2); - cache->SetLastMatchGlobalTableIndex(thread, index2); // update last match index - cache->SetUseLastMatch(thread, true); // fast path cache->SetEntry(thread, entry2, patternValue, flagsValue, inputValue, lastIndexInputValue, lastIndexValue, extendValue, resTableArrayValue); cache->UpdateResultArray(thread, entry2, resultArrayCopy.GetTaggedValue(), type); diff --git a/test/moduletest/regexp/regexp.js b/test/moduletest/regexp/regexp.js index 279b7e07784166d21a139773ab60142e75fdbf12..dd1589c3de794d9b1bc426c516a573214a50a817 100644 --- a/test/moduletest/regexp/regexp.js +++ b/test/moduletest/regexp/regexp.js @@ -672,6 +672,18 @@ relpfun.apply(f, [1, 2, 3, 4]); var s = "success" assert_equal(s,"success"); +{ + let pattern = /^\s*([^;\s]*)/; + let match1 = "text/html".match(pattern); + assert_equal(match1[1], 'text/html'); + + let match2 = "text/plain".match(pattern); + assert_equal(match2[1], 'text/plain'); + + let match3 = "text/html".match(pattern); + assert_equal(match3[1], 'text/html'); +} + { let str = /^\s*([^;\s]*)/; str.test("text/html");