summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/class/superPropOrdering.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/superPropOrdering.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/superPropOrdering.js')
-rw-r--r--js/src/tests/non262/class/superPropOrdering.js93
1 files changed, 93 insertions, 0 deletions
diff --git a/js/src/tests/non262/class/superPropOrdering.js b/js/src/tests/non262/class/superPropOrdering.js
new file mode 100644
index 0000000000..1374d52c1c
--- /dev/null
+++ b/js/src/tests/non262/class/superPropOrdering.js
@@ -0,0 +1,93 @@
+class base {
+ constructor() { }
+ method() { this.methodCalled++; }
+}
+
+class derived extends base {
+ constructor() { super(); this.methodCalled = 0; }
+
+ // Test orderings of various evaluations relative to the superbase
+
+ // Unlike in regular element evaluation, the propVal is evaluated before
+ // checking the starting object ([[HomeObject]].[[Prototype]])
+ testElem() { super[ruin()]; }
+
+ // The starting object for looking up super.method is determined before
+ // ruin() is called.
+ testProp() { super.method(ruin()); }
+
+ // The entire super.method property lookup has concluded before the args
+ // are evaluated
+ testPropCallDeleted() { super.method(()=>delete base.prototype.method); }
+
+ // The starting object for looking up super["prop"] is determined before
+ // ruin() is called.
+ testElemAssign() { super["prop"] = ruin(); }
+
+ // Test the normal assignment gotchas
+ testAssignElemPropValChange() {
+ let x = "prop1";
+ super[x] = (()=>(x = "prop2", 0))();
+ assertEq(this.prop1, 0);
+ assertEq(this.prop2, undefined);
+ }
+
+ testAssignProp() {
+ Object.defineProperty(base.prototype, "piggy",
+ {
+ configurable: true,
+ set() { throw "WEE WEE WEE WEE"; }
+ });
+
+ // The property lookup is noted, but not actually evaluated, until the
+ // right hand side is. Please don't make the piggy cry.
+ super.piggy = (() => delete base.prototype.piggy)();
+ }
+ testCompoundAssignProp() {
+ let getterCalled = false;
+ Object.defineProperty(base.prototype, "horse",
+ {
+ configurable: true,
+ get() { getterCalled = true; return "Of course"; },
+ set() { throw "NO!"; }
+ });
+ super.horse += (()=>(delete base.prototype.horse, ", of course!"))();
+ assertEq(getterCalled, true);
+
+ // So, is a horse a horse?
+ assertEq(this.horse, "Of course, of course!");
+ }
+}
+
+function ruin() {
+ Object.setPrototypeOf(derived.prototype, null);
+ return 5;
+}
+
+function reset() {
+ Object.setPrototypeOf(derived.prototype, base.prototype);
+}
+
+let instance = new derived();
+assertThrowsInstanceOf(() => instance.testElem(), TypeError);
+reset();
+
+instance.testProp();
+assertEq(instance.methodCalled, 1);
+reset();
+
+instance.testPropCallDeleted();
+assertEq(instance.methodCalled, 2);
+
+instance.testElemAssign();
+assertEq(instance.prop, 5);
+reset();
+
+instance.testAssignElemPropValChange();
+
+instance.testAssignProp();
+
+instance.testCompoundAssignProp();
+
+if (typeof reportCompare === 'function')
+ reportCompare(0,0,"OK");