?
u
/
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 hygienicTemp 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 hygienicTemp 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 declaration 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 declaration.
|
The abstract operation InitializeReferencedBinding takes arguments V and W and returns either a
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 resources was added by a using declaration (using await declaration ( |
[[DisposeMethod]] |
A |
A |
The abstract operation AddDisposableResource takes arguments disposable (an object with a [[DisposableResourceStack]] internal slot), V (an
The abstract operation CreateDisposableResource takes arguments V (an Object or
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 disposable (an object with a [[DisposableResourceStack]] internal slot or
The
It is defined piecewise over the following productions:
The
It is not necessary to treat export default
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 [[DisposableResourceStack]] field, which is a using
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
No matter how control leaves the
A const
declaration.
The
A const
declaration.
The
The
When
It is defined piecewise over the following productions:
for
StatementThe
The abstract operation ForBodyEvaluation takes arguments test, increment, stmt, perIterationBindings, and labelSet and returns either a
The abstract operation CreatePerIterationEnvironment takes argument perIterationBindings and returns either a
for-in
, for-of
, and for-await-of
StatementsThe abstract operation ForIn/OfHeadEvaluation takes arguments uninitializedBoundNames, expr, and iterationKind (
The abstract operation ForIn/OfBodyEvaluation takes arguments lhs, stmt, iteratorRecord, iterationKind, lhsKind (
switch
StatementNo matter how control leaves the
The
The
The
call is a
A using
or using await
declaration that precedes a call in the same
A potential tail position call that is immediately followed by return
The
The ExecuteModule concrete method of a
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
DisposableStack[@@species]
is an
The value of the
The DisposableStack prototype object:
DisposableStack.prototype.dispose
is an
A DisposableStack dispose function is an anonymous built-in
When a DisposableStack dispose function is called, the following steps are taken:
When the use
function is called with one or two arguments, the following steps are taken:
The onDispose argument is optional. If it is not provided,
A DisposableStack callback function is an anonymous built-in
When a DisposableStack callback function is called, the following steps are taken:
When the move
function is called, the following steps are taken:
When the @@dispose
method is called, the following steps are taken:
The value of the
The initial value of the @@toStringTag
property is the String value
This property has the attributes { [[Writable]]:
DisposableStack instances are
Internal Slot | Description |
---|---|
[[DisposableState]] |
One of @@dispose method.
|
[[DisposableResourceStack]] |
A |
[[BoundDispose]] |
Either DisposableStack.prototype.dispose accessor ( |
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
AsyncDisposableStack[@@species]
is an
The value of the
The AsyncDisposableStack prototype object:
AsyncDisposableStack.prototype.disposeAsync
is an
An AsyncDisposableStack dispose function is an anonymous built-in function that has [[AsyncDisposableStack]] and [[DisposeAsyncMethod]] internal slots.
When an AsyncDisposableStack dispose function is called, the following steps are taken:
When the use
function is called with one or two arguments, the following steps are taken:
The onDisposeAsync argument is optional. If it is not provided,
An AsyncDisposableStack callback function is an anonymous built-in function that has [[Argument]] and [[OnDisposeAsyncCallback]] internal slots.
When an AsyncDisposableStack callback function is called, the following steps are taken:
When the move
function is called, the following steps are taken:
When the @@asyncDispose
method is called, the following steps are taken:
The value of the
The initial value of the @@toStringTag
property is the String value
This property has the attributes { [[Writable]]:
AsyncDisposableStack instances are
Internal Slot | Description |
---|---|
[[AsyncDisposableState]] |
One of @@asyncDispose method.
|
[[DisposableResourceStack]] |
A |
[[BoundDisposeAsync]] |
Either AsyncDisposableStack.prototype.disposeAsync accessor ( |
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
© 2022 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.