Skip to content

Commit

Permalink
Normative: Add Object Rest Spread
Browse files Browse the repository at this point in the history
  • Loading branch information
keithamus committed Dec 23, 2017
1 parent fa82e04 commit 73cd0e8
Showing 1 changed file with 169 additions and 13 deletions.
182 changes: 169 additions & 13 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -4764,6 +4764,34 @@ <h1>GetFunctionRealm ( _obj_ )</h1>
<p>Step 5 will only be reached if _obj_ is a non-standard function exotic object that does not have a [[Realm]] internal slot.</p>
</emu-note>
</emu-clause>

<emu-clause id="sec-copydataproperties" aoid="CopyDataProperties">
<h1>CopyDataProperties (_target_, _source_, _excluded_)</h1>
<p>When the abstract operation CopyDataProperties is called with arguments _target_, _source_ and _excluded_, the following steps are taken:</p>
<emu-alg>
1. Assert: Type(_target_) is Object.
1. Assert: Type(_excluded_) is List.
1. If _source_ is *undefined* or *null*, let _keys_ be a new empty List.
1. Else,
1. Let _from_ be ! ToObject(_source_).
1. Let _keys_ be ? _from_.[[OwnPropertyKeys]]().
1. Repeat for each element _nextKey_ of _keys_ in List order,
1. Let _found_ be *false*.
1. Repeat for each element _e_ of _excluded_,
1. If _e_ is not empty and SameValue(_e_, _nextKey_) is true, then
1. Set _found_ to *true*.
1. If _found_ is *false*, then
1. Let _desc_ be ? _from_.[[GetOwnProperty]](_nextKey_).
1. If _desc_ is not *undefined* and _desc_.[[Enumerable]] is *true*, then
1. Let _propValue_ be ? Get(_from_, _nextKey_).
1. Perform ! CreateDataProperty(_target_, _nextKey_, _propValue_).
1. Return _target_.
</emu-alg>
<emu-note>
<p>The target passed is in here is always a newly created object which doesn't leak in case of an error being thrown. It's not observable when the actual object construction and initialization happens nor whether it is interleaved with reading the properties off the original object.</p>
</emu-note>
</emu-clause>

</emu-clause>

<!-- es6num="7.4" -->
Expand Down Expand Up @@ -11656,6 +11684,7 @@ <h2>Syntax</h2>
CoverInitializedName[?Yield, ?Await]
PropertyName[?Yield, ?Await] `:` AssignmentExpression[+In, ?Yield, ?Await]
MethodDefinition[?Yield, ?Await]
`...` AssignmentExpression[In, ?Yield, ?Await]

PropertyName[Yield, Await] :
LiteralPropertyName
Expand Down Expand Up @@ -11848,6 +11877,7 @@ <h1>Runtime Semantics: PropertyDefinitionEvaluation</h1>
1. Perform ? PropertyDefinitionEvaluation of |PropertyDefinitionList| with arguments _object_ and _enumerable_.
1. Return the result of performing PropertyDefinitionEvaluation of |PropertyDefinition| with arguments _object_ and _enumerable_.
</emu-alg>
<emu-grammar>PropertyDefinition : `...` AssignmentExpression</emu-grammar>
<emu-grammar>PropertyDefinition : IdentifierReference</emu-grammar>
<emu-alg>
1. Let _propName_ be StringValue of |IdentifierReference|.
Expand All @@ -11868,6 +11898,13 @@ <h1>Runtime Semantics: PropertyDefinitionEvaluation</h1>
1. Assert: _enumerable_ is *true*.
1. Return CreateDataPropertyOrThrow(_object_, _propKey_, _propValue_).
</emu-alg>
<emu-alg>
1. Let _exprValue_ be the result of evaluating _AssignmentExpression_.
1. Let _fromValue_ be GetValue(_exprValue_).
1. ReturnIfAbrupt(_fromValue_).
1. Let _excludedNames_ be a new empty List.
1. Return ? CopyDataProperties(_object_, _fromValue_, _excludedNames_).
</emu-alg>
<emu-note>
<p>An alternative semantics for this production is given in <emu-xref href="#sec-__proto__-property-names-in-object-initializers"></emu-xref>.</p>
</emu-note>
Expand Down Expand Up @@ -14306,14 +14343,18 @@ <h2>Supplemental Syntax</h2>

