Skip to content

Commit 257a81f

Browse files
committed
LibJS: Avoid Symbol methods for RegExp on primitives
Normative PR: tc39/ecma262#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.
1 parent 183c847 commit 257a81f

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

Libraries/LibJS/Runtime/StringPrototype.cpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -564,9 +564,9 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::match)
564564
// 1. Let O be ? RequireObjectCoercible(this value).
565565
auto this_object = TRY(require_object_coercible(vm, vm.this_value()));
566566

567-
// 2. If regexp is neither undefined nor null, then
567+
// 2. If regexp is an Object, then
568568
auto regexp = vm.argument(0);
569-
if (!regexp.is_nullish()) {
569+
if (regexp.is_object()) {
570570
// a. Let matcher be ? GetMethod(regexp, @@match).
571571
auto matcher = TRY(regexp.get_method(vm, vm.well_known_symbol_match()));
572572

@@ -595,8 +595,8 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::match_all)
595595
// 1. Let O be ? RequireObjectCoercible(this value).
596596
auto this_object = TRY(require_object_coercible(vm, vm.this_value()));
597597

598-
// 2. If regexp is neither undefined nor null, then
599-
if (!regexp.is_nullish()) {
598+
// 2. If regexp is an Object, then
599+
if (regexp.is_object()) {
600600
// a. Let isRegExp be ? IsRegExp(regexp).
601601
auto is_regexp = TRY(regexp.is_regexp(vm));
602602

@@ -782,8 +782,8 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::replace)
782782
// 1. Let O be ? RequireObjectCoercible(this value).
783783
auto this_object = TRY(require_object_coercible(vm, vm.this_value()));
784784

785-
// 2. If searchValue is neither undefined nor null, then
786-
if (!search_value.is_nullish()) {
785+
// 2. If searchValue is an Object, then
786+
if (search_value.is_object()) {
787787
// a. Let replacer be ? GetMethod(searchValue, @@replace).
788788
auto replacer = TRY(search_value.get_method(vm, vm.well_known_symbol_replace()));
789789

@@ -861,8 +861,8 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::replace_all)
861861
// 1. Let O be ? RequireObjectCoercible(this value).
862862
auto this_object = TRY(require_object_coercible(vm, vm.this_value()));
863863

864-
// 2. If searchValue is neither undefined nor null, then
865-
if (!search_value.is_nullish()) {
864+
// 2. If searchValue is an Object, then
865+
if (search_value.is_object()) {
866866
// a. Let isRegExp be ? IsRegExp(searchValue).
867867
bool is_regexp = TRY(search_value.is_regexp(vm));
868868

@@ -977,8 +977,8 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::search)
977977
// 1. Let O be ? RequireObjectCoercible(this value).
978978
auto this_object = TRY(require_object_coercible(vm, vm.this_value()));
979979

980-
// 2. If regexp is neither undefined nor null, then
981-
if (!regexp.is_nullish()) {
980+
// 2. If regexp is an Object, then
981+
if (regexp.is_object()) {
982982
// a. Let searcher be ? GetMethod(regexp, @@search).
983983
auto searcher = TRY(regexp.get_method(vm, vm.well_known_symbol_search()));
984984

@@ -1058,8 +1058,8 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::split)
10581058
// 1. Let O be ? RequireObjectCoercible(this value).
10591059
auto object = TRY(require_object_coercible(vm, vm.this_value()));
10601060

1061-
// 2. If separator is neither undefined nor null, then
1062-
if (!separator_argument.is_nullish()) {
1061+
// 2. If separator is an Object, then
1062+
if (separator_argument.is_object()) {
10631063
// a. Let splitter be ? GetMethod(separator, @@split).
10641064
auto splitter = TRY(separator_argument.get_method(vm, vm.well_known_symbol_split()));
10651065
// b. If splitter is not undefined, then

0 commit comments

Comments
 (0)