diff options
author | Linus Groh <mail@linusgroh.de> | 2021-03-14 12:06:29 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-03-14 12:24:57 +0100 |
commit | b68509569edbc02e12cbd0311357ab84e386e385 (patch) | |
tree | 3ceef0a8f8c9741a1a8696386f2d1b3b609ac255 /Userland/Libraries/LibJS/Runtime | |
parent | 32052b3198c7a47b8a20f301c5ec003d0a748c40 (diff) | |
download | serenity-b68509569edbc02e12cbd0311357ab84e386e385.zip |
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.
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/StringPrototype.cpp | 12 |
1 files changed, 3 insertions, 9 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp b/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp index 98e5365954..e7cf3428fa 100644 --- a/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp @@ -666,19 +666,13 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::match) if (auto* matcher = get_method(global_object, regexp, vm.well_known_symbol_match())) return vm.call(*matcher, regexp, this_object); } - auto s = this_object.to_primitive_string(global_object); - if (!s) - return {}; - auto regexp_string = regexp.to_string(global_object); - if (regexp_string.is_null()) + auto s = this_object.to_string(global_object); + if (vm.exception()) return {}; auto rx = regexp_create(global_object, regexp, js_undefined()); if (!rx) return {}; - auto* matcher = get_method(global_object, rx, vm.well_known_symbol_match()); - if (!matcher) - return {}; - return vm.call(*matcher, rx, this_object); + return rx->invoke(vm.well_known_symbol_match(), js_string(vm, s)); } } |