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

Unified Diff: src/runtime/runtime-regexp.cc

Issue 2786933002: [regexp] Only access result.groups if named captures are enabled (Closed)
Patch Set: Created 3 years, 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime/runtime-regexp.cc
diff --git a/src/runtime/runtime-regexp.cc b/src/runtime/runtime-regexp.cc
index 5005a5ecda6e1223d7931588af8d0b39516e874d..c887d459e76dfc5a8d1c23285e4d2f3a8aa8c0c9 100644
--- a/src/runtime/runtime-regexp.cc
+++ b/src/runtime/runtime-regexp.cc
@@ -1116,6 +1116,7 @@ class VectorBackedMatch : public String::Match {
Handle<JSObject> ConstructNamedCaptureGroupsObject(
Isolate* isolate, Handle<FixedArray> capture_map,
std::function<Object*(int)> f_get_capture) {
+ DCHECK(FLAG_harmony_regexp_named_captures);
Handle<JSObject> groups = isolate->factory()->NewJSObjectWithNullProto();
const int capture_count = capture_map->length() >> 1;
@@ -1228,6 +1229,7 @@ static Object* SearchRegExpMultiple(Isolate* isolate, Handle<String> subject,
Handle<Object> maybe_capture_map(regexp->CaptureNameMap(), isolate);
const bool has_named_captures = maybe_capture_map->IsFixedArray();
+ DCHECK_IMPLIES(has_named_captures, FLAG_harmony_regexp_named_captures);
const int argc =
has_named_captures ? 4 + capture_count : 3 + capture_count;
@@ -1254,7 +1256,6 @@ static Object* SearchRegExpMultiple(Isolate* isolate, Handle<String> subject,
elements->set(cursor++, *subject);
if (has_named_captures) {
- DCHECK(FLAG_harmony_regexp_named_captures);
Handle<FixedArray> capture_map =
Handle<FixedArray>::cast(maybe_capture_map);
Handle<JSObject> groups = ConstructNamedCaptureGroupsObject(
@@ -1499,12 +1500,12 @@ RUNTIME_FUNCTION(Runtime_StringReplaceNonGlobalRegExpWithFunction) {
Object* maybe_capture_map = regexp->CaptureNameMap();
if (maybe_capture_map->IsFixedArray()) {
- DCHECK(FLAG_harmony_regexp_named_captures);
has_named_captures = true;
capture_map = handle(FixedArray::cast(maybe_capture_map));
}
}
+ DCHECK_IMPLIES(has_named_captures, FLAG_harmony_regexp_named_captures);
const int argc = has_named_captures ? m + 3 : m + 2;
ScopedVector<Handle<Object>> argv(argc);
@@ -1853,12 +1854,15 @@ RUNTIME_FUNCTION(Runtime_RegExpReplace) {
captures.push_back(capture);
}
- Handle<Object> groups_obj;
- ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
- isolate, groups_obj,
- Object::GetProperty(result, factory->groups_string()));
+ Handle<Object> groups_obj = isolate->factory()->undefined_value();
+ if (FLAG_harmony_regexp_named_captures) {
+ ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
+ isolate, groups_obj,
+ Object::GetProperty(result, factory->groups_string()));
+ }
const bool has_named_captures = !groups_obj->IsUndefined(isolate);
+ DCHECK_IMPLIES(has_named_captures, FLAG_harmony_regexp_named_captures);
Handle<String> replacement;
if (functional_replace) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698