ObjectAssignmentPattern[Yield, Await] :
`{` `}`
`{` AssignmentRestProperty[?Yield, ?Await] `}`
`{` AssignmentPropertyList[?Yield, ?Await] `}`
`{` AssignmentPropertyList[?Yield, ?Await] `,` `}`
`{` AssignmentPropertyList[?Yield, ?Await] `,` AssignmentRestProperty[?Yield, ?Await]? `}`

ArrayAssignmentPattern[Yield, Await] :
`[` Elision? AssignmentRestElement[?Yield, ?Await]? `]`
`[` AssignmentElementList[?Yield, ?Await] `]`
`[` AssignmentElementList[?Yield, ?Await] `,` Elision? AssignmentRestElement[?Yield, ?Await]? `]`

AssignmentRestProperty[Yield, Await] :
`...` DestructuringAssignmentTarget[?Yield, ?Await]

AssignmentPropertyList[Yield, Await] :
AssignmentProperty[?Yield, ?Await]
AssignmentPropertyList[?Yield, ?Await] `,` AssignmentProperty[?Yield, ?Await]
Expand Down Expand Up @@ -14370,12 +14411,13 @@ <h1>Runtime Semantics: DestructuringAssignmentEvaluation</h1>
</emu-alg>
<emu-grammar>
ObjectAssignmentPattern :
`{` AssignmentPropertyList `}`
`{` AssignmentPropertyList `,` `}`
`{` AssignmentPropertyList `}`
`{` AssignmentPropertyList `,` `}`
</emu-grammar>
<emu-alg>
1. Perform ? RequireObjectCoercible(_value_).
1. Return the result of performing DestructuringAssignmentEvaluation for |AssignmentPropertyList| using _value_ as the argument.
1. Perform ? PropertyDestructuringAssignmentEvaluation for |AssignmentPropertyList| using _value_ as the argument.
1. Return NormalCompletion(~empty~).
</emu-alg>
<emu-grammar>ArrayAssignmentPattern : `[` `]`</emu-grammar>
<emu-alg>
Expand Down Expand Up @@ -14425,11 +14467,44 @@ <h1>Runtime Semantics: DestructuringAssignmentEvaluation</h1>
1. If _iteratorRecord_.[[Done]] is *false*, return ? IteratorClose(_iteratorRecord_, _status_).
1. Return Completion(_status_).
</emu-alg>
<emu-grammar>ObjectAssignmentPattern : `{` AssignmentRestProperty `}`</emu-grammar>
<emu-alg>
1. Let _excludedNames_ be a new empty List.
1. Return the result of performing RestDestructuringAssignmentEvaluation of _AssignmentRestProperty_ with _value_ and _excludedNames_ as the arguments.
</emu-alg>

<emu-grammar>ObjectAssignmentPattern : `{` AssignmentPropertyList `,` AssignmentRestProperty `}`</emu-grammar>
<emu-alg>
1. Let _excludedNames_ be the result of performing ? PropertyDestructuringAssignmentEvaluation for _AssignmentPropertyList_ using _value_ as the argument.
1. Return the result of performing RestDestructuringAssignmentEvaluation of _AssignmentRestProperty_ with _value_ and _excludedNames_ as the arguments.
</emu-alg>
</emu-clause>

<emu-clause id="sec-runtime-semantics-destructuringassignmentevaluation-nested-rest-prohibition">
<h1>Static Semantics: Early Errors</h1>
<emu-grammar>
AssignmentRestProperty[Yield, Await] :
`...` DestructuringAssignmentTarget[Yield, Await]
</emu-grammar>
<ul><li>It is a Syntax Error if |DestructuringAssignmentTarget| is an |ArrayLiteral| or an |ObjectLiteral|.</li></ul>
</emu-clause>

<emu-clause id="Rest-RuntimeSemantics-PropertyDestructuringAssignmentEvaluation">
<h1>Runtime Semantics: PropertyDestructuringAssignmentEvaluation</h1>
<p>With parameters _value_.</p>

<emu-note>These collect a list of all destructured property names.</emu-note>

