diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..31e2b43 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,3 @@ +index.html -diff merge=ours +spec.js -diff merge=ours +spec.css -diff merge=ours diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1c8cdd1 --- /dev/null +++ b/.gitignore @@ -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 diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..43c97e7 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +package-lock=false diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ab51301 --- /dev/null +++ b/LICENSE @@ -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. diff --git a/index.html b/index.html new file mode 100644 index 0000000..52ad67b --- /dev/null +++ b/index.html @@ -0,0 +1,2012 @@ + +Slice notation

Stage 1 Draft / June 24, 2020

Slice notation

+ + +

1 Well-Known Symbols

+

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 (8.2).

+

Within this specification a well-known symbol is referred to by using a notation of the form @@name, where “name” is one of the values listed in Table 1.

+
Table 1: Well-known Symbols
+ + + + + + + + + + + + + +
+ Specification Name + + [[Description]] + + Value and Purpose +
+ @@slice + + "Symbol.slice" + + A method that slices the receiver based on a start and end index. +
+
+
+ + +

2 Properties of the Symbol Constructor

+ +

2.1 Symbol.slice

+

The initial value of Symbol.slice is the well known symbol @@slice (Table 1).

+

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

+
+
+ + +

3 Properties of the Array Prototype

+ +

3.1 Array.prototype [ @@slice ] (start, end)

+

The initial value of the @@slice property is the same function object as the initial value of the Array.prototype.slice property.

+
+
+ + +

4 Properties of the %TypedArray.prototype% Object

+ +

4.1 %TypedArray%.prototype [ @@slice ] (start, end)

+

The initial value of the @@slice property is the same function object as the initial value of the %TypedArray%.prototype.slice property.

+
+
+ + +

5 Properties of the ArrayBuffer Prototype Object

+ +

5.1 ArrayBuffer.prototype [ @@slice ] (start, end)

+

The initial value of the @@slice property is the same function object as the initial value of the ArrayBuffer.prototype.slice property.

+
+
+ + +

6 Properties of the SharedArrayBuffer Prototype Object

+ +

6.1 SharedArrayBuffer.prototype [ @@slice ] (start, end)

+

The initial value of the @@slice property is the same function object as the initial value of the SharedArrayBuffer.prototype.slice property.

+
+
+ + +

7 Left-Hand-Side Expressions

+

Syntax

+ + 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 + newMemberExpression[?Yield, ?Await]Arguments[?Yield, ?Await] + MemberExpression[?Yield, ?Await][AssignmentExpression[+In, ?Yield, ?Await]opt:AssignmentExpression[+In, ?Yield, ?Await]opt] + + + + CallExpression[Yield, Await]:CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await] + 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] + CallExpression[?Yield, ?Await][AssignmentExpression[+In, ?Yield, ?Await]opt:AssignmentExpression[+In, ?Yield, ?Await]opt] + + + + 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] + ?.[AssignmentExpression[+In, ?Yield, ?Await]opt:AssignmentExpression[+In, ?Yield, ?Await]opt] + OptionalChain[?Yield, ?Await][Expression[+In, ?Yield, ?Await]] + OptionalChain[?Yield, ?Await].IdentifierName + OptionalChain[?Yield, ?Await]Arguments[?Yield, ?Await] + OptionalChain[?Yield, ?Await]TemplateLiteral[?Yield, ?Await, +Tagged] + OptionalChain[?Yield, ?Await][AssignmentExpression[+In, ?Yield, ?Await]opt:AssignmentExpression[+In, ?Yield, ?Await]opt] + + + +

7.1 Static Semantics: AssignmentTargetType

+ + + MemberExpression:MemberExpression[AssignmentExpressionopt:AssignmentExpressionopt] + + + CallExpression:CallExpression[AssignmentExpressionopt:AssignmentExpressionopt] + +
  1. Return invalid.
+
+ + +

7.2 Runtime Semantics

+ +

7.2.1 Runtime Semantics: EvaluateSliceNotation ( baseValue, startExpression, endExpression )

+

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:

+
  1. If the startExpression is present, then
    1. Let startRef be the result of evaluating the startExpression.
    2. Let start be ? GetValue(startRef).
  2. Else,
    1. Let start be 0.
  3. If the endExpression is present, then
    1. Let endRef be the result of evaluating the endExpression.
    2. Let end be ? GetValue(endRef).
  4. Else,
    1. Let end be undefined.
  5. Let base be ? ToObject(baseValue).
  6. Let method be ? GetMethod(base, @@slice).
  7. Return ? Call(method, base, « start, end »).
+
+ + +

7.2.2 Runtime Semantics: Evaluation

+ + MemberExpression:MemberExpression[AssignmentExpressionopt:AssignmentExpressionopt] + +
  1. Let baseReference be the result of evaluating MemberExpression.
  2. Let baseValue be ? GetValue(baseReference).
  3. Let startExpression be the first AssignmentExpression.
  4. Let endExpression be the second AssignmentExpression.
  5. Return ? EvaluateSliceNotation(baseReference, startExpression, endExpression).
+ + + CallExpression:CallExpression[AssignmentExpressionopt:AssignmentExpressionopt] + +
  1. Let baseReference be the result of evaluating CallExpression.
  2. Let baseValue be ? GetValue(baseReference).
  3. Let startExpression be the first AssignmentExpression.
  4. Let endExpression be the second AssignmentExpression.
  5. Return ? EvaluateSliceNotation(baseValue, startExpression, endExpression).
+
+ + +

7.2.3 Runtime Semantics: ChainEvaluation

+

With parameters baseValue and baseReference.

