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/Intl/PluralRules/construct-newtarget.js | |
parent | Initial commit. (diff) | |
download | firefox-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/Intl/PluralRules/construct-newtarget.js')
-rw-r--r-- | js/src/tests/non262/Intl/PluralRules/construct-newtarget.js | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/js/src/tests/non262/Intl/PluralRules/construct-newtarget.js b/js/src/tests/non262/Intl/PluralRules/construct-newtarget.js new file mode 100644 index 0000000000..356c2dd221 --- /dev/null +++ b/js/src/tests/non262/Intl/PluralRules/construct-newtarget.js @@ -0,0 +1,76 @@ +// |reftest| skip-if(!this.hasOwnProperty("Intl")) + +// Test subclassing %Intl.PluralRules% works correctly. +class MyPluralRules extends Intl.PluralRules {} + +var obj = new MyPluralRules(); +assertEq(obj instanceof MyPluralRules, true); +assertEq(obj instanceof Intl.PluralRules, true); +assertEq(Object.getPrototypeOf(obj), MyPluralRules.prototype); + +obj = Reflect.construct(MyPluralRules, []); +assertEq(obj instanceof MyPluralRules, true); +assertEq(obj instanceof Intl.PluralRules, true); +assertEq(Object.getPrototypeOf(obj), MyPluralRules.prototype); + +obj = Reflect.construct(MyPluralRules, [], MyPluralRules); +assertEq(obj instanceof MyPluralRules, true); +assertEq(obj instanceof Intl.PluralRules, true); +assertEq(Object.getPrototypeOf(obj), MyPluralRules.prototype); + +obj = Reflect.construct(MyPluralRules, [], Intl.PluralRules); +assertEq(obj instanceof MyPluralRules, false); +assertEq(obj instanceof Intl.PluralRules, true); +assertEq(Object.getPrototypeOf(obj), Intl.PluralRules.prototype); + + +// Set a different constructor as NewTarget. +obj = Reflect.construct(MyPluralRules, [], Array); +assertEq(obj instanceof MyPluralRules, false); +assertEq(obj instanceof Intl.PluralRules, false); +assertEq(obj instanceof Array, true); +assertEq(Object.getPrototypeOf(obj), Array.prototype); + +obj = Reflect.construct(Intl.PluralRules, [], Array); +assertEq(obj instanceof Intl.PluralRules, false); +assertEq(obj instanceof Array, true); +assertEq(Object.getPrototypeOf(obj), Array.prototype); + + +// The prototype defaults to %PluralRulesPrototype% if null. +function NewTargetNullPrototype() {} +NewTargetNullPrototype.prototype = null; + +obj = Reflect.construct(Intl.PluralRules, [], NewTargetNullPrototype); +assertEq(obj instanceof Intl.PluralRules, true); +assertEq(Object.getPrototypeOf(obj), Intl.PluralRules.prototype); + +obj = Reflect.construct(MyPluralRules, [], NewTargetNullPrototype); +assertEq(obj instanceof MyPluralRules, false); +assertEq(obj instanceof Intl.PluralRules, true); +assertEq(Object.getPrototypeOf(obj), Intl.PluralRules.prototype); + + +// "prototype" property is retrieved exactly once. +var trapLog = [], getLog = []; +var ProxiedConstructor = new Proxy(Intl.PluralRules, new Proxy({ + get(target, propertyKey, receiver) { + getLog.push(propertyKey); + return Reflect.get(target, propertyKey, receiver); + } +}, { + get(target, propertyKey, receiver) { + trapLog.push(propertyKey); + return Reflect.get(target, propertyKey, receiver); + } +})); + +obj = Reflect.construct(Intl.PluralRules, [], ProxiedConstructor); +assertEqArray(trapLog, ["get"]); +assertEqArray(getLog, ["prototype"]); +assertEq(obj instanceof Intl.PluralRules, true); +assertEq(Object.getPrototypeOf(obj), Intl.PluralRules.prototype); + + +if (typeof reportCompare === "function") + reportCompare(0, 0); |