?
u
/
This proposal introduces syntax and semantics around explicit resource management.
See the proposal repository for background material and discussion.
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 await using 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 (a
See Common Resource Management Interfaces (
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. |
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 (await using 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
@@dispose
method will not be awaited and that any exception thrown will not be thrown synchronously.The abstract operation Dispose takes arguments V (an Object or
The abstract operation DisposeResources takes arguments disposeCapability (a
await using
declaration.The
It is defined piecewise over the following productions:
The
It is not necessary to treat export default
The
The
The
The
When
It is defined piecewise over the following productions:
The
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 (await using 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 await using
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 NewDeclarativeEnvironment takes argument E (an
The abstract operation NewFunctionEnvironment takes arguments F (an ECMAScript function) and newTarget (an Object or
The abstract operation NewModuleEnvironment takes argument E (an
The abstract operation FunctionDeclarationInstantiation takes arguments func (a
When an
It performs the following steps when called:
eval
in eval
.
When processing an instance of the production
the interpretation of
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
, using
, or await using
declaration.
The
The
When
It is defined piecewise over the following productions:
for
StatementThe
for-in
, for-of
, and for-await-of
StatementsThis section is extended by Annex
The
The abstract operation ForIn/OfBodyEvaluation takes arguments lhs (a
switch
StatementNo matter how control leaves the
The
The
An alternative semantics is provided in
A
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
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 (a
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
(
This method performs the following steps when called:
"return"
).The value of the
The method performs the following steps when called:
"return"
).The value of the
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.This function performs the following steps when called:
The DisposableStack
The initial value of DisposableStack.prototype
is the
This property has the attributes { [[Writable]]:
The DisposableStack prototype object:
This method performs the following steps when called:
This method performs the following steps when called:
This method performs the following steps when called:
DisposableStack.prototype.disposed
is an
This method performs the following steps when called:
This method performs the following steps when called:
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 |
Holds the stack of disposable resources. |
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.This function performs the following steps when called:
The AsyncDisposableStack
The initial value of AsyncDisposableStack.prototype
is the
This property has the attributes { [[Writable]]:
The AsyncDisposableStack prototype object:
This method performs the following steps when called:
This method performs the following steps when called:
This method performs the following steps when called:
AsyncDisposableStack.prototype.disposed
is an
This method performs the following steps when called:
This method performs the following steps when called:
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 an async disposable stack will react to incoming calls to its @@asyncDispose method.
|
[[DisposeCapability]] |
a |
Resources to be disposed when the disposable stack is disposed. |
During
During
© 2024 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.