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/Collator/call.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/Collator/call.js')
-rw-r--r-- | js/src/tests/non262/Intl/Collator/call.js | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/js/src/tests/non262/Intl/Collator/call.js b/js/src/tests/non262/Intl/Collator/call.js new file mode 100644 index 0000000000..089764a2cb --- /dev/null +++ b/js/src/tests/non262/Intl/Collator/call.js @@ -0,0 +1,74 @@ +// |reftest| skip-if(!this.hasOwnProperty("Intl")) + +function IsIntlService(c) { + return typeof c === "function" && + c.hasOwnProperty("prototype") && + c.prototype.hasOwnProperty("resolvedOptions"); +} + +function IsObject(o) { + return Object(o) === o; +} + +function thisValues() { + const intlConstructors = Object.getOwnPropertyNames(Intl).map(name => Intl[name]).filter(IsIntlService); + + return [ + // Primitive values. + ...[undefined, null, true, "abc", Symbol(), 123], + + // Object values. + ...[{}, [], /(?:)/, function(){}, new Proxy({}, {})], + + // Intl objects. + ...[].concat(...intlConstructors.map(ctor => { + let args = []; + if (ctor === Intl.DisplayNames) { + // Intl.DisplayNames can't be constructed without any arguments. + args = [undefined, {type: "language"}]; + } + + return [ + // Instance of an Intl constructor. + new ctor(...args), + + // Instance of a subclassed Intl constructor. + new class extends ctor {}(...args), + + // Object inheriting from an Intl constructor prototype. + Object.create(ctor.prototype), + + // Intl object not inheriting from its default prototype. + Object.setPrototypeOf(new ctor(...args), Object.prototype), + ]; + })), + ]; +} + +// Invoking [[Call]] for Intl.Collator always returns a new Collator instance. +for (let thisValue of thisValues()) { + let obj = Intl.Collator.call(thisValue); + assertEq(Object.is(obj, thisValue), false); + assertEq(obj instanceof Intl.Collator, true); + + // Ensure Intl.[[FallbackSymbol]] wasn't installed on |thisValue|. + if (IsObject(thisValue)) + assertEqArray(Object.getOwnPropertySymbols(thisValue), []); +} + +// Intl.Collator doesn't use the legacy Intl constructor compromise semantics. +for (let thisValue of thisValues()) { + // Ensure instanceof operator isn't invoked for Intl.Collator. + Object.defineProperty(Intl.Collator, Symbol.hasInstance, { + get() { + assertEq(false, true, "@@hasInstance operator called"); + }, configurable: true + }); + let obj = Intl.Collator.call(thisValue); + delete Intl.Collator[Symbol.hasInstance]; + assertEq(Object.is(obj, thisValue), false); + assertEq(obj instanceof Intl.Collator, true); +} + +if (typeof reportCompare === "function") + reportCompare(true, true); |