Skip to content

Commit 01c3845

Browse files
ptomatoMs2ger
authored andcommitted
Polyfill: Fix util.inspect output of polyfilled Intl.DateTimeFormat
The default formatter would look for a property called _repr_, which does not exist, and therefore would be confusingly formatted as "undefined". Instead, delegate to the original Intl.DateTimeFormat's util.inspect output.
1 parent 23c74b6 commit 01c3845

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

polyfill/lib/intl.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
EPOCHNANOSECONDS,
3131
ISO_DATE,
3232
ISO_DATE_TIME,
33+
ORIGINAL,
3334
SetSlot,
3435
TIME,
3536
CALENDAR
@@ -41,7 +42,6 @@ const MD = SymbolCtor('md');
4142
const TIME_FMT = SymbolCtor('time');
4243
const DATETIME = SymbolCtor('datetime');
4344
const INST = SymbolCtor('instant');
44-
const ORIGINAL = SymbolCtor('original');
4545
const TZ_CANONICAL = SymbolCtor('timezone-canonical');
4646
const TZ_ORIGINAL = SymbolCtor('timezone-original');
4747
const CAL_ID = SymbolCtor('calendar-id');

polyfill/lib/intrinsicclass.mjs

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
SymbolFor,
1010
SymbolToStringTag
1111
} from './primordials.mjs';
12+
import { GetSlot, ORIGINAL } from './slots.mjs';
1213

1314
import Call from 'es-abstract/2024/Call.js';
1415

@@ -17,6 +18,9 @@ import ESGetIntrinsic from 'es-abstract/GetIntrinsic.js';
1718
const INTRINSICS = {};
1819

1920
const customUtilInspectFormatters = {
21+
['Intl.DateTimeFormat'](depth, options, inspect) {
22+
return inspect(GetSlot(this, ORIGINAL), { depth, ...options });
23+
},
2024
['Temporal.Duration'](depth, options) {
2125
const descr = options.stylize(this._repr_, 'special');
2226
if (depth < 1) return descr;

polyfill/lib/slots.mjs

+3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ export const MILLISECONDS = 'slot-milliseconds';
3838
export const MICROSECONDS = 'slot-microseconds';
3939
export const NANOSECONDS = 'slot-nanoseconds';
4040

41+
// Intl.DateTimeFormat
42+
export const ORIGINAL = 'slot-original';
43+
4144
const slots = new WeakMapCtor();
4245
export function CreateSlots(container) {
4346
Call(WeakMapPrototypeSet, slots, [container, ObjectCreate(null)]);

0 commit comments

Comments
 (0)