605 lines
36 KiB
HTML
605 lines
36 KiB
HTML
<meta charset="utf8">
|
|
<title>Decorators</title>
|
|
<link rel="stylesheet" href="./css/elements.css">
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/styles/github.min.css">
|
|
<emu-biblio href="./biblio.json"></emu-biblio>
|
|
|
|
<h1>Decorators Proposal - ECMAScript</h1>
|
|
<emu-intro id="introduction">
|
|
<h1>Introduction</h1>
|
|
<p>Proposal to add Decorators to ECMAScript.</p>
|
|
<p>For the TypeScript specific proposal, see <a href="typescript.html">http://rbuckton.github.io/reflectdecorators/typescript.html</a></p>
|
|
</emu-intro>
|
|
|
|
<emu-clause id="proposal-terms">
|
|
<h1>Terms</h1>
|
|
<emu-clause id="proposal-terms-decorator">
|
|
<h1>Decorator</h1>
|
|
<emu-note>This section is non-normative.</emu-note>
|
|
<p>A <em>decorator</em> is an expression that is evaluated after a class has been defined, that can be used to annotate or modify the class in some fashion. This expression must evaluate to a <code>function</code>, which is executed by the runtime to apply the decoration.</p>
|
|
<pre><code class="javascript">@decoratorExpression
|
|
class C {
|
|
}
|
|
</code></pre>
|
|
</emu-clause>
|
|
<emu-clause id="proposal-terms-classdecoratorfunction">
|
|
<h1>Class Decorator Function</h1>
|
|
<emu-note>This section is non-normative.</emu-note>
|
|
<p>A <em>class decorator function</em> is a function that accepts a constructor function as its argument, and returns either <code>undefined</code>, the provided constructor function, or a new constructor function. Returning <code>undefined</code> is equivalent to returning the provided constructor function.</p>
|
|
<pre><code class="javascript">// A class decorator function
|
|
function dec(target) {
|
|
// modify, annotate, or replace target...
|
|
}
|
|
</code></pre>
|
|
</emu-clause>
|
|
<emu-clause id="proposal-terms-propertydecoratorfunction">
|
|
<h1>Property/Method Decorator Function</h1>
|
|
<emu-note>This section is non-normative.</emu-note>
|
|
<p>A <em>property decorator function</em> is a function that accepts three arguments: The object that owns the property, the key for the property (a <code>string</code> or a <code>symbol</code>), and optionally the property descriptor of the property. The function must return either <code>undefined</code>, the provided property descriptor, or a new property descriptor. Returning <code>undefined</code> is equivalent to returning the provided property descriptor.</p>
|
|
<pre><code class="javascript">// A property (or method/accessor) decorator function
|
|
function dec(target, key, descriptor) {
|
|
// annotate the target and key; or modify or replace the descriptor...
|
|
}
|
|
</code></pre>
|
|
</emu-clause>
|
|
<emu-clause id="proposal-terms-decoratorfactory">
|
|
<h1>Decorator Factory</h1>
|
|
<emu-note>This section is non-normative.</emu-note>
|
|
<p>A <em>decorator factory</em> is a function that can accept any number of arguments, and must return one of the above types of decorator function.</p>
|
|
<pre><code class="javascript">// a class decorator factory function
|
|
function dec(x, y) {
|
|
// the class decorator function
|
|
return function (target) {
|
|
// modify, annotate, or replace target...
|
|
}
|
|
}
|
|
</code></pre>
|
|
</emu-clause>
|
|
</emu-clause>
|
|
<emu-clause id="proposal-decoratortargets">
|
|
<h1>Decorator Targets</h1>
|
|
<emu-note>This section is non-normative.</emu-note>
|
|
<p>A <em>decorator</em> <strong>can</strong> be legally applied to any of the following:</p>
|
|
<ul>
|
|
<li>A class declaration</li>
|
|
<li>A class property initializer (static or prototype)</li>
|
|
<li>A class method declaration (static or prototype)</li>
|
|
<li>A class get or set accessor declaration (static or prototype)</li>
|
|
</ul>
|
|
<p>Please note that a <em>decorator</em> currently <strong>cannot</strong> be legally applied to any of the following:</p>
|
|
<ul>
|
|
<li>A class constructor - This is to reduce ambiguity between where you can apply a decorator (on the class or on its constructor) and which of the above decorator function forms is called.</li>
|
|
<li>A function declaration - Decorators on a function declaration would introduce a TDZ (Temporal Dead Zone), which would make the function unreachable until its declaration is executed. This could cause confusion as an undecorated function declaration is hoisted and can be used in a statement preceeding the declaration.</li>
|
|
<li>A function expression - This is to reduce confusion and maintain parity with disallowing decorators on a function declaration.</li>
|
|
<li>An arrow function - This is to reduce confusion and maintain parity with disallowing decorators on a function expression.</li>
|
|
</ul>
|
|
<p>This list may change in the future.</p>
|
|
</emu-clause>
|
|
<emu-clause id="proposal-decoratoreval">
|
|
<h1>Decorator Evaluation and Application Order</h1>
|
|
<emu-note>This section is non-normative.</emu-note>
|
|
<p>Decorators are <em>evaluated</em> in the order they appear preceeding their target declaration, to preserve side-effects due to evaluation order. Decorators are <em>applied</em> to their target declaration in reverse order, starting with the decorator closest to the declaration. This behavior is specified to preserve the expected behavior of decorators without a declarative syntax.</p>
|
|
<pre><code class="javascript">@F
|
|
@G
|
|
class C {
|
|
}
|
|
</code></pre>
|
|
<p>For example, the above listing could be approximately written without decorators in the following fashion:</p>
|
|
<pre><code class="javascript">C = F(G(C))</code></pre>
|
|
<p>In the above example, the expression <code>F</code> is evaluated first, followed by the expression <code>G</code>. <code>G</code> is then called with the constructor function as its argument, followed by calling <code>F</code> with the result. The actual process of applying decorators is more complex than the above example however, though you may still imperatively apply decorators with a reflection API.</p>
|
|
<p>If a class declaration has decorators on both the class and any of its members or parameters, the decorators are applied using the following pseudocode:</p>
|
|
<pre>
|
|
for each member M of class C
|
|
if M is an accessor then
|
|
let accessor = first accessor (get or set, in declaration order) of M
|
|
let memberDecorators = decorators of accessor
|
|
for each parameter of accessor
|
|
let paramDecorators = decorators of parameter
|
|
let paramIndex = ordinal index of parameter
|
|
Reflect.decorate(paramDecorators, accessor, paramIndex)
|
|
next parameter
|
|
|
|
let accessor = second accessor (get or set, in declaration order) of M
|
|
if accessor then
|
|
let memberDecorators = memberDecorators + decorators of accessor
|
|
for each parameter of accessor
|
|
let paramDecorators = decorators of parameter
|
|
let paramIndex = ordinal index of parameter
|
|
Reflect.decorate(paramDecorators, accessor, paramIndex)
|
|
next parameter
|
|
end if
|
|
else if M is a method
|
|
let memberDecorators = decorators of M
|
|
for each parameter of M
|
|
let paramDecorators = decorators of parameter
|
|
let paramIndex = ordinal index of parameter
|
|
Reflect.decorate(paramDecorators, M, paramIndex)
|
|
next parameter
|
|
else
|
|
let memberDecorators = decorators of M
|
|
end if
|
|
|
|
let name = name of M
|
|
let target = C.prototype if M is on the prototype; otherwise, C if M is static
|
|
Reflect.decorate(memberDecorators, C, name)
|
|
next member
|
|
|
|
for each parameter of C
|
|
let paramDecorators = decorators of parameter
|
|
let paramIndex = ordinal index of parameter
|
|
Reflect.decorate(paramDecorators, C, paramIndex)
|
|
next parameter
|
|
|
|
let classDecorators = decorators of C
|
|
let C = Reflect.decorate(classDecorators, C)
|
|
</pre>
|
|
</emu-clause>
|
|
|
|
<emu-clause id="operations">
|
|
<h1>Abstract Operations</h1>
|
|
<emu-clause id="operations-decoration">
|
|
<h1>Decorator Operations</h1>
|
|
<emu-clause id="operations-decoration-decorate">
|
|
<h1>Decorate ( Decorators, O, P, desc )</h1>
|
|
<p>When the abstract operation Decorate is called with ECMAScript language value <var>Decorators</var>, Object <var>O</var>, property key <var>P</var>, and property descriptor <var>desc</var>, the following steps are taken:</p>
|
|
<emu-alg aoid="Decorate">
|
|
1. If _P_ is *undefined* and _desc_ is *undefined*, then
|
|
1. If IsCallable(_O_) is not *true*, throw a *TypeError* exception.
|
|
2. Return DecorateConstructor(_Decorators_, _O_).
|
|
2. Else
|
|
1. Return DecorateProperty(_Decorators_, _O_, _P_, _desc_).
|
|
</emu-alg>
|
|
</emu-clause>
|
|
<emu-clause id="operations-decoration-decorateconstructor">
|
|
<h1>DecorateConstructor ( Decorators, F )</h1>
|
|
<p>When the abstract operation DecorateConstructor is called with ECMAScript language value <var>Decorators</var> and Object <var>F</var>, the following steps are taken:</p>
|
|
<emu-alg aoid="DecorateConstructor">
|
|
1. Let _result_ be _F_.
|
|
2. Let _iterator_ be GetIterator(_Decorators_).
|
|
3. Let _list_ be CreateListFromIterator(_iterator_, «Object»).
|
|
4. For each _decorator_ in _list_ in reverse order
|
|
1. Let _decorated_ be Call(_decorator_, *null*, _result_).
|
|
2. ReturnIfAbrupt(_decorated_).
|
|
3. If IsCallable(_decorated_), then
|
|
1. Set _result_ to be _decorated_.
|
|
4. Else if _decorated_ is not *undefined*, throw a *TypeError* exception.
|
|
</emu-alg>
|
|
</emu-clause>
|
|
<emu-clause id="operations-decoration-decorateproperty">
|
|
<h1>DecorateProperty ( Decorators, O, P, desc )</h1>
|
|
<p>When the abstract operation DecorateProperty is called with ECMAScript language value <var>Decorators</var>, Object <var>O</var>, property key <var>P</var>, and property descriptor <var>desc</var>, the following steps are taken:</p>
|
|
<emu-alg aoid="DecorateProperty">
|
|
1. Let _result_ be _desc_.
|
|
2. Let _key_ be ToPropertyKey(_P_).
|
|
3. Let _iterator_ be GetIterator(_Decorators_).
|
|
4. Let _list_ be CreateListFromIterator(_iterator_, «Object»).
|
|
5. For each _decorator_ in _list_ in reverse order
|
|
6. Let _decorated_ be Call(_decorator_, *null*, _O_, _key_, _result_).
|
|
7. ReturnIfAbrupt(_decorated_).
|
|
8. If Type(_decorated_) is Object, then
|
|
1. Set _result_ to be _decorated_.
|
|
9. Else if _decorated_ is not *undefined*, throw a *TypeError* exception.
|
|
</emu-alg>
|
|
</emu-clause>
|
|
</emu-clause>
|
|
<emu-clause id="operations-object">
|
|
<h1>Operations on Objects</h1>
|
|
<emu-clause id="createlistfromiterator">
|
|
<h1>CreateListFromIterator ( iterator [, elementTypes] )</h1>
|
|
<p>When the abstract operation CreateListFromIterator is called with ECMAScript language value <var>iterator</var>, the following steps are taken:</p>
|
|
<emu-alg aoid="CreateListFromIterator">
|
|
1. ReturnIfAbrupt(_iterator_).
|
|
2. If _elementTypes_ was not passed, let _elementTypes_ be (Undefined, Null, Boolean, String, Symbol, Number, Object).
|
|
3. Let _list_ be an empty List.
|
|
4. Repeat
|
|
1. Let _next_ be IteratorStep(_iterator_).
|
|
2. ReturnIfAbrupt(_next_).
|
|
3. If _next_ is *false*, return _list_.
|
|
4. Let _nextValue_ be IteratorValue(_next_).
|
|
5. ReturnIfAbrupt(_nextValue_).
|
|
6. If Type(_nextValue_) is not an element of _elementTypes_, then
|
|
1. Return IteratorClose(_iterator_, Completion{[[type]]: throw, [[value]]: a newly created *TypeError* object, [[target]: empty}).
|
|
7. Append _nextValue_ as the last element of _list_.
|
|
</emu-alg>
|
|
</emu-clause>
|
|
<emu-clause id="getorcreatemetadatamap">
|
|
<h1>GetOrCreateMetadataMap ( O, P, Create )</h1>
|
|
<p>When the abstract operation GetOrCreateMetadataMap is called with Object <var>O</var>, property key <var>P</var>, and Boolean <var>Create</var> the following steps are taken:</p>
|
|
<emu-alg aoid="GetOrCreateMetadataMap">
|
|
1. Assert: _P_ is *undefined* or IsPropertyKey(_P_) is *true*.
|
|
2. Let _metadataMap_ be *undefined*.
|
|
3. Let _succeeded_ be *true*.
|
|
4. Let _targetMetadata_ be the value of _O_'s [[Metadata]] internal slot.
|
|
5. If _targetMetadata_ is *undefined*, then
|
|
1. If _Create_ is *false*, return *undefined*.
|
|
2. Set _targetMetadata_ to be a newly created *Map* object.
|
|
3. Set the [[Metadata]] internal slot of _O_ to _targetMetadata_.
|
|
6. Let _metadataMap_ be Invoke(_targetMetadata_, "get", _P_).
|
|
7. ReturnIfAbrupt(_metadataMap_).
|
|
8. If _metadataMap_ is *undefined*, then
|
|
1. If _Create_ is *false*, return *undefined*.
|
|
2. Set _metadataMap_ to be a newly created *Map* object.
|
|
3. Let _setStatus_ be Invoke(_targetMetadata_, "set", _P_, _metadataMap_).
|
|
4. ReturnIfAbrupt(_setStatus_).
|
|
9. Return _metadataMap_.
|
|
</emu-alg>
|
|
</emu-clause>
|
|
<emu-clause id="hasmetadata">
|
|
<h1>[[HasMetadata]] ( MetadataKey, P )</h1>
|
|
<p>When the [[HasMetadata]] internal method of _O_ is called with ECMAScript language value <var>MetadataKey</var> and property key <var>P</var>, the following steps are taken:</p>
|
|
<emu-alg>
|
|
1. Return OrdinaryHasMetadata(_MetadataKey_, _O_, _P_).
|
|
</emu-alg>
|
|
</emu-clause>
|
|
<emu-clause id="ordinaryhasmetadata">
|
|
<h1>OrdinaryHasMetadata ( MetadataKey, O, P )</h1>
|
|
<p>When the abstract operation OrdinaryHasMetadata is called with ECMAScript language value <var>MetadataKey</var>, Object <var>O</var>, and property key <var>P</var>, the following steps are taken:</p>
|
|
<emu-alg aoid="OrdinaryHasMetadata">
|
|
1. Assert: _P_ is *undefined* or IsPropertyKey(_P_) is *true*.
|
|
2. Let _hasOwn_ be OrdinaryHasOwnMetadata(_MetadataKey_, _O_, _P_).
|
|
3. If _hasOwn_ is *true*, return *true*.
|
|
4. Let _parent_ be _O_.[[GetPrototypeOf]]().
|
|
5. ReturnIfAbrupt(_parent_).
|
|
6. If _parent_ is not *null*, then
|
|
1. return <var>parent</var>.[[HasMetadata]](_MetadataKey_, _P_).
|
|
7. Return *false*.
|
|
</emu-alg>
|
|
</emu-clause>
|
|
<emu-clause id="hasownmetadata">
|
|
<h1>[[HasOwnMetadata]] ( MetadataKey, P )</h1>
|
|
<p>When the [[HasOwnMetadata]] internal method of _O_ is called with ECMAScript language value <var>MetadataKey</var> and property key <var>P</var>, the following steps are taken:</p>
|
|
<emu-alg>
|
|
1. Return OrdinaryHasOwnMetadata(_MetadataKey_, _O_, _P_).
|
|
</emu-alg>
|
|
</emu-clause>
|
|
<emu-clause id="ordinaryhasownmetadata">
|
|
<h1>OrdinaryHasOwnMetadata ( MetadataKey, O, P )</h1>
|
|
<p>When the abstract operation OrdinaryHasOwnMetadata is called with ECMAScript language value <var>MetadataKey</var>, Object <var>O</var>, and property key <var>P</var>, the following steps are taken:</p>
|
|
<emu-alg aoid="OrdinaryHasOwnMetadata">
|
|
1. Assert: _P_ is *undefined* or IsPropertyKey(_P_) is *true*.
|
|
2. Let _metadataMap_ be GetOrCreateMetadataMap(_O_, _P_, *false*).
|
|
3. ReturnIfAbrupt(_metadataMap_).
|
|
4. If _metadataMap_ is *undefined*, return *false*.
|
|
5. Return Invoke(_metadataMap_, "has", _MetadataKey_).
|
|
</emu-alg>
|
|
</emu-clause>
|
|
<emu-clause id="getmetadata">
|
|
<h1>[[GetMetadata]] ( MetadataKey, P )</h1>
|
|
<p>When the [[GetMatadata]] internal method of _O_ is called with ECMAScript language value <var>MetadataKey</var> and property key <var>P</var>, the following steps are taken:</p>
|
|
<emu-alg>
|
|
1. Return OrdinaryGetMetadata(_MetadataKey_, _O_, _P_).
|
|
</emu-alg>
|
|
</emu-clause>
|
|
<emu-clause id="ordinarygetmetadata">
|
|
<h1>OrdinaryGetMetadata ( MetadataKey, O, P )</h1>
|
|
<p>When the abstract operation OrdinaryGetMetadata is called with ECMAScript language value <var>MetadataKey</var>, Object <var>O</var>, and property key <var>P</var>, the following steps are taken:</p>
|
|
<emu-alg aoid="OrdinaryGetMetadata">
|
|
1. Assert: _P_ is *undefined* or IsPropertyKey(_P_) is *true*.
|
|
2. Let _hasOwn_ be OrdinaryHasOwnMetadata(_MetadataKey_, _O_, _P_).
|
|
3. If _hasOwn_ is *true*, then
|
|
1. return OrdinaryGetOwnMetadata(_MetadataKey_, _O_, _P_).
|
|
4. Let _parent_ be _O_.[[GetPrototypeOf]]().
|
|
5. ReturnIfAbrupt(_parent_).
|
|
6. If _parent_ is not *null*, then
|
|
1. return <var>parent</var>.[[GetMetadata]](_MetadataKey_, _P_).
|
|
7. Return *undefined*.
|
|
</emu-alg>
|
|
</emu-clause>
|
|
<emu-clause id="getownmetadata">
|
|
<h1>[[GetOwnMetadata]] ( MetadataKey, P, ParamIndex )</h1>
|
|
<p>When the [[GetOwnMetadata]] internal method of _O_ is called with ECMAScript language value <var>MetadataKey</var> and property key <var>P</var>, the following steps are taken:</p>
|
|
<emu-alg>
|
|
1. Return OrdinaryGetOwnMetadata(_MetadataKey_, _O_, _P_).
|
|
</emu-alg>
|
|
</emu-clause>
|
|
<emu-clause id="ordinarygetownmetadata">
|
|
<h1>OrdinaryGetOwnMetadata ( MetadataKey, O, P )</h1>
|
|
<p>When the abstract operation OrdinaryGetOwnMetadata is called with ECMAScript language value <var>MetadataKey</var>, Object <var>O</var>, and property key <var>P</var>, the following steps are taken:</p>
|
|
<emu-alg aoid="OrdinaryGetOwnMetadata">
|
|
1. Assert: _P_ is *undefined* or IsPropertyKey(_P_) is *true*.
|
|
2. Let _metadataMap_ be GetOrCreateMetadataMap(_O_, _P_, *false*).
|
|
3. ReturnIfAbrupt(_metadataMap_).
|
|
4. If _metadataMap_ is *undefined*, return *undefined*.
|
|
5. Return Invoke(_metadataMap_, "get", _MetadataKey_).
|
|
</emu-alg>
|
|
</emu-clause>
|
|
<emu-clause id="defineownmetadata">
|
|
<h1>[[DefineOwnMetadata]] ( MetadataKey, MetadataValue, P )</h1>
|
|
<p>When the [[DefineOwnMetadata]] internal method of _O_ is called with ECMAScript language value <var>MetadataKey</var>, ECMAScript language value <var>MetadataValue</var>, and property key <var>P</var>, the following steps are taken:</p>
|
|
<emu-alg>
|
|
1. Return OrdinaryDefineOwnMetadata(_MetadataKey_, _MetadataValue_, _O_, _P_)
|
|
</emu-alg>
|
|
</emu-clause>
|
|
<emu-clause id="ordinarydefineownmetadata">
|
|
<h1>OrdinaryDefineOwnMetadata ( MetadataKey, MetadataValue, O, P )</h1>
|
|
<p>When the abstract operation OrdinaryDefineOwnProperty is called with ECMAScript language value <var>MetadataKey</var>, ECMAScript language value <var>MetadataValue</var>, Object <var>O</var>, and property key <var>P</var>, the following steps are taken:</p>
|
|
<emu-alg aoid="OrdinaryDefineOwnMetadata">
|
|
1. Assert: _P_ is *undefined* or IsPropertyKey(_P_) is *true*.
|
|
2. Let _metadataMap_ be GetOrCreateMetadataMap(_O_, _P_, *true*).
|
|
3. ReturnIfAbrupt(_metadataMap_).
|
|
4. Return Invoke(_metadataMap_, "set", _MetadataKey_, _MetadataValue_).
|
|
</emu-alg>
|
|
</emu-clause>
|
|
<emu-clause id="metadatakeys">
|
|
<h1>[[MetadataKeys]] ( P )</h1>
|
|
<p>When the [[MetadataKeys]] internal method of <var>O</var> is called with property key <var>P</var> the following steps are taken:</p>
|
|
<emu-alg>
|
|
1. Return OrdinaryMetadataKeys(_O_, _P_).
|
|
</emu-alg>
|
|
</emu-clause>
|
|
<emu-clause id="ordinarymetadatakeys">
|
|
<h1>OrdinaryMetadataKeys ( O, P )</h1>
|
|
<p>When the abstract operation OrdinaryMetadataKeys is called with Object <var>O</var> and property key <var>P</var> the following steps are taken:</p>
|
|
<emu-alg aoid="OrdinaryMetadataKeys">
|
|
1. Assert: _P_ is *undefined* or IsPropertyKey(_P_) is *true*.
|
|
2. Let _ownKeys_ be OrdinaryOwnMetadataKeys(_O_, _P_).
|
|
3. Let _parent_ = _O_.[[GetPrototypeOf]]().
|
|
4. ReturnIfAbrupt(_parent_).
|
|
5. If _parent_ is *null*, then return _ownKeys_.
|
|
6. Let _parentKeys_ be <var>O</var>.[[OrdinaryMetadataKeys]](_P_).
|
|
7. ReturnIfAbrupt(_parentKeys_).
|
|
8. Let _ownKeysLen_ = Get(_ownKeys_, "length").
|
|
9. ReturnIfAbrupt(_ownKeysLen_).
|
|
10. If _ownKeysLen_ is 0, return _parentKeys_.
|
|
11. Let _parentKeysLen_ = Get(_parentKeys_, "length").
|
|
12. ReturnIfAbrupt(_parentKeysLen_).
|
|
13. If _parentKeysLen_ is 0, return _ownKeys_.
|
|
14. Let _set_ be a newly created *Set* object.
|
|
15. Let _keys_ be ArrayCreate(0).
|
|
16. Let _k_ be 0.
|
|
17. For each element _key_ of _ownKeys_
|
|
1. Let _hasKey_ be Invoke(_set_, "has", _key_).
|
|
2. ReturnIfAbrupt(_hasKey_).
|
|
3. If _hasKey_ is *false*, then
|
|
1. Let _Pk_ be ToString(_k_).
|
|
2. Let _addStatus_ be Invoke(_set_, "add", _key_).
|
|
3. ReturnIfAbrupt(_addStatus_).
|
|
4. Let _defineStatus_ be CreateDataPropertyOrThrow(_keys_, _Pk_, _key_).
|
|
5. ReturnIfAbrupt(_defineStatus_).
|
|
6. Increase _k_ by 1.
|
|
18. For each element _key_ of _parentKeys_
|
|
1. Let _hasKey_ be Invoke(_set_, "has", _key_).
|
|
2. ReturnIfAbrupt(_hasKey_).
|
|
3. If _hasKey_ is *false*, then
|
|
1. Let _Pk_ be ToString(_k_).
|
|
2. Let _addStatus_ be Invoke(_set_, "add", _key_).
|
|
3. ReturnIfAbrupt(_addStatus_).
|
|
4. Let _defineStatus_ be CreateDataPropertyOrThrow(_keys_, _Pk_, _key_).
|
|
5. ReturnIfAbrupt(_defineStatus_).
|
|
6. Increase _k_ by 1.
|
|
19. Let _setStatus_ be Set(_keys_, "length", _k_).
|
|
20. ReturnIfAbrupt(_setStatus_).
|
|
21. return _keys_.
|
|
</emu-alg>
|
|
</emu-clause>
|
|
<emu-clause id="ownmetadatakeys">
|
|
<h1>[[OwnMetadataKeys]] ( P )</h1>
|
|
<p>When the [[OwnMetadataKeys]] internal method of <var>O</var> is called with property key <var>P</var> the following steps are taken:</p>
|
|
<emu-alg>
|
|
1. Return OrdinaryOwnMetadataKeys(_O_, _P_).
|
|
</emu-alg>
|
|
</emu-clause>
|
|
<emu-clause id="ordinaryownmetadatakeys">
|
|
<h1>OrdinaryOwnMetadataKeys ( O, P )</h1>
|
|
<p>When the abstract operation OrdinaryOwnMetadataKeys is called with Object <var>O</var> and property key <var>P</var> the following steps are taken:</p>
|
|
<emu-alg aoid="OrdinaryOwnMetadataKeys">
|
|
1. Assert: _P_ is *undefined* or IsPropertyKey(_P_) is *true*.
|
|
2. Let _keys_ be ArrayCreate(0).
|
|
3. Let _metadataMap_ be GetOrCreateMetadataMap(_O_, _P_, *false*).
|
|
4. ReturnIfAbrupt(_metadataMap_).
|
|
5. If _metadataMap_ is *undefined*, return _keys_.
|
|
6. Let _keysObj_ be Invoke(_metadataMap_, "keys").
|
|
7. ReturnIfAbrupt(_keysObj_).
|
|
8. Let _iterator_ be GetIterator(_keysObj_).
|
|
9. ReturnIfAbrupt(_iterator_).
|
|
10. Let _k_ be 0.
|
|
11. Repeat
|
|
1. Let _Pk_ be ToString(k).
|
|
2. Let _next_ be IteratorStep(_iterator_).
|
|
3. ReturnIfAbrupt(_next_).
|
|
4. If _next_ is *false*, then
|
|
1. Let _setStatus_ be Set(_keys_, "length", _k_, _true_).
|
|
2. ReturnIfAbrupt(_setStatus_).
|
|
3. Return _keys_.
|
|
5. Let _nextValue_ be IteratorValue(_next_).
|
|
6. ReturnIfAbrupt(_nextValue_).
|
|
7. Let _defineStatus_ be CreateDataPropertyOrThrow(_keys_, _Pk_, _nextValue_).
|
|
8. If _defineStatus_ is an abrupt completion, return IteratorClose(_iterator_, _defineStatus_).
|
|
9. Increase _k_ by 1.
|
|
</emu-alg>
|
|
</emu-clause>
|
|
<emu-clause id="deletemetadata">
|
|
<h1>[[DeleteMetadata]]( MetadataKey, P )</h1>
|
|
<p>When the [[DeleteMetadata]] internal method of <var>O</var> is called with ECMAScript language value <var>MetadataKey</var> and property key <var>P</var> the following steps are taken:</p>
|
|
<emu-alg>
|
|
1. Assert: _P_ is *undefined* or IsPropertyKey(_P_) is *true*.
|
|
2. Let _metadataMap_ be GetOrCreateMetadataMap(_O_, _P_, *false*).
|
|
3. ReturnIfAbrupt(_metadataMap_).
|
|
4. If _metadataMap_ is *undefined*, return *false*.
|
|
5. Return Invoke(_metadataMap_, "delete", _MetadataKey_).
|
|
</emu-alg>
|
|
</emu-clause>
|
|
</emu-clause>
|
|
</emu-clause>
|
|
|
|
<emu-clause id="reflection">
|
|
<h1>Reflection</h1>
|
|
<emu-clause id="reflect">
|
|
<h1>The Reflect Object</h1>
|
|
<p>This section contains amendments to the Reflect object.</p>
|
|
<emu-note>A shim for this API can be found here: <a href="https://github.com/rbuckton/ReflectDecorators">https://github.com/rbuckton/ReflectDecorators</a></emu-note>
|
|
<emu-clause id="reflect-metadatadecoratorfunctions">
|
|
<h1>Metadata Decorator Functions</h1>
|
|
<p>A metadata decorator function is an anonymous built-in function that has [[MetadataKey]] and [[MetadataValue]] internal slots.</p>
|
|
<p>When a metadata decorator function <var>F</var> is called with arguments <var>target</var> and <var>key</var>, the following steps are taken:</p>
|
|
<emu-alg>
|
|
1. Assert: _F_ has a [[MetadataKey]] internal slot whose value is an ECMAScript language value, or *undefined*.
|
|
2. Assert: _F_ has a [[MetadataValue]] internal slot whose value is an ECMAScript language value, or *undefined*.
|
|
3. If Type(_target_) is not Object, throw a *TypeError* exception.
|
|
4. If _key_ is not *undefined* and IsPropertyKey(_key_) is *false*, throw a *TypeError* exception.
|
|
5. Let _metadataKey_ be the value of _F_'s [[MetadataKey]] internal slot.
|
|
6. Let _metadataValue_ be the value of _F_'s [[MetadataValue]] internal slot.
|
|
7. Return <var>target</var>.[[DefineMetadata]](_metadataKey_, _metadataValue_, _target_, _key_).
|
|
</emu-alg>
|
|
</emu-clause>
|
|
<emu-clause id="reflect-decorate">
|
|
<h1>Reflect.decorate ( decorators, target, propertyKey, attributes )</h1>
|
|
<p>When the <code>decorator</code> function is called with arguments <var>decorators</var>, <var>target</var>, <var>propertyKey</var>, and <var>attributes</var>, the following steps are taken:</p>
|
|
<emu-alg>
|
|
1. If Type(_decorators_) is not Object, throw a *TypeError* exception.
|
|
2. If Type(_target_) is not Object, throw a *TypeError* exception.
|
|
3. Let _key_ be ToPropertyKey(_propertyKey_).
|
|
4. ReturnIfAbrupt(_propertyKey_).
|
|
5. Let _desc_ be ToPropertyDescriptor(_attributes_).
|
|
6. ReturnIfAbrupt(_desc_).
|
|
7. Return Decorate(_decorators_, _target_, _propertyKey_, _desc_).
|
|
</emu-alg>
|
|
</emu-clause>
|
|
<emu-clause id="reflect-metadata">
|
|
<h1>Reflect.metadata ( metadataKey, metadataValue )</h1>
|
|
<p>When the <code>metadata</code> function is called with arguments <var>metadataKey</var> and <var>metadataValue</var>, the following steps are taken:</p>
|
|
<emu-alg>
|
|
1. Let _decorator_ be a new built-in function object as defined in Metadata Decorator Functions.
|
|
2. Set the [[MetadataKey]] internal slot of _decorator_ to _metadataKey_.
|
|
3. Set the [[MetadataValue]] internal slot of _decorator_ to _metadataValue_.
|
|
4. return _decorator_.
|
|
</emu-alg>
|
|
</emu-clause>
|
|
<emu-clause id="reflect-definemetadata">
|
|
<h1>Reflect.defineMetadata ( metadataKey, metadataValue, target, propertyKey )</h1>
|
|
<p>When the <code>defineMetadata</code> function is called with arguments <var>metadataKey</var>, <var>metadataValue</var>, <var>target</var>, and <var>propertyKey</var>, the following steps are taken:</p>
|
|
<emu-alg>
|
|
1. If Type(_target_) is not Object, throw a *TypeError* exception.
|
|
2. return <var>target</var>.[[DefineMetadata]](_metadataKey_, _metadataValue_, _propertyKey_).
|
|
</emu-alg>
|
|
</emu-clause>
|
|
<emu-clause id="reflect-hasmetadata">
|
|
<h1>Reflect.hasMetadata ( metadataKey, target, propertyKey )</h1>
|
|
<p>When the <code>hasMetadata</code> function is called with arguments <var>metadataKey</var>, <var>target</var>, and <var>propertyKey</var>, the following steps are taken:</p>
|
|
<emu-alg>
|
|
1. If Type(_target_) is not Object, throw a *TypeError* exception.
|
|
2. return <var>target</var>.[[HasMetadata]](_metadataKey_, _propertyKey_).
|
|
</emu-alg>
|
|
</emu-clause>
|
|
<emu-clause id="reflect-hasownmetadata">
|
|
<h1>Reflect.hasOwnMetadata ( metadataKey, target, propertyKey )</h1>
|
|
<p>When the <code>hasOwnMetadata</code> function is called with arguments <var>metadataKey</var>, <var>target</var>, and <var>propertyKey</var>, the following steps are taken:</p>
|
|
<emu-alg>
|
|
1. If Type(_target_) is not Object, throw a *TypeError* exception.
|
|
2. return <var>target</var>.[[HasOwn]](_metadataKey_, _propertyKey_).
|
|
</emu-alg>
|
|
</emu-clause>
|
|
<emu-clause id="reflect-getmetadata">
|
|
<h1>Reflect.getMetadata ( metadataKey, target, propertyKey )</h1>
|
|
<p>When the <code>getMetadata</code> function is called with arguments <var>metadataKey</var>, <var>target</var>, and <var>propertyKey</var>, the following steps are taken:</p>
|
|
<emu-alg>
|
|
1. If Type(_target_) is not Object, throw a *TypeError* exception.
|
|
2. return <var>target</var>.[[GetMetadata]](_metadataKey_, _propertyKey_).
|
|
</emu-alg>
|
|
</emu-clause>
|
|
<emu-clause id="reflect-getownmetadata">
|
|
<h1>Reflect.getOwnMetadata ( metadataKey, target, propertyKey )</h1>
|
|
<p>When the <code>getOwnMetadata</code> function is called with arguments <var>metadataKey</var>, <var>target</var>, and <var>propertyKey</var>, the following steps are taken:</p>
|
|
<emu-alg>
|
|
1. If Type(_target_) is not Object, throw a *TypeError* exception.
|
|
2. return <var>target</var>.[[GetOwnMetadata]](_metadataKey_, _propertyKey_).
|
|
</emu-alg>
|
|
</emu-clause>
|
|
<emu-clause id="reflect-getmetadatakeys">
|
|
<h1>Reflect.getMetadataKeys ( target, propertyKey )</h1>
|
|
<p>When the <code>getMetadataKeys</code> function is called with arguments <var>target</var> and <var>propertyKey</var>, the following steps are taken:</p>
|
|
<emu-alg>
|
|
1. If Type(_target_) is not Object, throw a *TypeError* exception.
|
|
2. return <var>target</var>.[[GetMetadataKeys]](_propertyKey_).
|
|
</emu-alg>
|
|
</emu-clause>
|
|
<emu-clause id="reflect-getownmetadata">
|
|
<h1>Reflect.getOwnMetadataKeys ( target, propertyKey )</h1>
|
|
<p>When the <code>getOwnMetadataKeys</code> function is called with arguments <var>target</var> and <var>propertyKey</var>, the following steps are taken:</p>
|
|
<emu-alg>
|
|
1. If Type(_target_) is not Object, throw a *TypeError* exception.
|
|
2. return <var>target</var>.[[GetOwnMetadataKeys]](_propertyKey_).
|
|
</emu-alg>
|
|
</emu-clause>
|
|
<emu-clause id="reflect-deletemetadata">
|
|
<h1>Reflect.deleteMetadata ( metadataKey, target, propertyKey )</h1>
|
|
<p>When the <code>deleteMetadata</code> function is called with arguments <var>metadataKey</var>, <var>target</var>, and <var>propertyKey</var>, the following steps are taken:</p>
|
|
<emu-alg>
|
|
1. If Type(_target_) is not Object, throw a *TypeError* exception.
|
|
2. return <var>target</var>.[[DeleteMetadata]](_metadataKey_, _propertyKey_).
|
|
</emu-alg>
|
|
</emu-clause>
|
|
</emu-clause>
|
|
</emu-clause>
|
|
<emu-annex id="grammar">
|
|
<h1>Grammar</h1>
|
|
<emu-annex id="grammar-expressions">
|
|
<h1>Expressions</h1>
|
|
<emu-production id="grammar-memberexpression" name="MemberExpression" params="Yield, Decorator">
|
|
<emu-rhs><emu-nt params="?Yield">PrimaryExpression</emu-nt></emu-rhs>
|
|
<emu-rhs constraints="~Decorator"><emu-nt params="?Yield, ?Decorator">MemberExpression</emu-nt><emu-t>[</emu-t><emu-nt params="In, ?Yield">Expression</emu-nt><emu-t>]</emu-t></emu-rhs>
|
|
<emu-rhs><emu-nt params="?Yield, ?Decorator">MemberExpression</emu-nt><emu-t>.</emu-t><emu-nt>IdentifierName</emu-nt></emu-rhs>
|
|
<emu-rhs><emu-nt params="?Yield, ?Decorator">MemberExpression</emu-nt><emu-nt params="?Yield">TemplateLiteral</emu-nt></emu-rhs>
|
|
<emu-rhs><emu-nt params="?Yield, ?Decorator">SuperProperty</emu-nt></emu-rhs>
|
|
<emu-rhs><emu-nt>MetaProperty</emu-nt></emu-rhs>
|
|
<emu-rhs><emu-t>new</emu-t><emu-nt params="?Yield, ?Decorator">MemberExpression</emu-nt><emu-nt params="?Yield">Arguments</emu-nt></emu-rhs>
|
|
</emu-production>
|
|
<emu-production id="grammar-superproperty" name="SuperProperty" params="Yield, Decorator">
|
|
<emu-rhs constraints="~Decorator"><emu-t>super</emu-t><emu-t>[</emu-t><emu-nt params="In, ?Yield">Expression</emu-nt><emu-t>]</emu-t></emu-rhs>
|
|
</emu-production>
|
|
<emu-production id="grammar-newexpression" name="NewExpression" params="Yield, Decorator">
|
|
<emu-rhs><emu-nt params="?Yield, ?Decorator">MemberExpression</emu-nt></emu-rhs>
|
|
<emu-rhs><emu-t>new</emu-t><emu-nt params="?Yield, ?Decorator">NewExpression</emu-nt></emu-rhs>
|
|
</emu-production>
|
|
<emu-production id="grammar-callexpression" name="CallExpression" params="Yield, Decorator">
|
|
<emu-rhs><emu-nt params="?Yield, ?Decorator">MemberExpression</emu-nt> <emu-nt params="?Yield">Arguments</emu-nt></emu-rhs>
|
|
<emu-rhs><emu-nt params="?Yield">SuperCall</emu-nt></emu-rhs>
|
|
<emu-rhs><emu-nt params="?Yield, ?Decorator">CallExpression</emu-nt> <emu-nt params="?Yield">Arguments</emu-nt></emu-rhs>
|
|
<emu-rhs constraints="~Decorator"><emu-nt params="?Yield">CallExpression</emu-nt> <emu-t>[</emu-t> <emu-nt params="In, ?Yield">Expression</emu-nt> <emu-t>]</emu-t></emu-rhs>
|
|
<emu-rhs><emu-nt params="?Yield, ?Decorator">CallExpression</emu-nt> <emu-t>.</emu-t> <emu-nt>IdentifierName</emu-nt></emu-rhs>
|
|
<emu-rhs><emu-nt params="?Yield, ?Decorator">CallExpression</emu-nt> <emu-nt params="?Yield">TemplateLiteral</emu-nt></emu-rhs>
|
|
</emu-production>
|
|
<emu-production id="grammar-lefthandsideexpression" name="LeftHandSideExpression" params="Yield, Decorator">
|
|
<emu-rhs><emu-nt params="?Yield, ?Decorator">NewExpression</emu-nt></emu-rhs>
|
|
<emu-rhs><emu-nt params="?Yield, ?Decorator">CallExpression</emu-nt></emu-rhs>
|
|
</emu-production>
|
|
</emu-annex>
|
|
|
|
<emu-annex id="functions-and-classes">
|
|
<h1>Functions and Classes</h1>
|
|
<emu-production id="grammar-classdeclaration" name="ClassDeclaration" params="Yield, Default">
|
|
<emu-rhs><emu-nt params="?Yield" optional>DecoratorList</emu-nt> <emu-t>class</emu-t> <emu-nt params="?Yield">BindingIdentifier</emu-nt> <emu-nt params="?Yield">ClassTail</emu-nt></emu-rhs>
|
|
<emu-rhs constraints="+Default"><emu-nt params="?Yield" optional>DecoratorList</emu-nt> <emu-t>class</emu-t> <emu-nt params="?Yield">ClassTail</emu-nt></emu-rhs>
|
|
</emu-production>
|
|
<emu-production id="grammar-classexpression" name="ClassExpression" params="Yield, GeneratorParameter">
|
|
<emu-rhs><emu-nt params="?Yield" optional>DecoratorList</emu-nt> <emu-t>class</emu-t> <emu-nt params="?Yield" optional>BindingIdentifier</emu-nt> <emu-nt params="?Yield, ?GeneratorParameter">ClassTail</emu-nt></emu-rhs>
|
|
</emu-production>
|
|
<emu-production id="grammar-classelement" name="ClassElement" params="Yield">
|
|
<emu-rhs><emu-nt params="?Yield" optional>DecoratorList</emu-nt> <emu-nt params="?Yield">MethodDefinition</emu-nt></emu-rhs>
|
|
<emu-rhs><emu-nt params="?Yield" optional>DecoratorList</emu-nt> <emu-t>static</emu-t> <emu-nt params="?Yield">MethodDefinition</emu-nt></emu-rhs>
|
|
<emu-rhs><emu-t>;</emu-t></emu-rhs>
|
|
</emu-production>
|
|
<emu-production id="grammar-decoratorlist" name="DecoratorList" params="Yield">
|
|
<emu-rhs><emu-nt params="?Yield" optional>DecoratorList</emu-nt> <emu-nt params="?Yield">Decorator</emu-nt></emu-rhs>
|
|
</emu-production>
|
|
<emu-production id="grammar-decorator" name="Decorator" params="Yield">
|
|
<emu-rhs><emu-t>@</emu-t> <emu-nt params="Decorator, ?Yield">LeftHandSideExpression</emu-nt></emu-rhs>
|
|
</emu-production>
|
|
</emu-annex>
|
|
|
|
<emu-annex id="scripts-and-modules">
|
|
<h1>Scripts and Modules</h1>
|
|
<emu-production id="grammar-exportdeclaration" name="ExportDeclaration">
|
|
<emu-rhs><emu-t>export</emu-t> <emu-t>*</emu-t> <emu-nt>FromClause</emu-nt> <emu-t>;</emu-t></emu-rhs>
|
|
<emu-rhs><emu-t>export</emu-t> <emu-nt>ExportClause</emu-nt> <emu-nt>FromClause</emu-nt> <emu-t>;</emu-t></emu-rhs>
|
|
<emu-rhs><emu-t>export</emu-t> <emu-nt>ExportClause</emu-nt> <emu-t>;</emu-t></emu-rhs>
|
|
<emu-rhs><emu-t>export</emu-t> <emu-nt>VariableStatement</emu-nt></emu-rhs>
|
|
<emu-rhs><emu-t>export</emu-t> <emu-gann>lookahead ≠ <emu-t>@</emu-t></emu-gann> <emu-nt>Declaration</emu-nt></emu-rhs>
|
|
<emu-rhs><emu-t>export</emu-t> <emu-t>default</emu-t> <emu-nt params="Default">HoistableDeclaration</emu-nt></emu-rhs>
|
|
<emu-rhs><emu-t>export</emu-t> <emu-t>default</emu-t> <emu-gann>lookahead ≠ <emu-t>@</emu-t></emu-gann> <emu-nt params="Default">ClassDeclaration</emu-nt></emu-rhs>
|
|
<emu-rhs><emu-t>export</emu-t> <emu-t>default</emu-t> <emu-gann>lookahead ∉ { <emu-t>function</emu-t>, <emu-t>class</emu-t>, <emu-t>@</emu-t> }</emu-gann> <emu-nt>AssignmentExpression</emu-nt></emu-rhs>
|
|
<emu-rhs><emu-nt>DecoratorList</emu-nt> <emu-t>export</emu-t> <emu-gann>lookahead ≠ <emu-t>@</emu-t></emu-gann> <emu-nt>ClassDeclaration</emu-nt></emu-rhs>
|
|
<emu-rhs><emu-nt>DecoratorList</emu-nt> <emu-t>export</emu-t> <emu-t>default</emu-t> <emu-gann>lookahead ≠ <emu-t>@</emu-t></emu-gann> <emu-nt params="Default">ClassDeclaration</emu-nt></emu-rhs>
|
|
</emu-production>
|
|
</emu-annex>
|
|
</emu-annex> |