?
u
/
This proposal introduces syntax and semantics around explicit resource management.
See the proposal repository for background material and discussion.
This document includes specification text also proposed in Explicit Resource Management to provide a comprehensive, holistic specification.
Specification Name | [[Description]] | Value and Purpose |
---|---|---|
@@asyncDispose |
"Symbol.asyncDispose"
|
A method that performs explicit resource cleanup on an object. Called by the semantics of the using await declaration and AsyncDisposableStack objects.
|
@@dispose |
"Symbol.dispose"
|
A method that performs explicit resource cleanup on an object. Called by the semantics of the using declaration and DisposableStack objects.
|
Intrinsic Name | Global Name | ECMAScript Language Association |
---|---|---|
|
AggregateError
|
The AggregateError |
|
Array
|
The Array |
|
ArrayBuffer
|
The ArrayBuffer |
|
The prototype of Array iterator objects ( |
|
|
AsyncDisposableStack
|
The AsyncDisposableStack |
|
The prototype of async-from-sync iterator objects ( |
|
|
The |
|
|
The |
|
|
An object that all standard built-in async iterator objects indirectly inherit from | |
|
Atomics
|
The Atomics object ( |
|
BigInt
|
The BigInt |
|
BigInt64Array
|
The BigInt64Array |
|
BigUint64Array
|
The BigUint64Array |
|
Boolean
|
The Boolean |
|
DataView
|
The DataView |
|
Date
|
The Date |
|
decodeURI
|
The decodeURI function ( |
|
decodeURIComponent
|
The decodeURIComponent function ( |
|
DisposableStack
|
The DisposableStack |
|
encodeURI
|
The encodeURI function ( |
|
encodeURIComponent
|
The encodeURIComponent function ( |
|
Error
|
The Error |
|
eval
|
The eval function ( |
|
EvalError
|
The EvalError |
|
FinalizationRegistry
|
The |
|
Float32Array
|
The Float32Array |
|
Float64Array
|
The Float64Array |
|
The prototype of For-In iterator objects ( |
|
|
Function
|
The Function |
|
The |
|
|
Int8Array
|
The Int8Array |
|
Int16Array
|
The Int16Array |
|
Int32Array
|
The Int32Array |
|
isFinite
|
The isFinite function ( |
|
isNaN
|
The isNaN function ( |
|
An object that all standard built-in iterator objects indirectly inherit from | |
|
JSON
|
The JSON object ( |
|
Map
|
The Map |
|
The prototype of Map iterator objects ( |
|
|
Math
|
The Math object ( |
|
Number
|
The Number |
|
Object
|
The Object |
|
parseFloat
|
The parseFloat function ( |
|
parseInt
|
The parseInt function ( |
|
Promise
|
The Promise |
|
Proxy
|
The Proxy |
|
RangeError
|
The RangeError |
|
ReferenceError
|
The ReferenceError |
|
Reflect
|
The Reflect object ( |
|
RegExp
|
The RegExp |
|
The prototype of RegExp String Iterator objects ( |
|
|
Set
|
The Set |
|
The prototype of Set iterator objects ( |
|
|
SharedArrayBuffer
|
The SharedArrayBuffer |
|
String
|
The String |
|
The prototype of String iterator objects ( |
|
|
SuppressedError
|
The SuppressedError |
|
Symbol
|
The Symbol |
|
SyntaxError
|
The SyntaxError |
|
A |
|
|
The super class of all typed Array |
|
|
TypeError
|
The TypeError |
|
Uint8Array
|
The Uint8Array |
|
Uint8ClampedArray
|
The Uint8ClampedArray |
|
Uint16Array
|
The Uint16Array |
|
Uint32Array
|
The Uint32Array |
|
URIError
|
The URIError |
|
WeakMap
|
The WeakMap |
|
WeakRef
|
The |
|
WeakSet
|
The WeakSet |
The abstract operation InitializeReferencedBinding takes arguments V, W, and hint (one of
A DisposeCapability Record is a
DisposeCapability Records have the fields listed in
Field Name | Value | Meaning |
---|---|---|
[[DisposableResourceStack]] |
a |
The resources to be disposed. Resources are added in the order they are initialized, and are disposed in reverse order. |
See Common Resource Management Interfaces (
A DisposableResource Record is a
DisposableResource Records have the fields listed in
Field Name | Value | Meaning |
---|---|---|
[[ResourceValue]] |
An Object or |
The value to be disposed. |
[[Hint]] |
|
Indicates whether the resource was added by a using declaration or DisposableStack object (using await declaration or AsyncDisposableStack object ( |
[[DisposeMethod]] |
A |
A |
The abstract operation NewDisposeCapability takes no arguments and returns a
The abstract operation AddDisposableResource takes arguments disposeCapability (a
The abstract operation CreateDisposableResource takes arguments V (an
The abstract operation GetDisposeMethod takes arguments V (an Object) and hint (either
The abstract operation Dispose takes arguments V (an Object or
The abstract operation DisposeResources takes arguments disposeCapability (a
The
It is defined piecewise over the following productions:
The
It is not necessary to treat export default
The
The
The
The
The
Every grammar production alternative in this specification which is not listed below implicitly has the following default definition of Contains:
Static semantic rules that depend upon substructure generally do not look into function definitions.
Static semantic rules that depend upon substructure generally do not look into class bodies except for
Static semantic rules that depend upon substructure generally do not look into static
initialization blocks.
super
or this
, return super
, or this
, return super
, or this
, return Contains is used to detect new.target
, this
, and super
usage within an
super
, return The
When
It is defined piecewise over the following productions:
Environment Record is a specification type used to define the association of
Every Environment Record has an [[OuterEnv]] field, which is either
Environment Records are purely specification mechanisms and need not correspond to any specific artefact of an ECMAScript implementation. It is impossible for an ECMAScript program to directly access or manipulate such values.
The
Method | Purpose |
---|---|
HasBinding(N) |
Determine if an |
CreateMutableBinding(N, D) |
Create a new but uninitialized mutable binding in an |
CreateImmutableBinding(N, S) |
Create a new but uninitialized immutable binding in an |
InitializeBinding(N, V, hint) |
Set the value of an already existing but uninitialized binding in an using declaration (using await declaration ( |
SetMutableBinding(N, V, S) |
Set the value of an already existing mutable binding in an |
GetBindingValue(N, S) |
Returns the value of an already existing binding from an |
DeleteBinding(N) |
Delete a binding from an |
HasThisBinding() |
Determine if an this binding. Return |
HasSuperBinding() |
Determine if an super method binding. Return |
WithBaseObject() |
If this with statement, return the with object. Otherwise, return |
Each Declarative Environment Record is associated with an ECMAScript program scope containing variable, constant, let, class, module, import, and/or function declarations. A declarative Environment Record binds the set of identifiers defined by the declarations contained within its scope.
Every Declarative Environment Record also has a [[DisposeCapability]] field, which contains a using
declarations and using await
declarations that must be disposed when the Evaluation step that constructed the
The behaviour of the concrete specification methods for Declarative Environment Records is defined by the following algorithms.
The InitializeBinding concrete method of a
The InitializeBinding concrete method of an
In this specification, all uses of CreateMutableBinding for
The InitializeBinding concrete method of a
The abstract operation FunctionDeclarationInstantiation takes arguments func (a
When an
It performs the following steps when called:
eval
in eval
.In the following rules, “token” means the actual recognized lexical token determined using the current lexical
There are three basic rules of semicolon insertion:
When, as the source text is parsed from left to right, a token (called the offending token) is encountered that is not allowed by any production of the grammar, then a semicolon is automatically inserted before the offending token if one or more of the following conditions is true:
}
.
)
and the inserted semicolon would then be parsed as the terminating semicolon of a do-while statement (However, there is an additional overriding condition on the preceding rules: a semicolon is never inserted automatically if the semicolon would then be parsed as an empty statement or if that semicolon would become one of the two semicolons in the header of a for
statement (see
The following are the only restricted productions in the grammar:
The practical effect of these restricted productions is as follows:
++
or --
token is encountered where the parser would treat it as a postfix operator, and at least one ++
or --
token, then a semicolon is automatically inserted before the ++
or --
token.
continue
, break
, return
, throw
, or yield
token is encountered and a continue
, break
, return
, throw
, or yield
token.
=>
token, a semicolon is automatically inserted and the punctuator causes a syntax error.
async
token is followed by a function
or (
token, a semicolon is automatically inserted and the async
token is not treated as part of the same expression or class element as the following tokens.
async
token is followed by a *
token, a semicolon is automatically inserted and the punctuator causes a syntax error.
The resulting practical advice to ECMAScript programmers is:
++
or --
operator should be on the same line as its operand.
return
or throw
statement or an yield
expression should start on the same line as the return
, throw
, or yield
token.
break
or continue
statement should be on the same line as the break
or continue
token.
=>
should be on the same line.
async
token preceding an asynchronous function or method should be on the same line as the immediately following token.
No matter how control leaves the
The abstract operation BlockDeclarationInstantiation takes arguments code (a
When a
It performs the following steps when called:
When processing an instance of the production
the interpretation of
A const
declaration.
The
A const
declaration.
The
The
When
It is defined piecewise over the following productions:
for
StatementThe
for-in
, for-of
, and for-await-of
StatementsThe
The abstract operation ForIn/OfBodyEvaluation takes arguments lhs, stmt, iteratorRecord, iterationKind, lhsKind (
switch
StatementNo matter how control leaves the
The
The
The
The
The
The
The
The
The
The
For ease of specification, private methods and accessors are included alongside private fields in the [[PrivateElements]] slot of class instances. However, any given object has either all or none of the private methods and accessors defined by a given class. This feature has been designed so that implementations may choose to implement private methods and accessors using a strategy which does not require tracking each method or accessor individually.
For example, an implementation could directly associate instance private methods with their corresponding this
value. Looking up an instance private method on an object then consists of checking that the class
This differs from private fields: because field initializers can throw during class instantiation, an individual object may have some proper subset of the private fields of a given class, and so private fields must in general be tracked individually.
It is defined piecewise over the following productions:
constructor(...args) { super(...args); }
. The most notable distinction is that while the aforementioned ECMAScript source text observably calls the %Array.prototype%
, this function does not.constructor() {}
.The
The
When processing an instance of the production
the interpretation of
When processing an instance of the production
the interpretation of
The
The
call is a
A potential tail position call that is immediately followed by return
It is defined piecewise over the following productions:
The
The InitializeEnvironment concrete method of a
The ExecuteModule concrete method of a
The abstract operation EvalDeclarationInstantiation takes arguments body, varEnv, lexEnv, privateEnv, and strict. It performs the following steps when called:
eval
will not create a global var declaration that would be shadowed by a global lexical declaration.An alternative version of this algorithm is described in
Instances of Error objects are thrown as exceptions when runtime errors occur. The Error objects may also serve as base objects for user-defined exception classes.
When an ECMAScript implementation detects a runtime error, it throws a new instance of one of the NativeError objects defined in
Error instances are Object.prototype.toString
.
When an ECMAScript implementation detects a runtime error, it throws a new instance of one of the NativeError objects defined in
For each error object, references to NativeError in the definition should be replaced with the appropriate error object name from
NativeError instances are Object.prototype.toString
(
AggregateError instances are Object.prototype.toString
(
The SuppressedError
SuppressedError(…)
is equivalent to the object creation expression new SuppressedError(…)
with the same arguments.extends
clause of a class definition. Subclass super
call to the SuppressedError This function performs the following steps when called:
The SuppressedError
The initial value of SuppressedError.prototype
is
This property has the attributes { [[Writable]]:
The SuppressedError prototype object:
The initial value of SuppressedError.prototype.constructor
is
The initial value of SuppressedError.prototype.message
is the empty String.
The initial value of SuppressedError.prototype.name
is
SuppressedError instances are Object.prototype.toString
(
The following steps are taken:
"return"
).The value of the
The following steps are taken:
"return"
).The value of the
An interface is a set of
The Disposable interface includes the property described in
Property | Value | Requirements |
---|---|---|
@@dispose
|
A function. |
Invoking this method notifies the Disposable object that the caller does not intend to continue to use this object. This method should perform any necessary logic to perform explicit clean-up of the resource including, but not limited to, file system handles, streams, If called more than once on the same object, the function should not throw an exception. However, this requirement is not enforced. When using a Disposable object, it is good practice to create the instance with a |
The AsyncDisposable interface includes the property described in
Property | Value | Requirements |
---|---|---|
@@asyncDispose
|
A function that returns a promise. |
Invoking this method notifies the AsyncDisposable object that the caller does not intend to continue to use this object. This method should perform any necessary logic to perform explicit clean-up of the resource including, but not limited to, file system handles, streams, If called more than once on the same object, the function should not throw an exception. However, this requirement is not enforced. When using an AsyncDisposable object, it is good practice to create the instance with a |
A DisposableStack is an object that can be used to contain one or more resources that should be disposed together.
Any DisposableStack object is in one of two mutually exclusive states: disposed or pending:
d
is pending if d[Symbol.dispose]()
has yet to be invoked for d
.d
is disposed if d[Symbol.dispose]()
has already been invoked once for d
.The DisposableStack
extends
clause of a class definition. Subclass super
call to the DisposableStack DisposableStack
and DisposableStack.prototype
built-in methods.When the DisposableStack
function is called, the following steps are taken:
The DisposableStack
The DisposableStack prototype object:
DisposableStack.prototype.disposed
is an
When the dispose
method is called, the following steps are taken:
When the use
function is called with one argument, the following steps are taken:
When the adopt
function is called with two arguments, the following steps are taken:
When the defer
function is called with one argument, the following steps are taken:
When the move
function is called, the following steps are taken:
The initial value of the @@dispose property is %DisposableStack.prototype.dispose%, defined in
The initial value of the @@toStringTag
property is the String value
This property has the attributes { [[Writable]]:
DisposableStack instances are
Internal Slot | Type | Description |
---|---|---|
[[DisposableState]] |
|
Governs how a disposable stack will react to incoming calls to its @@dispose method.
|
[[DisposeCapability]] |
a |
Resources to be disposed when the disposable stack is disposed. |
An AsyncDisposableStack is an object that can be used to contain one or more resources that should be asynchronously disposed together.
Any AsyncDisposableStack object is in one of two mutually exclusive states: disposed or pending:
d
is pending if d[Symbol.asyncDispose]()
has yet to be invoked for d
.d
is disposed if d[Symbol.asyncDispose]()
has already been invoked once for d
.The AsyncDisposableStack
extends
clause of a class definition. Subclass super
call to the AsyncDisposableStack AsyncDisposableStack
and AsyncDisposableStack.prototype
built-in methods.When the AsyncDisposableStack
function is called, the following steps are taken:
The AsyncDisposableStack
The AsyncDisposableStack prototype object:
AsyncDisposableStack.prototype.disposed
is an
When the disposeAsync
method is called, the following steps are taken:
When the use
function is called with one argument, the following steps are taken:
When the adopt
function is called with two arguments, the following steps are taken:
When the defer
function is called with one argument, the following steps are taken:
When the move
function is called, the following steps are taken:
The initial value of the @@asyncDispose property is %AsyncDisposableStack.prototype.disposeAsync%, defined in
The initial value of the @@toStringTag
property is the String value
This property has the attributes { [[Writable]]:
AsyncDisposableStack instances are
Internal Slot | Type | Description |
---|---|---|
[[AsyncDisposableState]] |
|
Governs how a disposable stack will react to incoming calls to its @@asyncDispose method.
|
[[DisposeCapability]] |
a |
Resources to be disposed when the disposable stack is disposed. |
The abstract operation GeneratorStart takes arguments generator and generatorBody (a
The abstract operation AsyncGeneratorStart takes arguments generator (an AsyncGenerator) and generatorBody (a
The abstract operation AsyncBlockStart takes arguments promiseCapability (a
During
During
© 2023 Ron Buckton, Ecma International
All Software contained in this document ("Software") is protected by copyright and is being made available under the "BSD License", included below. This Software may be subject to third party rights (rights from parties other than Ecma International), including patent rights, and no licenses under such third party rights are granted under this license even if the third party concerned is a member of Ecma International. SEE THE ECMA CODE OF CONDUCT IN PATENT MATTERS AVAILABLE AT https://ecma-international.org/memento/codeofconduct.htm FOR INFORMATION REGARDING THE LICENSING OF PATENT CLAIMS THAT ARE REQUIRED TO IMPLEMENT ECMA INTERNATIONAL STANDARDS.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE ECMA INTERNATIONAL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ECMA INTERNATIONAL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.