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/methodInstallation.js | 101 ++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 js/src/tests/non262/class/methodInstallation.js (limited to 'js/src/tests/non262/class/methodInstallation.js') diff --git a/js/src/tests/non262/class/methodInstallation.js b/js/src/tests/non262/class/methodInstallation.js new file mode 100644 index 0000000000..bbb6c2f727 --- /dev/null +++ b/js/src/tests/non262/class/methodInstallation.js @@ -0,0 +1,101 @@ +// Do the things we write in classes actually appear as they are supposed to? + +var methodCalled; +var getterCalled; +var setterCalled; +var constructorCalled; +var staticMethodCalled; +var staticGetterCalled; +var staticSetterCalled; +class testClass { + constructor() { constructorCalled = true; } + __proto__() { methodCalled = true } + get getter() { getterCalled = true; } + set setter(x) { setterCalled = true; } + static staticMethod() { staticMethodCalled = true; } + static get staticGetter() { staticGetterCalled = true; } + static set staticSetter(x) { staticSetterCalled = true; } + *[Symbol.iterator]() { yield "cow"; yield "pig"; } +} + +for (let a of [testClass, + class { + constructor() { constructorCalled = true; } + __proto__() { methodCalled = true } + get getter() { getterCalled = true; } + set setter(x) { setterCalled = true; } + static staticMethod() { staticMethodCalled = true; } + static get staticGetter() { staticGetterCalled = true; } + static set staticSetter(x) { staticSetterCalled = true; } + *[Symbol.iterator]() { yield "cow"; yield "pig"; } + }]) { + + methodCalled = false; + getterCalled = false; + setterCalled = false; + constructorCalled = false; + staticMethodCalled = false; + staticGetterCalled = false; + staticSetterCalled = false; + + var aConstDesc = Object.getOwnPropertyDescriptor(a.prototype, "constructor"); + assertEq(aConstDesc.writable, true); + assertEq(aConstDesc.configurable, true); + assertEq(aConstDesc.enumerable, false); + new aConstDesc.value(); + assertEq(constructorCalled, true); + + // __proto__ is just an identifier for classes. No prototype changes are made. + assertEq(Object.getPrototypeOf(a.prototype), Object.prototype); + var aMethDesc = Object.getOwnPropertyDescriptor(a.prototype, "__proto__"); + assertEq(aMethDesc.writable, true); + assertEq(aMethDesc.configurable, true); + assertEq(aMethDesc.enumerable, false); + aMethDesc.value(); + assertEq(methodCalled, true); + + var aGetDesc = Object.getOwnPropertyDescriptor(a.prototype, "getter"); + assertEq(aGetDesc.configurable, true); + assertEq(aGetDesc.enumerable, false); + aGetDesc.get(); + assertThrowsInstanceOf(() => new aGetDesc.get, TypeError); + assertEq(getterCalled, true); + + var aSetDesc = Object.getOwnPropertyDescriptor(a.prototype, "setter"); + assertEq(aSetDesc.configurable, true); + assertEq(aSetDesc.enumerable, false); + aSetDesc.set(); + assertThrowsInstanceOf(() => new aSetDesc.set, TypeError); + assertEq(setterCalled, true); + assertDeepEq(aSetDesc, Object.getOwnPropertyDescriptor(a.prototype, "setter")); + + assertEq(Object.getOwnPropertyDescriptor(new a(), "staticMethod"), undefined); + var aStaticMethDesc = Object.getOwnPropertyDescriptor(a, "staticMethod"); + assertEq(aStaticMethDesc.configurable, true); + assertEq(aStaticMethDesc.enumerable, false); + assertEq(aStaticMethDesc.writable, true); + aStaticMethDesc.value(); + assertThrowsInstanceOf(() => new aStaticMethDesc.value, TypeError); + assertEq(staticMethodCalled, true); + + assertEq(Object.getOwnPropertyDescriptor(new a(), "staticGetter"), undefined); + var aStaticGetDesc = Object.getOwnPropertyDescriptor(a, "staticGetter"); + assertEq(aStaticGetDesc.configurable, true); + assertEq(aStaticGetDesc.enumerable, false); + aStaticGetDesc.get(); + assertThrowsInstanceOf(() => new aStaticGetDesc.get, TypeError); + assertEq(staticGetterCalled, true); + + assertEq(Object.getOwnPropertyDescriptor(new a(), "staticSetter"), undefined); + var aStaticSetDesc = Object.getOwnPropertyDescriptor(a, "staticSetter"); + assertEq(aStaticSetDesc.configurable, true); + assertEq(aStaticSetDesc.enumerable, false); + aStaticSetDesc.set(); + assertThrowsInstanceOf(() => new aStaticSetDesc.set, TypeError); + assertEq(staticSetterCalled, true); + + assertEq([...new a()].join(), "cow,pig"); +} + +if (typeof reportCompare === "function") + reportCompare(0, 0, "OK"); -- cgit v1.2.3