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:
Linus Groh 2021-03-14 12:11:45 +01:00 committed by Andreas Kling
parent b68509569e
commit 304e193836
Notes: sideshowbarker 2024-07-18 21:22:25 +09:00

View File

@ -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));
}
}