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 || |
Yang
2016/06/13 10:54:53
We don't actually have to check this, right? We ca
jgruber
2016/06/13 13:10:00
I think we need to check, as ATOM JSRegExps have a
|
+ !regexp->DataAt(JSRegExp::kIrregexpCaptureNameMapIndex)->IsFixedArray()) |
Yang
2016/06/13 10:54:53
Please add brackets around the then-block.
jgruber
2016/06/13 13:10:00
Done.
|
+ 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(); |
Yang
2016/06/13 10:54:53
Accessing captures like this is not GC-safe. You n
jgruber
2016/06/13 13:10:00
Done.
|
+ |
+ MaybeHandle<Object> existing = Object::GetProperty(result_handle, name); |
+ if (!existing.ToHandleChecked()->IsUndefined()) { |
+ continue; // Skip conflicts. |
Yang
2016/06/13 10:54:53
I don't think this can actually happen unless the
jgruber
2016/06/13 13:10:00
This happens for regexp properties 'index' and 'in
Yang
2016/06/13 13:38:00
I see. Can we use JSReceiver::HasOwnProperty for t
jgruber
2016/06/14 07:53:12
Sounds good, will change this when we look at addi
|
+ } |
+ |
+ 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); |