summaryrefslogtreecommitdiffstats
path: root/js/src/tests/ecma_6/Class/methodOverwrites.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /js/src/tests/ecma_6/Class/methodOverwrites.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'js/src/tests/ecma_6/Class/methodOverwrites.js')
-rw-r--r--js/src/tests/ecma_6/Class/methodOverwrites.js80
1 files changed, 80 insertions, 0 deletions
diff --git a/js/src/tests/ecma_6/Class/methodOverwrites.js b/js/src/tests/ecma_6/Class/methodOverwrites.js
new file mode 100644
index 000000000..c1c460a28
--- /dev/null
+++ b/js/src/tests/ecma_6/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");