Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Use prototype-less return object #1

Merged
merged 1 commit into from
Jul 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
@@ -2261,9 +2261,10 @@ <h1><span class="secnum">2.1</span> Array.prototype.groupBy ( <var>callbackfn</v
<p><var>callbackfn</var> is called with three arguments: the value of the element, the index of the element, and the object being traversed.</p>
<p><code>groupBy</code> does not directly mutate the object on which it is called but the object may be mutated by the calls to <var>callbackfn</var>.</p>
<p>The range of elements processed by <code>groupBy</code> is set before the first call to <var>callbackfn</var>. Elements which are appended to the array after the call to <code>groupBy</code> begins will not be visited by <var>callbackfn</var>. If existing elements of the array are changed their value as passed to <var>callbackfn</var> will be the value at the time <code>groupBy</code> visits them; elements that are deleted after the call to <code>groupBy</code> begins and before being visited are not visited.</p>
<p>The return value of <code>groupBy</code> is an object that does not inherit from <var>Object.prototype</var>.</p>
</div></emu-note>
<p>When the <code>groupBy</code> method is called with one or two arguments, the following steps are taken:</p>
<emu-alg><ol><li>Let <var>O</var> be ?&nbsp;<emu-xref aoid="ToObject" id="_ref_0"><a href="https://tc39.es/ecma262/#sec-toobject">ToObject</a></emu-xref>(<emu-val>this</emu-val> value).</li><li>Let <var>len</var> be ?&nbsp;<emu-xref aoid="LengthOfArrayLike" id="_ref_1"><a href="https://tc39.es/ecma262/#sec-lengthofarraylike">LengthOfArrayLike</a></emu-xref>(<var>O</var>).</li><li>If <emu-xref aoid="IsCallable" id="_ref_2"><a href="https://tc39.es/ecma262/#sec-iscallable">IsCallable</a></emu-xref>(<var>callbackfn</var>) is <emu-val>false</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>k</var> be 0.</li><li>Let <var>obj</var> be !&nbsp;OrdinaryObjectCreate(%Object.prototype%).</li><li><emu-xref href="#assert"><a href="https://tc39.es/ecma262/#assert">Assert</a></emu-xref>: <var>obj</var> is an extensible ordinary object with no own properties.</li><li>Repeat, while <var>k</var> &lt; <var>len</var><ol><li>Let <var>Pk</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_3"><a href="https://tc39.es/ecma262/#sec-tostring">ToString</a></emu-xref>(<var>k</var>).</li><li>Let <var>kValue</var> be ?&nbsp;<emu-xref aoid="Get" id="_ref_4"><a href="https://tc39.es/ecma262/#sec-get-o-p">Get</a></emu-xref>(<var>O</var>, <var>Pk</var>).</li><li>Let <var>propertyKey</var> be ?&nbsp;<emu-xref aoid="ToPropertyKey" id="_ref_5"><a href="https://tc39.es/ecma262/#sec-topropertykey">ToPropertyKey</a></emu-xref>(? <emu-xref aoid="Call" id="_ref_6"><a href="https://tc39.es/ecma262/#sec-call">Call</a></emu-xref>(<var>callbackfn</var>, <var>thisArg</var>, « <var>kValue</var>, <var>k</var>, <var>O</var> »)).</li><li>Let <var>seen</var> be ?&nbsp;<emu-xref aoid="HasOwnProperty" id="_ref_7"><a href="https://tc39.es/ecma262/#sec-hasownproperty">HasOwnProperty</a></emu-xref>(<var>obj</var>, <var>propertyKey</var>).</li><li>If <var>seen</var> is <emu-val>true</emu-val>, then<ol><li>Let <var>arr</var> be !&nbsp;<emu-xref aoid="Get" id="_ref_8"><a href="https://tc39.es/ecma262/#sec-get-o-p">Get</a></emu-xref>(<var>obj</var>, <var>propertyKey</var>).</li></ol></li><li>Else<ol><li>Let <var>arr</var> be ?&nbsp;<emu-xref aoid="ArraySpeciesCreate" id="_ref_9"><a href="https://tc39.es/ecma262/#sec-arrayspeciescreate">ArraySpeciesCreate</a></emu-xref>(O, 0).</li><li>Perform !&nbsp;<emu-xref aoid="CreateDataPropertyOrThrow" id="_ref_10"><a href="https://tc39.es/ecma262/#sec-createdatapropertyorthrow">CreateDataPropertyOrThrow</a></emu-xref>(<var>obj</var>, <var>propertyKey</var>, <var>arr</var>).</li></ol></li><li>Perform ?&nbsp;<emu-xref aoid="Call" id="_ref_11"><a href="https://tc39.es/ecma262/#sec-call">Call</a></emu-xref>(%Array.prototype.push%, <var>arr</var>, <var>kValue</var>).</li><li>Set <var>k</var> to <var>k</var> + 1.</li></ol></li><li>Return <var>obj</var>.</li></ol></emu-alg>
<emu-alg><ol><li>Let <var>O</var> be ?&nbsp;<emu-xref aoid="ToObject" id="_ref_0"><a href="https://tc39.es/ecma262/#sec-toobject">ToObject</a></emu-xref>(<emu-val>this</emu-val> value).</li><li>Let <var>len</var> be ?&nbsp;<emu-xref aoid="LengthOfArrayLike" id="_ref_1"><a href="https://tc39.es/ecma262/#sec-lengthofarraylike">LengthOfArrayLike</a></emu-xref>(<var>O</var>).</li><li>If <emu-xref aoid="IsCallable" id="_ref_2"><a href="https://tc39.es/ecma262/#sec-iscallable">IsCallable</a></emu-xref>(<var>callbackfn</var>) is <emu-val>false</emu-val>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Let <var>k</var> be 0.</li><li>Let <var>obj</var> be !&nbsp;OrdinaryObjectCreate(null).</li><li><emu-xref href="#assert"><a href="https://tc39.es/ecma262/#assert">Assert</a></emu-xref>: <var>obj</var> is an extensible ordinary object with no own properties.</li><li>Repeat, while <var>k</var> &lt; <var>len</var><ol><li>Let <var>Pk</var> be !&nbsp;<emu-xref aoid="ToString" id="_ref_3"><a href="https://tc39.es/ecma262/#sec-tostring">ToString</a></emu-xref>(<var>k</var>).</li><li>Let <var>kValue</var> be ?&nbsp;<emu-xref aoid="Get" id="_ref_4"><a href="https://tc39.es/ecma262/#sec-get-o-p">Get</a></emu-xref>(<var>O</var>, <var>Pk</var>).</li><li>Let <var>propertyKey</var> be ?&nbsp;<emu-xref aoid="ToPropertyKey" id="_ref_5"><a href="https://tc39.es/ecma262/#sec-topropertykey">ToPropertyKey</a></emu-xref>(? <emu-xref aoid="Call" id="_ref_6"><a href="https://tc39.es/ecma262/#sec-call">Call</a></emu-xref>(<var>callbackfn</var>, <var>thisArg</var>, « <var>kValue</var>, <var>k</var>, <var>O</var> »)).</li><li>Let <var>seen</var> be ?&nbsp;<emu-xref aoid="HasOwnProperty" id="_ref_7"><a href="https://tc39.es/ecma262/#sec-hasownproperty">HasOwnProperty</a></emu-xref>(<var>obj</var>, <var>propertyKey</var>).</li><li>If <var>seen</var> is <emu-val>true</emu-val>, then<ol><li>Let <var>arr</var> be !&nbsp;<emu-xref aoid="Get" id="_ref_8"><a href="https://tc39.es/ecma262/#sec-get-o-p">Get</a></emu-xref>(<var>obj</var>, <var>propertyKey</var>).</li></ol></li><li>Else<ol><li>Let <var>arr</var> be ?&nbsp;<emu-xref aoid="ArraySpeciesCreate" id="_ref_9"><a href="https://tc39.es/ecma262/#sec-arrayspeciescreate">ArraySpeciesCreate</a></emu-xref>(O, 0).</li><li>Perform !&nbsp;<emu-xref aoid="CreateDataPropertyOrThrow" id="_ref_10"><a href="https://tc39.es/ecma262/#sec-createdatapropertyorthrow">CreateDataPropertyOrThrow</a></emu-xref>(<var>obj</var>, <var>propertyKey</var>, <var>arr</var>).</li></ol></li><li>Perform ?&nbsp;<emu-xref aoid="Call" id="_ref_11"><a href="https://tc39.es/ecma262/#sec-call">Call</a></emu-xref>(%Array.prototype.push%, <var>arr</var>, <var>kValue</var>).</li><li>Set <var>k</var> to <var>k</var> + 1.</li></ol></li><li>Return <var>obj</var>.</li></ol></emu-alg>
<emu-note><span class="note">Note 2</span><div class="note-contents">
<p>The <code>groupBy</code> function is intentionally generic; it does not require that its <emu-val>this</emu-val> value be an Array object. Therefore it can be transferred to other kinds of objects for use as a method.</p>
</div></emu-note>
3 changes: 2 additions & 1 deletion spec.emu
Original file line number Diff line number Diff line change
@@ -30,14 +30,15 @@ location: https://tc39.es/proposal-array-grouping/
<p>_callbackfn_ is called with three arguments: the value of the element, the index of the element, and the object being traversed.</p>
<p>`groupBy` does not directly mutate the object on which it is called but the object may be mutated by the calls to _callbackfn_.</p>
<p>The range of elements processed by `groupBy` is set before the first call to _callbackfn_. Elements which are appended to the array after the call to `groupBy` begins will not be visited by _callbackfn_. If existing elements of the array are changed their value as passed to _callbackfn_ will be the value at the time `groupBy` visits them; elements that are deleted after the call to `groupBy` begins and before being visited are not visited.</p>
<p>The return value of `groupBy` is an object that does not inherit from _Object.prototype_.</p>
</emu-note>
<p>When the `groupBy` method is called with one or two arguments, the following steps are taken:</p>
<emu-alg>
1. Let _O_ be ? ToObject(*this* value).
1. Let _len_ be ? LengthOfArrayLike(_O_).
1. If IsCallable(_callbackfn_) is *false*, throw a *TypeError* exception.
1. Let _k_ be 0.
1. Let _obj_ be ! OrdinaryObjectCreate(%Object.prototype%).
1. Let _obj_ be ! OrdinaryObjectCreate(null).
1. Assert: _obj_ is an extensible ordinary object with no own properties.
1. Repeat, while _k_ &lt; _len_
1. Let _Pk_ be ! ToString(_k_).