Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1101)

Unified Diff: src/regexp/jsregexp.cc

Issue 1630633002: [regexp] correctly advance zero length matches for global/unicode. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@backrefbounds
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/regexp/jsregexp.cc
diff --git a/src/regexp/jsregexp.cc b/src/regexp/jsregexp.cc
index ef2ac41cc0332aa109ce6f8e9c571da7cd1f635f..c188a1d966f93f682374e4fb2a3cfa416e7c07f5 100644
--- a/src/regexp/jsregexp.cc
+++ b/src/regexp/jsregexp.cc
@@ -633,7 +633,6 @@ Handle<JSArray> RegExpImpl::SetLastMatchInfo(Handle<JSArray> last_match_info,
RegExpImpl::GlobalCache::GlobalCache(Handle<JSRegExp> regexp,
Handle<String> subject,
- bool is_global,
Isolate* isolate)
: register_array_(NULL),
register_array_size_(0),
@@ -658,7 +657,8 @@ RegExpImpl::GlobalCache::GlobalCache(Handle<JSRegExp> regexp,
}
}
- if (is_global && !interpreted) {
+ DCHECK_NE(0, regexp->GetFlags() & JSRegExp::kGlobal);
+ if (!interpreted) {
register_array_size_ =
Max(registers_per_match_, Isolate::kJSRegexpStaticOffsetsVectorSize);
max_matches_ = register_array_size_ / registers_per_match_;
@@ -687,6 +687,16 @@ RegExpImpl::GlobalCache::GlobalCache(Handle<JSRegExp> regexp,
last_match[1] = 0;
}
+int RegExpImpl::GlobalCache::AdvanceZeroLength(int last_index) {
+ if ((regexp_->GetFlags() & JSRegExp::kUnicode) != 0 &&
+ last_index + 1 < subject_->length() &&
+ unibrow::Utf16::IsLeadSurrogate(subject_->Get(last_index)) &&
+ unibrow::Utf16::IsTrailSurrogate(subject_->Get(last_index + 1))) {
+ // Advance over the surrogate pair.
+ return last_index + 2;
+ }
+ return last_index + 1;
+}
// -------------------------------------------------------------------
// Implementation of the Irregexp regular expression engine.
@@ -6526,6 +6536,7 @@ RegExpEngine::CompilationResult RegExpEngine::Compile(
bool ignore_case = flags & JSRegExp::kIgnoreCase;
bool is_sticky = flags & JSRegExp::kSticky;
bool is_global = flags & JSRegExp::kGlobal;
+ bool is_unicode = flags & JSRegExp::kUnicode;
RegExpCompiler compiler(isolate, zone, data->capture_count, flags,
is_one_byte);
@@ -6643,10 +6654,13 @@ RegExpEngine::CompilationResult RegExpEngine::Compile(
}
if (is_global) {
- macro_assembler.set_global_mode(
- (data->tree->min_match() > 0)
- ? RegExpMacroAssembler::GLOBAL_NO_ZERO_LENGTH_CHECK
- : RegExpMacroAssembler::GLOBAL);
+ RegExpMacroAssembler::GlobalMode mode = RegExpMacroAssembler::GLOBAL;
+ if (data->tree->min_match() > 0) {
+ mode = RegExpMacroAssembler::GLOBAL_NO_ZERO_LENGTH_CHECK;
+ } else if (is_unicode) {
+ mode = RegExpMacroAssembler::GLOBAL_UNICODE;
+ }
+ macro_assembler.set_global_mode(mode);
}
return compiler.Assemble(&macro_assembler,

Powered by Google App Engine
This is Rietveld 408576698