Skip to content

Commit

Permalink
Editorial: Introduce SortStringListByCodeUnit operation
Browse files Browse the repository at this point in the history
There are a few places where Lists of Strings are sorted with the awkward
phrasing "ordered as if an Array of the same values had been sorted using
%Array.prototype.sort% using *undefined* as _comparefn_." Encapsulate this
sorting into a new AO, SortStringListByCodeUnit. I find this clearer about
the intention (the current language leaves it implicit that the sorting is
by code unit), and more concise.

This phrasing is used in several places in ECMA-402 as well, so this
change will bring additional benefit there.
  • Loading branch information
ptomato committed Mar 22, 2024
1 parent 3d5a70b commit 4c190c8
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -6460,6 +6460,23 @@ <h1>
</emu-alg>
</emu-clause>

<emu-clause id="sec-sortstringlistbycodeunit" type="abstract operation">
<h1>
SortStringListByCodeUnit (
_strings_: a List of Strings,
): a List of Strings
</h1>
<dl class="header">
<dt>description</dt>
<dd>The returned List contains the same Strings as _strings_, but sorted lexicographically by UTF-16 code unit in ascending order.</dd>
</dl>
<emu-alg>
1. Let _result_ be a copy of _strings_.
1. [declared="comparefn"] Sort _result_ into the same order as if an Array of the same values had been sorted using %Array.prototype.sort% with *undefined* as _comparefn_.
1. Return _result_.
</emu-alg>
</emu-clause>

<emu-clause id="sec-invoke" type="abstract operation">
<h1>
Invoke (
Expand Down Expand Up @@ -14994,7 +15011,7 @@ <h1>Module Namespace Exotic Objects</h1>
a List of Strings
</td>
<td>
A List whose elements are the String values of the exported names exposed as own properties of this object. The list is ordered as if an Array of those String values had been sorted using %Array.prototype.sort% using *undefined* as _comparefn_.
A List whose elements are the String values of the exported names exposed as own properties of this object. The list is ordered as if sorted using SortStringListByCodeUnit.
</td>
</tr>
</table>
Expand Down Expand Up @@ -15207,8 +15224,7 @@ <h1>
1. Let _M_ be MakeBasicObject(_internalSlotsList_).
1. Set _M_'s essential internal methods to the definitions specified in <emu-xref href="#sec-module-namespace-exotic-objects"></emu-xref>.
1. Set _M_.[[Module]] to _module_.
1. [declared="comparefn"] Let _sortedExports_ be a List whose elements are the elements of _exports_ ordered as if an Array of the same values had been sorted using %Array.prototype.sort% using *undefined* as _comparefn_.
1. Set _M_.[[Exports]] to _sortedExports_.
1. Set _M_.[[Exports]] to SortStringListByCodeUnit(_exports_).
1. Create own properties of _M_ corresponding to the definitions in <emu-xref href="#sec-module-namespace-objects"></emu-xref>.
1. Set _module_.[[Namespace]] to _M_.
1. Return _M_.
Expand Down Expand Up @@ -32744,7 +32760,7 @@ <h1>AvailableNamedTimeZoneIdentifiers ( ): a List of Time Zone Identifier Record
1. If the implementation does not include local political rules for any time zones, then
1. Return « the Time Zone Identifier Record { [[Identifier]]: *"UTC"*, [[PrimaryIdentifier]]: *"UTC"* } ».
1. Let _identifiers_ be the List of unique available named time zone identifiers.
1. [declared="comparefn"] Sort _identifiers_ into the same order as if an Array of the same values had been sorted using %Array.prototype.sort% with *undefined* as _comparefn_.
1. Set _identifiers_ to SortStringListByCodeUnit(_identifiers_).
1. Let _result_ be a new empty List.
1. For each element _identifier_ of _identifiers_, do
1. Let _primary_ be _identifier_.
Expand Down

0 comments on commit 4c190c8

Please sign in to comment.