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.
This commit is contained in:
parent
b68509569e
commit
304e193836
Notes:
sideshowbarker
2024-07-18 21:22:25 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/304e1938362 Pull-request: https://github.com/SerenityOS/serenity/pull/5781
1 changed files with 10 additions and 7 deletions
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue