mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 20:37:34 +00:00
LibJS: Do not use "this" object in RegExpExec
As an abstraction, RegExpExec should not assume that the RegExp object being used is "this" object. Instead, it should only interact with the provided object. This prepares for some methods, such as @@split, which invoke RegExpExec with a secondary RegExp object.
This commit is contained in:
parent
1d19649a19
commit
2686c5f503
1 changed files with 7 additions and 6 deletions
|
@ -165,16 +165,16 @@ static Value regexp_builtin_exec(GlobalObject& global_object, RegExpObject& rege
|
||||||
}
|
}
|
||||||
|
|
||||||
// 22.2.5.2.1 RegExpExec ( R, S ), https://tc39.es/ecma262/#sec-regexpexec
|
// 22.2.5.2.1 RegExpExec ( R, S ), https://tc39.es/ecma262/#sec-regexpexec
|
||||||
static Value regexp_exec(GlobalObject& global_object, Object& rx, String const& string)
|
static Value regexp_exec(GlobalObject& global_object, Object& regexp_object, String const& string)
|
||||||
{
|
{
|
||||||
auto& vm = global_object.vm();
|
auto& vm = global_object.vm();
|
||||||
|
|
||||||
auto exec = rx.get(vm.names.exec);
|
auto exec = regexp_object.get(vm.names.exec);
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
if (exec.is_function()) {
|
if (exec.is_function()) {
|
||||||
auto result = vm.call(exec.as_function(), &rx, js_string(vm, string));
|
auto result = vm.call(exec.as_function(), ®exp_object, js_string(vm, string));
|
||||||
if (vm.exception())
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
|
@ -184,11 +184,12 @@ static Value regexp_exec(GlobalObject& global_object, Object& rx, String const&
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto regexp_object = regexp_object_from(vm, global_object);
|
if (!is<RegExpObject>(regexp_object)) {
|
||||||
if (!regexp_object)
|
vm.throw_exception<TypeError>(global_object, ErrorType::NotA, "RegExp");
|
||||||
return {};
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
return regexp_builtin_exec(global_object, *regexp_object, string);
|
return regexp_builtin_exec(global_object, static_cast<RegExpObject&>(regexp_object), string);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 22.2.5.3 get RegExp.prototype.dotAll, https://tc39.es/ecma262/#sec-get-regexp.prototype.dotAll
|
// 22.2.5.3 get RegExp.prototype.dotAll, https://tc39.es/ecma262/#sec-get-regexp.prototype.dotAll
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue