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 --- .../non262/Intl/PluralRules/construct-newtarget.js | 76 ++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 js/src/tests/non262/Intl/PluralRules/construct-newtarget.js (limited to 'js/src/tests/non262/Intl/PluralRules/construct-newtarget.js') 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); -- cgit v1.2.3