Skip to content
Merged
Show file tree
Hide file tree
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: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
index.html -diff merge=ours
spec.js -diff merge=ours
spec.css -diff merge=ours
42 changes: 42 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules
jspm_packages

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history

# Only apps should have lockfiles
yarn.lock
package-lock.json
npm-shrinkwrap.json
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 ECMA TC39 and contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2,012 changes: 2,012 additions & 0 deletions index.html

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"private": true,
"name": "proposals-slice-notation",
"description": "A proposal to add slice notation to ECMAScript",
"scripts": {
"build": "ecmarkup spec.emu index.html"
},
"homepage": "https://github.com/tc39/proposal-slice-notationt#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/tc39/proposal-slice-notation.git"
},
"license": "MIT",
"devDependencies": {
"ecmarkup": "^3.11.5"
}
}
210 changes: 210 additions & 0 deletions spec.emu
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
<pre class="metadata">
title: Slice notation
status: proposal
stage: 1
location: https://github.com/tc39/proposal-slice-notation
copyright: false
contributors: Sathya Gunasekaran
</pre>

<emu-clause id="sec-well-known-symbols">
<h1>Well-Known Symbols</h1>
<p>Well-known symbols are built-in Symbol values that are explicitly referenced by algorithms of this specification. They are typically used as the keys of properties whose values serve as extension points of a specification algorithm. Unless otherwise specified, well-known symbols values are shared by all realms (<emu-xref href="#sec-code-realms"></emu-xref>).</p>
<p>Within this specification a well-known symbol is referred to by using a notation of the form @@name, where &ldquo;name&rdquo; is one of the values listed in <emu-xref href="#table-1"></emu-xref>.</p>
<emu-table id="table-1" caption="Well-known Symbols">
<table>
<tbody>
<tr>
<th>
Specification Name
</th>
<th>
[[Description]]
</th>
<th>
Value and Purpose
</th>
</tr>
<tr>
<td>
<ins><dfn>@@slice</dfn></ins>
</td>
<td>
<ins>*"Symbol.slice"*</ins>
</td>
<td>
<ins>A method that slices the receiver based on a start and end index.</ins>
</td>
</tr>
</tbody>
</table>
</emu-table>
</emu-clause>

<emu-clause id="sec-properties-of-the-symbol-constructor">
<h1>Properties of the Symbol Constructor</h1>
<ins class=block><emu-clause id="sec-symbol.slice">
<h1>Symbol.slice</h1>
<p>The initial value of `Symbol.slice` is the well known symbol @@slice (<emu-xref href="#table-1"></emu-xref>).</p>
<p>This property has the attributes { [[Writable]]: *false*, [[Enumerable]]: *false*, [[Configurable]]: *false* }.</p>
</emu-clause></ins>
</emu-clause>

<emu-clause id="sec-properties-of-the-array-prototype-object">
<h1>Properties of the Array Prototype</h1>
<emu-clause id="sec-array.prototype-@@slice">
<h1>Array.prototype [ @@slice ] (start, end)</h1>
<p> The initial value of the @@slice property is the same function object as the initial value of the `Array.prototype.slice` property. </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.

Suggested change
<p> The initial value of the @@slice property is the same function object as the initial value of the `Array.prototype.slice` property. </p>
<p> The initial value of the @@slice property is %Array.prototype.slice%.</p>

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.

This (and the ones below) are directly copied from the spec text: https://tc39.es/ecma262/#sec-array.prototype-@@iterator

Do you prefer to have different (but more concise) text than the spec? I'm ok with either.

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.

Good call; I’ll make a PR to update the spec itself.

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.

In that case, I'll leave this as is (consistent with spec ) for now and update it once the spec is changed.

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.

@gsathya this has now been updated in the main spec.

</emu-clause>
</emu-clause>

<emu-clause id="sec-properties-of-the-%typedarrayprototype%-object">
<h1>Properties of the %TypedArray.prototype% Object</h1>
<emu-clause id="sec-properties-of-the-%typedarrayprototype%-@@slice">
<h1>%TypedArray%.prototype [ @@slice ] (start, end)</h1>
<p> The initial value of the @@slice property is the same function object as the initial value of the `%TypedArray%.prototype.slice` property. </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.

Suggested change
<p> The initial value of the @@slice property is the same function object as the initial value of the `%TypedArray%.prototype.slice` property. </p>
<p> The initial value of the @@slice property is `%TypedArray.prototype.slice%`. </p>

</emu-clause>
</emu-clause>

