Skip to content

Commit

Permalink
Merge pull request #23 from tc39/to-inf-on-bigint
Browse files Browse the repository at this point in the history
feat: allow range to inf on bigint, close #8
  • Loading branch information
Jack-Works authored Apr 11, 2020
2 parents 003ced8 + 4aa2a51 commit e05d026
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 88 deletions.
11 changes: 4 additions & 7 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1845,11 +1845,8 @@ <h1><span class="secnum">3.1</span> BigInt.range(<var>from</var>, <var>to</var>,
<h1><span class="secnum">4</span> Algorithms</h1>
<emu-clause id="sec-algor">
<h1><span class="secnum">4.1</span> <dfn>CreateRangeIterator</dfn>(<var>from</var>, <var>to</var>, <var>step</var>, <var>type</var>)</h1>
<emu-alg><ol><li>If <emu-xref aoid="Type" id="_ref_2"><a href="https://tc39.es/ecma262/#sec-ecmascript-data-types-and-values">Type</a></emu-xref>(from) is not <var>type</var>, throw a <emu-val>TypeError</emu-val> exception.</li><li><emu-xref href="#assert"><a href="https://tc39.es/ecma262/#assert">Assert</a></emu-xref>: <var>type</var> is <emu-val>"number"</emu-val> or
<emu-val>"bigint"</emu-val></li><li>If <var>type</var> is <emu-val>"bigint"</emu-val>, let <var>zero</var> be <emu-val>0n</emu-val>, else let <var>zero</var> be <emu-val>0</emu-val>.</li><li>If <var>type</var> is <emu-val>"bigint"</emu-val>, let <var>one</var> be <emu-val>1n</emu-val>, else let <var>one</var> be <emu-val>1</emu-val>.
1.<ol><li>If variant <var>isAcceptAlias</var> is <emu-val>false</emu-val>, do nothing.</li><li>Else, if <emu-xref aoid="Type" id="_ref_3"><a href="https://tc39.es/ecma262/#sec-ecmascript-data-types-and-values">Type</a></emu-xref>(to) is undefined, let <var>to</var> be <var>from</var>, then <var>from</var> be <var>zero</var></li></ol></li><li>If <emu-xref aoid="Type" id="_ref_4"><a href="https://tc39.es/ecma262/#sec-ecmascript-data-types-and-values">Type</a></emu-xref>(step) is <emu-val>undefined</emu-val>, let <var>step</var> = <var>one</var>
<!-- Type Check --></li><li>If <emu-xref aoid="Type" id="_ref_5"><a href="https://tc39.es/ecma262/#sec-ecmascript-data-types-and-values">Type</a></emu-xref>(from) is not <var>type</var>, throw a <emu-val>TypeError</emu-val> exception.</li><li>If <emu-xref aoid="Type" id="_ref_6"><a href="https://tc39.es/ecma262/#sec-ecmascript-data-types-and-values">Type</a></emu-xref>(to) is not <var>type</var>, throw a <emu-val>TypeError</emu-val> exception.</li><li>If <emu-xref aoid="Type" id="_ref_7"><a href="https://tc39.es/ecma262/#sec-ecmascript-data-types-and-values">Type</a></emu-xref>(step) is not <var>type</var>, throw a <emu-val>TypeError</emu-val> exception.
<!-- Value range check --></li><li>If <var>from</var> is <emu-val>Infinity</emu-val>, throws a <emu-val>RangeError</emu-val> exception.</li><li>If <var>step</var> is <emu-val>Infinity</emu-val>, throws a <emu-val>RangeError</emu-val> exception.</li><li>If <var>step</var> is <var>zero</var>, throws an <emu-val>RangeError</emu-val> exception.</li><li>Let <var>iterator</var> be <emu-xref aoid="ObjectCreate" id="_ref_8"><a href="https://tc39.es/ecma262/#sec-objectcreate">ObjectCreate</a></emu-xref>(<emu-xref href="#sec-properties-of-the-rangeiterator-prototype-object" id="_ref_9"><a href="#sec-properties-of-the-rangeiterator-prototype-object">%RangeIteratorPrototype%</a></emu-xref>, « [[from]], [[to]], [[step]], [[type]], [[currentCount]], [[lastValue]] »).</li><li>Set <var>iterator</var>.[[from]] to from.</li><li>Set <var>iterator</var>.[[to]] to to.</li><li>Set <var>iterator</var>.[[step]] to step.</li><li>Set <var>iterator</var>.[[type]] to type.</li><li>Set <var>iterator</var>.[[currentCount]] to one.</li><li>Set <var>iterator</var>.[[lastValue]] to from.</li><li>Return <var>iterator</var>.
<emu-alg><ol><li>If <emu-xref aoid="Type" id="_ref_2"><a href="https://tc39.es/ecma262/#sec-ecmascript-data-types-and-values">Type</a></emu-xref>(<var>from</var>) is not <var>type</var>, throw a <emu-val>TypeError</emu-val> exception.</li><li><emu-xref href="#assert"><a href="https://tc39.es/ecma262/#assert">Assert</a></emu-xref>: <var>type</var> is <emu-val>"number"</emu-val> or
<emu-val>"bigint"</emu-val></li><li>If <var>type</var> is <emu-val>"bigint"</emu-val>, let <var>zero</var> be <emu-val>0n</emu-val>, else let <var>zero</var> be <emu-val>0</emu-val>.</li><li>If <var>type</var> is <emu-val>"bigint"</emu-val>, let <var>one</var> be <emu-val>1n</emu-val>, else let <var>one</var> be <emu-val>1</emu-val>.</li><li>Variants<ol><li>If variant <var>isAcceptAlias</var> is <emu-val>false</emu-val>, do nothing.</li><li>Else, if <emu-xref aoid="Type" id="_ref_3"><a href="https://tc39.es/ecma262/#sec-ecmascript-data-types-and-values">Type</a></emu-xref>(<var>to</var>) is <emu-val>"undefined"</emu-val>, let <var>to</var> be <var>from</var>, then <var>from</var> be <var>zero</var></li></ol></li><li>If <emu-xref aoid="Type" id="_ref_4"><a href="https://tc39.es/ecma262/#sec-ecmascript-data-types-and-values">Type</a></emu-xref>(<var>step</var>) is <emu-val>undefined</emu-val>, let <var>step</var> = <var>one</var></li><li>If <emu-xref aoid="Type" id="_ref_5"><a href="https://tc39.es/ecma262/#sec-ecmascript-data-types-and-values">Type</a></emu-xref>(<var>from</var>) is not <var>type</var>, throw a <emu-val>TypeError</emu-val> exception.</li><li>Note: <emu-note type="editor"><span class="note">Editor's Note</span><div class="note-contents">Allowing all kinds of number (number, bigint, decimals, ...) to range from a finite number to infinity.</div></emu-note></li><li>If <var>to</var> is not <emu-val>+∞</emu-val> or <emu-val>-∞</emu-val> and if <emu-xref aoid="Type" id="_ref_6"><a href="https://tc39.es/ecma262/#sec-ecmascript-data-types-and-values">Type</a></emu-xref>(<var>to</var>) is not <var>type</var>, throw a <emu-val>TypeError</emu-val> exception.</li><li>If <emu-xref aoid="Type" id="_ref_7"><a href="https://tc39.es/ecma262/#sec-ecmascript-data-types-and-values">Type</a></emu-xref>(<var>step</var>) is not <var>type</var>, throw a <emu-val>TypeError</emu-val> exception.</li><li>If <var>from</var> is <emu-val>+∞</emu-val> or <emu-val>-∞</emu-val>, throws a <emu-val>RangeError</emu-val> exception.</li><li>If <var>step</var> is <emu-val>+∞</emu-val> or <emu-val>-∞</emu-val>, throws a <emu-val>RangeError</emu-val> exception.</li><li>If <var>step</var> is <var>zero</var>, throws an <emu-val>RangeError</emu-val> exception.</li><li>Let <var>iterator</var> be <emu-xref aoid="ObjectCreate" id="_ref_8"><a href="https://tc39.es/ecma262/#sec-objectcreate">ObjectCreate</a></emu-xref>(<emu-xref href="#sec-properties-of-the-rangeiterator-prototype-object" id="_ref_9"><a href="#sec-properties-of-the-rangeiterator-prototype-object">%RangeIteratorPrototype%</a></emu-xref>, « [[from]], [[to]], [[step]], [[type]], [[currentCount]], [[lastValue]] »).</li><li>Set <var>iterator</var>.[[from]] to from.</li><li>Set <var>iterator</var>.[[to]] to to.</li><li>Set <var>iterator</var>.[[step]] to step.</li><li>Set <var>iterator</var>.[[type]] to type.</li><li>Set <var>iterator</var>.[[currentCount]] to one.</li><li>Set <var>iterator</var>.[[lastValue]] to from.</li><li>Return <var>iterator</var>.
</li></ol></emu-alg>
</emu-clause>
</emu-clause>
Expand All @@ -1860,7 +1857,7 @@ <h1><span class="secnum">5</span> Properties of the RangeIterator Prototype Obje
<p>The value has a [[Prototype]] internal slot whose value is the intrinsic object <emu-xref href="#sec-%iteratorprototype%-object"><a href="https://tc39.es/ecma262/#sec-%iteratorprototype%-object">%IteratorPrototype%</a></emu-xref>.</p>
<emu-clause id="sec-properties-of-the-rangeiterator-prototype-object-next">
<h1><span class="secnum">5.1</span> %RangeIterator%.next()</h1>
<emu-alg><ol><li> Let <var>iterator</var> be the <emu-val>this</emu-val> value.</li><li> If <emu-xref aoid="Type" id="_ref_10"><a href="https://tc39.es/ecma262/#sec-ecmascript-data-types-and-values">Type</a></emu-xref>(iterator) is not Object, throw a <emu-val>TypeError</emu-val> exception.</li><li> If <var>iterator</var> does not have all of the internal slots of a Range Iterator Instance, throw a <emu-val>TypeError</emu-val> exception.
<emu-alg><ol><li> Let <var>iterator</var> be the <emu-val>this</emu-val> value.</li><li> If <emu-xref aoid="Type" id="_ref_10"><a href="https://tc39.es/ecma262/#sec-ecmascript-data-types-and-values">Type</a></emu-xref>(<var>iterator</var>) is not Object, throw a <emu-val>TypeError</emu-val> exception.</li><li> If <var>iterator</var> does not have all of the internal slots of a Range Iterator Instance, throw a <emu-val>TypeError</emu-val> exception.
<!-- Deconstruct variables --></li><li> Let <var>from</var> be <var>iterator</var>.[[from]].</li><li> Let <var>to</var> be <var>iterator</var>.[[to]].</li><li> Let <var>step</var> be <var>iterator</var>.[[step]].</li><li> Let <var>type</var> be <var>iterator</var>.[[type]].</li><li> <emu-xref href="#assert"><a href="https://tc39.es/ecma262/#assert">Assert</a></emu-xref>: <var>type</var> is <emu-val>"number"</emu-val> or <emu-val>"bigint"</emu-val></li><li> If <var>type</var> is <emu-val>"bigint"</emu-val>, let <var>zero</var> be <emu-val>0n</emu-val>, else let <var>zero</var> be <emu-val>0</emu-val></li><li> If <var>type</var> is <emu-val>"bigint"</emu-val>, let <var>one</var> be <emu-val>1n</emu-val>, else let <var>one</var> be <emu-val>1</emu-val>
<!-- Early return --></li><li> If <var>from</var> is <emu-val>NaN</emu-val>, return <emu-xref aoid="CreateIterResultObject" id="_ref_11"><a href="https://tc39.es/ecma262/#sec-createiterresultobject">CreateIterResultObject</a></emu-xref>(<emu-val>undefined</emu-val>, <emu-val>true</emu-val>).</li><li> If <var>to</var> is <emu-val>NaN</emu-val>, return <emu-xref aoid="CreateIterResultObject" id="_ref_12"><a href="https://tc39.es/ecma262/#sec-createiterresultobject">CreateIterResultObject</a></emu-xref>(<emu-val>undefined</emu-val>, <emu-val>true</emu-val>).</li><li> If <var>step</var> is <emu-val>NaN</emu-val>, return <emu-xref aoid="CreateIterResultObject" id="_ref_13"><a href="https://tc39.es/ecma262/#sec-createiterresultobject">CreateIterResultObject</a></emu-xref>(<emu-val>undefined</emu-val>, <emu-val>true</emu-val>).
<!-- Direction mismatch --></li><li> Let <var>ifIncrease</var> be <code>to &gt; from</code></li><li> Let <var>ifStepIncrease</var> to be <code>step &gt; zero</code></li><li> Variants<ol><li>If variant <var>directionMismatch</var> is <emu-val>"throw"</emu-val><ol><li>If <var>ifIncrease</var> is not equal to <var>ifStepIncrease</var>, throw a <emu-val>RangeError</emu-val> exception.</li></ol></li><li>If variant <var>directionMismatch</var> is <emu-val>"yield-no-value"</emu-val><ol><li>If <var>ifIncrease</var> is not equal to <var>ifStepIncrease</var>, return <emu-xref aoid="CreateIterResultObject" id="_ref_14"><a href="https://tc39.es/ecma262/#sec-createiterresultobject">CreateIterResultObject</a></emu-xref>(<emu-val>undefined</emu-val>, <emu-val>true</emu-val>).</li></ol></li><li>If variant <var>directionMismatch</var> is <emu-val>"ignore"</emu-val><ol><li>If <var>ifIncrease</var> is <emu-val>true</emu-val>, let <var>step</var> to be <code>abs(step)</code></li><li>Else let <var>step</var> to be <code>-abs(step)</code></li></ol></li><li>If variant <var>directionMismatch</var> is <emu-val>"noop"</emu-val><ol><li>Do nothing
Expand All @@ -1877,7 +1874,7 @@ <h1><span class="secnum">5.1</span> %RangeIterator%.next()</h1>
currentCount++
yield yielding
}</code>
</div></emu-note></li><li> Let <var>currentCount</var> be <var>iterator</var>.[[currentCount]]</li><li> Let <var>lastValue</var> be <var>iterator</var>.[[lastValue]]</li><li> Let <var>now</var> be <var>from</var></li><li> If <var>ifIncrease</var> is true, let <var>condition</var> be <code>!(lastValue &gt;= to)</code>, else let <var>condition</var> be <code>!(to &gt;= lastValue)</code></li><li> Repeat, while <var>condition</var> evaluates to <emu-val>true</emu-val>,<ol><li>Let <var>yielding</var> be <var>lastValue</var></li><li>Set <var>lastValue</var> be <var>from</var> + (<var>step</var> * <var>currentCount</var>)</li><li>Set <var>currentCount</var> to <var>currentCount</var> + <var>one</var></li><li>Set <var>iterator</var>.[[currentCount]] to currentCount</li><li>Return <emu-xref aoid="CreateIterResultObject" id="_ref_15"><a href="https://tc39.es/ecma262/#sec-createiterresultobject">CreateIterResultObject</a></emu-xref>(<var>yielding</var>, <emu-val>false</emu-val>).
</div></emu-note></li><li> Let <var>currentCount</var> be <var>iterator</var>.[[currentCount]]</li><li> Let <var>lastValue</var> be <var>iterator</var>.[[lastValue]]</li><li> If <var>ifIncrease</var> is true, let <var>condition</var> be <code>!(lastValue &gt;= to)</code>, else let <var>condition</var> be <code>!(to &gt;= lastValue)</code></li><li> Repeat, while <var>condition</var> evaluates to <emu-val>true</emu-val>,<ol><li>Set <var>lastValue</var> be <var>from</var> + (<var>step</var> * <var>currentCount</var>)</li><li>Set <var>currentCount</var> to <var>currentCount</var> + <var>one</var></li><li>Set <var>iterator</var>.[[currentCount]] to currentCount</li><li>Set <var>iterator</var>.[[lastValue]] to lastValue</li><li>Return <emu-xref aoid="CreateIterResultObject" id="_ref_15"><a href="https://tc39.es/ecma262/#sec-createiterresultobject">CreateIterResultObject</a></emu-xref>(<var>lastValue</var>, <emu-val>false</emu-val>).
<!-- Finish --></li></ol></li><li> return <emu-xref aoid="CreateIterResultObject" id="_ref_16"><a href="https://tc39.es/ecma262/#sec-createiterresultobject">CreateIterResultObject</a></emu-xref>(<emu-val>undefined</emu-val>, <emu-val>true</emu-val>).
</li></ol></emu-alg>
</emu-clause>
Expand Down
Loading

0 comments on commit e05d026

Please sign in to comment.