<emu-grammar>AssignmentPropertyList : AssignmentPropertyList `,` AssignmentProperty</emu-grammar>
<emu-alg>
1. Perform ? DestructuringAssignmentEvaluation for |AssignmentPropertyList| using _value_ as the argument.
1. Return the result of performing DestructuringAssignmentEvaluation for |AssignmentProperty| using _value_ as the argument.
1. Let _propertyNames_ be the result of performing PropertyDestructuringAssignmentEvaluation for |AssignmentPropertyList| using _value_ as the argument.
1. ReturnIfAbrupt(_propertyNames_).
1. Let _nextNames_ be the result of performing PropertyDestructuringAssignmentEvaluation for |AssignmentProperty| using _value_ as the argument.
1. ReturnIfAbrupt(_nextNames_).
1. Append each item in _nextNames_ to the end of _propertyNames_.
1. Return _propertyNames_.
</emu-alg>

<emu-grammar>AssignmentProperty : IdentifierReference Initializer?</emu-grammar>
<emu-alg>
1. Let _P_ be StringValue of |IdentifierReference|.
Expand All @@ -14441,13 +14516,32 @@ <h1>Runtime Semantics: DestructuringAssignmentEvaluation</h1>
1. If IsAnonymousFunctionDefinition(|Initializer|) is *true*, then
1. Let _hasNameProperty_ be ? HasOwnProperty(_v_, `"name"`).
1. If _hasNameProperty_ is *false*, perform SetFunctionName(_v_, _P_).
1. Return ? PutValue(_lref_, _v_).
1. Perform ? PutValue(_lref_, _v_).
1. Return a new List containing _P_.
</emu-alg>

<emu-grammar>AssignmentProperty : PropertyName `:` AssignmentElement</emu-grammar>
<emu-alg>
1. Let _name_ be the result of evaluating |PropertyName|.
1. ReturnIfAbrupt(_name_).
1. Return the result of performing KeyedDestructuringAssignmentEvaluation of |AssignmentElement| with _value_ and _name_ as the arguments.
1. Let _status_ be the result of performing KeyedDestructuringAssignmentEvaluation of |AssignmentElement| with _value_ and _name_ as the arguments.
1. ReturnIfAbrupt(_status_).
1. Return a new List containing _name_.
</emu-alg>
</emu-clause>

<emu-clause id="Rest-RuntimeSemantics-RestDestructuringAssignmentEvaluation">
<h1>Runtime Semantics: RestDestructuringAssignmentEvaluation</h1>
<p>With parameters _value_ and _excludedNames_.</p>

<emu-grammar>AssignmentRestProperty[Yield, Await] : `...` DestructuringAssignmentTarget</emu-grammar>
<emu-alg>
1. Let _lref_ be the result of evaluating |DestructuringAssignmentTarget|.
1. ReturnIfAbrupt(_lref_).
1. Let _restObj_ be ObjectCreate(%ObjectPrototype%).
1. Let _assignStatus_ be CopyDataProperties(_restObj_, _value_, _excludedNames_).
1. ReturnIfAbrupt(_assignStatus_).
1. Return PutValue(_lref_, _restObj_).
</emu-alg>
</emu-clause>

Expand Down Expand Up @@ -15463,14 +15557,18 @@ <h2>Syntax</h2>

ObjectBindingPattern[Yield, Await] :
`{` `}`
`{` BindingRestProperty[?Yield, ?Await] `}`
`{` BindingPropertyList[?Yield, ?Await] `}`
`{` BindingPropertyList[?Yield, ?Await] `,` `}`
`{` BindingPropertyList[?Yield, ?Await] `,` BindingRestProperty[?Yield, ?Await]? `}`

ArrayBindingPattern[Yield, Await] :
`[` Elision? BindingRestElement[?Yield, ?Await]? `]`
`[` BindingElementList[?Yield, ?Await] `]`
`[` BindingElementList[?Yield, ?Await] `,` Elision? BindingRestElement[?Yield, ?Await]? `]`

BindingRestProperty[Yield, Await] :
`...` BindingIdentifier[?Yield, ?Await]

BindingPropertyList[Yield, Await] :
BindingProperty[?Yield, ?Await]
BindingPropertyList[?Yield, ?Await] `,` BindingProperty[?Yield, ?Await]
Expand Down Expand Up @@ -15692,21 +15790,79 @@ <h1>Runtime Semantics: BindingInitialization</h1>
<emu-alg>
1. Return NormalCompletion(~empty~).
</emu-alg>
<emu-grammar>
ObjectBindingPattern :
`{` BindingPropertyList `}`
`{` BindingPropertyList `,` `}`
</emu-grammar>
<emu-alg>
1. Let _excludedNames_ be the result of performing PropertyBindingInitialization for |BindingPropertyList| using _value_ and _environment_ as the argument.
1. ReturnIfAbrupt(_excludedNames_).
1. Return NormalCompletion(~empty~).
</emu-alg>

