diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/non262/RegExp/constructor-constructor.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | js/src/tests/non262/RegExp/constructor-constructor.js | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/js/src/tests/non262/RegExp/constructor-constructor.js b/js/src/tests/non262/RegExp/constructor-constructor.js new file mode 100644 index 0000000000..528f4978c2 --- /dev/null +++ b/js/src/tests/non262/RegExp/constructor-constructor.js @@ -0,0 +1,78 @@ +var BUGNUMBER = 1147817; +var summary = "RegExp constructor should check pattern.constructor."; + +print(BUGNUMBER + ": " + summary); + +var g = newGlobal(); + +var re = /foo/; +assertEq(RegExp(re), re); +re.constructor = 10; +assertEq(RegExp(re) === re, false); +assertEq(RegExp(re).toString(), re.toString()); + +// If pattern comes from different global, RegExp shouldn't return it. +re = g.eval(`var re = /foo/; re;`); +assertEq(RegExp(re) === re, false); +assertEq(RegExp(re).toString(), re.toString()); +g.eval(`re.constructor = 10;`); +assertEq(RegExp(re) === re, false); +assertEq(RegExp(re).toString(), re.toString()); + + +re = new Proxy(/a/, { + get(that, name) { + return that[name]; + } +}); +assertEq(RegExp(re), re); +re = new Proxy(/a/, { + get(that, name) { + if (name == "constructor") { + return function() {}; + } + return that[name]; + } +}); +assertEq(RegExp(re) === re, false); +re = new Proxy(/a/, { + get(that, name) { + if (name == Symbol.match) { + return undefined; + } + return that[name]; + } +}); +assertEq(RegExp(re) === re, false); + +re = new Proxy(g.eval(`/a/`), { + get(that, name) { + return that[name]; + } +}); +assertEq(RegExp(re) === re, false); + +re = g.eval(`new Proxy(/a/, { + get(that, name) { + return that[name]; + } +});`); +assertEq(RegExp(re) === re, false); + + +var obj = { [Symbol.match]: true, source: "foo", flags: "gi" }; +assertEq(RegExp(obj) === obj, false); +assertEq(RegExp(obj).toString(), "/foo/gi"); +obj.constructor = RegExp; +assertEq(RegExp(obj), obj); + +obj = g.eval(`var obj = { [Symbol.match]: true, source: "foo", flags: "gi" }; obj;`); +assertEq(RegExp(obj) === obj, false); +assertEq(RegExp(obj).toString(), "/foo/gi"); +g.eval(`obj.constructor = RegExp`); +assertEq(RegExp(obj) === obj, false); +obj.constructor = RegExp; +assertEq(RegExp(obj), obj); + +if (typeof reportCompare === "function") + reportCompare(true, true); |