WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 860519f

Browse files
[runtime] Don't call well-known Symbol methods for RegExp on primitive values (#201)
## Summary Implement the normative change in tc39/ecma262#3009 where well-known Symbol methods for RegExps are no longer called on primitive values in `String.prototype.{match, matchAll, replace, replaceAll, search, split}`. These methods now verify that the target value is a object before looking for methods instead of just checking that the target value is non-nullish. ## Tests test262 tests for this case now pass.
1 parent 0bb6fa0 commit 860519f

File tree

2 files changed

+6
-31
lines changed

2 files changed

+6
-31
lines changed

src/js/runtime/intrinsics/string_prototype.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ impl StringPrototype {
426426
let this_object = require_object_coercible(cx, this_value)?;
427427

428428
let regexp_arg = get_argument(cx, arguments, 0);
429-
if !regexp_arg.is_nullish() {
429+
if regexp_arg.is_object() {
430430
let matcher = get_method(cx, regexp_arg, cx.well_known_symbols.match_())?;
431431
if let Some(matcher) = matcher {
432432
return call_object(cx, matcher, regexp_arg, &[this_object]);
@@ -454,7 +454,7 @@ impl StringPrototype {
454454
let this_object = require_object_coercible(cx, this_value)?;
455455

456456
let regexp_arg = get_argument(cx, arguments, 0);
457-
if !regexp_arg.is_nullish() {
457+
if regexp_arg.is_object() {
458458
if is_regexp(cx, regexp_arg)? {
459459
let regexp_object = regexp_arg.as_object();
460460

@@ -654,7 +654,7 @@ impl StringPrototype {
654654
let replace_arg = get_argument(cx, arguments, 1);
655655

656656
// Use the @@replace method of the argument if one exists
657-
if !search_arg.is_nullish() {
657+
if search_arg.is_object() {
658658
let replacer = get_method(cx, search_arg, cx.well_known_symbols.replace())?;
659659
if let Some(replacer) = replacer {
660660
return call_object(cx, replacer, search_arg, &[object, replace_arg]);
@@ -734,7 +734,7 @@ impl StringPrototype {
734734
let replace_arg = get_argument(cx, arguments, 1);
735735

736736
// Use the @@replace method of the argument if one exists
737-
if !search_arg.is_nullish() {
737+
if search_arg.is_object() {
738738
// If search argument is a RegExp, check that it has the global flag
739739
if is_regexp(cx, search_arg)? {
740740
let search_regexp = search_arg.as_object();
@@ -846,7 +846,7 @@ impl StringPrototype {
846846

847847
// Use the @@search method of the argument if one exists
848848
let regexp_arg = get_argument(cx, arguments, 0);
849-
if !regexp_arg.is_nullish() {
849+
if regexp_arg.is_object() {
850850
let searcher = get_method(cx, regexp_arg, cx.well_known_symbols.search())?;
851851
if let Some(searcher) = searcher {
852852
return call_object(cx, searcher, regexp_arg, &[object]);
@@ -924,7 +924,7 @@ impl StringPrototype {
924924
let limit_argument = get_argument(cx, arguments, 1);
925925

926926
// Use the @@split method of the separator if one exists
927-
if !separator_argument.is_nullish() {
927+
if separator_argument.is_object() {
928928
let split_key = cx.well_known_symbols.split();
929929
let splitter = get_method(cx, separator_argument, split_key)?;
930930

tests/test262/ignored_tests.jsonc

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,6 @@
88
//
99
////////////////////////////////////////
1010

11-
// Do not call well-known symbols on primitives for string methods (https://github.com/tc39/test262/pull/4404)
12-
"built-ins/String/prototype/match/cstm-matcher-on-bigint-primitive.js",
13-
"built-ins/String/prototype/match/cstm-matcher-on-boolean-primitive.js",
14-
"built-ins/String/prototype/match/cstm-matcher-on-number-primitive.js",
15-
"built-ins/String/prototype/match/cstm-matcher-on-string-primitive.js",
16-
"built-ins/String/prototype/matchAll/cstm-matchall-on-bigint-primitive.js",
17-
"built-ins/String/prototype/matchAll/cstm-matchall-on-number-primitive.js",
18-
"built-ins/String/prototype/matchAll/cstm-matchall-on-string-primitive.js",
19-
"built-ins/String/prototype/replace/cstm-replace-on-bigint-primitive.js",
20-
"built-ins/String/prototype/replace/cstm-replace-on-boolean-primitive.js",
21-
"built-ins/String/prototype/replace/cstm-replace-on-number-primitive.js",
22-
"built-ins/String/prototype/replace/cstm-replace-on-string-primitive.js",
23-
"built-ins/String/prototype/replaceAll/cstm-replaceall-on-bigint-primitive.js",
24-
"built-ins/String/prototype/replaceAll/cstm-replaceall-on-boolean-primitive.js",
25-
"built-ins/String/prototype/replaceAll/cstm-replaceall-on-number-primitive.js",
26-
"built-ins/String/prototype/replaceAll/cstm-replaceall-on-string-primitive.js",
27-
"built-ins/String/prototype/search/cstm-search-on-bigint-primitive.js",
28-
"built-ins/String/prototype/search/cstm-search-on-boolean-primitive.js",
29-
"built-ins/String/prototype/search/cstm-search-on-number-primitive.js",
30-
"built-ins/String/prototype/search/cstm-search-on-string-primitive.js",
31-
"built-ins/String/prototype/split/cstm-split-on-bigint-primitive.js",
32-
"built-ins/String/prototype/split/cstm-split-on-boolean-primitive.js",
33-
"built-ins/String/prototype/split/cstm-split-on-number-primitive.js",
34-
"built-ins/String/prototype/split/cstm-split-on-string-primitive.js",
35-
3611
// The newTarget getter must not be evaluated if argument processing throws an error before AllocateTypedArray is reached
3712
"built-ins/TypedArrayConstructors/ctors/typedarray-arg/throw-type-error-before-custom-proto-access.js",
3813

0 commit comments

Comments
 (0)