1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 06:17:35 +00:00

LibJS: Fix String.prototype.match() for non-string argument

This is supposed to pass the to_string()'d argument to @@match, not the
this value.
This commit is contained in:
Linus Groh 2021-03-14 12:06:29 +01:00 committed by Andreas Kling
parent 32052b3198
commit b68509569e

View file

@ -666,19 +666,13 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::match)
if (auto* matcher = get_method(global_object, regexp, vm.well_known_symbol_match())) if (auto* matcher = get_method(global_object, regexp, vm.well_known_symbol_match()))
return vm.call(*matcher, regexp, this_object); return vm.call(*matcher, regexp, this_object);
} }
auto s = this_object.to_primitive_string(global_object); auto s = this_object.to_string(global_object);
if (!s) if (vm.exception())
return {};
auto regexp_string = regexp.to_string(global_object);
if (regexp_string.is_null())
return {}; return {};
auto rx = regexp_create(global_object, regexp, js_undefined()); auto rx = regexp_create(global_object, regexp, js_undefined());
if (!rx) if (!rx)
return {}; return {};
auto* matcher = get_method(global_object, rx, vm.well_known_symbol_match()); return rx->invoke(vm.well_known_symbol_match(), js_string(vm, s));
if (!matcher)
return {};
return vm.call(*matcher, rx, this_object);
} }
} }