Skip to content

Commit

Permalink
Bug 1781206 - Part 5: Check RegExp flags using "flags" property. r=iain
Browse files Browse the repository at this point in the history
Implement the changes from <tc39/ecma262#2791>.

Depends on D156843

Differential Revision: https://phabricator.services.mozilla.com/D156844
  • Loading branch information
anba committed Sep 9, 2022
1 parent 119bd2b commit cb2578c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 56 deletions.
18 changes: 12 additions & 6 deletions js/src/builtin/RegExp.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,16 @@ function RegExpMatch(string) {
// ES 2017 draft rev 6859bb9ccaea9c6ede81d71e5320e3833b92cb3e 21.2.5.6
// steps 4-6.
function RegExpMatchSlowPath(rx, S) {
// Steps 4-5.
if (!rx.global) {
// Step 4.
var flags = ToString(rx.flags);

// Step 5.
if (!callFunction(std_String_includes, flags, "g")) {
return RegExpExec(rx, S, false);
}

// Step 6.a.
var fullUnicode = !!rx.unicode;
var fullUnicode = callFunction(std_String_includes, flags, "u");

// Step 6.b.
rx.lastIndex = 0;
Expand Down Expand Up @@ -397,13 +400,16 @@ function RegExpReplaceSlowPath(
firstDollarIndex
) {
// Step 7.
var global = !!rx.global;
var flags = ToString(rx.flags);

// Step 8.
var global = callFunction(std_String_includes, flags, "g");

// Step 9.
var fullUnicode = false;
if (global) {
// Step 8.a.
fullUnicode = !!rx.unicode;
// Step 9.a.
fullUnicode = callFunction(std_String_includes, flags, "u");

// Step 8.b.
rx.lastIndex = 0;
Expand Down
8 changes: 0 additions & 8 deletions js/src/tests/jstests.list
Original file line number Diff line number Diff line change
Expand Up @@ -612,14 +612,6 @@ skip script test262/built-ins/AsyncGeneratorPrototype/return/return-state-comple
skip script test262/built-ins/AsyncGeneratorPrototype/return/return-suspendedStart-broken-promise.js
skip script test262/built-ins/AsyncGeneratorPrototype/return/return-suspendedYield-broken-promise-try-catch.js

# https://bugzilla.mozilla.org/show_bug.cgi?id=1781206
skip script test262/built-ins/RegExp/prototype/Symbol.replace/get-flags-err.js
skip script test262/built-ins/RegExp/prototype/Symbol.replace/get-unicode-error.js
skip script test262/built-ins/RegExp/prototype/Symbol.replace/flags-tostring-error.js
skip script test262/built-ins/RegExp/prototype/Symbol.match/get-flags-err.js
skip script test262/built-ins/RegExp/prototype/Symbol.match/get-unicode-error.js
skip script test262/built-ins/RegExp/prototype/Symbol.match/flags-tostring-error.js

# https://bugzilla.mozilla.org/show_bug.cgi?id=1781205
skip script test262/language/statements/async-generator/yield-star-return-then-getter-ticks.js
skip script test262/language/statements/async-generator/yield-star-promise-not-unwrapped.js
Expand Down
1 change: 1 addition & 0 deletions js/src/tests/non262/RegExp/lastIndex-match-or-replace.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class DuckRegExp extends RegExp {

get source() { return this.regExp.source; }

get flags() { return this.regExp.flags; }
get global() { return this.regExp.global; }
get ignoreCase() { return this.regExp.ignoreCase; }
get multiline() { return this.regExp.multiline; }
Expand Down
27 changes: 11 additions & 16 deletions js/src/tests/non262/RegExp/match-trace.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ function P(A) {
}

var myRegExp = {
get global() {
log += "get:global,";
return global;
get flags() {
log += "get:flags,";
var flags = "";
if (global) flags += "g";
if (unicode) flags += "u";
return flags;
},
get lastIndex() {
log += "get:lastIndex,";
Expand All @@ -37,10 +40,6 @@ var myRegExp = {
log += "set:lastIndex,";
assertEq(v, lastIndexExpected[n]);
},
get unicode() {
log += "get:unicode,";
return unicode;
},
get exec() {
log += "get:exec,";
return function(S) {
Expand Down Expand Up @@ -68,8 +67,7 @@ lastIndexExpected = [ 0, , , ];
var ret = RegExp.prototype[Symbol.match].call(myRegExp, target);
assertEq(JSON.stringify(ret), `["abc","ABC"]`);
assertEq(log,
"get:global," +
"get:unicode," +
"get:flags," +
"set:lastIndex," +
"get:exec,call:exec,get:result[0]," +
"get:exec,call:exec,get:result[0]," +
Expand All @@ -83,8 +81,7 @@ lastIndexExpected = [ 0, 5, 21, ];
ret = RegExp.prototype[Symbol.match].call(myRegExp, target);
assertEq(JSON.stringify(ret), `["",""]`);
assertEq(log,
"get:global," +
"get:unicode," +
"get:flags," +
"set:lastIndex," +
"get:exec,call:exec,get:result[0],get:lastIndex,set:lastIndex," +
"get:exec,call:exec,get:result[0],get:lastIndex,set:lastIndex," +
Expand All @@ -106,8 +103,7 @@ lastIndexExpected = [ 0, 3, 5, 5, 9, 10, ];
ret = RegExp.prototype[Symbol.match].call(myRegExp, target);
assertEq(JSON.stringify(ret), `["","","","",""]`);
assertEq(log,
"get:global," +
"get:unicode," +
"get:flags," +
"set:lastIndex," +
"get:exec,call:exec,get:result[0],get:lastIndex,set:lastIndex," +
"get:exec,call:exec,get:result[0],get:lastIndex,set:lastIndex," +
Expand All @@ -124,8 +120,7 @@ lastIndexExpected = [ 0, ];
ret = RegExp.prototype[Symbol.match].call(myRegExp, target);
assertEq(ret, null);
assertEq(log,
"get:global," +
"get:unicode," +
"get:flags," +
"set:lastIndex," +
"get:exec,call:exec,");

Expand All @@ -140,7 +135,7 @@ ret = RegExp.prototype[Symbol.match].call(myRegExp, target);
logProxy = false;
assertEq(JSON.stringify(ret), `["abc"]`);
assertEq(log,
"get:global," +
"get:flags," +
"get:exec,call:exec,");

if (typeof reportCompare === "function")
Expand Down
42 changes: 16 additions & 26 deletions js/src/tests/non262/RegExp/replace-trace.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ function P(A, index, matched2) {
}

var myRegExp = {
get global() {
log += "get:global,";
return global;
get flags() {
log += "get:flags,";
var flags = "";
if (global) flags += "g";
if (unicode) flags += "u";
return flags;
},
get lastIndex() {
log += "get:lastIndex,";
Expand All @@ -64,10 +67,6 @@ var myRegExp = {
log += "set:lastIndex,";
assertEq(v, lastIndexExpected[n]);
},
get unicode() {
log += "get:unicode,";
return unicode;
},
get exec() {
log += "get:exec,";
return function(S) {
Expand Down Expand Up @@ -96,8 +95,7 @@ var ret = RegExp.prototype[Symbol.replace].call(myRegExp, target, "_XYZ_");
assertEq(arraySetterObserved, false);
assertEq(ret, "a_XYZ_AbcABC");
assertEq(log,
"get:global," +
"get:unicode," +
"get:flags," +
"set:lastIndex," +
"get:exec,call:exec," +
"get:result[0]," +
Expand All @@ -113,8 +111,7 @@ ret = RegExp.prototype[Symbol.replace].call(myRegExp, target, "_XYZ_");
assertEq(arraySetterObserved, false);
assertEq(ret, "a_XYZ_bcAbcABC");
assertEq(log,
"get:global," +
"get:unicode," +
"get:flags," +
"set:lastIndex," +
"get:exec,call:exec," +
"get:result[0]," +
Expand All @@ -139,8 +136,7 @@ ret = RegExp.prototype[Symbol.replace].call(myRegExp, target, "_XYZ_");
assertEq(arraySetterObserved, false);
assertEq(ret, "-_XYZ_-_XYZ_-_XYZ_\uD83D_XYZ_\uDC38_XYZ_---\uD83D");
assertEq(log,
"get:global," +
"get:unicode," +
"get:flags," +
"set:lastIndex," +
"get:exec,call:exec," +
"get:result[0]," +
Expand Down Expand Up @@ -173,8 +169,7 @@ ret = RegExp.prototype[Symbol.replace].call(myRegExp, target, "[$&,$`,$',$1,$2,$
assertEq(arraySetterObserved, false);
assertEq(ret, "a[bc,a,AbcABC,b,c,$3,$]AbcABC");
assertEq(log,
"get:global," +
"get:unicode," +
"get:flags," +
"set:lastIndex," +
"get:exec,call:exec," +
"get:result[0]," +
Expand All @@ -192,8 +187,7 @@ ret = RegExp.prototype[Symbol.replace].call(myRegExp, target, "[$&,$`,$',$1,$2,$
assertEq(arraySetterObserved, false);
assertEq(ret, "a[BC,a,AbcABC,b,c,$3,$]AbcABC");
assertEq(log,
"get:global," +
"get:unicode," +
"get:flags," +
"set:lastIndex," +
"get:exec,call:exec," +
"get:result[0]," +
Expand Down Expand Up @@ -223,8 +217,7 @@ ret = RegExp.prototype[Symbol.replace].call(myRegExp, target, replaceFunc);
assertEq(arraySetterObserved, false);
assertEq(ret, "a_ret_AbcABC");
assertEq(log,
"get:global," +
"get:unicode," +
"get:flags," +
"set:lastIndex," +
"get:exec,call:exec," +
"get:result[0]," +
Expand All @@ -244,8 +237,7 @@ ret = RegExp.prototype[Symbol.replace].call(myRegExp, target, "_XYZ_");
assertEq(arraySetterObserved, false);
assertEq(ret, "abcAb_XYZ_ABC");
assertEq(log,
"get:global," +
"get:unicode," +
"get:flags," +
"set:lastIndex," +
"get:exec,call:exec," +
"get:result[0]," +
Expand All @@ -264,8 +256,7 @@ ret = RegExp.prototype[Symbol.replace].call(myRegExp, target, "_XYZ_");
assertEq(arraySetterObserved, false);
assertEq(ret, "abcAbcA_XYZ_");
assertEq(log,
"get:global," +
"get:unicode," +
"get:flags," +
"set:lastIndex," +
"get:exec,call:exec," +
"get:result[0]," +
Expand All @@ -281,8 +272,7 @@ ret = RegExp.prototype[Symbol.replace].call(myRegExp, target, "_XYZ_");
assertEq(arraySetterObserved, false);
assertEq(ret, "abcAbcABC_XYZ_");
assertEq(log,
"get:global," +
"get:unicode," +
"get:flags," +
"set:lastIndex," +
"get:exec,call:exec," +
"get:result[0]," +
Expand All @@ -299,7 +289,7 @@ ret = RegExp.prototype[Symbol.replace].call(myRegExp, target, "_XYZ_");
assertEq(arraySetterObserved, false);
assertEq(ret, "a_XYZ_AbcABC");
assertEq(log,
"get:global," +
"get:flags," +
"get:exec,call:exec," +
"get:result[length],get:result[0],get:result[index],get:result[groups],");

Expand Down

0 comments on commit cb2578c

Please sign in to comment.