Skip to content

Commit a6cac18

Browse files
committed
Bug 1998177 - Don't call well-known Symbol methods for regexp on primitives; r=jandem
Differential Revision: https://phabricator.services.mozilla.com/D273154
1 parent 3ceca40 commit a6cac18

File tree

5 files changed

+18
-124
lines changed

5 files changed

+18
-124
lines changed

js/src/builtin/String.js

Lines changed: 18 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,10 @@ function String_match(regexp) {
1414
}
1515

1616
// Step 2.
17-
var isPatternString = typeof regexp === "string";
18-
if (
19-
!(isPatternString && CanOptimizeStringProtoSymbolLookup()) &&
20-
!IsNullOrUndefined(regexp)
21-
) {
17+
if (IsObject(regexp)) {
2218
// Fast path for regular expressions with the original
2319
// RegExp.prototype[@@match] function.
24-
if (IsObject(regexp) && IsOptimizableRegExpObject(regexp)) {
20+
if (IsOptimizableRegExpObject(regexp)) {
2521
return callFunction(RegExpMatch, regexp, this);
2622
}
2723

@@ -30,17 +26,14 @@ function String_match(regexp) {
3026

3127
// Step 2.b.
3228
if (matcher !== undefined) {
33-
if (!IsObject(regexp)) {
34-
RegExpSymbolProtocolOnPrimitiveCounter();
35-
}
3629
return callContentFunction(matcher, regexp, this);
3730
}
3831
}
3932

4033
// Step 3.
4134
var S = ToString(this);
4235

43-
if (isPatternString && IsRegExpPrototypeOptimizable()) {
36+
if (typeof regexp === "string" && IsRegExpPrototypeOptimizable()) {
4437
var flatResult = FlatStringMatch(S, regexp);
4538
if (flatResult !== undefined) {
4639
return flatResult;
@@ -69,7 +62,7 @@ function String_matchAll(regexp) {
6962
}
7063

7164
// Step 2.
72-
if (!IsNullOrUndefined(regexp)) {
65+
if (IsObject(regexp)) {
7366
// Steps 2.a-b.
7467
if (IsRegExp(regexp)) {
7568
// Step 2.b.i.
@@ -88,7 +81,7 @@ function String_matchAll(regexp) {
8881

8982
// Fast path for regular expressions with the original
9083
// RegExp.prototype[@@matchAll] function.
91-
if (IsObject(regexp) && IsOptimizableRegExpObject(regexp)) {
84+
if (IsOptimizableRegExpObject(regexp)) {
9285
return callFunction(RegExpMatchAll, regexp, this);
9386
}
9487

@@ -97,9 +90,6 @@ function String_matchAll(regexp) {
9790

9891
// Step 2.d.
9992
if (matcher !== undefined) {
100-
if (!IsObject(regexp)) {
101-
RegExpSymbolProtocolOnPrimitiveCounter();
102-
}
10393
return callContentFunction(matcher, regexp, this);
10494
}
10595
}
@@ -212,13 +202,10 @@ function String_replace(searchValue, replaceValue) {
212202
}
213203

214204
// Step 2.
215-
if (
216-
!(typeof searchValue === "string" && CanOptimizeStringProtoSymbolLookup()) &&
217-
!IsNullOrUndefined(searchValue)
218-
) {
205+
if (IsObject(searchValue)) {
219206
// Fast path for regular expressions with the original
220207
// RegExp.prototype[@@replace] function.
221-
if (IsObject(searchValue) && IsOptimizableRegExpObject(searchValue)) {
208+
if (IsOptimizableRegExpObject(searchValue)) {
222209
return callFunction(RegExpReplace, searchValue, this, replaceValue);
223210
}
224211

@@ -227,9 +214,6 @@ function String_replace(searchValue, replaceValue) {
227214

228215
// Step 2.b.
229216
if (replacer !== undefined) {
230-
if (!IsObject(searchValue)) {
231-
RegExpSymbolProtocolOnPrimitiveCounter();
232-
}
233217
return callContentFunction(replacer, searchValue, this, replaceValue);
234218
}
235219
}
@@ -294,7 +278,7 @@ function String_replaceAll(searchValue, replaceValue) {
294278
}
295279

296280
// Step 2.
297-
if (!IsNullOrUndefined(searchValue)) {
281+
if (IsObject(searchValue)) {
298282
// Steps 2.a-b.
299283
if (IsRegExp(searchValue)) {
300284
// Step 2.b.i.
@@ -313,7 +297,7 @@ function String_replaceAll(searchValue, replaceValue) {
313297

314298
// Fast path for regular expressions with the original
315299
// RegExp.prototype[@@replace] function.
316-
if (IsObject(searchValue) && IsOptimizableRegExpObject(searchValue)) {
300+
if (IsOptimizableRegExpObject(searchValue)) {
317301
return callFunction(RegExpReplace, searchValue, this, replaceValue);
318302
}
319303

@@ -322,9 +306,6 @@ function String_replaceAll(searchValue, replaceValue) {
322306

323307
// Step 2.b.
324308
if (replacer !== undefined) {
325-
if (!IsObject(searchValue)) {
326-
RegExpSymbolProtocolOnPrimitiveCounter();
327-
}
328309
return callContentFunction(replacer, searchValue, this, replaceValue);
329310
}
330311
}
@@ -425,13 +406,10 @@ function String_search(regexp) {
425406

426407
// Step 2.
427408
var isPatternString = typeof regexp === "string";
428-
if (
429-
!(isPatternString && CanOptimizeStringProtoSymbolLookup()) &&
430-
!IsNullOrUndefined(regexp)
431-
) {
409+
if (IsObject(regexp)) {
432410
// Fast path for regular expressions with the original
433411
// RegExp.prototype[@@search] function.
434-
if (IsObject(regexp) && IsOptimizableRegExpObject(regexp)) {
412+
if (IsOptimizableRegExpObject(regexp)) {
435413
return callFunction(RegExpSearch, regexp, this);
436414
}
437415

@@ -440,9 +418,6 @@ function String_search(regexp) {
440418

441419
// Step 2.b.
442420
if (searcher !== undefined) {
443-
if (!IsObject(regexp)) {
444-
RegExpSymbolProtocolOnPrimitiveCounter();
445-
}
446421
return callContentFunction(searcher, regexp, this);
447422
}
448423
}
@@ -479,25 +454,20 @@ function String_split(separator, limit) {
479454
// are constants. Following sequence of if's cannot be put together in
480455
// order that IonMonkey sees the constant if present (bug 1246141).
481456
if (typeof this === "string") {
482-
if (CanOptimizeStringProtoSymbolLookup()) {
483-
if (typeof separator === "string") {
484-
if (limit === undefined) {
485-
// inlineConstantStringSplitString needs both arguments to
486-
// be MConstant, so pass them directly.
487-
return StringSplitString(this, separator);
488-
}
457+
if (typeof separator === "string") {
458+
if (limit === undefined) {
459+
// inlineConstantStringSplitString needs both arguments to
460+
// be MConstant, so pass them directly.
461+
return StringSplitString(this, separator);
489462
}
490463
}
491464
}
492465

493466
// Step 2.
494-
if (
495-
!(typeof separator === "string" && CanOptimizeStringProtoSymbolLookup()) &&
496-
!IsNullOrUndefined(separator)
497-
) {
467+
if (IsObject(separator)) {
498468
// Fast path for regular expressions with the original
499469
// RegExp.prototype[@@split] function.
500-
if (IsObject(separator) && IsOptimizableRegExpObject(separator)) {
470+
if (IsOptimizableRegExpObject(separator)) {
501471
return callFunction(RegExpSplit, separator, this, limit);
502472
}
503473

@@ -506,9 +476,6 @@ function String_split(separator, limit) {
506476

507477
// Step 2.b.
508478
if (splitter !== undefined) {
509-
if (!IsObject(separator)) {
510-
RegExpSymbolProtocolOnPrimitiveCounter();
511-
}
512479
return callContentFunction(splitter, separator, this, limit);
513480
}
514481
}

js/src/jit-test/tests/basic/bug1549035.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

js/src/jit-test/tests/fuses/string-proto-symbols-3.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

js/src/jit-test/tests/ion/testStringMatch.js

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,6 @@ function testMod(apply, unapply) {
3737
}
3838
}
3939
}
40-
testMod(() => {
41-
String.prototype[Symbol.match] = () => ["mod"];
42-
}, () => {
43-
delete String.prototype[Symbol.match];
44-
});
45-
testMod(() => {
46-
Object.prototype[Symbol.match] = () => ["mod"];
47-
}, () => {
48-
delete Object.prototype[Symbol.match];
49-
});
50-
51-
testMod(() => {
52-
Object.setPrototypeOf(String.prototype, {
53-
[Symbol.match]: () => ["mod"]
54-
});
55-
}, () => {
56-
Object.setPrototypeOf(String.prototype, Object.prototype);
57-
});
5840

5941
var orig_exec = RegExp.prototype.exec;
6042
testMod(() => {

js/src/tests/jstests.list

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -662,31 +662,6 @@ skip script test262/language/statements/with/set-mutable-binding-idref-compound-
662662
skip script test262/built-ins/Iterator/concat/fresh-iterator-result.js
663663
skip script test262/built-ins/Iterator/concat/next-method-returns-throwing-value.js
664664

665-
# https://bugzilla.mozilla.org/show_bug.cgi?id=1950211
666-
skip script test262/built-ins/String/prototype/replace/cstm-replace-on-boolean-primitive.js
667-
skip script test262/built-ins/String/prototype/replace/cstm-replace-on-string-primitive.js
668-
skip script test262/built-ins/String/prototype/replace/cstm-replace-on-number-primitive.js
669-
skip script test262/built-ins/String/prototype/replace/cstm-replace-on-bigint-primitive.js
670-
skip script test262/built-ins/String/prototype/matchAll/cstm-matchall-on-number-primitive.js
671-
skip script test262/built-ins/String/prototype/matchAll/cstm-matchall-on-bigint-primitive.js
672-
skip script test262/built-ins/String/prototype/matchAll/cstm-matchall-on-string-primitive.js
673-
skip script test262/built-ins/String/prototype/replaceAll/cstm-replaceall-on-bigint-primitive.js
674-
skip script test262/built-ins/String/prototype/replaceAll/cstm-replaceall-on-number-primitive.js
675-
skip script test262/built-ins/String/prototype/replaceAll/cstm-replaceall-on-boolean-primitive.js
676-
skip script test262/built-ins/String/prototype/replaceAll/cstm-replaceall-on-string-primitive.js
677-
skip script test262/built-ins/String/prototype/split/cstm-split-on-boolean-primitive.js
678-
skip script test262/built-ins/String/prototype/split/cstm-split-on-string-primitive.js
679-
skip script test262/built-ins/String/prototype/split/cstm-split-on-number-primitive.js
680-
skip script test262/built-ins/String/prototype/split/cstm-split-on-bigint-primitive.js
681-
skip script test262/built-ins/String/prototype/match/cstm-matcher-on-boolean-primitive.js
682-
skip script test262/built-ins/String/prototype/match/cstm-matcher-on-bigint-primitive.js
683-
skip script test262/built-ins/String/prototype/match/cstm-matcher-on-number-primitive.js
684-
skip script test262/built-ins/String/prototype/match/cstm-matcher-on-string-primitive.js
685-
skip script test262/built-ins/String/prototype/search/cstm-search-on-bigint-primitive.js
686-
skip script test262/built-ins/String/prototype/search/cstm-search-on-string-primitive.js
687-
skip script test262/built-ins/String/prototype/search/cstm-search-on-boolean-primitive.js
688-
skip script test262/built-ins/String/prototype/search/cstm-search-on-number-primitive.js
689-
690665
# https://bugzilla.mozilla.org/show_bug.cgi?id=1970162
691666
# https://github.com/tc39/ecma402/pull/989
692667
skip script test262/intl402/PluralRules/constructor-options-throwing-getters.js

0 commit comments

Comments
 (0)