From 8dd16259287f58f9273002717ec4d27e97127719 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 12 Jun 2024 07:43:14 +0200 Subject: Merging upstream version 127.0. Signed-off-by: Daniel Baumann --- .../add-dotAll-does-not-affect-dotAll-property.js | 49 ++++++++++ .../add-dotAll-does-not-affect-ignoreCase-flag.js | 67 +++++++++++++ .../add-dotAll-does-not-affect-multiline-flag.js | 59 ++++++++++++ .../RegExp/regexp-modifiers/add-dotAll.js | 105 +++++++++++++++++++++ .../add-ignoreCase-affects-backreferences.js | 55 +++++++++++ .../add-ignoreCase-affects-characterClasses.js | 67 +++++++++++++ .../add-ignoreCase-affects-characterEscapes.js | 67 +++++++++++++ .../add-ignoreCase-affects-slash-lower-b.js | 77 +++++++++++++++ .../add-ignoreCase-affects-slash-lower-p.js | 61 ++++++++++++ .../add-ignoreCase-affects-slash-lower-w.js | 77 +++++++++++++++ .../add-ignoreCase-affects-slash-upper-b.js | 57 +++++++++++ .../add-ignoreCase-affects-slash-upper-p.js | 63 +++++++++++++ .../add-ignoreCase-affects-slash-upper-w.js | 57 +++++++++++ .../add-ignoreCase-does-not-affect-dotAll-flag.js | 67 +++++++++++++ ...noreCase-does-not-affect-ignoreCase-property.js | 55 +++++++++++ ...dd-ignoreCase-does-not-affect-multiline-flag.js | 67 +++++++++++++ .../RegExp/regexp-modifiers/add-ignoreCase.js | 47 +++++++++ .../add-multiline-does-not-affect-dotAll-flag.js | 59 ++++++++++++ ...dd-multiline-does-not-affect-ignoreCase-flag.js | 67 +++++++++++++ ...multiline-does-not-affect-multiline-property.js | 49 ++++++++++ .../RegExp/regexp-modifiers/add-multiline.js | 49 ++++++++++ .../regexp-modifiers/add-remove-modifiers.js | 45 +++++++++ .../built-ins/RegExp/regexp-modifiers/browser.js | 0 ...-dotAll-flag-does-not-affect-dotAll-modifier.js | 77 +++++++++++++++ ...ase-flag-does-not-affect-ignoreCase-modifier.js | 55 +++++++++++ ...line-flag-does-not-affect-multiline-modifier.js | 51 ++++++++++ .../nested-add-remove-modifiers.js | 45 +++++++++ .../nesting-add-dotAll-within-remove-dotAll.js | 71 ++++++++++++++ ...ting-add-ignoreCase-within-remove-ignoreCase.js | 45 +++++++++ ...esting-add-multiline-within-remove-multiline.js | 47 +++++++++ .../nesting-remove-dotAll-within-add-dotAll.js | 71 ++++++++++++++ ...ting-remove-ignoreCase-within-add-ignoreCase.js | 45 +++++++++ ...esting-remove-multiline-within-add-multiline.js | 47 +++++++++ ...emove-dotAll-does-not-affect-dotAll-property.js | 43 +++++++++ ...emove-dotAll-does-not-affect-ignoreCase-flag.js | 49 ++++++++++ ...remove-dotAll-does-not-affect-multiline-flag.js | 49 ++++++++++ .../RegExp/regexp-modifiers/remove-dotAll.js | 71 ++++++++++++++ .../remove-ignoreCase-affects-backreferences.js | 43 +++++++++ .../remove-ignoreCase-affects-characterClasses.js | 55 +++++++++++ .../remove-ignoreCase-affects-characterEscapes.js | 52 ++++++++++ .../remove-ignoreCase-affects-slash-lower-b.js | 53 +++++++++++ .../remove-ignoreCase-affects-slash-lower-p.js | 55 +++++++++++ .../remove-ignoreCase-affects-slash-lower-w.js | 53 +++++++++++ .../remove-ignoreCase-affects-slash-upper-b.js | 53 +++++++++++ .../remove-ignoreCase-affects-slash-upper-p.js | 56 +++++++++++ .../remove-ignoreCase-affects-slash-upper-w.js | 53 +++++++++++ ...emove-ignoreCase-does-not-affect-dotAll-flag.js | 49 ++++++++++ ...noreCase-does-not-affect-ignoreCase-property.js | 49 ++++++++++ ...ve-ignoreCase-does-not-affect-multiline-flag.js | 49 ++++++++++ .../RegExp/regexp-modifiers/remove-ignoreCase.js | 49 ++++++++++ ...remove-multiline-does-not-affect-dotAll-flag.js | 49 ++++++++++ ...ve-multiline-does-not-affect-ignoreCase-flag.js | 49 ++++++++++ ...multiline-does-not-affect-multiline-property.js | 43 +++++++++ .../RegExp/regexp-modifiers/remove-multiline.js | 45 +++++++++ .../built-ins/RegExp/regexp-modifiers/shell.js | 0 .../RegExp/regexp-modifiers/syntax/browser.js | 0 .../RegExp/regexp-modifiers/syntax/shell.js | 0 ...ve-modifiers-can-have-empty-remove-modifiers.js | 68 +++++++++++++ .../syntax/valid/add-and-remove-modifiers.js | 74 +++++++++++++++ .../syntax/valid/add-modifiers-when-nested.js | 44 +++++++++ .../valid/add-modifiers-when-not-set-as-flags.js | 68 +++++++++++++ .../valid/add-modifiers-when-set-as-flags.js | 46 +++++++++ .../regexp-modifiers/syntax/valid/browser.js | 0 .../syntax/valid/remove-modifiers-when-nested.js | 44 +++++++++ .../remove-modifiers-when-not-set-as-flags.js | 68 +++++++++++++ .../valid/remove-modifiers-when-set-as-flags.js | 68 +++++++++++++ .../RegExp/regexp-modifiers/syntax/valid/shell.js | 0 67 files changed, 3467 insertions(+) create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-dotAll-does-not-affect-dotAll-property.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-dotAll-does-not-affect-ignoreCase-flag.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-dotAll-does-not-affect-multiline-flag.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-dotAll.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase-affects-backreferences.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase-affects-characterClasses.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase-affects-characterEscapes.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase-affects-slash-lower-b.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase-affects-slash-lower-p.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase-affects-slash-lower-w.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase-affects-slash-upper-b.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase-affects-slash-upper-p.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase-affects-slash-upper-w.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase-does-not-affect-dotAll-flag.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase-does-not-affect-ignoreCase-property.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase-does-not-affect-multiline-flag.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-multiline-does-not-affect-dotAll-flag.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-multiline-does-not-affect-ignoreCase-flag.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-multiline-does-not-affect-multiline-property.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-multiline.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-remove-modifiers.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/browser.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/changing-dotAll-flag-does-not-affect-dotAll-modifier.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/changing-ignoreCase-flag-does-not-affect-ignoreCase-modifier.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/changing-multiline-flag-does-not-affect-multiline-modifier.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/nested-add-remove-modifiers.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/nesting-add-dotAll-within-remove-dotAll.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/nesting-add-ignoreCase-within-remove-ignoreCase.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/nesting-add-multiline-within-remove-multiline.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/nesting-remove-dotAll-within-add-dotAll.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/nesting-remove-ignoreCase-within-add-ignoreCase.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/nesting-remove-multiline-within-add-multiline.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-dotAll-does-not-affect-dotAll-property.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-dotAll-does-not-affect-ignoreCase-flag.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-dotAll-does-not-affect-multiline-flag.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-dotAll.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-affects-backreferences.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-affects-characterClasses.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-affects-characterEscapes.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-affects-slash-lower-b.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-affects-slash-lower-p.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-affects-slash-lower-w.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-affects-slash-upper-b.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-affects-slash-upper-p.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-affects-slash-upper-w.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-does-not-affect-dotAll-flag.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-does-not-affect-ignoreCase-property.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-does-not-affect-multiline-flag.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-multiline-does-not-affect-dotAll-flag.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-multiline-does-not-affect-ignoreCase-flag.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-multiline-does-not-affect-multiline-property.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-multiline.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/shell.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/syntax/browser.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/syntax/shell.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/syntax/valid/add-and-remove-modifiers-can-have-empty-remove-modifiers.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/syntax/valid/add-and-remove-modifiers.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/syntax/valid/add-modifiers-when-nested.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/syntax/valid/add-modifiers-when-not-set-as-flags.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/syntax/valid/add-modifiers-when-set-as-flags.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/syntax/valid/browser.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/syntax/valid/remove-modifiers-when-nested.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/syntax/valid/remove-modifiers-when-not-set-as-flags.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/syntax/valid/remove-modifiers-when-set-as-flags.js create mode 100644 js/src/tests/test262/built-ins/RegExp/regexp-modifiers/syntax/valid/shell.js (limited to 'js/src/tests/test262/built-ins/RegExp/regexp-modifiers') diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-dotAll-does-not-affect-dotAll-property.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-dotAll-does-not-affect-dotAll-property.js new file mode 100644 index 0000000000..7edf9b90a4 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-dotAll-does-not-affect-dotAll-property.js @@ -0,0 +1,49 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Adding dotAll (`s`) modifier does not affect RegExp instance `dotAll` property. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by RegularExpressionFlags. + 2. Let removeModifiers be the empty String. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), removeModifiers). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(?s:)/; +assert(!re1.dotAll, "RegExp instance dotAll flag should not be set"); + +var re2 = new RegExp("(?s:)"); +assert(!re2.dotAll, "RegExp instance dotAll flag should not be set"); + +var re3 = /(?s-:)/; +assert(!re3.dotAll, "RegExp instance dotAll flag should not be set"); + +var re4 = new RegExp("(?s-:)"); +assert(!re4.dotAll, "RegExp instance dotAll flag should not be set"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-dotAll-does-not-affect-ignoreCase-flag.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-dotAll-does-not-affect-ignoreCase-flag.js new file mode 100644 index 0000000000..1ebb730625 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-dotAll-does-not-affect-ignoreCase-flag.js @@ -0,0 +1,67 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Adding dotAll (`s`) modifier in group should not affect ignoreCase (`i`) flag. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by RegularExpressionFlags. + 2. Let removeModifiers be the empty String. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), removeModifiers). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + Atom :: `(` `?` RegularExpressionFlags `-` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by the first RegularExpressionFlags. + 2. Let removeModifiers be the source text matched by the second RegularExpressionFlags. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), CodePointsToString(removeModifiers)). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(?s:.es)/; +assert(re1.test("aes"), "s should match s in modified group"); +assert(re1.test("\nes"), "s should match s in modified group"); +assert(!re1.test("aeS"), "s should not match S in modified group"); +assert(!re1.test("\neS"), "s should not match S in modified group"); + +var re2 = /(?s:.es)/i; +assert(re2.test("aes"), "s should match s in modified group"); +assert(re2.test("aeS"), "s should match S in modified group"); +assert(re2.test("\nes"), "s should match s in modified group"); +assert(re2.test("\neS"), "s should match S in modified group"); + +var re3 = /(?s-:.es)/; +assert(re3.test("aes"), "s should match s in modified group"); +assert(re3.test("\nes"), "s should match s in modified group"); +assert(!re3.test("aeS"), "s should not match S in modified group"); +assert(!re3.test("\neS"), "s should not match S in modified group"); + +var re4 = /(?s-:.es)/i; +assert(re4.test("aes"), "s should match s in modified group"); +assert(re4.test("aeS"), "s should match S in modified group"); +assert(re4.test("\nes"), "s should match s in modified group"); +assert(re4.test("\neS"), "s should match S in modified group"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-dotAll-does-not-affect-multiline-flag.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-dotAll-does-not-affect-multiline-flag.js new file mode 100644 index 0000000000..2f9adf75e3 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-dotAll-does-not-affect-multiline-flag.js @@ -0,0 +1,59 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Adding dotAll (`s`) modifier in group should not affect multiline (`m`) flag. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by RegularExpressionFlags. + 2. Let removeModifiers be the empty String. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), removeModifiers). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + Atom :: `(` `?` RegularExpressionFlags `-` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by the first RegularExpressionFlags. + 2. Let removeModifiers be the source text matched by the second RegularExpressionFlags. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), CodePointsToString(removeModifiers)). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(?s:.es$)/; +assert(re1.test("\nes"), ". should match newline in modified group"); +assert(!re1.test("\nes\nz"), "$ should not match newline in modified group"); + +var re2 = /(?s:.es$)/m; +assert(re2.test("\nes"), ". should match newline in modified group"); +assert(re2.test("\nes\nz"), "$ should match newline in modified group"); + +var re3 = /(?s-:.es$)/; +assert(re3.test("\nes"), ". should match newline in modified group"); +assert(!re3.test("\nes\nz"), "$ should not match newline in modified group"); + +var re4 = /(?s-:.es$)/m; +assert(re4.test("\nes"), ". should match newline in modified group"); +assert(re4.test("\nes\nz"), "$ should match newline in modified group"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-dotAll.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-dotAll.js new file mode 100644 index 0000000000..8c163adf54 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-dotAll.js @@ -0,0 +1,105 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + dotAll (`s`) modifier can be added via `(?s:)` or `(?s-:)`. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by RegularExpressionFlags. + 2. Let removeModifiers be the empty String. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), removeModifiers). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(?s:^.$)/; +assert(re1.test("a"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re1.test("3"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re1.test("π"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re1.test("\u2027"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re1.test("\u0085"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re1.test("\v"), "Pattern character '.' should match mon-line terminators in modified group"); +assert(re1.test("\f"), "Pattern character '.' should match mon-line terminators in modified group"); +assert(re1.test("\u180E"), "Pattern character '.' should match non-line terminators in modified group"); +assert(!re1.test("\u{10300}"), "Supplementary plane not matched by a single ."); +assert(re1.test("\n"), "Pattern character '.' should match line terminators in modified group"); +assert(re1.test("\r"), "Pattern character '.' should match line terminators in modified group"); +assert(re1.test("\u2028"), "Pattern character '.' should match line terminators in modified group"); +assert(re1.test("\u2029"), "Pattern character '.' should match line terminators in modified group"); +assert(re1.test("\uD800"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re1.test("\uDFFF"), "Pattern character '.' should match non-line terminators in modified group"); + +var re2 = new RegExp("(?s:^.$)"); +assert(re2.test("a"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re2.test("3"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re2.test("π"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re2.test("\u2027"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re2.test("\u0085"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re2.test("\v"), "Pattern character '.' should match mon-line terminators in modified group"); +assert(re2.test("\f"), "Pattern character '.' should match mon-line terminators in modified group"); +assert(re2.test("\u180E"), "Pattern character '.' should match non-line terminators in modified group"); +assert(!re2.test("\u{10300}"), "Supplementary plane not matched by a single ."); +assert(re2.test("\n"), "Pattern character '.' should match line terminators in modified group"); +assert(re2.test("\r"), "Pattern character '.' should match line terminators in modified group"); +assert(re2.test("\u2028"), "Pattern character '.' should match line terminators in modified group"); +assert(re2.test("\u2029"), "Pattern character '.' should match line terminators in modified group"); +assert(re2.test("\uD800"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re2.test("\uDFFF"), "Pattern character '.' should match non-line terminators in modified group"); + +var re3 = /(?s-:^.$)/; +assert(re3.test("a"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re3.test("3"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re3.test("π"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re3.test("\u2027"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re3.test("\u0085"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re3.test("\v"), "Pattern character '.' should match mon-line terminators in modified group"); +assert(re3.test("\f"), "Pattern character '.' should match mon-line terminators in modified group"); +assert(re3.test("\u180E"), "Pattern character '.' should match non-line terminators in modified group"); +assert(!re3.test("\u{10300}"), "Supplementary plane not matched by a single ."); +assert(re3.test("\n"), "Pattern character '.' should match line terminators in modified group"); +assert(re3.test("\r"), "Pattern character '.' should match line terminators in modified group"); +assert(re3.test("\u2028"), "Pattern character '.' should match line terminators in modified group"); +assert(re3.test("\u2029"), "Pattern character '.' should match line terminators in modified group"); +assert(re3.test("\uD800"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re3.test("\uDFFF"), "Pattern character '.' should match non-line terminators in modified group"); + +var re4 = new RegExp("(?s-:^.$)"); +assert(re4.test("a"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re4.test("3"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re4.test("π"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re4.test("\u2027"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re4.test("\u0085"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re4.test("\v"), "Pattern character '.' should match mon-line terminators in modified group"); +assert(re4.test("\f"), "Pattern character '.' should match mon-line terminators in modified group"); +assert(re4.test("\u180E"), "Pattern character '.' should match non-line terminators in modified group"); +assert(!re4.test("\u{10300}"), "Supplementary plane not matched by a single ."); +assert(re4.test("\n"), "Pattern character '.' should match line terminators in modified group"); +assert(re4.test("\r"), "Pattern character '.' should match line terminators in modified group"); +assert(re4.test("\u2028"), "Pattern character '.' should match line terminators in modified group"); +assert(re4.test("\u2029"), "Pattern character '.' should match line terminators in modified group"); +assert(re4.test("\uD800"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re4.test("\uDFFF"), "Pattern character '.' should match non-line terminators in modified group"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase-affects-backreferences.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase-affects-backreferences.js new file mode 100644 index 0000000000..53e9ecb991 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase-affects-backreferences.js @@ -0,0 +1,55 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Adding ignoreCase (`i`) modifier in group affects backreferences in group. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by RegularExpressionFlags. + 2. Let removeModifiers be the empty String. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), removeModifiers). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + Atom :: `(` `?` RegularExpressionFlags `-` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by the first RegularExpressionFlags. + 2. Let removeModifiers be the source text matched by the second RegularExpressionFlags. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), CodePointsToString(removeModifiers)). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(a)(?i:\1)/; +assert(!re1.test("AA"), "a should not match first A"); +assert(!re1.test("Aa"), "a should not match A"); +assert(re1.test("aa"), "a matches first a, so \\1 should match second a"); +assert(re1.test("aA"), "a matches a, so \\1 should match A (ignores case)"); + +var re2 = /(a)(?i-:\1)/; +assert(!re2.test("AA"), "a should not match first A"); +assert(!re2.test("Aa"), "a should not match A"); +assert(re2.test("aa"), "a matches first a, so \\1 should match second a"); +assert(re2.test("aA"), "a matches a, so \\1 should match A (ignores case)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase-affects-characterClasses.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase-affects-characterClasses.js new file mode 100644 index 0000000000..75c50a97fa --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase-affects-characterClasses.js @@ -0,0 +1,67 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Adding ignoreCase (`i`) modifier in group affects character classes in group. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by RegularExpressionFlags. + 2. Let removeModifiers be the empty String. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), removeModifiers). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + Atom :: `(` `?` RegularExpressionFlags `-` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by the first RegularExpressionFlags. + 2. Let removeModifiers be the source text matched by the second RegularExpressionFlags. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), CodePointsToString(removeModifiers)). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(?i:[ab])c/; +assert(re1.test("ac"), "[ab] should match a"); +assert(re1.test("Ac"), "[ab] should match A"); +assert(re1.test("bc"), "[ab] should match b"); +assert(re1.test("Bc"), "[ab] should match B"); + +var re2 = /(?i-:[ab])c/; +assert(re2.test("ac"), "[ab] should match a"); +assert(re2.test("Ac"), "[ab] should match A"); +assert(re2.test("bc"), "[ab] should match b"); +assert(re2.test("Bc"), "[ab] should match B"); + +var re3 = /(?i:[^ab])c/; +assert(!re3.test("ac"), "[^ab] should not match a"); +assert(!re3.test("Ac"), "[^ab] should not match A"); +assert(!re3.test("bc"), "[^ab] should not match b"); +assert(!re3.test("Bc"), "[^ab] should not match B"); + +var re4 = /(?i-:[^ab])c/; +assert(!re4.test("ac"), "[^ab] should not match a"); +assert(!re4.test("Ac"), "[^ab] should not match A"); +assert(!re4.test("bc"), "[^ab] should not match b"); +assert(!re4.test("Bc"), "[^ab] should not match B"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase-affects-characterEscapes.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase-affects-characterEscapes.js new file mode 100644 index 0000000000..98fa435027 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase-affects-characterEscapes.js @@ -0,0 +1,67 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Adding ignoreCase (`i`) modifier in group affects character escapes in group. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by RegularExpressionFlags. + 2. Let removeModifiers be the empty String. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), removeModifiers). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + Atom :: `(` `?` RegularExpressionFlags `-` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by the first RegularExpressionFlags. + 2. Let removeModifiers be the source text matched by the second RegularExpressionFlags. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), CodePointsToString(removeModifiers)). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(?i:\x61)b/; +assert(re1.test("ab"), "\\x61 should match a"); +assert(re1.test("Ab"), "\\x61 should match A"); + +var re2 = /(?i:\u0061)b/; +assert(re2.test("ab"), "\\u0061 should match a"); +assert(re2.test("Ab"), "\\u0061 should match A"); + +var re3 = /(?i:\u{0061})b/u; +assert(re3.test("ab"), "\\u0061 should match a"); +assert(re3.test("Ab"), "\\u0061 should match A"); + +var re4 = /(?i-:\x61)b/; +assert(re4.test("ab"), "\\x61 should match a"); +assert(re4.test("Ab"), "\\x61 should match A"); + +var re5 = /(?i-:\u0061)b/; +assert(re5.test("ab"), "\\u0061 should match a"); +assert(re5.test("Ab"), "\\u0061 should match A"); + +var re6 = /(?i-:\u{0061})b/u; +assert(re6.test("ab"), "\\u0061 should match a"); +assert(re6.test("Ab"), "\\u0061 should match A"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase-affects-slash-lower-b.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase-affects-slash-lower-b.js new file mode 100644 index 0000000000..a3f5b9f009 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase-affects-slash-lower-b.js @@ -0,0 +1,77 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Adding ignoreCase (`i`) modifier affects matching for `\b`. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by RegularExpressionFlags. + 2. Let removeModifiers be the empty String. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), removeModifiers). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + Atom :: `(` `?` RegularExpressionFlags `-` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by the first RegularExpressionFlags. + 2. Let removeModifiers be the source text matched by the second RegularExpressionFlags. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), CodePointsToString(removeModifiers)). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + + GetWordCharacters ( modifiers ) + The abstract operation GetWordCharacters takes argument modifiers (a Modifiers Record) and returns a CharSet. It performs the following steps when called: + + 1. Let wordCharacters be the mathematical set that is the union of all sixty-three characters in "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_" (letters, numbers, and U+005F (LOW LINE) in the Unicode Basic Latin block) and all characters c for which c is not in that set but Canonicalize(c, modifiers) is. + 2. Return wordCharacters. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(?i:\b)/; +assert(re1.test("A"), "\\b should match after A"); +assert(re1.test("a"), "\\b should match after a"); +assert(re1.test("z"), "\\b should match after z"); +assert(re1.test("Z"), "\\b should match after Z"); + +var re2 = /(?i:\b)/u; +assert(re2.test("A"), "\\b should match after A"); +assert(re2.test("a"), "\\b should match after a"); +assert(re2.test("z"), "\\b should match after z"); +assert(re2.test("Z"), "\\b should match after Z"); +assert(re2.test("\u017f"), "\\b should match after \u017f"); +assert(re2.test("\u212a"), "\\b should match after \u212a"); + +var re3 = /(?i-:\b)/; +assert(re3.test("A"), "\\b should match after A"); +assert(re3.test("a"), "\\b should match after a"); +assert(re3.test("z"), "\\b should match after z"); +assert(re3.test("Z"), "\\b should match after Z"); + +var re4 = /(?i-:\b)/u; +assert(re4.test("A"), "\\b should match after A"); +assert(re4.test("a"), "\\b should match after a"); +assert(re4.test("z"), "\\b should match after z"); +assert(re4.test("Z"), "\\b should match after Z"); +assert(re4.test("\u017f"), "\\b should match after \u017f"); +assert(re4.test("\u212a"), "\\b should match after \u212a"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase-affects-slash-lower-p.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase-affects-slash-lower-p.js new file mode 100644 index 0000000000..41788082ee --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase-affects-slash-lower-p.js @@ -0,0 +1,61 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Adding ignoreCase (`i`) modifier affects matching for `\p{}`. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by RegularExpressionFlags. + 2. Let removeModifiers be the empty String. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), removeModifiers). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + Atom :: `(` `?` RegularExpressionFlags `-` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by the first RegularExpressionFlags. + 2. Let removeModifiers be the source text matched by the second RegularExpressionFlags. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), CodePointsToString(removeModifiers)). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + + GetWordCharacters ( modifiers ) + The abstract operation GetWordCharacters takes argument modifiers (a Modifiers Record) and returns a CharSet. It performs the following steps when called: + + 1. Let wordCharacters be the mathematical set that is the union of all sixty-three characters in "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_" (letters, numbers, and U+005F (LOW LINE) in the Unicode Basic Latin block) and all characters c for which c is not in that set but Canonicalize(c, modifiers) is. + 2. Return wordCharacters. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(?i:\p{Lu})/u; +assert(re1.test("A"), "\\p{Lu} should match A"); +assert(re1.test("a"), "\\p{Lu} should match a (ignores case)"); +assert(re1.test("Z"), "\\p{Lu} should match Z"); +assert(re1.test("z"), "\\p{Lu} should match z (ignores case)"); + +var re2 = /(?i-:\p{Lu})/u; +assert(re2.test("A"), "\\p{Lu} should match A"); +assert(re2.test("a"), "\\p{Lu} should match a (ignores case)"); +assert(re2.test("Z"), "\\p{Lu} should match Z"); +assert(re2.test("z"), "\\p{Lu} should match z (ignores case)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase-affects-slash-lower-w.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase-affects-slash-lower-w.js new file mode 100644 index 0000000000..324961d782 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase-affects-slash-lower-w.js @@ -0,0 +1,77 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Adding ignoreCase (`i`) modifier affects matching for `\w`. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by RegularExpressionFlags. + 2. Let removeModifiers be the empty String. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), removeModifiers). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + Atom :: `(` `?` RegularExpressionFlags `-` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by the first RegularExpressionFlags. + 2. Let removeModifiers be the source text matched by the second RegularExpressionFlags. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), CodePointsToString(removeModifiers)). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + + GetWordCharacters ( modifiers ) + The abstract operation GetWordCharacters takes argument modifiers (a Modifiers Record) and returns a CharSet. It performs the following steps when called: + + 1. Let wordCharacters be the mathematical set that is the union of all sixty-three characters in "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_" (letters, numbers, and U+005F (LOW LINE) in the Unicode Basic Latin block) and all characters c for which c is not in that set but Canonicalize(c, modifiers) is. + 2. Return wordCharacters. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(?i:\w)/; +assert(re1.test("A"), "\\w should match A"); +assert(re1.test("a"), "\\w should match a"); +assert(re1.test("z"), "\\w should match z"); +assert(re1.test("Z"), "\\w should match Z"); + +var re2 = /(?i:\w)/u; +assert(re2.test("A"), "\\w should match A"); +assert(re2.test("a"), "\\w should match a"); +assert(re2.test("z"), "\\w should match z"); +assert(re2.test("Z"), "\\w should match Z"); +assert(re2.test("\u017f"), "\\w should match \u017f"); +assert(re2.test("\u212a"), "\\w should match \u212a"); + +var re3 = /(?i-:\w)/; +assert(re3.test("A"), "\\w should match A"); +assert(re3.test("a"), "\\w should match a"); +assert(re3.test("z"), "\\w should match z"); +assert(re3.test("Z"), "\\w should match Z"); + +var re4 = /(?i-:\w)/u; +assert(re4.test("A"), "\\w should match A"); +assert(re4.test("a"), "\\w should match a"); +assert(re4.test("z"), "\\w should match z"); +assert(re4.test("Z"), "\\w should match Z"); +assert(re4.test("\u017f"), "\\w should match \u017f"); +assert(re4.test("\u212a"), "\\w should match \u212a"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase-affects-slash-upper-b.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase-affects-slash-upper-b.js new file mode 100644 index 0000000000..ffb346277f --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase-affects-slash-upper-b.js @@ -0,0 +1,57 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Adding ignoreCase (`i`) modifier affects matching for `\B`. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by RegularExpressionFlags. + 2. Let removeModifiers be the empty String. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), removeModifiers). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + Atom :: `(` `?` RegularExpressionFlags `-` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by the first RegularExpressionFlags. + 2. Let removeModifiers be the source text matched by the second RegularExpressionFlags. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), CodePointsToString(removeModifiers)). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + + GetWordCharacters ( modifiers ) + The abstract operation GetWordCharacters takes argument modifiers (a Modifiers Record) and returns a CharSet. It performs the following steps when called: + + 1. Let wordCharacters be the mathematical set that is the union of all sixty-three characters in "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_" (letters, numbers, and U+005F (LOW LINE) in the Unicode Basic Latin block) and all characters c for which c is not in that set but Canonicalize(c, modifiers) is. + 2. Return wordCharacters. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(?i:Z\B)/u; +assert(re1.test("Z\u017f"), "\\B should match between Z and \u017f"); +assert(re1.test("Z\u212a"), "\\B should match between Z and \u212a"); + +var re2 = /(?i-:Z\B)/u; +assert(re2.test("Z\u017f"), "\\B should match between Z and \u017f"); +assert(re2.test("Z\u212a"), "\\B should match between Z and \u212a"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase-affects-slash-upper-p.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase-affects-slash-upper-p.js new file mode 100644 index 0000000000..d5f30655cb --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase-affects-slash-upper-p.js @@ -0,0 +1,63 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Adding ignoreCase (`i`) modifier affects matching for `\P{}`. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by RegularExpressionFlags. + 2. Let removeModifiers be the empty String. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), removeModifiers). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + Atom :: `(` `?` RegularExpressionFlags `-` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by the first RegularExpressionFlags. + 2. Let removeModifiers be the source text matched by the second RegularExpressionFlags. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), CodePointsToString(removeModifiers)). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + + GetWordCharacters ( modifiers ) + The abstract operation GetWordCharacters takes argument modifiers (a Modifiers Record) and returns a CharSet. It performs the following steps when called: + + 1. Let wordCharacters be the mathematical set that is the union of all sixty-three characters in "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_" (letters, numbers, and U+005F (LOW LINE) in the Unicode Basic Latin block) and all characters c for which c is not in that set but Canonicalize(c, modifiers) is. + 2. Return wordCharacters. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(?i:\P{Lu})/u; +assert(re1.test("A"), "\\P{Lu} should match A (ignores case)"); +assert(re1.test("a"), "\\P{Lu} should match a"); +assert(re1.test("Z"), "\\P{Lu} should match Z (ignores case)"); +assert(re1.test("z"), "\\P{Lu} should match z"); +assert(re1.test("0"), "\\P{Lu} should match 0"); + +var re2 = /(?i-:\P{Lu})/u; +assert(re2.test("A"), "\\P{Lu} should match A (ignores case)"); +assert(re2.test("a"), "\\P{Lu} should match a"); +assert(re2.test("Z"), "\\P{Lu} should match Z (ignores case)"); +assert(re2.test("z"), "\\P{Lu} should match z"); +assert(re2.test("0"), "\\P{Lu} should match 0"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase-affects-slash-upper-w.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase-affects-slash-upper-w.js new file mode 100644 index 0000000000..a0c527efa2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase-affects-slash-upper-w.js @@ -0,0 +1,57 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Adding ignoreCase (`i`) modifier affects matching for `\W`. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by RegularExpressionFlags. + 2. Let removeModifiers be the empty String. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), removeModifiers). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + Atom :: `(` `?` RegularExpressionFlags `-` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by the first RegularExpressionFlags. + 2. Let removeModifiers be the source text matched by the second RegularExpressionFlags. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), CodePointsToString(removeModifiers)). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + + GetWordCharacters ( modifiers ) + The abstract operation GetWordCharacters takes argument modifiers (a Modifiers Record) and returns a CharSet. It performs the following steps when called: + + 1. Let wordCharacters be the mathematical set that is the union of all sixty-three characters in "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_" (letters, numbers, and U+005F (LOW LINE) in the Unicode Basic Latin block) and all characters c for which c is not in that set but Canonicalize(c, modifiers) is. + 2. Return wordCharacters. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(?i:\W)/u; +assert(!re1.test("\u017f"), "\\W should not match \u017f"); +assert(!re1.test("\u212a"), "\\W should not match \u212a"); + +var re2 = /(?i-:\W)/u; +assert(!re2.test("\u017f"), "\\W should not match \u017f"); +assert(!re2.test("\u212a"), "\\W should not match \u212a"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase-does-not-affect-dotAll-flag.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase-does-not-affect-dotAll-flag.js new file mode 100644 index 0000000000..999598c492 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase-does-not-affect-dotAll-flag.js @@ -0,0 +1,67 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Adding ignoreCase (`i`) modifier in group should not affect dotAll (`s`) flag. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by RegularExpressionFlags. + 2. Let removeModifiers be the empty String. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), removeModifiers). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + Atom :: `(` `?` RegularExpressionFlags `-` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by the first RegularExpressionFlags. + 2. Let removeModifiers be the source text matched by the second RegularExpressionFlags. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), CodePointsToString(removeModifiers)). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(?i:.es)/; +assert(re1.test("aes"), ". should match a in modified group"); +assert(re1.test("aeS"), ". should match a in modified group"); +assert(!re1.test("\nes"), ". should not match newline in modified group"); +assert(!re1.test("\neS"), ". should not match newline in modified group"); + +var re2 = /(?i:.es)/s; +assert(re2.test("aes"), ". should match a in modified group"); +assert(re2.test("aeS"), ". should match a in modified group"); +assert(re2.test("\nes"), ". should match newline in modified group"); +assert(re2.test("\neS"), ". should match newline in modified group"); + +var re3 = /(?i-:.es)/; +assert(re3.test("aes"), ". should match a in modified group"); +assert(re3.test("aeS"), ". should match a in modified group"); +assert(!re3.test("\nes"), ". should not match newline in modified group"); +assert(!re3.test("\neS"), ". should not match newline in modified group"); + +var re4 = /(?i-:.es)/s; +assert(re4.test("aes"), ". should match a in modified group"); +assert(re4.test("aeS"), ". should match a in modified group"); +assert(re4.test("\nes"), ". should match newline in modified group"); +assert(re4.test("\neS"), ". should match newline in modified group"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase-does-not-affect-ignoreCase-property.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase-does-not-affect-ignoreCase-property.js new file mode 100644 index 0000000000..24da245c46 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase-does-not-affect-ignoreCase-property.js @@ -0,0 +1,55 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Adding ignoreCase (`i`) modifier does not affect RegExp instance `ignoreCase` property. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by RegularExpressionFlags. + 2. Let removeModifiers be the empty String. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), removeModifiers). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + Atom :: `(` `?` RegularExpressionFlags `-` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by the first RegularExpressionFlags. + 2. Let removeModifiers be the source text matched by the second RegularExpressionFlags. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), CodePointsToString(removeModifiers)). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(?i:)/; +assert(!re1.ignoreCase, "RegExp instance ignoreCase property should not be set"); + +var re2 = new RegExp("(?i:)"); +assert(!re2.ignoreCase, "RegExp instance ignoreCase property should not be set"); + +var re3 = /(?i-:)/; +assert(!re3.ignoreCase, "RegExp instance ignoreCase property should not be set"); + +var re4 = new RegExp("(?i-:)"); +assert(!re4.ignoreCase, "RegExp instance ignoreCase property should not be set"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase-does-not-affect-multiline-flag.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase-does-not-affect-multiline-flag.js new file mode 100644 index 0000000000..692cfd9f2f --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase-does-not-affect-multiline-flag.js @@ -0,0 +1,67 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Adding ignoreCase (`i`) modifier in group should not affect multiline (`m`) flag. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by RegularExpressionFlags. + 2. Let removeModifiers be the empty String. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), removeModifiers). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + Atom :: `(` `?` RegularExpressionFlags `-` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by the first RegularExpressionFlags. + 2. Let removeModifiers be the source text matched by the second RegularExpressionFlags. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), CodePointsToString(removeModifiers)). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(?i:es$)/; +assert(re1.test("es"), "s should match s in modified group"); +assert(re1.test("eS"), "s should match S in modified group"); +assert(!re1.test("es\nz"), "$ should not match newline in modified group"); +assert(!re1.test("eS\nz"), "$ should not match newline in modified group"); + +var re2 = /(?i:es$)/m; +assert(re2.test("es"), "s should match s in modified group"); +assert(re2.test("eS"), "s should match S in modified group"); +assert(re2.test("es\nz"), "$ should match newline in modified group"); +assert(re2.test("eS\nz"), "$ should match newline in modified group"); + +var re3 = /(?i-:es$)/; +assert(re3.test("es"), "s should match s in modified group"); +assert(re3.test("eS"), "s should match S in modified group"); +assert(!re3.test("es\nz"), "$ should not match newline in modified group"); +assert(!re3.test("eS\nz"), "$ should not match newline in modified group"); + +var re4 = /(?i-:es$)/m; +assert(re4.test("es"), "s should match s in modified group"); +assert(re4.test("eS"), "s should match S in modified group"); +assert(re4.test("es\nz"), "$ should match newline in modified group"); +assert(re4.test("eS\nz"), "$ should match newline in modified group"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase.js new file mode 100644 index 0000000000..bd07e7aa22 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-ignoreCase.js @@ -0,0 +1,47 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + ignoreCase (`i`) modifier can be added via `(?i:)` or `(?i-:)`. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by RegularExpressionFlags. + 2. Let removeModifiers be the empty String. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), removeModifiers). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(?i:a)b/; +assert(!re1.test("AB"), "b should not match B in AB"); +assert(re1.test("Ab"), "a should match A in AB"); +assert(re1.test("ab"), "should match AB"); + +var re2 = new RegExp("(?i:a)b"); +assert(!re2.test("AB"), "b should not match B in AB"); +assert(re2.test("Ab"), "a should match A in AB"); +assert(re2.test("ab"), "should match AB"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-multiline-does-not-affect-dotAll-flag.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-multiline-does-not-affect-dotAll-flag.js new file mode 100644 index 0000000000..c065d293ac --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-multiline-does-not-affect-dotAll-flag.js @@ -0,0 +1,59 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Adding multiline (`m`) modifier in group should not affect dotAll (`s`) flag. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by RegularExpressionFlags. + 2. Let removeModifiers be the empty String. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), removeModifiers). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + Atom :: `(` `?` RegularExpressionFlags `-` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by the first RegularExpressionFlags. + 2. Let removeModifiers be the source text matched by the second RegularExpressionFlags. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), CodePointsToString(removeModifiers)). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(?m:es.$)/; +assert(re1.test("esz\n"), "$ should match newline in modified group"); +assert(!re1.test("es\n\n"), ". should not match newline in modified group"); + +var re2 = /(?m:es.$)/s; +assert(re2.test("esz\n"), "$ should match newline in modified group"); +assert(re2.test("es\n\n"), ". should match newline in modified group"); + +var re3 = /(?m-:es.$)/; +assert(re3.test("esz\n"), "$ should match newline in modified group"); +assert(!re3.test("es\n\n"), ". should not match newline in modified group"); + +var re4 = /(?m-:es.$)/s; +assert(re4.test("esz\n"), "$ should match newline in modified group"); +assert(re4.test("es\n\n"), ". should match newline in modified group"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-multiline-does-not-affect-ignoreCase-flag.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-multiline-does-not-affect-ignoreCase-flag.js new file mode 100644 index 0000000000..b8b33e9c22 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-multiline-does-not-affect-ignoreCase-flag.js @@ -0,0 +1,67 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Adding multiline (`m`) modifier in group should not affect ignoreCase (`i`) flag. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by RegularExpressionFlags. + 2. Let removeModifiers be the empty String. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), removeModifiers). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + Atom :: `(` `?` RegularExpressionFlags `-` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by the first RegularExpressionFlags. + 2. Let removeModifiers be the source text matched by the second RegularExpressionFlags. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), CodePointsToString(removeModifiers)). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(?m:es$)/; +assert(re1.test("es"), "s should match s in modified group"); +assert(!re1.test("eS"), "s should not match S in modified group"); +assert(re1.test("es\nz"), "$ should match newline in modified group"); +assert(!re1.test("eS\nz"), "s should not match S in modified group"); + +var re2 = /(?m:es$)/i; +assert(re2.test("es"), "s should match s in modified group"); +assert(re2.test("eS"), "s should match S in modified group"); +assert(re2.test("es\nz"), "$ should match newline in modified group"); +assert(re2.test("eS\nz"), "$ should match newline in modified group"); + +var re3 = /(?m-:es$)/; +assert(re3.test("es"), "s should match s in modified group"); +assert(!re3.test("eS"), "s should not match S in modified group"); +assert(re3.test("es\nz"), "$ should match newline in modified group"); +assert(!re3.test("eS\nz"), "s should not match S in modified group"); + +var re4 = /(?m-:es$)/i; +assert(re4.test("es"), "s should match s in modified group"); +assert(re4.test("eS"), "s should match S in modified group"); +assert(re4.test("es\nz"), "$ should match newline in modified group"); +assert(re4.test("eS\nz"), "$ should match newline in modified group"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-multiline-does-not-affect-multiline-property.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-multiline-does-not-affect-multiline-property.js new file mode 100644 index 0000000000..3b960f5a6c --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-multiline-does-not-affect-multiline-property.js @@ -0,0 +1,49 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Adding multiline (`m`) modifier does not affect RegExp instance `multiline` property. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by RegularExpressionFlags. + 2. Let removeModifiers be the empty String. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), removeModifiers). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(?m:)/; +assert(!re1.multiline, "RegExp instance multiline flag should not be set"); + +var re2 = new RegExp("(?m:)"); +assert(!re2.multiline, "RegExp instance multiline flag should not be set"); + +var re3 = /(?m-:)/; +assert(!re3.multiline, "RegExp instance multiline flag should not be set"); + +var re4 = new RegExp("(?m-:)"); +assert(!re4.multiline, "RegExp instance multiline flag should not be set"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-multiline.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-multiline.js new file mode 100644 index 0000000000..ee1d0a65cc --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-multiline.js @@ -0,0 +1,49 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + multiline (`m`) modifier can be added via `(?m:)` or `(?m-:)`. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by RegularExpressionFlags. + 2. Let removeModifiers be the empty String. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), removeModifiers). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(?m:es$)/; +assert(re1.test("es\ns"), "$ should match newline in modified group"); + +var re2 = new RegExp("(?m:es$)"); +assert(re2.test("es\ns"), "$ should match newline in modified group"); + +var re3 = /(?m-:es$)/; +assert(re3.test("es\ns"), "$ should match newline in modified group"); + +var re4 = new RegExp("(?m-:es$)"); +assert(re4.test("es\ns"), "$ should match newline in modified group"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-remove-modifiers.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-remove-modifiers.js new file mode 100644 index 0000000000..68e4761cfc --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/add-remove-modifiers.js @@ -0,0 +1,45 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Modifiers can be both added and removed via `(?ims-ims:)`. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `-` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by the first RegularExpressionFlags. + 2. Let removeModifiers be the source text matched by the second RegularExpressionFlags. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), CodePointsToString(removeModifiers)). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(?m-i:^a$)/i; +assert(!re1.test("A\n"), "Should not match 'A\\n'"); +assert(re1.test("a\n"), "Should match 'a\\n'"); + +var re2 = new RegExp("(?m-i:^a$)", "i"); +assert(!re2.test("A\n"), "Should not match 'A\\n'"); +assert(re2.test("a\n"), "Should match 'a\\n'"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/browser.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/changing-dotAll-flag-does-not-affect-dotAll-modifier.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/changing-dotAll-flag-does-not-affect-dotAll-modifier.js new file mode 100644 index 0000000000..b275621155 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/changing-dotAll-flag-does-not-affect-dotAll-modifier.js @@ -0,0 +1,77 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + New dotAll (`s`) flag from RegExp constructor does not affect dotAll modifier in group. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by RegularExpressionFlags. + 2. Let removeModifiers be the empty String. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), removeModifiers). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + Atom :: `(` `?` RegularExpressionFlags `-` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by the first RegularExpressionFlags. + 2. Let removeModifiers be the source text matched by the second RegularExpressionFlags. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), CodePointsToString(removeModifiers)). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = new RegExp(/(?s:^.$)/s, ""); +assert(re1.test("a"), "Pattern character '.' still should match non-line terminators in modified group"); +assert(re1.test("3"), "Pattern character '.' still should match non-line terminators in modified group"); +assert(re1.test("π"), "Pattern character '.' still should match non-line terminators in modified group"); +assert(re1.test("\u2027"), "Pattern character '.' still should match non-line terminators in modified group"); +assert(re1.test("\u0085"), "Pattern character '.' still should match non-line terminators in modified group"); +assert(re1.test("\v"), "Pattern character '.' still should match mon-line terminators in modified group"); +assert(re1.test("\f"), "Pattern character '.' still should match mon-line terminators in modified group"); +assert(re1.test("\u180E"), "Pattern character '.' still should match non-line terminators in modified group"); +assert(!re1.test("\u{10300}"), "Supplementary plane still not matched by a single ."); +assert(re1.test("\n"), "Pattern character '.' still should match line terminators in modified group"); +assert(re1.test("\r"), "Pattern character '.' still should match line terminators in modified group"); +assert(re1.test("\u2028"), "Pattern character '.' still should match line terminators in modified group"); +assert(re1.test("\u2029"), "Pattern character '.' still should match line terminators in modified group"); +assert(re1.test("\uD800"), "Pattern character '.' still should match non-line terminators in modified group"); +assert(re1.test("\uDFFF"), "Pattern character '.' still should match non-line terminators in modified group"); + +var re2 = new RegExp(/(?-s:^.$)/, "s"); +assert(re2.test("a"), "Pattern character '.' still should match non-line terminators in modified group"); +assert(re2.test("3"), "Pattern character '.' still should match non-line terminators in modified group"); +assert(re2.test("π"), "Pattern character '.' still should match non-line terminators in modified group"); +assert(re2.test("\u2027"), "Pattern character '.' still should match non-line terminators in modified group"); +assert(re2.test("\u0085"), "Pattern character '.' still should match non-line terminators in modified group"); +assert(re2.test("\v"), "Pattern character '.' still should match mon-line terminators in modified group"); +assert(re2.test("\f"), "Pattern character '.' still should match mon-line terminators in modified group"); +assert(re2.test("\u180E"), "Pattern character '.' still should match non-line terminators in modified group"); +assert(!re2.test("\u{10300}"), "Supplementary plane still not matched by a single ."); +assert(!re2.test("\n"), "Pattern character '.' still should not match '\\n' in modified group"); +assert(!re2.test("\r"), "Pattern character '.' still should not match '\\r' in modified group"); +assert(!re2.test("\u2028"), "Pattern character '.' still should not match '\\u2028' in modified group"); +assert(!re2.test("\u2029"), "Pattern character '.' still should not match '\\u2029' in modified group"); +assert(re2.test("\uD800"), "Pattern character '.' still should match non-line terminators in modified group"); +assert(re2.test("\uDFFF"), "Pattern character '.' still should match non-line terminators in modified group"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/changing-ignoreCase-flag-does-not-affect-ignoreCase-modifier.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/changing-ignoreCase-flag-does-not-affect-ignoreCase-modifier.js new file mode 100644 index 0000000000..8db72f0742 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/changing-ignoreCase-flag-does-not-affect-ignoreCase-modifier.js @@ -0,0 +1,55 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + New ignoreCase (`i`) flag from RegExp constructor does not affect ignoreCase modifier in group. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by RegularExpressionFlags. + 2. Let removeModifiers be the empty String. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), removeModifiers). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + Atom :: `(` `?` RegularExpressionFlags `-` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by the first RegularExpressionFlags. + 2. Let removeModifiers be the source text matched by the second RegularExpressionFlags. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), CodePointsToString(removeModifiers)). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = new RegExp(/(?i:aB)/i, ""); +assert(re1.test("AB"), "still should ignore case in modified group"); +assert(re1.test("Ab"), "still should ignore case in modified group"); +assert(re1.test("aB"), "still should ignore case in modified group"); +assert(re1.test("ab"), "still should ignore case in modified group"); + +var re2 = new RegExp(/(?-i:aB)/, "i"); +assert(!re2.test("AB"), "still should preserve case in modified group"); +assert(!re2.test("Ab"), "still should preserve case in modified group"); +assert(!re2.test("ab"), "still should preserve case in modified group"); +assert(re2.test("aB"), "still should preserve case in modified group"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/changing-multiline-flag-does-not-affect-multiline-modifier.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/changing-multiline-flag-does-not-affect-multiline-modifier.js new file mode 100644 index 0000000000..b890200b21 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/changing-multiline-flag-does-not-affect-multiline-modifier.js @@ -0,0 +1,51 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + New multiline (`m`) flag from RegExp constructor does not affect multiline modifier in group. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by RegularExpressionFlags. + 2. Let removeModifiers be the empty String. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), removeModifiers). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + Atom :: `(` `?` RegularExpressionFlags `-` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by the first RegularExpressionFlags. + 2. Let removeModifiers be the source text matched by the second RegularExpressionFlags. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), CodePointsToString(removeModifiers)). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = new RegExp(/(?m:es$)/m, ""); +assert(re1.test("es"), "$ still should match end of input in modified group"); +assert(re1.test("es\ns"), "$ still should match newline in modified group"); + +var re2 = new RegExp(/^(?-m:es$)/, "m"); +assert(re2.test("es"), "$ still should match end of input in modified group"); +assert(!re2.test("es\ns"), "$ still should not match newline in modified group"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/nested-add-remove-modifiers.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/nested-add-remove-modifiers.js new file mode 100644 index 0000000000..f2e1052643 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/nested-add-remove-modifiers.js @@ -0,0 +1,45 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Modifiers can be nested. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `-` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by the first RegularExpressionFlags. + 2. Let removeModifiers be the source text matched by the second RegularExpressionFlags. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), CodePointsToString(removeModifiers)). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(?m:^(?-i:a)$)/i; +assert(!re1.test("A\n"), "Should not match 'A\\n'"); +assert(re1.test("a\n"), "Should match 'a\\n'"); + +var re2 = new RegExp("(?m:^(?-i:a)$)", "i"); +assert(!re2.test("A\n"), "Should not match 'A\\n'"); +assert(re2.test("a\n"), "Should match 'a\\n'"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/nesting-add-dotAll-within-remove-dotAll.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/nesting-add-dotAll-within-remove-dotAll.js new file mode 100644 index 0000000000..26b7d760b4 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/nesting-add-dotAll-within-remove-dotAll.js @@ -0,0 +1,71 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Can add multiline (`m`) modifier for group nested within a group that removes multiline modifier. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by RegularExpressionFlags. + 2. Let removeModifiers be the empty String. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), removeModifiers). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(?-s:(?s:^.$))/s; +assert(re1.test("a"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re1.test("3"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re1.test("π"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re1.test("\u2027"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re1.test("\u0085"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re1.test("\v"), "Pattern character '.' should match mon-line terminators in modified group"); +assert(re1.test("\f"), "Pattern character '.' should match mon-line terminators in modified group"); +assert(re1.test("\u180E"), "Pattern character '.' should match non-line terminators in modified group"); +assert(!re1.test("\u{10300}"), "Supplementary plane not matched by a single ."); +assert(re1.test("\n"), "Pattern character '.' should match line terminators in modified group"); +assert(re1.test("\r"), "Pattern character '.' should match line terminators in modified group"); +assert(re1.test("\u2028"), "Pattern character '.' should match line terminators in modified group"); +assert(re1.test("\u2029"), "Pattern character '.' should match line terminators in modified group"); +assert(re1.test("\uD800"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re1.test("\uDFFF"), "Pattern character '.' should match non-line terminators in modified group"); + +var re2 = /(?-s:(?s-:^.$))/s; +assert(re2.test("a"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re2.test("3"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re2.test("π"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re2.test("\u2027"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re2.test("\u0085"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re2.test("\v"), "Pattern character '.' should match mon-line terminators in modified group"); +assert(re2.test("\f"), "Pattern character '.' should match mon-line terminators in modified group"); +assert(re2.test("\u180E"), "Pattern character '.' should match non-line terminators in modified group"); +assert(!re2.test("\u{10300}"), "Supplementary plane not matched by a single ."); +assert(re2.test("\n"), "Pattern character '.' should match line terminators in modified group"); +assert(re2.test("\r"), "Pattern character '.' should match line terminators in modified group"); +assert(re2.test("\u2028"), "Pattern character '.' should match line terminators in modified group"); +assert(re2.test("\u2029"), "Pattern character '.' should match line terminators in modified group"); +assert(re2.test("\uD800"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re2.test("\uDFFF"), "Pattern character '.' should match non-line terminators in modified group"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/nesting-add-ignoreCase-within-remove-ignoreCase.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/nesting-add-ignoreCase-within-remove-ignoreCase.js new file mode 100644 index 0000000000..04103802c6 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/nesting-add-ignoreCase-within-remove-ignoreCase.js @@ -0,0 +1,45 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Can add ignoreCase (`i`) modifier for group nested within a group that removes ignoreCase modifier. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by RegularExpressionFlags. + 2. Let removeModifiers be the empty String. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), removeModifiers). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(?-i:a(?i:b))c/i; +assert(!re1.test("ABC"), "a should not match A in ABC"); +assert(!re1.test("ABc"), "a should not match A in ABc"); +assert(!re1.test("Abc"), "a should not match A in Abc"); +assert(re1.test("aBc"), "b should match B in aBc"); +assert(re1.test("abC"), "c should match C in abC"); +assert(re1.test("abc"), "should match abc"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/nesting-add-multiline-within-remove-multiline.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/nesting-add-multiline-within-remove-multiline.js new file mode 100644 index 0000000000..dcf7504067 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/nesting-add-multiline-within-remove-multiline.js @@ -0,0 +1,47 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Can add multiline (`m`) modifier for group nested within a group that removes multiline modifier. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by RegularExpressionFlags. + 2. Let removeModifiers be the empty String. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), removeModifiers). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(?-m:es(?m:$)|js$)/m; +assert(re1.test("es\ns"), "$ should match newline in modified group"); +assert(re1.test("js"), "$ should match end of input in nested modified group"); +assert(!re1.test("js\ns"), "$ should not match newline in nested modified group"); + +var re2 = /(?-m:es(?m-:$)|js$)/m; +assert(re2.test("es\ns"), "$ should match newline in modified group"); +assert(re2.test("js"), "$ should match end of input in nested modified group"); +assert(!re2.test("js\ns"), "$ should not match newline in nested modified group"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/nesting-remove-dotAll-within-add-dotAll.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/nesting-remove-dotAll-within-add-dotAll.js new file mode 100644 index 0000000000..e62290bedd --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/nesting-remove-dotAll-within-add-dotAll.js @@ -0,0 +1,71 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Can remove multiline (`m`) modifier for group nested within a group that adds multiline modifier. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by RegularExpressionFlags. + 2. Let removeModifiers be the empty String. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), removeModifiers). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(?s:(?-s:^.$))/; +assert(re1.test("a"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re1.test("3"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re1.test("π"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re1.test("\u2027"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re1.test("\u0085"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re1.test("\v"), "Pattern character '.' should match mon-line terminators in modified group"); +assert(re1.test("\f"), "Pattern character '.' should match mon-line terminators in modified group"); +assert(re1.test("\u180E"), "Pattern character '.' should match non-line terminators in modified group"); +assert(!re1.test("\u{10300}"), "Supplementary plane not matched by a single ."); +assert(!re1.test("\n"), "Pattern character '.' should not match '\\n' in modified group"); +assert(!re1.test("\r"), "Pattern character '.' should not match '\\r' in modified group"); +assert(!re1.test("\u2028"), "Pattern character '.' should not match '\\u2028' in modified group"); +assert(!re1.test("\u2029"), "Pattern character '.' should not match '\\u2029' in modified group"); +assert(re1.test("\uD800"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re1.test("\uDFFF"), "Pattern character '.' should match non-line terminators in modified group"); + +var re2 = /(?s-:(?-s:^.$))/; +assert(re2.test("a"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re2.test("3"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re2.test("π"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re2.test("\u2027"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re2.test("\u0085"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re2.test("\v"), "Pattern character '.' should match mon-line terminators in modified group"); +assert(re2.test("\f"), "Pattern character '.' should match mon-line terminators in modified group"); +assert(re2.test("\u180E"), "Pattern character '.' should match non-line terminators in modified group"); +assert(!re2.test("\u{10300}"), "Supplementary plane not matched by a single ."); +assert(!re2.test("\n"), "Pattern character '.' should not match '\\n' in modified group"); +assert(!re2.test("\r"), "Pattern character '.' should not match '\\r' in modified group"); +assert(!re2.test("\u2028"), "Pattern character '.' should not match '\\u2028' in modified group"); +assert(!re2.test("\u2029"), "Pattern character '.' should not match '\\u2029' in modified group"); +assert(re2.test("\uD800"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re2.test("\uDFFF"), "Pattern character '.' should match non-line terminators in modified group"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/nesting-remove-ignoreCase-within-add-ignoreCase.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/nesting-remove-ignoreCase-within-add-ignoreCase.js new file mode 100644 index 0000000000..6b260ab2cc --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/nesting-remove-ignoreCase-within-add-ignoreCase.js @@ -0,0 +1,45 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Can remove ignoreCase (`i`) modifier for group nested within a group that adds ignoreCase modifier. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by RegularExpressionFlags. + 2. Let removeModifiers be the empty String. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), removeModifiers). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(?-i:a(?i:b))c/i; +assert(!re1.test("ABC"), "a should not match A in ABC"); +assert(!re1.test("ABc"), "a should not match A in ABc"); +assert(!re1.test("Abc"), "a should not match A in Abc"); +assert(re1.test("aBc"), "b should match B in aBc"); +assert(re1.test("abC"), "c should match C in abC"); +assert(re1.test("abc"), "should match abc"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/nesting-remove-multiline-within-add-multiline.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/nesting-remove-multiline-within-add-multiline.js new file mode 100644 index 0000000000..b7aa1b9895 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/nesting-remove-multiline-within-add-multiline.js @@ -0,0 +1,47 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Can remove multiline (`m`) modifier for group nested within a group that adds multiline modifier. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by RegularExpressionFlags. + 2. Let removeModifiers be the empty String. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), removeModifiers). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(?m:es$|(?-m:js$))/; +assert(re1.test("es\ns"), "first $ should match newline in modified group"); +assert(re1.test("js"), "second $ should match end of input in nested modified group"); +assert(!re1.test("js\ns"), "second $ should not match newline in nested modified group"); + +var re2 = /(?m-:es$|(?-m:js$))/; +assert(re2.test("es\ns"), "first $ should match newline in modified group"); +assert(re2.test("js"), "second $ should match end of input in nested modified group"); +assert(!re2.test("js\ns"), "second $ should not match newline in nested modified group"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-dotAll-does-not-affect-dotAll-property.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-dotAll-does-not-affect-dotAll-property.js new file mode 100644 index 0000000000..23e607be8d --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-dotAll-does-not-affect-dotAll-property.js @@ -0,0 +1,43 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Removing dotAll (`s`) modifier does not affect RegExp instance `dotAll` property. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `-` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by the first RegularExpressionFlags. + 2. Let removeModifiers be the source text matched by the second RegularExpressionFlags. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), CodePointsToString(removeModifiers)). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(?-s:^.$)/s; +assert(re1.dotAll, "RegExp instance dotAll flag should still be set"); + +var re2 = new RegExp("(?-s:^.$)", "s"); +assert(re2.dotAll, "RegExp instance dotAll flag should still be set"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-dotAll-does-not-affect-ignoreCase-flag.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-dotAll-does-not-affect-ignoreCase-flag.js new file mode 100644 index 0000000000..2ccd21b4e2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-dotAll-does-not-affect-ignoreCase-flag.js @@ -0,0 +1,49 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Removing dotAll (`s`) modifier in group should not affect ignoreCase (`i`) flag. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `-` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by the first RegularExpressionFlags. + 2. Let removeModifiers be the source text matched by the second RegularExpressionFlags. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), CodePointsToString(removeModifiers)). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(?-s:.es)/s; +assert(re1.test("aes"), "s should match s in modified group"); +assert(!re1.test("aeS"), "s should not match S in modified group"); +assert(!re1.test("\nes"), ". should not match newline in modified group"); +assert(!re1.test("\neS"), ". should not match newline in modified group"); + +var re2 = /(?-s:.es)/si; +assert(re2.test("aes"), "s should match s in modified group"); +assert(re2.test("aeS"), "s should match S in modified group"); +assert(!re2.test("\nes"), ". should not match newline in modified group"); +assert(!re2.test("\neS"), ". should not match newline in modified group"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-dotAll-does-not-affect-multiline-flag.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-dotAll-does-not-affect-multiline-flag.js new file mode 100644 index 0000000000..1f73afc52c --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-dotAll-does-not-affect-multiline-flag.js @@ -0,0 +1,49 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Removing dotAll (`s`) modifier in group should not affect multiline (`m`) flag. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `-` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by the first RegularExpressionFlags. + 2. Let removeModifiers be the source text matched by the second RegularExpressionFlags. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), CodePointsToString(removeModifiers)). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(?-s:.es$)/s; +assert(re1.test("aes"), ". should match a in modified group"); +assert(!re1.test("aes\nz"), "$ should not match newline in modified group"); +assert(!re1.test("\nes"), ". should not match newline in modified group"); +assert(!re1.test("\nes\nz"), "$ should not match newline in modified group"); + +var re2 = /(?-s:.es$)/sm; +assert(re2.test("aes"), ". should match a in modified group"); +assert(re2.test("aes\nz"), "$ should match newline in modified group"); +assert(!re2.test("\nes"), ". should not match newline in modified group"); +assert(!re2.test("\nes\nz"), ". should not match newline in modified group"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-dotAll.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-dotAll.js new file mode 100644 index 0000000000..8abed77808 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-dotAll.js @@ -0,0 +1,71 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + dotAll (`s`) modifier can be added via `(?s:)` or `(?s-:)`. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `-` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by the first RegularExpressionFlags. + 2. Let removeModifiers be the source text matched by the second RegularExpressionFlags. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), CodePointsToString(removeModifiers)). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(?-s:^.$)/s; +assert(re1.test("a"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re1.test("3"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re1.test("π"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re1.test("\u2027"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re1.test("\u0085"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re1.test("\v"), "Pattern character '.' should match mon-line terminators in modified group"); +assert(re1.test("\f"), "Pattern character '.' should match mon-line terminators in modified group"); +assert(re1.test("\u180E"), "Pattern character '.' should match non-line terminators in modified group"); +assert(!re1.test("\u{10300}"), "Supplementary plane not matched by a single ."); +assert(!re1.test("\n"), "Pattern character '.' should not match '\\n' in modified group"); +assert(!re1.test("\r"), "Pattern character '.' should not match '\\r' in modified group"); +assert(!re1.test("\u2028"), "Pattern character '.' should not match '\\u2028' in modified group"); +assert(!re1.test("\u2029"), "Pattern character '.' should not match '\\u2029' in modified group"); +assert(re1.test("\uD800"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re1.test("\uDFFF"), "Pattern character '.' should match non-line terminators in modified group"); + +var re2 = new RegExp("(?-s:^.$)", "s"); +assert(re2.test("a"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re2.test("3"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re2.test("π"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re2.test("\u2027"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re2.test("\u0085"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re2.test("\v"), "Pattern character '.' should match mon-line terminators in modified group"); +assert(re2.test("\f"), "Pattern character '.' should match mon-line terminators in modified group"); +assert(re2.test("\u180E"), "Pattern character '.' should match non-line terminators in modified group"); +assert(!re2.test("\u{10300}"), "Supplementary plane not matched by a single ."); +assert(!re2.test("\n"), "Pattern character '.' should not match '\\n' in modified group"); +assert(!re2.test("\r"), "Pattern character '.' should not match '\\r' in modified group"); +assert(!re2.test("\u2028"), "Pattern character '.' should not match '\\u2028' in modified group"); +assert(!re2.test("\u2029"), "Pattern character '.' should not match '\\u2029' in modified group"); +assert(re2.test("\uD800"), "Pattern character '.' should match non-line terminators in modified group"); +assert(re2.test("\uDFFF"), "Pattern character '.' should match non-line terminators in modified group"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-affects-backreferences.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-affects-backreferences.js new file mode 100644 index 0000000000..1d1767651b --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-affects-backreferences.js @@ -0,0 +1,43 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Removing ignoreCase (`i`) modifier in group affects backreferences in group. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `-` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by the first RegularExpressionFlags. + 2. Let removeModifiers be the source text matched by the second RegularExpressionFlags. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), CodePointsToString(removeModifiers)). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(a)(?-i:\1)/i; +assert(re1.test("AA"), "a matches first A, so \\1 should match second A"); +assert(!re1.test("aA"), "a matches a, so \\1 should not match A (preserves case)"); +assert(!re1.test("Aa"), "a matches A, so \\1 should not match a (preserves case)"); +assert(re1.test("aa"), "a matches first a, so \\1 should match second a"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-affects-characterClasses.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-affects-characterClasses.js new file mode 100644 index 0000000000..fbe2d16256 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-affects-characterClasses.js @@ -0,0 +1,55 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Removing ignoreCase (`i`) modifier in group affects character classes in group. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by RegularExpressionFlags. + 2. Let removeModifiers be the empty String. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), removeModifiers). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + Atom :: `(` `?` RegularExpressionFlags `-` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by the first RegularExpressionFlags. + 2. Let removeModifiers be the source text matched by the second RegularExpressionFlags. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), CodePointsToString(removeModifiers)). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(?-i:[ab])c/i; +assert(re1.test("ac"), "[ab] should match a"); +assert(!re1.test("Ac"), "[ab] should not match A"); +assert(re1.test("bc"), "[ab] should match b"); +assert(!re1.test("Bc"), "[ab] should not match B"); + +var re2 = /(?-i:[^ab])c/i; +assert(!re2.test("ac"), "[^ab] should not match a"); +assert(re2.test("Ac"), "[^ab] should match A"); +assert(!re2.test("bc"), "[^ab] should not match b"); +assert(re2.test("Bc"), "[^ab] should match B"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-affects-characterEscapes.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-affects-characterEscapes.js new file mode 100644 index 0000000000..1edb2d2124 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-affects-characterEscapes.js @@ -0,0 +1,52 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Removing ignoreCase (`i`) modifier in group affects character escapes in group. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `-` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by the first RegularExpressionFlags. + 2. Let removeModifiers be the source text matched by the second RegularExpressionFlags. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), CodePointsToString(removeModifiers)). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(?-i:\x61)b/i; +assert(re1.test("ab"), "\\x61 should match a"); +assert(re1.test("aB"), "b should match B"); +assert(!re1.test("Ab"), "\\x61 should not match A"); + +var re2 = /(?-i:\u0061)b/i; +assert(re2.test("ab"), "\\u0061 should match a"); +assert(re2.test("aB"), "b should match B"); +assert(!re2.test("Ab"), "\\u0061 should not match A"); + +var re3 = /(?-i:\u{0061})b/iu; +assert(re3.test("ab"), "\\u0061 should match a"); +assert(re3.test("aB"), "b should match B"); +assert(!re3.test("Ab"), "\\u0061 should not match A"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-affects-slash-lower-b.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-affects-slash-lower-b.js new file mode 100644 index 0000000000..b8b51d794b --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-affects-slash-lower-b.js @@ -0,0 +1,53 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Removing ignoreCase (`i`) modifier affects matching for `\b`. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by RegularExpressionFlags. + 2. Let removeModifiers be the empty String. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), removeModifiers). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + Atom :: `(` `?` RegularExpressionFlags `-` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by the first RegularExpressionFlags. + 2. Let removeModifiers be the source text matched by the second RegularExpressionFlags. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), CodePointsToString(removeModifiers)). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + + GetWordCharacters ( modifiers ) + The abstract operation GetWordCharacters takes argument modifiers (a Modifiers Record) and returns a CharSet. It performs the following steps when called: + + 1. Let wordCharacters be the mathematical set that is the union of all sixty-three characters in "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_" (letters, numbers, and U+005F (LOW LINE) in the Unicode Basic Latin block) and all characters c for which c is not in that set but Canonicalize(c, modifiers) is. + 2. Return wordCharacters. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(?-i:\b)/ui; +assert(!re1.test("\u017f"), "\\b should not match after \u017f"); +assert(!re1.test("\u212a"), "\\b should not match after \u212a"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-affects-slash-lower-p.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-affects-slash-lower-p.js new file mode 100644 index 0000000000..2a0167b689 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-affects-slash-lower-p.js @@ -0,0 +1,55 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Removing ignoreCase (`i`) modifier affects matching for `\p{}`. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by RegularExpressionFlags. + 2. Let removeModifiers be the empty String. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), removeModifiers). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + Atom :: `(` `?` RegularExpressionFlags `-` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by the first RegularExpressionFlags. + 2. Let removeModifiers be the source text matched by the second RegularExpressionFlags. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), CodePointsToString(removeModifiers)). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + + GetWordCharacters ( modifiers ) + The abstract operation GetWordCharacters takes argument modifiers (a Modifiers Record) and returns a CharSet. It performs the following steps when called: + + 1. Let wordCharacters be the mathematical set that is the union of all sixty-three characters in "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_" (letters, numbers, and U+005F (LOW LINE) in the Unicode Basic Latin block) and all characters c for which c is not in that set but Canonicalize(c, modifiers) is. + 2. Return wordCharacters. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(?-i:\p{Lu})/ui; +assert(re1.test("A"), "\\p{Lu} should match A"); +assert(!re1.test("a"), "\\p{Lu} should not match a"); +assert(re1.test("Z"), "\\p{Lu} should match Z"); +assert(!re1.test("z"), "\\p{Lu} should not match z"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-affects-slash-lower-w.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-affects-slash-lower-w.js new file mode 100644 index 0000000000..e8686f2e9d --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-affects-slash-lower-w.js @@ -0,0 +1,53 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Removing ignoreCase (`i`) modifier affects matching for `\w`. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by RegularExpressionFlags. + 2. Let removeModifiers be the empty String. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), removeModifiers). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + Atom :: `(` `?` RegularExpressionFlags `-` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by the first RegularExpressionFlags. + 2. Let removeModifiers be the source text matched by the second RegularExpressionFlags. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), CodePointsToString(removeModifiers)). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + + GetWordCharacters ( modifiers ) + The abstract operation GetWordCharacters takes argument modifiers (a Modifiers Record) and returns a CharSet. It performs the following steps when called: + + 1. Let wordCharacters be the mathematical set that is the union of all sixty-three characters in "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_" (letters, numbers, and U+005F (LOW LINE) in the Unicode Basic Latin block) and all characters c for which c is not in that set but Canonicalize(c, modifiers) is. + 2. Return wordCharacters. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(?-i:\w)/ui; +assert(!re1.test("\u017f"), "\\w should not match \u017f"); +assert(!re1.test("\u212a"), "\\w should not match \u212a"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-affects-slash-upper-b.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-affects-slash-upper-b.js new file mode 100644 index 0000000000..9ed611bbe9 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-affects-slash-upper-b.js @@ -0,0 +1,53 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Removing ignoreCase (`i`) modifier affects matching for `\B`. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by RegularExpressionFlags. + 2. Let removeModifiers be the empty String. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), removeModifiers). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + Atom :: `(` `?` RegularExpressionFlags `-` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by the first RegularExpressionFlags. + 2. Let removeModifiers be the source text matched by the second RegularExpressionFlags. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), CodePointsToString(removeModifiers)). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + + GetWordCharacters ( modifiers ) + The abstract operation GetWordCharacters takes argument modifiers (a Modifiers Record) and returns a CharSet. It performs the following steps when called: + + 1. Let wordCharacters be the mathematical set that is the union of all sixty-three characters in "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_" (letters, numbers, and U+005F (LOW LINE) in the Unicode Basic Latin block) and all characters c for which c is not in that set but Canonicalize(c, modifiers) is. + 2. Return wordCharacters. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(?-i:Z\B)/ui; +assert(!re1.test("Z\u017f"), "\\B should not match between Z and \u017f"); +assert(!re1.test("Z\u212a"), "\\B should not match between Z and \u212a"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-affects-slash-upper-p.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-affects-slash-upper-p.js new file mode 100644 index 0000000000..c764e66610 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-affects-slash-upper-p.js @@ -0,0 +1,56 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Removing ignoreCase (`i`) modifier affects matching for `\P{}`. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by RegularExpressionFlags. + 2. Let removeModifiers be the empty String. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), removeModifiers). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + Atom :: `(` `?` RegularExpressionFlags `-` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by the first RegularExpressionFlags. + 2. Let removeModifiers be the source text matched by the second RegularExpressionFlags. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), CodePointsToString(removeModifiers)). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + + GetWordCharacters ( modifiers ) + The abstract operation GetWordCharacters takes argument modifiers (a Modifiers Record) and returns a CharSet. It performs the following steps when called: + + 1. Let wordCharacters be the mathematical set that is the union of all sixty-three characters in "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_" (letters, numbers, and U+005F (LOW LINE) in the Unicode Basic Latin block) and all characters c for which c is not in that set but Canonicalize(c, modifiers) is. + 2. Return wordCharacters. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(?-i:\P{Lu})/ui; +assert(!re1.test("A"), "\\P{Lu} should not match A"); +assert(re1.test("a"), "\\P{Lu} should match a"); +assert(!re1.test("Z"), "\\P{Lu} should not match Z"); +assert(re1.test("z"), "\\P{Lu} should match z"); +assert(re1.test("0"), "\\P{Lu} should match 0"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-affects-slash-upper-w.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-affects-slash-upper-w.js new file mode 100644 index 0000000000..fe2a24a2a2 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-affects-slash-upper-w.js @@ -0,0 +1,53 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Removing ignoreCase (`i`) modifier affects matching for `\W`. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by RegularExpressionFlags. + 2. Let removeModifiers be the empty String. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), removeModifiers). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + Atom :: `(` `?` RegularExpressionFlags `-` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by the first RegularExpressionFlags. + 2. Let removeModifiers be the source text matched by the second RegularExpressionFlags. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), CodePointsToString(removeModifiers)). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + + GetWordCharacters ( modifiers ) + The abstract operation GetWordCharacters takes argument modifiers (a Modifiers Record) and returns a CharSet. It performs the following steps when called: + + 1. Let wordCharacters be the mathematical set that is the union of all sixty-three characters in "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_" (letters, numbers, and U+005F (LOW LINE) in the Unicode Basic Latin block) and all characters c for which c is not in that set but Canonicalize(c, modifiers) is. + 2. Return wordCharacters. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(?-i:\W)/ui; +assert(re1.test("\u017f"), "\\W should match \u017f"); +assert(re1.test("\u212a"), "\\W should match \u212a"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-does-not-affect-dotAll-flag.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-does-not-affect-dotAll-flag.js new file mode 100644 index 0000000000..f66c8f0857 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-does-not-affect-dotAll-flag.js @@ -0,0 +1,49 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Removing ignoreCase (`i`) modifier in group should not affect dotAll (`s`) flag. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `-` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by the first RegularExpressionFlags. + 2. Let removeModifiers be the source text matched by the second RegularExpressionFlags. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), CodePointsToString(removeModifiers)). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(?-i:.es)/i; +assert(re1.test("aes"), "s should match s in modified group"); +assert(!re1.test("aeS"), "s should not match S in modified group"); +assert(!re1.test("\nes"), ". should not match newline in modified group"); +assert(!re1.test("\neS"), ". should not match newline in modified group"); + +var re2 = /(?-i:.es)/is; +assert(re2.test("aes"), "s should match s in modified group"); +assert(!re2.test("aeS"), "s should not match S in modified group"); +assert(re2.test("\nes"), ". should match newline in modified group"); +assert(!re2.test("\neS"), "s should not match S in modified group"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-does-not-affect-ignoreCase-property.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-does-not-affect-ignoreCase-property.js new file mode 100644 index 0000000000..4b68807d35 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-does-not-affect-ignoreCase-property.js @@ -0,0 +1,49 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Removing ignoreCase (`i`) modifier does not affect RegExp instance `ignoreCase` property. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by RegularExpressionFlags. + 2. Let removeModifiers be the empty String. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), removeModifiers). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + Atom :: `(` `?` RegularExpressionFlags `-` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by the first RegularExpressionFlags. + 2. Let removeModifiers be the source text matched by the second RegularExpressionFlags. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), CodePointsToString(removeModifiers)). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(?-i:)/i; +assert(re1.ignoreCase, "RegExp instance ignoreCase property should still be set"); + +var re2 = new RegExp("(?-i:)", "i"); +assert(re2.ignoreCase, "RegExp instance ignoreCase property should still be set"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-does-not-affect-multiline-flag.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-does-not-affect-multiline-flag.js new file mode 100644 index 0000000000..26bc3278b1 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase-does-not-affect-multiline-flag.js @@ -0,0 +1,49 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Removing ignoreCase (`i`) modifier in group should not affect multiline (`m`) flag. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `-` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by the first RegularExpressionFlags. + 2. Let removeModifiers be the source text matched by the second RegularExpressionFlags. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), CodePointsToString(removeModifiers)). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(?-i:es$)/i; +assert(re1.test("es"), "s should match s in modified group"); +assert(!re1.test("eS"), "s should not match S in modified group"); +assert(!re1.test("es\nz"), "$ should not match newline in modified group"); +assert(!re1.test("eS\nz"), "s should not match S in modified group"); + +var re2 = /(?-i:es$)/im; +assert(re2.test("es"), "s should match s in modified group"); +assert(!re2.test("eS"), "s should not match S in modified group"); +assert(re2.test("es\nz"), "$ should match newline in modified group"); +assert(!re2.test("eS\nz"), "s should not match S in modified group"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase.js new file mode 100644 index 0000000000..87fa013049 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-ignoreCase.js @@ -0,0 +1,49 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + ignoreCase (`i`) modifier can be removed via `(?i:)` or `(?i-:)`. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `-` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by the first RegularExpressionFlags. + 2. Let removeModifiers be the source text matched by the second RegularExpressionFlags. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), CodePointsToString(removeModifiers)). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(?-i:fo)o/i; +assert(!re1.test("FOO"), "Pattern should not match as modified group does not ignore case"); +assert(!re1.test("FOo"), "Pattern should not match as modified group does not ignore case"); +assert(re1.test("foo"), "Pattern should not ignore case in modified group"); +assert(re1.test("foO"), "Pattern should not ignore case in modified group"); + +var re2 = new RegExp("(?-i:fo)o", "i"); +assert(!re2.test("FOO"), "Pattern should not match as modified group does not ignore case"); +assert(!re2.test("FOo"), "Pattern should not match as modified group does not ignore case"); +assert(re2.test("foo"), "Pattern should not ignore case in modified group"); +assert(re2.test("foO"), "Pattern should not ignore case in modified group"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-multiline-does-not-affect-dotAll-flag.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-multiline-does-not-affect-dotAll-flag.js new file mode 100644 index 0000000000..b28b545cc0 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-multiline-does-not-affect-dotAll-flag.js @@ -0,0 +1,49 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Removing multiline (`m`) modifier in group should not affect dotAll (`s`) flag. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `-` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by the first RegularExpressionFlags. + 2. Let removeModifiers be the source text matched by the second RegularExpressionFlags. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), CodePointsToString(removeModifiers)). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(?-m:es.$)/m; +assert(re1.test("esz"), ". should match z in modified group"); +assert(!re1.test("es\n"), ". should not match newline in modified group"); +assert(!re1.test("esz\n"), "$ should not match newline in modified group"); +assert(!re1.test("es\n\n"), "$ should not match newline in modified group"); + +var re2 = /(?-m:es.$)/ms; +assert(re2.test("esz"), ". should match z in modified group"); +assert(re2.test("es\n"), ". should match newline in modified group"); +assert(!re2.test("esz\n"), "$ should not match newline in modified group"); +assert(!re2.test("es\n\n"), "$ should not match newline in modified group"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-multiline-does-not-affect-ignoreCase-flag.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-multiline-does-not-affect-ignoreCase-flag.js new file mode 100644 index 0000000000..a482105dee --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-multiline-does-not-affect-ignoreCase-flag.js @@ -0,0 +1,49 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Removing multiline (`m`) modifier in group should not affect ignoreCase (`i`) flag. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `-` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by the first RegularExpressionFlags. + 2. Let removeModifiers be the source text matched by the second RegularExpressionFlags. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), CodePointsToString(removeModifiers)). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(?-m:es$)/m; +assert(re1.test("es"), "s should match s in modified group"); +assert(!re1.test("eS"), "s should not match S in modified group"); +assert(!re1.test("es\nz"), "$ should not match newline in modified group"); +assert(!re1.test("eS\nz"), "s should not match S in modified group"); + +var re2 = /(?-m:es$)/mi; +assert(re2.test("es"), "s should match s in modified group"); +assert(re2.test("eS"), "s should match S in modified group"); +assert(!re2.test("es\nz"), "$ should not match newline in modified group"); +assert(!re2.test("eS\nz"), "$ should not match newline in modified group"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-multiline-does-not-affect-multiline-property.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-multiline-does-not-affect-multiline-property.js new file mode 100644 index 0000000000..885ae9b242 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-multiline-does-not-affect-multiline-property.js @@ -0,0 +1,43 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Removing multiline (`m`) modifier does not affect RegExp instance `multiline` property. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by RegularExpressionFlags. + 2. Let removeModifiers be the empty String. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), removeModifiers). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /(?-m:)/m; +assert(re1.multiline, "RegExp instance multiline flag should still be set"); + +var re2 = new RegExp("(?-m:)", "m"); +assert(re2.multiline, "RegExp instance multiline flag should still be set"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-multiline.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-multiline.js new file mode 100644 index 0000000000..730888a662 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/remove-multiline.js @@ -0,0 +1,45 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + multiline (`m`) modifier can be removed via `(?-m:)`. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `-` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by the first RegularExpressionFlags. + 2. Let removeModifiers be the source text matched by the second RegularExpressionFlags. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), CodePointsToString(removeModifiers)). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +var re1 = /^(?-m:es$)/m; +assert(!re1.test("\nes\ns"), "$ should not match newline in modified group"); +assert(re1.test("\nes"), "$ should match end of input in modified group"); + +var re2 = new RegExp("^(?-m:es$)", "m"); +assert(!re2.test("\nes\ns"), "$ should not match newline in modified group"); +assert(re2.test("\nes"), "$ should match end of input in modified group"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/shell.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/shell.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/syntax/browser.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/syntax/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/syntax/shell.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/syntax/shell.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/syntax/valid/add-and-remove-modifiers-can-have-empty-remove-modifiers.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/syntax/valid/add-and-remove-modifiers-can-have-empty-remove-modifiers.js new file mode 100644 index 0000000000..9d5fd6c879 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/syntax/valid/add-and-remove-modifiers-can-have-empty-remove-modifiers.js @@ -0,0 +1,68 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Modifiers syntax `(?ims-:)` is legal. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `-` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by the first RegularExpressionFlags. + 2. Let removeModifiers be the source text matched by the second RegularExpressionFlags. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), CodePointsToString(removeModifiers)). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +/(?i-:)/; +/(?is-:)/; +/(?im-:)/; +/(?s-:)/; +/(?si-:)/; +/(?sm-:)/; +/(?m-:)/; +/(?mi-:)/; +/(?ms-:)/; +/(?ims-:)/; +/(?ism-:)/; +/(?sim-:)/; +/(?smi-:)/; +/(?mis-:)/; +/(?msi-:)/; +new RegExp("(?i-:)"); +new RegExp("(?is-:)"); +new RegExp("(?im-:)"); +new RegExp("(?s-:)"); +new RegExp("(?si-:)"); +new RegExp("(?sm-:)"); +new RegExp("(?m-:)"); +new RegExp("(?mi-:)"); +new RegExp("(?ms-:)"); +new RegExp("(?ims-:)"); +new RegExp("(?ism-:)"); +new RegExp("(?sim-:)"); +new RegExp("(?smi-:)"); +new RegExp("(?mis-:)"); +new RegExp("(?msi-:)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/syntax/valid/add-and-remove-modifiers.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/syntax/valid/add-and-remove-modifiers.js new file mode 100644 index 0000000000..728d47d3a0 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/syntax/valid/add-and-remove-modifiers.js @@ -0,0 +1,74 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Modifiers syntax `(?im-s:)` (and similar) is legal, as long as they do not overlap. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `-` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by the first RegularExpressionFlags. + 2. Let removeModifiers be the source text matched by the second RegularExpressionFlags. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), CodePointsToString(removeModifiers)). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +/(?i-s:)/; +/(?i-sm:)/; +/(?i-m:)/; +/(?i-ms:)/; +/(?s-i:)/; +/(?s-im:)/; +/(?s-m:)/; +/(?s-mi:)/; +/(?m-i:)/; +/(?m-is:)/; +/(?m-s:)/; +/(?m-si:)/; +/(?is-m:)/; +/(?im-s:)/; +/(?si-m:)/; +/(?sm-i:)/; +/(?mi-s:)/; +/(?ms-i:)/; +new RegExp("(?i-s:)"); +new RegExp("(?i-sm:)"); +new RegExp("(?i-m:)"); +new RegExp("(?i-ms:)"); +new RegExp("(?s-i:)"); +new RegExp("(?s-im:)"); +new RegExp("(?s-m:)"); +new RegExp("(?s-mi:)"); +new RegExp("(?m-i:)"); +new RegExp("(?m-is:)"); +new RegExp("(?m-s:)"); +new RegExp("(?m-si:)"); +new RegExp("(?is-m:)"); +new RegExp("(?im-s:)"); +new RegExp("(?si-m:)"); +new RegExp("(?sm-i:)"); +new RegExp("(?mi-s:)"); +new RegExp("(?ms-i:)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/syntax/valid/add-modifiers-when-nested.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/syntax/valid/add-modifiers-when-nested.js new file mode 100644 index 0000000000..278633d304 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/syntax/valid/add-modifiers-when-nested.js @@ -0,0 +1,44 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Modifiers syntax `(?ims:)` is legal, even when modifiers are already set via an outer non-capturing group. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by RegularExpressionFlags. + 2. Let removeModifiers be the empty String. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), removeModifiers). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +/(?i:(?i:))/; +/(?s:(?s:))/; +/(?m:(?m:))/; +new RegExp("(?i:(?i:))"); +new RegExp("(?s:(?s:))"); +new RegExp("(?m:(?m:))"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/syntax/valid/add-modifiers-when-not-set-as-flags.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/syntax/valid/add-modifiers-when-not-set-as-flags.js new file mode 100644 index 0000000000..e288c833c6 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/syntax/valid/add-modifiers-when-not-set-as-flags.js @@ -0,0 +1,68 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Modifiers syntax `(?ims:)` is legal. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by RegularExpressionFlags. + 2. Let removeModifiers be the empty String. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), removeModifiers). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +/(?i:)/; +/(?is:)/; +/(?im:)/; +/(?s:)/; +/(?si:)/; +/(?sm:)/; +/(?m:)/; +/(?mi:)/; +/(?ms:)/; +/(?ims:)/; +/(?ism:)/; +/(?sim:)/; +/(?smi:)/; +/(?mis:)/; +/(?msi:)/; +new RegExp("(?i:)"); +new RegExp("(?is:)"); +new RegExp("(?im:)"); +new RegExp("(?s:)"); +new RegExp("(?si:)"); +new RegExp("(?sm:)"); +new RegExp("(?m:)"); +new RegExp("(?mi:)"); +new RegExp("(?ms:)"); +new RegExp("(?ims:)"); +new RegExp("(?ism:)"); +new RegExp("(?sim:)"); +new RegExp("(?smi:)"); +new RegExp("(?mis:)"); +new RegExp("(?msi:)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/syntax/valid/add-modifiers-when-set-as-flags.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/syntax/valid/add-modifiers-when-set-as-flags.js new file mode 100644 index 0000000000..f1d5cedc83 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/syntax/valid/add-modifiers-when-set-as-flags.js @@ -0,0 +1,46 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Modifiers syntax `(?ims:)` is legal, even when modifiers are already set via flags. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by RegularExpressionFlags. + 2. Let removeModifiers be the empty String. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), removeModifiers). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +/(?i:)/i; +/(?s:)/s; +/(?m:)/m; +/(?ims:)/ims; +new RegExp("(?i:)", "i"); +new RegExp("(?s:)", "s"); +new RegExp("(?m:)", "m"); +new RegExp("(?ims:)", "ims"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/syntax/valid/browser.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/syntax/valid/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/syntax/valid/remove-modifiers-when-nested.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/syntax/valid/remove-modifiers-when-nested.js new file mode 100644 index 0000000000..90d5e5e606 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/syntax/valid/remove-modifiers-when-nested.js @@ -0,0 +1,44 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Modifiers syntax `(?-ims:)` is legal, even when modifiers are already cleared via an outer non-capturing group. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `-` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by the first RegularExpressionFlags. + 2. Let removeModifiers be the source text matched by the second RegularExpressionFlags. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), CodePointsToString(removeModifiers)). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +/(?-i:(?-i:))/; +/(?-s:(?-s:))/; +/(?-m:(?-m:))/; +new RegExp("(?-i:(?-i:))"); +new RegExp("(?-s:(?-s:))"); +new RegExp("(?-m:(?-m:))"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/syntax/valid/remove-modifiers-when-not-set-as-flags.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/syntax/valid/remove-modifiers-when-not-set-as-flags.js new file mode 100644 index 0000000000..397e94ce6b --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/syntax/valid/remove-modifiers-when-not-set-as-flags.js @@ -0,0 +1,68 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Modifiers syntax `(?-ims:)` is legal, even when not set as flags. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `-` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by the first RegularExpressionFlags. + 2. Let removeModifiers be the source text matched by the second RegularExpressionFlags. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), CodePointsToString(removeModifiers)). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +/(?-i:)/; +/(?-is:)/; +/(?-im:)/; +/(?-s:)/; +/(?-si:)/; +/(?-sm:)/; +/(?-m:)/; +/(?-mi:)/; +/(?-ms:)/; +/(?-ims:)/; +/(?-ism:)/; +/(?-smi:)/; +/(?-sim:)/; +/(?-mis:)/; +/(?-msi:)/; +new RegExp("(?-i:)"); +new RegExp("(?-is:)"); +new RegExp("(?-im:)"); +new RegExp("(?-s:)"); +new RegExp("(?-si:)"); +new RegExp("(?-sm:)"); +new RegExp("(?-m:)"); +new RegExp("(?-mi:)"); +new RegExp("(?-ms:)"); +new RegExp("(?-ims:)"); +new RegExp("(?-ism:)"); +new RegExp("(?-smi:)"); +new RegExp("(?-sim:)"); +new RegExp("(?-mis:)"); +new RegExp("(?-msi:)"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/syntax/valid/remove-modifiers-when-set-as-flags.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/syntax/valid/remove-modifiers-when-set-as-flags.js new file mode 100644 index 0000000000..1b96c747a8 --- /dev/null +++ b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/syntax/valid/remove-modifiers-when-set-as-flags.js @@ -0,0 +1,68 @@ +// |reftest| skip -- regexp-modifiers is not supported +// Copyright 2023 Ron Buckton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Ron Buckton +description: > + Modifiers syntax `(?-ims:)` is legal. +info: | + Runtime Semantics: CompileAtom + The syntax-directed operation CompileAtom takes arguments direction (forward or backward) and modifiers (a Modifiers Record) and returns a Matcher. + + Atom :: `(` `?` RegularExpressionFlags `-` RegularExpressionFlags `:` Disjunction `)` + 1. Let addModifiers be the source text matched by the first RegularExpressionFlags. + 2. Let removeModifiers be the source text matched by the second RegularExpressionFlags. + 3. Let newModifiers be UpdateModifiers(modifiers, CodePointsToString(addModifiers), CodePointsToString(removeModifiers)). + 4. Return CompileSubpattern of Disjunction with arguments direction and newModifiers. + + UpdateModifiers ( modifiers, add, remove ) + The abstract operation UpdateModifiers takes arguments modifiers (a Modifiers Record), add (a String), and remove (a String) and returns a Modifiers. It performs the following steps when called: + + 1. Let dotAll be modifiers.[[DotAll]]. + 2. Let ignoreCase be modifiers.[[IgnoreCase]]. + 3. Let multiline be modifiers.[[Multiline]]. + 4. If add contains "s", set dotAll to true. + 5. If add contains "i", set ignoreCase to true. + 6. If add contains "m", set multiline to true. + 7. If remove contains "s", set dotAll to false. + 8. If remove contains "i", set ignoreCase to false. + 9. If remove contains "m", set multiline to false. + 10. Return the Modifiers Record { [[DotAll]]: dotAll, [[IgnoreCase]]: ignoreCase, [[Multiline]]: multiline }. + +esid: sec-compileatom +features: [regexp-modifiers] +---*/ + +/(?-i:)/i; +/(?-is:)/is; +/(?-im:)/im; +/(?-s:)/s; +/(?-si:)/si; +/(?-sm:)/sm; +/(?-m:)/m; +/(?-mi:)/mi; +/(?-ms:)/ms; +/(?-ims:)/ims; +/(?-ism:)/ism; +/(?-sim:)/sim; +/(?-smi:)/smi; +/(?-mis:)/mis; +/(?-msi:)/msi; +new RegExp("(?-i:)", "i"); +new RegExp("(?-is:)", "is"); +new RegExp("(?-im:)", "im"); +new RegExp("(?-s:)", "s"); +new RegExp("(?-si:)", "si"); +new RegExp("(?-sm:)", "sm"); +new RegExp("(?-m:)", "m"); +new RegExp("(?-mi:)", "mi"); +new RegExp("(?-ms:)", "ms"); +new RegExp("(?-ims:)", "ims"); +new RegExp("(?-ism:)", "ism"); +new RegExp("(?-sim:)", "sim"); +new RegExp("(?-smi:)", "smi"); +new RegExp("(?-mis:)", "mis"); +new RegExp("(?-msi:)", "msi"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/syntax/valid/shell.js b/js/src/tests/test262/built-ins/RegExp/regexp-modifiers/syntax/valid/shell.js new file mode 100644 index 0000000000..e69de29bb2 -- cgit v1.2.3