Skip to content

Commit a241f2a

Browse files
authored
Fix String.prototype match/split/etc methods (#1064)
test262's expectation is that String methods don't try to look up well-known symbols like Symbol.match and Symbol.split on primitive values, even when those values have prototypes that do contain the symbol. Make it so.
1 parent 246090a commit a241f2a

File tree

2 files changed

+3
-49
lines changed

2 files changed

+3
-49
lines changed

quickjs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43547,7 +43547,7 @@ static JSValue js_string_match(JSContext *ctx, JSValueConst this_val,
4354743547
if (JS_IsUndefined(O) || JS_IsNull(O))
4354843548
return JS_ThrowTypeError(ctx, "cannot convert to object");
4354943549

43550-
if (!JS_IsUndefined(regexp) && !JS_IsNull(regexp)) {
43550+
if (JS_IsObject(regexp)) {
4355143551
matcher = JS_GetProperty(ctx, regexp, atom);
4355243552
if (JS_IsException(matcher))
4355343553
return JS_EXCEPTION;
@@ -43713,7 +43713,7 @@ static JSValue js_string_replace(JSContext *ctx, JSValueConst this_val,
4371343713
replaceValue_str = JS_UNDEFINED;
4371443714
repl_str = JS_UNDEFINED;
4371543715

43716-
if (!JS_IsUndefined(searchValue) && !JS_IsNull(searchValue)) {
43716+
if (JS_IsObject(searchValue)) {
4371743717
JSValue replacer;
4371843718
if (is_replaceAll) {
4371943719
if (check_regexp_g_flag(ctx, searchValue) < 0)
@@ -43824,7 +43824,7 @@ static JSValue js_string_split(JSContext *ctx, JSValueConst this_val,
4382443824
A = JS_UNDEFINED;
4382543825
R = JS_UNDEFINED;
4382643826

43827-
if (!JS_IsUndefined(separator) && !JS_IsNull(separator)) {
43827+
if (JS_IsObject(separator)) {
4382843828
JSValue splitter;
4382943829
splitter = JS_GetProperty(ctx, separator, JS_ATOM_Symbol_split);
4383043830
if (JS_IsException(splitter))

test262_errors.txt

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -30,62 +30,16 @@ test262/test/built-ins/RegExp/prototype/exec/regexp-builtin-exec-v-u-flag.js:45:
3030
test262/test/built-ins/RegExp/prototype/exec/regexp-builtin-exec-v-u-flag.js:45: strict mode: Test262Error: Actual argument shouldn't be nullish. Unicode property escapes with v flag
3131
test262/test/built-ins/RegExp/unicodeSets/generated/rgi-emoji-16.0.js:16: Test262Error: `\p{RGI_Emoji}` should match 🇨🇶 (U+01F1E8 U+01F1F6)
3232
test262/test/built-ins/RegExp/unicodeSets/generated/rgi-emoji-16.0.js:16: strict mode: Test262Error: `\p{RGI_Emoji}` should match 🇨🇶 (U+01F1E8 U+01F1F6)
33-
test262/test/built-ins/String/prototype/match/cstm-matcher-on-bigint-primitive.js:22: Test262Error: should not be called
34-
test262/test/built-ins/String/prototype/match/cstm-matcher-on-bigint-primitive.js:22: strict mode: Test262Error: should not be called
35-
test262/test/built-ins/String/prototype/match/cstm-matcher-on-boolean-primitive.js:22: Test262Error: should not be called
36-
test262/test/built-ins/String/prototype/match/cstm-matcher-on-boolean-primitive.js:22: strict mode: Test262Error: should not be called
37-
test262/test/built-ins/String/prototype/match/cstm-matcher-on-number-primitive.js:22: Test262Error: should not be called
38-
test262/test/built-ins/String/prototype/match/cstm-matcher-on-number-primitive.js:22: strict mode: Test262Error: should not be called
39-
test262/test/built-ins/String/prototype/match/cstm-matcher-on-string-primitive.js:22: Test262Error: should not be called
40-
test262/test/built-ins/String/prototype/match/cstm-matcher-on-string-primitive.js:22: strict mode: Test262Error: should not be called
4133
test262/test/built-ins/String/prototype/match/regexp-prototype-match-v-u-flag.js:10: Test262Error: Actual argument shouldn't be nullish. Unicode property escapes with v flag
4234
test262/test/built-ins/String/prototype/match/regexp-prototype-match-v-u-flag.js:10: strict mode: Test262Error: Actual argument shouldn't be nullish. Unicode property escapes with v flag
43-
test262/test/built-ins/String/prototype/matchAll/cstm-matchall-on-bigint-primitive.js:22: Test262Error: should not be called
44-
test262/test/built-ins/String/prototype/matchAll/cstm-matchall-on-bigint-primitive.js:22: strict mode: Test262Error: should not be called
45-
test262/test/built-ins/String/prototype/matchAll/cstm-matchall-on-number-primitive.js:22: Test262Error: should not be called
46-
test262/test/built-ins/String/prototype/matchAll/cstm-matchall-on-number-primitive.js:22: strict mode: Test262Error: should not be called
47-
test262/test/built-ins/String/prototype/matchAll/cstm-matchall-on-string-primitive.js:22: Test262Error: should not be called
48-
test262/test/built-ins/String/prototype/matchAll/cstm-matchall-on-string-primitive.js:22: strict mode: Test262Error: should not be called
4935
test262/test/built-ins/String/prototype/matchAll/regexp-prototype-matchAll-v-u-flag.js:73: Test262Error: Actual [] and expected [𠮷, 𠮷, 𠮷, 0, 3, 6] should have the same contents.
5036
test262/test/built-ins/String/prototype/matchAll/regexp-prototype-matchAll-v-u-flag.js:73: strict mode: Test262Error: Actual [] and expected [𠮷, 𠮷, 𠮷, 0, 3, 6] should have the same contents.
51-
test262/test/built-ins/String/prototype/replace/cstm-replace-on-bigint-primitive.js:21: Test262Error: should not be called
52-
test262/test/built-ins/String/prototype/replace/cstm-replace-on-bigint-primitive.js:21: strict mode: Test262Error: should not be called
53-
test262/test/built-ins/String/prototype/replace/cstm-replace-on-boolean-primitive.js:21: Test262Error: should not be called
54-
test262/test/built-ins/String/prototype/replace/cstm-replace-on-boolean-primitive.js:21: strict mode: Test262Error: should not be called
55-
test262/test/built-ins/String/prototype/replace/cstm-replace-on-number-primitive.js:21: Test262Error: should not be called
56-
test262/test/built-ins/String/prototype/replace/cstm-replace-on-number-primitive.js:21: strict mode: Test262Error: should not be called
57-
test262/test/built-ins/String/prototype/replace/cstm-replace-on-string-primitive.js:21: Test262Error: should not be called
58-
test262/test/built-ins/String/prototype/replace/cstm-replace-on-string-primitive.js:21: strict mode: Test262Error: should not be called
5937
test262/test/built-ins/String/prototype/replace/regexp-prototype-replace-v-u-flag.js:9: Test262Error: Unicode property escapes with v flag Expected SameValue(«"𠮷a𠮷b𠮷"», «"XaXbX"») to be true
6038
test262/test/built-ins/String/prototype/replace/regexp-prototype-replace-v-u-flag.js:9: strict mode: Test262Error: Unicode property escapes with v flag Expected SameValue(«"𠮷a𠮷b𠮷"», «"XaXbX"») to be true
61-
test262/test/built-ins/String/prototype/replaceAll/cstm-replaceall-on-bigint-primitive.js:21: Test262Error: should not be called
62-
test262/test/built-ins/String/prototype/replaceAll/cstm-replaceall-on-bigint-primitive.js:21: strict mode: Test262Error: should not be called
63-
test262/test/built-ins/String/prototype/replaceAll/cstm-replaceall-on-boolean-primitive.js:21: Test262Error: should not be called
64-
test262/test/built-ins/String/prototype/replaceAll/cstm-replaceall-on-boolean-primitive.js:21: strict mode: Test262Error: should not be called
65-
test262/test/built-ins/String/prototype/replaceAll/cstm-replaceall-on-number-primitive.js:21: Test262Error: should not be called
66-
test262/test/built-ins/String/prototype/replaceAll/cstm-replaceall-on-number-primitive.js:21: strict mode: Test262Error: should not be called
67-
test262/test/built-ins/String/prototype/replaceAll/cstm-replaceall-on-string-primitive.js:21: Test262Error: should not be called
68-
test262/test/built-ins/String/prototype/replaceAll/cstm-replaceall-on-string-primitive.js:21: strict mode: Test262Error: should not be called
69-
test262/test/built-ins/String/prototype/search/cstm-search-on-bigint-primitive.js:21: Test262Error: should not be called
70-
test262/test/built-ins/String/prototype/search/cstm-search-on-bigint-primitive.js:21: strict mode: Test262Error: should not be called
71-
test262/test/built-ins/String/prototype/search/cstm-search-on-boolean-primitive.js:21: Test262Error: should not be called
72-
test262/test/built-ins/String/prototype/search/cstm-search-on-boolean-primitive.js:21: strict mode: Test262Error: should not be called
73-
test262/test/built-ins/String/prototype/search/cstm-search-on-number-primitive.js:21: Test262Error: should not be called
74-
test262/test/built-ins/String/prototype/search/cstm-search-on-number-primitive.js:21: strict mode: Test262Error: should not be called
75-
test262/test/built-ins/String/prototype/search/cstm-search-on-string-primitive.js:21: Test262Error: should not be called
76-
test262/test/built-ins/String/prototype/search/cstm-search-on-string-primitive.js:21: strict mode: Test262Error: should not be called
7739
test262/test/built-ins/String/prototype/search/regexp-prototype-search-v-flag.js:9: Test262Error: Unicode property escapes with v flag Expected SameValue(«-1», «0») to be true
7840
test262/test/built-ins/String/prototype/search/regexp-prototype-search-v-flag.js:9: strict mode: Test262Error: Unicode property escapes with v flag Expected SameValue(«-1», «0») to be true
7941
test262/test/built-ins/String/prototype/search/regexp-prototype-search-v-u-flag.js:9: Test262Error: Unicode property escapes with v flag Expected SameValue(«-1», «0») to be true
8042
test262/test/built-ins/String/prototype/search/regexp-prototype-search-v-u-flag.js:9: strict mode: Test262Error: Unicode property escapes with v flag Expected SameValue(«-1», «0») to be true
81-
test262/test/built-ins/String/prototype/split/cstm-split-on-bigint-primitive.js:22: Test262Error: should not be called
82-
test262/test/built-ins/String/prototype/split/cstm-split-on-bigint-primitive.js:22: strict mode: Test262Error: should not be called
83-
test262/test/built-ins/String/prototype/split/cstm-split-on-boolean-primitive.js:22: Test262Error: should not be called
84-
test262/test/built-ins/String/prototype/split/cstm-split-on-boolean-primitive.js:22: strict mode: Test262Error: should not be called
85-
test262/test/built-ins/String/prototype/split/cstm-split-on-number-primitive.js:22: Test262Error: should not be called
86-
test262/test/built-ins/String/prototype/split/cstm-split-on-number-primitive.js:22: strict mode: Test262Error: should not be called
87-
test262/test/built-ins/String/prototype/split/cstm-split-on-string-primitive.js:22: Test262Error: should not be called
88-
test262/test/built-ins/String/prototype/split/cstm-split-on-string-primitive.js:22: strict mode: Test262Error: should not be called
8943
test262/test/built-ins/TypedArray/prototype/includes/search-undefined-after-shrinking-buffer-index-is-oob.js:23: Test262Error: Expected SameValue(«true», «false») to be true (Testing with Float64Array.)
9044
test262/test/built-ins/TypedArray/prototype/includes/search-undefined-after-shrinking-buffer-index-is-oob.js:23: strict mode: Test262Error: Expected SameValue(«true», «false») to be true (Testing with Float64Array.)
9145
test262/test/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-canonical-invalid-index-prototype-chain-set.js:35: Test262Error: value should not be coerced Expected SameValue(«22», «0») to be true

0 commit comments

Comments
 (0)