| 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);
|
|
|