<emu-clause id="sec-properties-of-the-arraybuffer-prototype-object">
<h1>Properties of the ArrayBuffer Prototype Object</h1>
<emu-clause id="sec-properties-of-the-arraybuffer-prototype-@@slice">
<h1>ArrayBuffer.prototype [ @@slice ] (start, end)</h1>
<p> The initial value of the @@slice property is the same function object as the initial value of the `ArrayBuffer.prototype.slice` property. </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.

Suggested change
<p> The initial value of the @@slice property is the same function object as the initial value of the `ArrayBuffer.prototype.slice` property. </p>
<p> The initial value of the @@slice property is `%ArrayBuffer.prototype.slice%`.</p>

</emu-clause>
</emu-clause>

<emu-clause id="sec-properties-of-the-sharedarraybuffer-prototype-object">
<h1>Properties of the SharedArrayBuffer Prototype Object</h1>
<emu-clause id="sec-properties-of-the-sharedarraybuffer-prototype-@@slice">
<h1>SharedArrayBuffer.prototype [ @@slice ] (start, end)</h1>
<p> The initial value of the @@slice property is the same function object as the initial value of the `SharedArrayBuffer.prototype.slice` property. </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.

Suggested change
<p> The initial value of the @@slice property is the same function object as the initial value of the `SharedArrayBuffer.prototype.slice` property. </p>
<p> The initial value of the @@slice property is `%SharedArrayBuffer.prototype.slice%`.</p>

</emu-clause>
</emu-clause>

<emu-clause id="sec-left-hand-side-expressions">
<h1>Left-Hand-Side Expressions</h1>
<h2>Syntax</h2>
<emu-grammar>
MemberExpression[Yield, Await] :
PrimaryExpression[?Yield, ?Await]
MemberExpression[?Yield, ?Await] `[` Expression[+In, ?Yield, ?Await] `]`
MemberExpression[?Yield, ?Await] `.` IdentifierName
MemberExpression[?Yield, ?Await] TemplateLiteral[?Yield, ?Await]
SuperProperty[?Yield, ?Await]
MetaProperty
`new` MemberExpression[?Yield, ?Await] Arguments[?Yield, ?Await]
<ins>MemberExpression[?Yield, ?Await] `[` AssignmentExpression[+In, ?Yield, ?Await]? `:` AssignmentExpression[+In, ?Yield, ?Await]? `]` </ins>
</emu-grammar>

<emu-grammar>
CallExpression[Yield, Await] :
CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await] #callcover
SuperCall[?Yield, ?Await]
ImportCall[?Yield, ?Await]
CallExpression[?Yield, ?Await] Arguments[?Yield, ?Await]
CallExpression[?Yield, ?Await] `[` Expression[+In, ?Yield, ?Await] `]`
CallExpression[?Yield, ?Await] `.` IdentifierName
CallExpression[?Yield, ?Await] TemplateLiteral[?Yield, ?Await, +Tagged]
<ins>CallExpression[?Yield, ?Await] `[` AssignmentExpression[+In, ?Yield, ?Await]? `:` AssignmentExpression[+In, ?Yield, ?Await]? `]`</ins>
</emu-grammar>

<emu-grammar>
OptionalExpression[Yield, Await] :
MemberExpression[?Yield, ?Await] OptionalChain[?Yield, ?Await]
CallExpression[?Yield, ?Await] OptionalChain[?Yield, ?Await]
OptionalExpression[?Yield, ?Await] OptionalChain[?Yield, ?Await]

OptionalChain[Yield, Await] :
`?.` `[` Expression[+In, ?Yield, ?Await] `]`
`?.` IdentifierName
`?.` Arguments[?Yield, ?Await]
`?.` TemplateLiteral[?Yield, ?Await, +Tagged]
<ins>`?.` `[` AssignmentExpression[+In, ?Yield, ?Await]? `:` AssignmentExpression[+In, ?Yield, ?Await]? `]`</ins>
OptionalChain[?Yield, ?Await] `[` Expression[+In, ?Yield, ?Await] `]`
OptionalChain[?Yield, ?Await] `.` IdentifierName
OptionalChain[?Yield, ?Await] Arguments[?Yield, ?Await]
OptionalChain[?Yield, ?Await] TemplateLiteral[?Yield, ?Await, +Tagged]
<ins>OptionalChain[?Yield, ?Await] `[` AssignmentExpression[+In, ?Yield, ?Await]? `:` AssignmentExpression[+In, ?Yield, ?Await]? `]`</ins>
</emu-grammar>

