Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

formatToParts outdated from spec? #336

Open
erin-doyle opened this issue Feb 5, 2020 · 1 comment
Open

formatToParts outdated from spec? #336

erin-doyle opened this issue Feb 5, 2020 · 1 comment

Comments

@erin-doyle
Copy link

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: tc39/ecma402#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?

@cipater
Copy link

cipater commented Mar 6, 2020

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants