diff options
author | Timothy Flynn <trflynn89@pm.me> | 2022-08-25 10:53:47 -0400 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-08-25 16:39:45 +0100 |
commit | a803d9226fbc87a9e1c906d5a7d592f083eaaa14 (patch) | |
tree | abf7d912b44df41a0a87aca146c3e1f09718a9c3 /Userland/Libraries/LibJS/Tests | |
parent | 9a1f55afe568dc98fa811ba3632b809e55ae9e63 (diff) | |
download | serenity-a803d9226fbc87a9e1c906d5a7d592f083eaaa14.zip |
LibJS: Always access RegExp flags by its "flags" property
This is a normative change in the ECMA-262 spec. See:
https://github.com/tc39/ecma262/commit/35b7eb2
Note there is a bit of weirdness between the mainline spec and the set
notation proposal as the latter has not been updated with this change.
For now, this implements what the spec PR and other prototypes indicate
how the proposal will behave.
Diffstat (limited to 'Userland/Libraries/LibJS/Tests')
-rw-r--r-- | Userland/Libraries/LibJS/Tests/builtins/RegExp/RegExp.prototype.@@match.js | 27 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Tests/builtins/RegExp/RegExp.prototype.@@replace.js | 27 |
2 files changed, 54 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Tests/builtins/RegExp/RegExp.prototype.@@match.js b/Userland/Libraries/LibJS/Tests/builtins/RegExp/RegExp.prototype.@@match.js new file mode 100644 index 0000000000..b82574a574 --- /dev/null +++ b/Userland/Libraries/LibJS/Tests/builtins/RegExp/RegExp.prototype.@@match.js @@ -0,0 +1,27 @@ +describe("basic functionality", () => { + test("uses flags property instead of individual property lookups", () => { + let accessedFlags = false; + let accessedGlobal = false; + let accessedUnicode = false; + + class RegExp1 extends RegExp { + get flags() { + accessedFlags = true; + return "g"; + } + get global() { + accessedGlobal = true; + return false; + } + get unicode() { + accessedUnicode = true; + return false; + } + } + + RegExp.prototype[Symbol.match].call(new RegExp1("foo")); + expect(accessedFlags).toBeTrue(); + expect(accessedGlobal).toBeFalse(); + expect(accessedUnicode).toBeFalse(); + }); +}); diff --git a/Userland/Libraries/LibJS/Tests/builtins/RegExp/RegExp.prototype.@@replace.js b/Userland/Libraries/LibJS/Tests/builtins/RegExp/RegExp.prototype.@@replace.js new file mode 100644 index 0000000000..2d3440ab06 --- /dev/null +++ b/Userland/Libraries/LibJS/Tests/builtins/RegExp/RegExp.prototype.@@replace.js @@ -0,0 +1,27 @@ +describe("basic functionality", () => { + test("uses flags property instead of individual property lookups", () => { + let accessedFlags = false; + let accessedGlobal = false; + let accessedUnicode = false; + + class RegExp1 extends RegExp { + get flags() { + accessedFlags = true; + return "g"; + } + get global() { + accessedGlobal = true; + return false; + } + get unicode() { + accessedUnicode = true; + return false; + } + } + + RegExp.prototype[Symbol.replace].call(new RegExp1("foo")); + expect(accessedFlags).toBeTrue(); + expect(accessedGlobal).toBeFalse(); + expect(accessedUnicode).toBeFalse(); + }); +}); |