Skip to content

Editorial: Define an algorithm for %TypedArray%.prototype.toLocaleString - #3958

Open
gibson042 wants to merge 6 commits into
tc39:mainfrom
gibson042:2026-08-define-typedarray-tolocalestring
Open

gibson042 wants to merge 6 commits into
tc39:mainfrom
gibson042:2026-08-define-typedarray-tolocalestring

Conversation

@gibson042

@gibson042 gibson042 commented Aug 23, 2026 •

Copy link
Copy Markdown
Member

I noticed while reviewing #3940 that %TypedArray%.prototype.toLocaleString gestures at Array.prototype.toLocaleString rather than defining its own <emu-alg>, and further that it requires analogous use of the superseding ECMA-402 Array.prototype.toLocaleString algorithm in relevant implementations while ECMA-402 does not mention TypedArrays at all.

This PR addresses the ECMA-262 issue by defining the %TypedArray%.prototype.toLocaleString algorithm using a new JoinIndexedProperties operation common to both it and Array.prototype.toLocaleString, and prepares for addressing the ECMA-402 issue by defining that operation such that it will be usable by superseding definitions (specifically, that it accepts arguments for forwarding to "toLocaleString" method invocations, to be provided by ECMA-402 algorithms but not by ECMA-262 ones).

As its name suggests, JoinIndexedProperties is also used by {Array,%TypedArray%}.prototype.join methods.

@github-actions

Copy link
Copy Markdown

The rendered spec preview for this PR is available as a single page at https://tc39.es/ecma262/pr/3958 and as multiple pages at https://tc39.es/ecma262/pr/3958/multipage .

@linusg linusg left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like this direction and at a glance changes LGTM, though if you intend to have this merged unsquashed please avoid temporarily defining IndexableToLocaleString - having an AO in the commit history that never ended up being real is confusing, and if it was the end result of this PR I would have objected since Array and TypedArray toLocaleString are sufficiently different to warrant their own algorithms (one operates on arbitrary objects, the other on validated TAs - leading to different expectation wrt completions and element types and warranting TA-specific note steps). This concern goes away once the AO is broad enough to be used for join too.

Comment thread spec.html Outdated
@gibson042
gibson042 force-pushed the 2026-08-define-typedarray-tolocalestring branch from 4e167f6 to d7cf89f Compare August 24, 2026 16:56
gibson042 added a commit to gibson042/ecma402 that referenced this pull request Aug 24, 2026

@linusg linusg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit progression works nicely IMO, thanks!

@gibson042
gibson042 force-pushed the 2026-08-define-typedarray-tolocalestring branch from d7cf89f to c651b86 Compare September 17, 2026 15:31
Comment thread spec.html Outdated
Comment thread spec.html Outdated
gibson042 added a commit to gibson042/ecma402 that referenced this pull request Sep 17, 2026
Comment thread spec.html Outdated
@gibson042
gibson042 force-pushed the 2026-08-define-typedarray-tolocalestring branch from b68d8ea to 5579333 Compare September 17, 2026 19:30
gibson042 added a commit to gibson042/ecma402 that referenced this pull request Sep 17, 2026
Comment thread spec.html
<h1>LocalizedListSeparator ( ): a String</h1>
<dl class="header">
<dt>description</dt>
<dd>It returns an implementation-defined String appropriate for use as a list separator in the host environment's current locale (such as *", "*).</dd>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we clarify that it must return the same String every time it is called?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if the locale changes? or do we already guarantee it can't change without a pageload

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't make that guarantee, and there is no such constraint upon the toLocaleString methods, nor upon ECMA-402 DefaultLocale. I'd be open to exploring that, but not in the scope of this PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we should clarify that there is no such constraint.

@gibson042 gibson042 Sep 18, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see no value in making Array/TypedArray localization special in that way. Tackling that should cover all toLocaleString methods, and doesn't belong here.

Comment thread spec.html Outdated
Comment thread spec.html
<emu-note>
<p>If the ECMAScript implementation includes the ECMA-402 Internationalization API this method is based upon the algorithm for `Array.prototype.toLocaleString` that is in ECMA-402.</p>
</emu-note>
<p>An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement this method as specified in ECMA-402. Otherwise, the following specification of this method is used.</p>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But Ecma-402 doesn't currently define this method, right? Are we planning to hold off until tc39/ecma402#1094 is fixed?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix is tc39/ecma402#1095 which uses the AOs added here. I think it's fine to go ahead with this given the 402 PR is approved and likely to land shortly afterwards.

@linusg linusg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bunch of changes since I approved; still happy with the current state.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants