diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /js/src/tests/non262/Intl/DateTimeFormat/cross-compartment.js | |
parent | Initial commit. (diff) | |
download | thunderbird-upstream.tar.xz thunderbird-upstream.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/non262/Intl/DateTimeFormat/cross-compartment.js')
-rw-r--r-- | js/src/tests/non262/Intl/DateTimeFormat/cross-compartment.js | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/js/src/tests/non262/Intl/DateTimeFormat/cross-compartment.js b/js/src/tests/non262/Intl/DateTimeFormat/cross-compartment.js new file mode 100644 index 0000000000..dac99bdc19 --- /dev/null +++ b/js/src/tests/non262/Intl/DateTimeFormat/cross-compartment.js @@ -0,0 +1,70 @@ +// |reftest| skip-if(!this.hasOwnProperty("Intl")) + +var otherGlobal = newGlobal(); + +var dateTimeFormat = new Intl.DateTimeFormat(); +var ccwDateTimeFormat = new otherGlobal.Intl.DateTimeFormat(); + +// Test Intl.DateTimeFormat.prototype.format with a CCW object. +var Intl_DateTimeFormat_format_get = Object.getOwnPropertyDescriptor(Intl.DateTimeFormat.prototype, "format").get; + +assertEq(Intl_DateTimeFormat_format_get.call(ccwDateTimeFormat)(0), + Intl_DateTimeFormat_format_get.call(dateTimeFormat)(0)); + +// Test Intl.DateTimeFormat.prototype.formatToParts with a CCW object. +var Intl_DateTimeFormat_formatToParts = Intl.DateTimeFormat.prototype.formatToParts; + +assertEq(deepEqual(Intl_DateTimeFormat_formatToParts.call(ccwDateTimeFormat, 0), + Intl_DateTimeFormat_formatToParts.call(dateTimeFormat, 0)), + true); + +// Test Intl.DateTimeFormat.prototype.resolvedOptions with a CCW object. +var Intl_DateTimeFormat_resolvedOptions = Intl.DateTimeFormat.prototype.resolvedOptions; + +assertEq(deepEqual(Intl_DateTimeFormat_resolvedOptions.call(ccwDateTimeFormat), + Intl_DateTimeFormat_resolvedOptions.call(dateTimeFormat)), + true); + +// Special case for Intl.DateTimeFormat: The Intl fallback symbol. + +function fallbackSymbol(global) { + var DTF = global.Intl.DateTimeFormat; + return Object.getOwnPropertySymbols(DTF.call(Object.create(DTF.prototype)))[0]; +} + +const intlFallbackSymbol = fallbackSymbol(this); +const otherIntlFallbackSymbol = fallbackSymbol(otherGlobal); +assertEq(intlFallbackSymbol === otherIntlFallbackSymbol, false); + +// Test when the fallback symbol points to a CCW DateTimeFormat object. +var objWithFallbackCCWDateTimeFormat = { + __proto__: Intl.DateTimeFormat.prototype, + [intlFallbackSymbol]: ccwDateTimeFormat, +}; + +assertEq(Intl_DateTimeFormat_format_get.call(objWithFallbackCCWDateTimeFormat)(0), + Intl_DateTimeFormat_format_get.call(dateTimeFormat)(0)); + +assertEq(deepEqual(Intl_DateTimeFormat_resolvedOptions.call(objWithFallbackCCWDateTimeFormat), + Intl_DateTimeFormat_resolvedOptions.call(dateTimeFormat)), + true); + +// Ensure the fallback symbol(s) are not accessed for CCW DateTimeFormat objects. +var ccwDateTimeFormatWithPoisonedFallback = new otherGlobal.Intl.DateTimeFormat(); +Object.setPrototypeOf(ccwDateTimeFormatWithPoisonedFallback, Intl.DateTimeFormat.prototype); +Object.defineProperty(ccwDateTimeFormatWithPoisonedFallback, intlFallbackSymbol, { + get() { throw new Error(); } +}); +Object.defineProperty(ccwDateTimeFormatWithPoisonedFallback, otherIntlFallbackSymbol, { + get() { throw new Error(); } +}); + +assertEq(Intl_DateTimeFormat_format_get.call(ccwDateTimeFormatWithPoisonedFallback)(0), + Intl_DateTimeFormat_format_get.call(dateTimeFormat)(0)); + +assertEq(deepEqual(Intl_DateTimeFormat_resolvedOptions.call(ccwDateTimeFormatWithPoisonedFallback), + Intl_DateTimeFormat_resolvedOptions.call(dateTimeFormat)), + true); + +if (typeof reportCompare === "function") + reportCompare(true, true); |