From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- js/src/tests/non262/class/methodOverwrites.js | 80 +++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 js/src/tests/non262/class/methodOverwrites.js (limited to 'js/src/tests/non262/class/methodOverwrites.js') diff --git a/js/src/tests/non262/class/methodOverwrites.js b/js/src/tests/non262/class/methodOverwrites.js new file mode 100644 index 0000000000..c1c460a28c --- /dev/null +++ b/js/src/tests/non262/class/methodOverwrites.js @@ -0,0 +1,80 @@ +// Ensure that we can overwrite methods when more tha one is present. +{ + var result = 0; + // Regardless of order, the constructor is overridden by any CPN, because it's + // processed seperately. + class a { ["constructor"]() { result += 1; }; constructor() { result += 2; } } + var aInst = new a(); + assertEq(result, 2); + aInst.constructor(); + assertEq(result, 3); + + class b { constructor() { result += 2; } ["constructor"]() { result += 1; }; } + var bInst = new b(); + assertEq(result, 5); + bInst.constructor(); + assertEq(result, 6); + + class c { constructor() { } method() { result += 1 } get method() { result += 2 } } + new c().method; + assertEq(result, 8); + + class d { constructor() { } get method() { result += 1 } method() { result += 2 } } + new d().method(); + assertEq(result, 10); + + // getters and setter should not overwrite each other, but merge cleanly. + class e { constructor() { } get method() { result += 1 } set method(x) { } } + new e().method; + assertEq(result, 11); + + class f { constructor() { } + set method(x) { throw "NO"; } + method() { throw "NO" } + get method() { return new Function("result += 1"); } + } + new f().method(); + assertEq(result, 12); +} + +// Try again with expressions. +{ + var result = 0; + // Regardless of order, the constructor is overridden by any CPN, because it's + // processed seperately. + let a = class { ["constructor"]() { result += 1; }; constructor() { result += 2; } }; + var aInst = new a(); + assertEq(result, 2); + aInst.constructor(); + assertEq(result, 3); + + let b = class { constructor() { result += 2; } ["constructor"]() { result += 1; }; }; + var bInst = new b(); + assertEq(result, 5); + bInst.constructor(); + assertEq(result, 6); + + let c = class { constructor() { } method() { result += 1 } get method() { result += 2 } }; + new c().method; + assertEq(result, 8); + + let d = class { constructor() { } get method() { result += 1 } method() { result += 2 } }; + new d().method(); + assertEq(result, 10); + + // getters and setter should not overwrite each other, but merge cleanly. + let e = class { constructor() { } get method() { result += 1 } set method(x) { } }; + new e().method; + assertEq(result, 11); + + let f = class { constructor() { } + set method(x) { throw "NO"; } + method() { throw "NO" } + get method() { return new Function("result += 1"); } + }; + new f().method(); + assertEq(result, 12); +} + +if (typeof reportCompare === "function") + reportCompare(0, 0, "OK"); -- cgit v1.2.3