LibJS: Avoid Symbol methods for RegExp on primitives
Some checks are pending
CI / macOS, arm64, Sanitizer_CI, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers_CI, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer_CI, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer_CI, Clang (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run

Normative PR: https://github.com/tc39/ecma262/pull/3009 (unmerged as of this commit)

There are a few test262 tests for this, see https://test262.fyi/#built-ins/String/prototype
JSC and Rhino have have already added these changes.
This commit is contained in:
Carter Snook 2025-05-05 14:15:16 -05:00 committed by Andrew Kaster
commit 1861f24979
Notes: github-actions[bot] 2025-06-17 23:55:53 +00:00

View file

@ -564,9 +564,9 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::match)
// 1. Let O be ? RequireObjectCoercible(this value). // 1. Let O be ? RequireObjectCoercible(this value).
auto this_object = TRY(require_object_coercible(vm, vm.this_value())); auto this_object = TRY(require_object_coercible(vm, vm.this_value()));
// 2. If regexp is neither undefined nor null, then // 2. If regexp is an Object, then
auto regexp = vm.argument(0); auto regexp = vm.argument(0);
if (!regexp.is_nullish()) { if (regexp.is_object()) {
// a. Let matcher be ? GetMethod(regexp, @@match). // a. Let matcher be ? GetMethod(regexp, @@match).
auto matcher = TRY(regexp.get_method(vm, vm.well_known_symbol_match())); auto matcher = TRY(regexp.get_method(vm, vm.well_known_symbol_match()));
@ -595,8 +595,8 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::match_all)
// 1. Let O be ? RequireObjectCoercible(this value). // 1. Let O be ? RequireObjectCoercible(this value).
auto this_object = TRY(require_object_coercible(vm, vm.this_value())); auto this_object = TRY(require_object_coercible(vm, vm.this_value()));
// 2. If regexp is neither undefined nor null, then // 2. If regexp is an Object, then
if (!regexp.is_nullish()) { if (regexp.is_object()) {
// a. Let isRegExp be ? IsRegExp(regexp). // a. Let isRegExp be ? IsRegExp(regexp).
auto is_regexp = TRY(regexp.is_regexp(vm)); auto is_regexp = TRY(regexp.is_regexp(vm));
@ -782,8 +782,8 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::replace)
// 1. Let O be ? RequireObjectCoercible(this value). // 1. Let O be ? RequireObjectCoercible(this value).
auto this_object = TRY(require_object_coercible(vm, vm.this_value())); auto this_object = TRY(require_object_coercible(vm, vm.this_value()));
// 2. If searchValue is neither undefined nor null, then // 2. If searchValue is an Object, then
if (!search_value.is_nullish()) { if (search_value.is_object()) {
// a. Let replacer be ? GetMethod(searchValue, @@replace). // a. Let replacer be ? GetMethod(searchValue, @@replace).
auto replacer = TRY(search_value.get_method(vm, vm.well_known_symbol_replace())); auto replacer = TRY(search_value.get_method(vm, vm.well_known_symbol_replace()));
@ -861,8 +861,8 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::replace_all)
// 1. Let O be ? RequireObjectCoercible(this value). // 1. Let O be ? RequireObjectCoercible(this value).
auto this_object = TRY(require_object_coercible(vm, vm.this_value())); auto this_object = TRY(require_object_coercible(vm, vm.this_value()));
// 2. If searchValue is neither undefined nor null, then // 2. If searchValue is an Object, then
if (!search_value.is_nullish()) { if (search_value.is_object()) {
// a. Let isRegExp be ? IsRegExp(searchValue). // a. Let isRegExp be ? IsRegExp(searchValue).
bool is_regexp = TRY(search_value.is_regexp(vm)); bool is_regexp = TRY(search_value.is_regexp(vm));
@ -977,8 +977,8 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::search)
// 1. Let O be ? RequireObjectCoercible(this value). // 1. Let O be ? RequireObjectCoercible(this value).
auto this_object = TRY(require_object_coercible(vm, vm.this_value())); auto this_object = TRY(require_object_coercible(vm, vm.this_value()));
// 2. If regexp is neither undefined nor null, then // 2. If regexp is an Object, then
if (!regexp.is_nullish()) { if (regexp.is_object()) {
// a. Let searcher be ? GetMethod(regexp, @@search). // a. Let searcher be ? GetMethod(regexp, @@search).
auto searcher = TRY(regexp.get_method(vm, vm.well_known_symbol_search())); auto searcher = TRY(regexp.get_method(vm, vm.well_known_symbol_search()));
@ -1058,8 +1058,8 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::split)
// 1. Let O be ? RequireObjectCoercible(this value). // 1. Let O be ? RequireObjectCoercible(this value).
auto object = TRY(require_object_coercible(vm, vm.this_value())); auto object = TRY(require_object_coercible(vm, vm.this_value()));
// 2. If separator is neither undefined nor null, then // 2. If separator is an Object, then
if (!separator_argument.is_nullish()) { if (separator_argument.is_object()) {
// a. Let splitter be ? GetMethod(separator, @@split). // a. Let splitter be ? GetMethod(separator, @@split).
auto splitter = TRY(separator_argument.get_method(vm, vm.well_known_symbol_split())); auto splitter = TRY(separator_argument.get_method(vm, vm.well_known_symbol_split()));
// b. If splitter is not undefined, then // b. If splitter is not undefined, then