| 1 |
// |reftest| skip-if(!this.hasOwnProperty("Intl")) |
| 2 |
|
| 3 |
var otherGlobal = newGlobal(); |
| 4 |
|
| 5 |
var dateTimeFormat = new Intl.DateTimeFormat(); |
| 6 |
var ccwDateTimeFormat = new otherGlobal.Intl.DateTimeFormat(); |
| 7 |
|
| 8 |
// Test Intl.DateTimeFormat.prototype.format with a CCW object. |
| 9 |
var Intl_DateTimeFormat_format_get = Object.getOwnPropertyDescriptor(Intl.DateTimeFormat.prototype, "format").get; |
| 10 |
|
| 11 |
assertEq(Intl_DateTimeFormat_format_get.call(ccwDateTimeFormat)(0), |
| 12 |
Intl_DateTimeFormat_format_get.call(dateTimeFormat)(0)); |
| 13 |
|
| 14 |
// Test Intl.DateTimeFormat.prototype.formatToParts with a CCW object. |
| 15 |
var Intl_DateTimeFormat_formatToParts = Intl.DateTimeFormat.prototype.formatToParts; |
| 16 |
|
| 17 |
assertEq(deepEqual(Intl_DateTimeFormat_formatToParts.call(ccwDateTimeFormat, 0), |
| 18 |
Intl_DateTimeFormat_formatToParts.call(dateTimeFormat, 0)), |
| 19 |
true); |
| 20 |
|
| 21 |
// Test Intl.DateTimeFormat.prototype.resolvedOptions with a CCW object. |
| 22 |
var Intl_DateTimeFormat_resolvedOptions = Intl.DateTimeFormat.prototype.resolvedOptions; |
| 23 |
|
| 24 |
assertEq(deepEqual(Intl_DateTimeFormat_resolvedOptions.call(ccwDateTimeFormat), |
| 25 |
Intl_DateTimeFormat_resolvedOptions.call(dateTimeFormat)), |
| 26 |
true); |
| 27 |
|
| 28 |
// Special case for Intl.DateTimeFormat: The Intl fallback symbol. |
| 29 |
|
| 30 |
function fallbackSymbol(global) { |
| 31 |
var DTF = global.Intl.DateTimeFormat; |
| 32 |
return Object.getOwnPropertySymbols(DTF.call(Object.create(DTF.prototype)))[0]; |
| 33 |
} |
| 34 |
|
| 35 |
const intlFallbackSymbol = fallbackSymbol(this); |
| 36 |
const otherIntlFallbackSymbol = fallbackSymbol(otherGlobal); |
| 37 |
assertEq(intlFallbackSymbol === otherIntlFallbackSymbol, false); |
| 38 |
|
| 39 |
// Test when the fallback symbol points to a CCW DateTimeFormat object. |
| 40 |
var objWithFallbackCCWDateTimeFormat = { |
| 41 |
__proto__: Intl.DateTimeFormat.prototype, |
| 42 |
[intlFallbackSymbol]: ccwDateTimeFormat, |
| 43 |
}; |
| 44 |
|
| 45 |
assertEq(Intl_DateTimeFormat_format_get.call(objWithFallbackCCWDateTimeFormat)(0), |
| 46 |
Intl_DateTimeFormat_format_get.call(dateTimeFormat)(0)); |
| 47 |
|
| 48 |
assertEq(deepEqual(Intl_DateTimeFormat_resolvedOptions.call(objWithFallbackCCWDateTimeFormat), |
| 49 |
Intl_DateTimeFormat_resolvedOptions.call(dateTimeFormat)), |
| 50 |
true); |
| 51 |
|
| 52 |
// Ensure the fallback symbol(s) are not accessed for CCW DateTimeFormat objects. |
| 53 |
var ccwDateTimeFormatWithPoisonedFallback = new otherGlobal.Intl.DateTimeFormat(); |
| 54 |
Object.setPrototypeOf(ccwDateTimeFormatWithPoisonedFallback, Intl.DateTimeFormat.prototype); |
| 55 |
Object.defineProperty(ccwDateTimeFormatWithPoisonedFallback, intlFallbackSymbol, { |
| 56 |
get() { throw new Error(); } |
| 57 |
}); |
| 58 |
Object.defineProperty(ccwDateTimeFormatWithPoisonedFallback, otherIntlFallbackSymbol, { |
| 59 |
get() { throw new Error(); } |
| 60 |
}); |
| 61 |
|
| 62 |
assertEq(Intl_DateTimeFormat_format_get.call(ccwDateTimeFormatWithPoisonedFallback)(0), |
| 63 |
Intl_DateTimeFormat_format_get.call(dateTimeFormat)(0)); |
| 64 |
|
| 65 |
assertEq(deepEqual(Intl_DateTimeFormat_resolvedOptions.call(ccwDateTimeFormatWithPoisonedFallback), |
| 66 |
Intl_DateTimeFormat_resolvedOptions.call(dateTimeFormat)), |
| 67 |
true); |
| 68 |
|
| 69 |
if (typeof reportCompare === "function") |
| 70 |
reportCompare(true, true); |