diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/non262/class/methodInstallation.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | js/src/tests/non262/class/methodInstallation.js | 101 |
1 files changed, 101 insertions, 0 deletions
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"); |