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

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

Issue 2050343002: [regexp] Experimental support for regexp named captures (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Proper fixed array cast Created 4 years, 6 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/runtime/runtime-regexp.cc
diff --git a/src/runtime/runtime-regexp.cc b/src/runtime/runtime-regexp.cc
index a8133d349538e4f0742f25042653b793d0f8b877..01c6f31c0b77d2c451623925efad07f6323f7adf 100644
--- a/src/runtime/runtime-regexp.cc
+++ b/src/runtime/runtime-regexp.cc
@@ -797,7 +797,6 @@ RUNTIME_FUNCTION(Runtime_RegExpSource) {
return regexp->source();
}
-
RUNTIME_FUNCTION(Runtime_RegExpConstructResult) {
HandleScope handle_scope(isolate);
DCHECK(args.length() == 3);
@@ -1014,6 +1013,38 @@ RUNTIME_FUNCTION(Runtime_RegExpExecReThrow) {
return isolate->ReThrow(exception);
}
+RUNTIME_FUNCTION(Runtime_RegExpResultAttachNamedCaptures) {
+ HandleScope handle_scope(isolate);
+ DCHECK(args.length() == 2);
+ CONVERT_ARG_CHECKED(JSArray, result, 0);
+ CONVERT_ARG_CHECKED(JSRegExp, regexp, 1);
+
+ if (regexp->TypeTag() != JSRegExp::IRREGEXP ||
+ !regexp->DataAt(JSRegExp::kIrregexpCaptureNameMapIndex)->IsFixedArray())
+ return isolate->heap()->undefined_value();
+
+ FixedArray* captures =
+ FixedArray::cast(regexp->DataAt(JSRegExp::kIrregexpCaptureNameMapIndex));
+ DCHECK(captures->length() > 0);
+
+ Handle<JSArray> result_handle = handle(result, isolate);
+
+ for (int i = 0; i < captures->length(); i += 2) {
+ Handle<String> name = handle(String::cast(captures->get(i)), isolate);
+ const int ix = Smi::cast(captures->get(i + 1))->value();
+
+ MaybeHandle<Object> existing = Object::GetProperty(result_handle, name);
+ if (!existing.ToHandleChecked()->IsUndefined()) {
+ continue; // Skip conflicts.
+ }
+
+ Handle<Object> value =
+ Object::GetElement(isolate, result_handle, ix).ToHandleChecked();
+ JSObject::AddProperty(result_handle, name, value, NONE);
+ }
+
+ return isolate->heap()->undefined_value();
+}
RUNTIME_FUNCTION(Runtime_IsRegExp) {
SealHandleScope shs(isolate);

Powered by Google App Engine
This is Rietveld 408576698