From 185a9a750878ed1d9705fbd162dbfe9bf2e4ea0c Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Tue, 26 Nov 2019 13:37:09 +0100 Subject: Issue #1302 - Add self-hosted implementation for string regex .matchAll This resolves #1302. --- js/src/builtin/String.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'js/src/builtin/String.js') diff --git a/js/src/builtin/String.js b/js/src/builtin/String.js index f830b1aa2..d07ec6127 100644 --- a/js/src/builtin/String.js +++ b/js/src/builtin/String.js @@ -63,6 +63,33 @@ function String_generic_match(thisValue, regexp) { return callFunction(String_match, thisValue, regexp); } +// String.prototype.matchAll proposal. +// +// String.prototype.matchAll ( regexp ) +function String_matchAll(regexp) { + // Step 1. + RequireObjectCoercible(this); + + // Step 2. + if (regexp !== undefined && regexp !== null) { + // Step 2.a. + var matcher = GetMethod(regexp, std_matchAll); + + // Step 2.b. + if (matcher !== undefined) + return callContentFunction(matcher, regexp, this); + } + + // Step 3. + var string = ToString(this); + + // Step 4. + var rx = RegExpCreate(regexp, "g"); + + // Step 5. + return callContentFunction(GetMethod(rx, std_matchAll), rx, string); +} + /** * A helper function implementing the logic for both String.prototype.padStart * and String.prototype.padEnd as described in ES7 Draft March 29, 2016 -- cgit v1.2.3