mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 12:17:35 +00:00
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
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);
|
auto* rx = this_object_from(vm, global_object);
|
||||||
if (!rx)
|
if (!rx)
|
||||||
return {};
|
return {};
|
||||||
auto string = vm.argument(0);
|
auto s = vm.argument(0).to_string(global_object);
|
||||||
auto s = string.to_string(global_object);
|
if (vm.exception())
|
||||||
auto global_value = rx->get(vm.names.global);
|
return {};
|
||||||
if (global_value.is_empty())
|
auto global_value = rx->get(vm.names.global).value_or(js_undefined());
|
||||||
|
if (vm.exception())
|
||||||
return {};
|
return {};
|
||||||
bool global = global_value.to_boolean();
|
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);
|
auto* exec = get_method(global_object, rx, vm.names.exec);
|
||||||
if (!exec)
|
if (!exec)
|
||||||
return {};
|
return js_undefined();
|
||||||
|
// FIXME end
|
||||||
if (!global)
|
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"
|
// 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
Add a link
Reference in a new issue