Intl.js
Intl.js copied to clipboard
formatToParts outdated from spec?
I'm putting some pieces together so please forgive me if I'm just misreading things. I have the following polyfill code:
const fillNumberFormatFormatToParts = () => new Promise((resolve) => {
if (!Intl.NumberFormat.prototype.formatToParts) {
require.ensure(['intl'], (require) => {
const IntlPolyfill = require('intl');
Intl.NumberFormat.prototype.formatToParts = IntlPolyfill.NumberFormat.prototype.formatToParts;
return resolve();
}, 'Intl');
} else {
return resolve();
}
});
In iOS Safari 11 and 12 (where this is clearly being polyfilled) I get the following error:
"TypeError: this
value for formatToParts() is not an initialized Intl.NumberFormat object."
It looks as if here: https://github.com/tc39/ecma402/issues/122 the prototype for NumberFormat
was changed from being an instance of NumberFormat
to being a plain object. And that is documented here: https://tc39.es/proposal-unified-intl-numberformat/section11/numberformat_proposed_out.html#sec-properties-of-intl-numberformat-prototype-object.
But based on the implementation it seems to still be requiring NumberFormat
to be an instance:
function formatToParts(value = undefined) {
let internal = this !== null && typeof this === 'object' && getInternalProperties(this);
if (!internal || !internal['[[initializedNumberFormat]]'])
throw new TypeError('`this` value for formatToParts() is not an initialized Intl.NumberFormat object.');
let x = Number(value);
return FormatNumberToParts(this, x);
}
And this is the spec being referenced for the Intl.NumberFormat.prototype
from your documentation: http://www.ecma-international.org/ecma-402/1.0/#sec-11.3.
Or am I just doing something wrong here?
I haven't dug into the issue yet, but I can attest to the fact that all users visiting my sites on Mobile Safari 12.1 and 12.1.2 are failing to have formatToParts
correctly polyfilled.