summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/class/superPropHomeObject.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/non262/class/superPropHomeObject.js
parentInitial commit. (diff)
downloadfirefox-esr-upstream.tar.xz
firefox-esr-upstream.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/non262/class/superPropHomeObject.js')
-rw-r--r--js/src/tests/non262/class/superPropHomeObject.js61
1 files changed, 61 insertions, 0 deletions
diff --git a/js/src/tests/non262/class/superPropHomeObject.js b/js/src/tests/non262/class/superPropHomeObject.js
new file mode 100644
index 0000000000..b23c115dd5
--- /dev/null
+++ b/js/src/tests/non262/class/superPropHomeObject.js
@@ -0,0 +1,61 @@
+// This is super weird. A super property reference in the spec contains two
+// things. The first is the object to do the lookup on, the super base. This
+// should be unchanged, no matter what's going on: I can move the method to
+// another object. I can pull it out as its own function. I can put it on my
+// head and run around the front yard. No changes. The other half, the |this|
+// for invoked calls, is the this at the time of referencing the property, which
+// means it's gonna vary wildly as stuff gets moved around.
+
+class base {
+ constructor() { }
+ test(expectedThis) { assertEq(this, expectedThis); }
+}
+
+class derived extends base {
+ constructor() { super(); }
+ test(expected) { super.test(expected); }
+ testArrow() { return (() => super.test(this)); }
+ ["testCPN"](expected) { super.test(expected); }
+}
+
+let derivedInstance = new derived();
+derivedInstance.test(derivedInstance);
+derivedInstance.testCPN(derivedInstance);
+
+let obj = { test: derivedInstance.test };
+obj.test(obj);
+
+// Classes are strict, so primitives are not boxed/turned into globals
+let testSolo = derivedInstance.test;
+testSolo(undefined);
+
+let anotherObject = { };
+derivedInstance.test.call(anotherObject, anotherObject);
+
+let strThis = "this is not an object!";
+derivedInstance.test.call(strThis, strThis);
+
+// You can take the arrow function out of the super, ... or something like that
+let arrowTest = derivedInstance.testArrow();
+arrowTest();
+
+// There's no magic "super script index" per code location.
+class base1 {
+ constructor() { }
+ test() { return "llama"; }
+}
+class base2 {
+ constructor() { }
+ test() { return "alpaca"; }
+}
+
+let animals = [];
+for (let exprBase of [base1, base2])
+ new class extends exprBase {
+ constructor() { super(); }
+ test() { animals.push(super["test"]()); }
+ }().test();
+assertDeepEq(animals, ["llama", "alpaca"]);
+
+if (typeof reportCompare === 'function')
+ reportCompare(0,0,"OK");