<emu-grammar>ObjectBindingPattern : `{` BindingRestProperty `}`</emu-grammar>
<emu-alg>
1. Let _excludedNames_ be a new empty List.
1. Return the result of performing RestBindingInitialization of _BindingRestProperty_ with _value_, _environment_ and _excludedNames_ as the arguments.
</emu-alg>

<emu-grammar>ObjectBindingPattern : `{` BindingPropertyList `,` BindingRestProperty `}`</emu-grammar>
<emu-alg>
1. Let _excludedNames_ be the result of performing PropertyBindingInitialization of |BindingPropertyList| using _value_ and _environment_ as arguments.
1. ReturnIfAbrupt(_excludedNames_).
1. Return the result of performing RestBindingInitialization of _BindingRestProperty_ with _value_, _environment_ and _excludedNames_ as the arguments.
</emu-alg>
</emu-clause>

<emu-clause id="Rest-RuntimeSemantics-PropertyBindingInitialization">
<h1>Runtime Semantics: PropertyBindingInitialization</h1>
<p>With parameters _value_ and _environment_.</p>

<emu-note>These collect a list of all bound property names rather than just empty completion.</emu-note>

<emu-grammar>BindingPropertyList : BindingPropertyList `,` BindingProperty</emu-grammar>
<emu-alg>
1. Perform ? BindingInitialization for |BindingPropertyList| using _value_ and _environment_ as arguments.
1. Return the result of performing BindingInitialization for |BindingProperty| using _value_ and _environment_ as arguments.
1. Let _boundNames_ be the result of performing PropertyBindingInitialization for |BindingPropertyList| using _value_ and _environment_ as arguments.
1. ReturnIfAbrupt(_boundNames_).
1. Let _nextNames_ be the result of performing PropertyBindingInitialization for |BindingProperty| using _value_ and _environment_ as arguments.
1. ReturnIfAbrupt(_nextNames_).
1. Append each item in _nextNames_ to the end of _boundNames_.
1. Return _boundNames_.
</emu-alg>

<emu-grammar>BindingProperty : SingleNameBinding</emu-grammar>
<emu-alg>
1. Let _name_ be the string that is the only element of BoundNames of |SingleNameBinding|.
1. Return the result of performing KeyedBindingInitialization for |SingleNameBinding| using _value_, _environment_, and _name_ as the arguments.
1. Let _status_ be the result of performing KeyedBindingInitialization for |SingleNameBinding| using _value_, _environment_, and _name_ as the arguments.
1. ReturnIfAbrupt(_status_).
1. Return a new List containing _name_.
</emu-alg>

<emu-grammar>BindingProperty : PropertyName `:` BindingElement</emu-grammar>
<emu-alg>
1. Let _P_ be the result of evaluating |PropertyName|.
1. ReturnIfAbrupt(_P_).
1. Return the result of performing KeyedBindingInitialization for |BindingElement| using _value_, _environment_, and _P_ as arguments.
1. Let _status_ be the result of performing KeyedBindingInitialization of |BindingElement| with _value_, _environment_, and _P_ as the arguments.
1. ReturnIfAbrupt(_status_).
1. Return a new List containing _P_.
</emu-alg>
</emu-clause>

<emu-clause id="Rest-RuntimeSemantics-RestBindingInitialization">
<h1>Runtime Semantics: RestBindingInitialization</h1>
<p>With parameters _value_, _environment_ and _excludedNames_.</p>

<emu-grammar>BindingRestProperty : `...` BindingIdentifier</emu-grammar>
<emu-alg>
1. Let _restObj_ be ObjectCreate(%ObjectPrototype%).
1. Let _assignStatus_ be CopyDataProperties(_restObj_, _value_, _excludedNames_).
1. ReturnIfAbrupt(_assignStatus_).
1. Let _bindingId_ be StringValue of |BindingIdentifier|.
1. Let _lhs_ be ResolveBinding(_bindingId_, _environment_).
1. ReturnIfAbrupt(_lhs_).
1. If _environment_ is *undefined*, return PutValue(_lhs_, _restObj_).
1. Return InitializeReferencedBinding(_lhs_, _restObj_).
</emu-alg>
</emu-clause>

Expand Down

0 comments on commit 73cd0e8

Please sign in to comment.