1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 14:18:12 +00:00

LibJS: Remove RegExp 'do_match' helper

This was previously used as a wrapper for Regex::match when that method
was invoked by multiple RegExp.prototype implementations. But now all
implementations go through the RegExpExec abstraction, so this helper
is not needed. Remove it to discourage its usage.

Also update a comment about using dynamic properties for lastIndex; this
is no longer a FIXME.
This commit is contained in:
Timothy Flynn 2021-07-07 18:13:23 -04:00 committed by Linus Groh
parent 2d0589f93c
commit ce2651a320

View file

@ -100,29 +100,16 @@ static void increment_last_index(GlobalObject& global_object, Object& regexp_obj
regexp_object.set(vm.names.lastIndex, Value(last_index), true);
}
static RegexResult do_match(const Regex<ECMA262>& re, const StringView& subject)
{
auto result = re.match(subject);
// The 'lastIndex' property is reset on failing tests (if 'global')
if (!result.success && re.options().has_flag_set(ECMAScriptFlags::Global))
re.start_offset = 0;
return result;
}
// 22.2.5.2.2 RegExpBuiltinExec ( R, S ), https://tc39.es/ecma262/#sec-regexpbuiltinexec
static Value regexp_builtin_exec(GlobalObject& global_object, RegExpObject& regexp_object, String const& string)
{
// FIXME: This should try using dynamic properties for 'lastIndex',
// and internal slots [[RegExpMatcher]], [[OriginalFlags]], etc.
// FIXME: This should try using internal slots [[RegExpMatcher]], [[OriginalFlags]], etc.
auto& vm = global_object.vm();
auto str = vm.argument(0).to_string(global_object);
if (vm.exception())
return {};
StringView str_to_match = string;
// RegExps without "global" and "sticky" always start at offset 0.
if (!regexp_object.regex().options().has_flag_set((ECMAScriptFlags)regex::AllFlags::Internal_Stateful)) {
regexp_object.set(vm.names.lastIndex, Value(0), true);
@ -137,7 +124,10 @@ static Value regexp_builtin_exec(GlobalObject& global_object, RegExpObject& rege
if (vm.exception())
return {};
auto result = do_match(regexp_object.regex(), str_to_match);
auto result = regexp_object.regex().match(string);
// The 'lastIndex' property is reset on failing tests (if 'global')
if (!result.success && regexp_object.regex().options().has_flag_set(ECMAScriptFlags::Global))
regexp_object.regex().start_offset = 0;
regexp_object.set(vm.names.lastIndex, Value(regexp_object.regex().start_offset), true);
if (vm.exception())