This proposal introduces syntax and semantics around explicit resource management.
See the proposal repository for background material and discussion.
Algorithm steps that say or are otherwise equivalent to:
mean the same thing as:
Algorithm steps that say or are otherwise equivalent to:
mean the same thing as:
Algorithm steps that say or are otherwise equivalent to:
mean the same thing as:
Where hygenicTemp is ephemeral and visible only in the steps pertaining to DisposeIfAbrupt.
Algorithm steps that say or are otherwise equivalent to:
mean the same thing as:
Where hygenicTemp is ephemeral and visible only in the steps pertaining to DisposeIfAbrupt.
Algorithm steps that say or are otherwise equivalent to:
mean the same thing as:
Algorithm steps that say or are otherwise equivalent to:
mean the same thing as:
DisposeIfAbrupt can be combined with the ? and ! prefixes, so that for example
means the same thing as:
| 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 const statement while in an async function, async generator, or the top level of a Module.
|
| @@dispose |
"Symbol.dispose"
|
A method that performs explicit resource cleanup on an object. Called by the semantics of the using const statement.
|
The abstract operation InitializeReferencedBinding takes arguments V and W, W, and hint. It performs the following steps when called:
See Common Resource Management Interfaces (
A DisposableResource is a
DisposableResource Records have the fields listed in
| Field Name | Value | Meaning |
|---|---|---|
| [[ResourceValue]] |
Any |
The value to be disposed. |
| [[Hint]] |
|
Indicates whether the resources was added by a using const statement (using await const statement ( |
| [[DisposeMethod]] |
A |
A |
The abstract operation CreateDisposableResource takes arguments V (an
The abstract operation GetDisposeMethod takes arguments V (an
The abstract operation Dispose takes arguments V (an
The abstract operation AddDisposableResource takes arguments disposable (an object with a [[DisposableResourceStack]] internal slot), V (an
The abstract operation DisposeResources takes arguments disposable (an object with a [[DisposableResourceStack]] internal slot or
AggregateError object.With parameters iteratorRecord and environment.
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 const statement (using await const statement ( |
| 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 [[DisposableResourceStack]] field, which is a using const and using await const statements 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 and, V (an
The InitializeBinding concrete method of an object and, V (an
In this specification, all uses of CreateMutableBinding for object Environment Records are immediately followed by a call to InitializeBinding for the same name. Hence, this specification does not explicitly track the initialization state of bindings in object Environment Records.
The InitializeBinding concrete method of a global and, V (an
The [[Call]] internal method of an ECMAScript
When calleeContext is removed from the
No matter how control leaves the
await, let hint be A const declaration.
With parameter hint (either
A const declaration.
With parameters value, environment, and excludedNames.
With parameters value, environment, and propertyName.
When
With parameter labelSet.
for StatementThe abstract operation ForBodyEvaluation takes arguments test, increment, stmt, perIterationBindings, and labelSet. It performs the following steps when called:
The abstract operation CreatePerIterationEnvironment takes argument perIterationBindings. It performs the following steps when called:
for-in, for-of, and for-await-of StatementsThe abstract operation ForIn/OfHeadEvaluation takes arguments uninitializedBoundNames, expr, and iterationKind (either
The abstract operation ForIn/OfBodyEvaluation takes arguments lhs, stmt, iteratorRecord, iterationKind, lhsKind (either
switch StatementNo matter how control leaves the
With parameters functionObject and argumentsList (a
With parameters functionObject and argumentsList (a
With parameter functionObject.
The abstract operation IsInTailPosition takes argument call (a
Tail Position calls are only defined in
With parameter call.
call is a
The ExecuteModule concrete method of a
The following steps are taken:
"return").The following steps are taken:
"return").An interface is a set of property keys whose associated values match a specific specification. Any object that provides all the properties as described by an interface's specification conforms to that interface. An interface is not represented by a distinct object. There may be many separately implemented objects that conform to any interface. An individual object may conform to multiple interfaces.
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 handled, streams, host objects, etc. When an exception is thrown from this method, it typically means that the resource could not be explicitly freed. 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 handled, streams, host objects, etc. When an exception is thrown from this method, it typically means that the resource could not be explicitly freed. An AsyncDisposable object is not considered "disposed" until the resulting Promise has been fulfilled. 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 Disposable is an object that can be used to contain one or more resources that should be disposed together.
Any Disposable 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 Disposable
extends clause of a class definition. Subclass constructors that intend to inherit the specified Disposable behaviour must include a super call to the Disposable Disposable and Disposable.prototype built-in methods.When the Disposable function is called with argument onDispose, the following steps are taken:
The Disposable
The from function returns a new disposable that can be used to dispose of each resource in the provided iterable, in reverse order. Exceptions thrown when the resources are disposed are caught and rethrown as an AggregateError.
Errors that occur during the calls to
Errors that occur during the call to
The Disposable prototype object:
When the @@dispose method is called, the following steps are taken:
The initial value of the @@toStringTag property is the String value
This property has the attributes { [[Writable]]:
Disposable instances are ordinary objects that inherit properties from the
| Internal Slot | Description |
|---|---|
| [[DisposableState]] |
One of @@dispose method.
|
| [[DisposableResourceStack]] |
A |
An AsyncDisposable is an object that can be used to contain one or more resources that should be disposed together.
Any AsyncDisposable 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 AsyncDisposable
extends clause of a class definition. Subclass constructors that intend to inherit the specified AsyncDisposable behaviour must include a super call to the AsyncDisposable AsyncDisposable and AsyncDisposable.prototype built-in methods.When the AsyncDisposable function is called with argument onAsyncDispose, the following steps are taken:
The AsyncDisposable
The from function returns a promise for a new async disposable that can be used to dispose of each resource in the provided iterable, in reverse order. Exceptions thrown when the resources are disposed are caught and rethrown as an AggregateError.
Errors that occur during the calls to
Errors that occur during the call to
The AsyncDisposable prototype object:
When the @@asyncDispose method is called, the following steps are taken:
The initial value of the @@toStringTag property is the String value
This property has the attributes { [[Writable]]:
AsyncDisposable instances are ordinary objects that inherit properties from the
| Internal Slot | Description |
|---|---|
| [[DisposableState]] |
One of @@dispose method.
|
| [[DisposableResourceStack]] |
A |
The abstract operation GeneratorStart takes arguments generator and generatorBody (a
The abstract operation AsyncGeneratorStart takes arguments generator and generatorBody (a
The abstract operation AsyncFunctionStart takes arguments promiseCapability (a PromiseCapability
© 2021 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.