diff options
author | Linus Groh <mail@linusgroh.de> | 2021-03-14 12:11:45 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-03-14 12:24:57 +0100 |
commit | 304e1938362636eeebc5f94d424ecbc4e9cd7072 (patch) | |
tree | f23dd81bf92bc60609e3ab321593ff4fa64c0184 | |
parent | b68509569edbc02e12cbd0311357ab84e386e385 (diff) | |
download | serenity-304e1938362636eeebc5f94d424ecbc4e9cd7072.zip |
LibJS: Fix some issues in RegExp.prototype[@@match]
- We were not passing the to_string()'d argument to the exec function
but the original argument
- We were leaking an empty value in two cases, which almost certainly
will crash something down the line
- We were not checking for exceptions after to_string() and get(), which
both may throw. If the getter is an accessor, it'll assert upon being
called with the VM already storing an exception.
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp b/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp index bb74ee8550..473af54fc3 100644 --- a/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp @@ -262,20 +262,23 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_match) auto* rx = this_object_from(vm, global_object); if (!rx) return {}; - auto string = vm.argument(0); - auto s = string.to_string(global_object); - auto global_value = rx->get(vm.names.global); - if (global_value.is_empty()) + auto s = vm.argument(0).to_string(global_object); + if (vm.exception()) + return {}; + auto global_value = rx->get(vm.names.global).value_or(js_undefined()); + if (vm.exception()) return {}; bool global = global_value.to_boolean(); + // FIXME: Implement and use RegExpExec, this does something different - https://tc39.es/ecma262/#sec-regexpexec auto* exec = get_method(global_object, rx, vm.names.exec); if (!exec) - return {}; + return js_undefined(); + // FIXME end if (!global) - return vm.call(*exec, rx, string); + return vm.call(*exec, rx, js_string(vm, s)); // FIXME: This should exec the RegExp repeatedly while updating "lastIndex" - return vm.call(*exec, rx, string); + return vm.call(*exec, rx, js_string(vm, s)); } } |