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/superPropOrdering.js | 93 ++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 js/src/tests/non262/class/superPropOrdering.js (limited to 'js/src/tests/non262/class/superPropOrdering.js') 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"); -- cgit v1.2.3