+ + OptionalChain:?.[AssignmentExpressionopt:AssignmentExpressionopt] + +
  1. Let startExpression be the first AssignmentExpression.
  2. Let endExpression be the second AssignmentExpression.
  3. Return ? EvaluateSliceNotation(baseValue, startExpression, endExpression).
+ + + OptionalChain:OptionalChain[AssignmentExpressionopt:AssignmentExpressionopt] + +
  1. Let optionalChain be OptionalChain.
  2. Let newBaseReference be ? ChainEvaluation of optionalChain with arguments baseValue and baseReference.
  3. Let newBaseValue be ? GetValue(newBaseReference).
  4. Let startExpression be the first AssignmentExpression.
  5. Let endExpression be the second AssignmentExpression.
  6. Return ? EvaluateSliceNotation(newBaseValue, startExpression, endExpression).
+
+
+
+
\ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..f7898ba --- /dev/null +++ b/package.json @@ -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" + } +} diff --git a/spec.emu b/spec.emu new file mode 100644 index 0000000..0c4cbf7 --- /dev/null +++ b/spec.emu @@ -0,0 +1,210 @@ +
+  title: Slice notation
+  status: proposal
+  stage: 1
+  location: https://github.com/tc39/proposal-slice-notation
+  copyright: false
+  contributors: Sathya Gunasekaran
+
+ + +

Well-Known Symbols

+

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 ().

+

Within this specification a well-known symbol is referred to by using a notation of the form @@name, where “name” is one of the values listed in .

+ + + + + + + + + + + + + + +
+ Specification Name + + [[Description]] + + Value and Purpose +
+ @@slice + + *"Symbol.slice"* + + A method that slices the receiver based on a start and end index. +
+
+
+ + +

Properties of the Symbol Constructor

+ +

Symbol.slice

+

The initial value of `Symbol.slice` is the well known symbol @@slice ().

+

This property has the attributes { [[Writable]]: *false*, [[Enumerable]]: *false*, [[Configurable]]: *false* }.

+
+
+ + +

Properties of the Array Prototype

+ +

Array.prototype [ @@slice ] (start, end)

+

The initial value of the @@slice property is the same function object as the initial value of the `Array.prototype.slice` property.

+
+
+ + +

Properties of the %TypedArray.prototype% Object

+ +

%TypedArray%.prototype [ @@slice ] (start, end)

+

The initial value of the @@slice property is the same function object as the initial value of the `%TypedArray%.prototype.slice` property.

+
+
+ + +

Properties of the ArrayBuffer Prototype Object

+ +

ArrayBuffer.prototype [ @@slice ] (start, end)

+

The initial value of the @@slice property is the same function object as the initial value of the `ArrayBuffer.prototype.slice` property.

+
+
+ + +

Properties of the SharedArrayBuffer Prototype Object

+ +

SharedArrayBuffer.prototype [ @@slice ] (start, end)

+

The initial value of the @@slice property is the same function object as the initial value of the `SharedArrayBuffer.prototype.slice` property.

+
+
+ + +

Left-Hand-Side Expressions

+

Syntax

+ + 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] + MemberExpression[?Yield, ?Await] `[` AssignmentExpression[+In, ?Yield, ?Await]? `:` AssignmentExpression[+In, ?Yield, ?Await]? `]` + + + + 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] + CallExpression[?Yield, ?Await] `[` AssignmentExpression[+In, ?Yield, ?Await]? `:` AssignmentExpression[+In, ?Yield, ?Await]? `]` + + + + 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] + `?.` `[` AssignmentExpression[+In, ?Yield, ?Await]? `:` AssignmentExpression[+In, ?Yield, ?Await]? `]` + OptionalChain[?Yield, ?Await] `[` Expression[+In, ?Yield, ?Await] `]` + OptionalChain[?Yield, ?Await] `.` IdentifierName + OptionalChain[?Yield, ?Await] Arguments[?Yield, ?Await] + OptionalChain[?Yield, ?Await] TemplateLiteral[?Yield, ?Await, +Tagged] + OptionalChain[?Yield, ?Await] `[` AssignmentExpression[+In, ?Yield, ?Await]? `:` AssignmentExpression[+In, ?Yield, ?Await]? `]` + + + +

Static Semantics: AssignmentTargetType

+ + + MemberExpression : + MemberExpression `[` AssignmentExpression? `:` AssignmentExpression? `]` + + CallExpression : + CallExpression `[` AssignmentExpression? `:` AssignmentExpression? `]` + + + 1. Return ~invalid~. + +
+ + +

Runtime Semantics

+ +

Runtime Semantics: EvaluateSliceNotation ( _baseValue_, _startExpression_, _endExpression_ )

+

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:

+ + 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_, « _start_, _end_ »). + +
+ + +

Runtime Semantics: Evaluation

+ MemberExpression : MemberExpression `[` AssignmentExpression? `:` AssignmentExpression? `]` + + 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_). + + + CallExpression : CallExpression `[` AssignmentExpression? `:` AssignmentExpression? `]` + + 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_). + +
+ + +

Runtime Semantics: ChainEvaluation

+

With parameters _baseValue_ and _baseReference_.

+ OptionalChain: `?.` `[` AssignmentExpression? `:` AssignmentExpression? `]` + + 1. Let _startExpression_ be the first |AssignmentExpression|. + 1. Let _endExpression_ be the second |AssignmentExpression|. + 1. Return ? EvaluateSliceNotation(_baseValue_, _startExpression_, _endExpression_). + + + OptionalChain: OptionalChain `[` AssignmentExpression? `:` AssignmentExpression? `]` + + 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_). + +
+
+