<emu-clause oldids="sec-static-semantics-static-semantics-isvalidsimpleassignmenttarget" id="sec-static-semantics-static-semantics-assignmenttargettype">
<h1>Static Semantics: AssignmentTargetType</h1>
<emu-see-also-para op="AssignmentTargetType"></emu-see-also-para>
<emu-grammar>
MemberExpression :
MemberExpression `[` AssignmentExpression? `:` AssignmentExpression? `]`

CallExpression :
CallExpression `[` AssignmentExpression? `:` AssignmentExpression? `]`
</emu-grammar>
<emu-alg>
1. Return ~invalid~.
</emu-alg>
</emu-clause>

<emu-clause id="sec-slice-notation-runtime-semantics-evaluation">
<h1>Runtime Semantics</h1>
<emu-clause id="sec-evaluate-slice-notation" aoid="EvaluateSliceNotation">
<h1>Runtime Semantics: EvaluateSliceNotation ( _baseValue_, _startExpression_, _endExpression_ )</h1>
<p>The abstract operation EvaluateSliceNotation takes as arguments a _baseValue_ (an ECMAScript langauge value), _startExpression_ (a Parse Node), and _endExpression_ (a Parse Node). It performs the following steps:</p>
<emu-alg>
1. If the _startExpression_ is present, then
1. Let _startRef_ be the result of evaluating the _startExpression_.
1. Let _start_ be ? GetValue(_startRef_).
1. Else,
1. Let _start_ be 0.
1. If the _endExpression_ is present, then
1. Let _endRef_ be the result of evaluating the _endExpression_.
1. Let _end_ be ? GetValue(_endRef_).
1. Else,
1. Let _end_ be *undefined*.
1. Let _base_ be ? ToObject(_baseValue_).
1. Let _method_ be ? GetMethod(_base_, @@slice).
1. Return ? Call(_method_, _base_, &laquo; _start_, _end_ &raquo;).
</emu-alg>
</emu-clause>

<emu-clause id="sec-member-expression-slice-notation">
<h1>Runtime Semantics: Evaluation</h1>
<emu-grammar> MemberExpression : MemberExpression `[` AssignmentExpression? `:` AssignmentExpression? `]`</emu-grammar>
<emu-alg>
1. Let _baseReference_ be the result of evaluating |MemberExpression|.
1. Let _baseValue_ be ? GetValue(_baseReference_).
1. Let _startExpression_ be the first |AssignmentExpression|.
1. Let _endExpression_ be the second |AssignmentExpression|.
1. Return ? EvaluateSliceNotation(_baseReference_, _startExpression_, _endExpression_).
</emu-alg>

<emu-grammar> CallExpression : CallExpression `[` AssignmentExpression? `:` AssignmentExpression? `]`</emu-grammar>
<emu-alg>
1. Let _baseReference_ be the result of evaluating |CallExpression|.
1. Let _baseValue_ be ? GetValue(_baseReference_).
1. Let _startExpression_ be the first |AssignmentExpression|.
1. Let _endExpression_ be the second |AssignmentExpression|.
1. Return ? EvaluateSliceNotation(_baseValue_, _startExpression_, _endExpression_).
</emu-alg>
</emu-clause>

<emu-clause id="sec-optional-chaining-chain-evaluation">
<h1>Runtime Semantics: ChainEvaluation</h1>
<p>With parameters _baseValue_ and _baseReference_.</p>
<emu-grammar> OptionalChain: `?.` `[` AssignmentExpression? `:` AssignmentExpression? `]`</emu-grammar>
<emu-alg>
1. Let _startExpression_ be the first |AssignmentExpression|.
1. Let _endExpression_ be the second |AssignmentExpression|.
1. Return ? EvaluateSliceNotation(_baseValue_, _startExpression_, _endExpression_).
</emu-alg>

<emu-grammar> OptionalChain: OptionalChain `[` AssignmentExpression? `:` AssignmentExpression? `]`</emu-grammar>
<emu-alg>
1. Let _optionalChain_ be |OptionalChain|.
1. Let _newBaseReference_ be ? ChainEvaluation of _optionalChain_ with arguments _baseValue_ and _baseReference_.
1. Let _newBaseValue_ be ? GetValue(_newBaseReference_).
1. Let _startExpression_ be the first |AssignmentExpression|.
1. Let _endExpression_ be the second |AssignmentExpression|.
1. Return ? EvaluateSliceNotation(_newBaseValue_, _startExpression_, _endExpression_).
</emu-alg>
</emu-clause>
</emu-clause>
</emu-clause>