From 8bf37a53a1b68fc5a8a4ea69170f1773a68cd56d Mon Sep 17 00:00:00 2001 From: legendecas Date: Tue, 30 May 2023 22:47:37 +0800 Subject: [PATCH] fixup! --- README.md | 6 +++--- spec.html | 25 +++++++++++++------------ 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index af8c9b0..32cf6b8 100644 --- a/README.md +++ b/README.md @@ -172,7 +172,7 @@ interface AsyncLocalOptions { class AsyncSnapshot { constructor(); - run(fn: (...args: any[]) => R, ...args: any[]): R; + restore(fn: (...args: any[]) => R, ...args: any[]): R; } ``` @@ -225,7 +225,7 @@ function main() { // The snapshotDuringTop will restore all AsyncLocal to their snapshot // state and invoke the wrapped function. We pass a function which it will // invoke. - snapshotDuringTop.run(() => { + snapshotDuringTop.restore(() => { // Despite being lexically nested inside 'C', the snapshot restored us to // to the 'top' state. console.log(local.get()); // => 'top' @@ -249,7 +249,7 @@ export function enqueueCallback(cb: () => void) { // Each callback is stored with the context at which it was enqueued. const snapshot = new AsyncSnapshot(); queue.push(() => { - snapshot.run(cb); + snapshot.restore(cb); }); } diff --git a/spec.html b/spec.html index 015c236..858effe 100644 --- a/spec.html +++ b/spec.html @@ -40,7 +40,7 @@

The Async Context Mapping Record Specification Type

an AsyncLocal instance - The name of the AsyncLocal instance. + The AsyncLocal instance as the key in the mapping. @@ -51,7 +51,7 @@

The Async Context Mapping Record Specification Type

an ECMAScript language value - The default value of the AsyncLocal instance when no entry is found in the mapping. + The value of the AsyncLocal instance in the mapping. @@ -122,7 +122,7 @@

Agents

a List of Async Context Mapping Records - A map from the AsyncContext's key symbol to the saved ECMAScript language value. Every Record in the List contains a unique [[AsyncContextKey]]. + A map from the AsyncLocal instances to the saved ECMAScript language value. Every Record in the List contains a unique [[AsyncContextKey]]. The map is initially empty. @@ -167,7 +167,7 @@

JobCallback Records

a List of Async Context Mapping Records - A map from the AsyncContext's key symbol to the saved ECMAScript language value. Every Record in the List contains a unique [[AsyncContextKey]]. + A map from the AsyncLocal instances to the saved ECMAScript language value. Every Record in the List contains a unique [[AsyncContextKey]]. @@ -320,8 +320,8 @@

Properties of the AsyncSnapshot Prototype Object

  • does not have any of the other internal slots of AsyncSnapshot instances.
  • - -

    AsyncSnapshot.prototype.run ( _func_, ..._args_ )

    + +

    AsyncSnapshot.prototype.restore ( _func_, ..._args_ )

    This method performs the following steps when called:

    1. Let _asyncSnapshot_ be the *this* value. @@ -380,7 +380,7 @@

    The AsyncLocal Constructor

  • is the initial value of the *"AsyncLocal"* property of the global object.
  • creates and initializes a new AsyncLocal when called as a constructor.
  • is not intended to be called as a function and will throw an exception when called in that manner.
  • -
  • may be used as the value in an `extends` clause of a class definition. Subclass constructors that intend to inherit the specified AsyncLocal behaviour must include a `super` call to the AsyncLocal constructor to create and initialize the subclass instance with the internal state necessary to support the `AsyncLocal` and `AsyncLocal.prototype` built-in methods.
  • +
  • may be used as the value in an `extends` clause of a class definition. Subclass constructors that intend to inherit the specified AsyncLocal behaviour must include a `super` call to the AsyncLocal constructor to create and initialize the subclass instance with the internal state necessary to support the `AsyncLocal.prototype` built-in methods.
  • @@ -389,13 +389,14 @@

    AsyncLocal ( _options_ )

    1. If NewTarget is *undefined*, throw a *TypeError* exception. + 1. Let _nameStr_ be the empty String. + 1. Let _defaultValue_ be *undefined*. 1. If _options_ is an Object, then - 1. Let _name_ be ? Get(_options_, *"name"*). - 1. Let _nameStr_ be ? ToString(_name_). + 1. Let _namePresent_ be ? HasProperty(_options_, *"name"*). + 1. If _namePresent_ is *true*, then + 1. Let _name_ be ? Get(_options_, *"name"*). + 1. Let _nameStr_ be ? ToString(_name_). 1. Let _defaultValue_ be ? Get(_options_, *"defaultValue"*). - 1. Else, - 1. Let _nameStr_ be the empty String. - 1. Let _defaultValue_ be *undefined*. 1. Let _asyncLocal_ be ? OrdinaryCreateFromConstructor(NewTarget, *"%AsyncLocal.prototype%"*, « [[AsyncLocalName]], [[AsyncLocalDefaultValue]] »). 1. Set _asyncLocal_.[[AsyncLocalName]] to _nameStr_. 1. Set _asyncLocal_.[[AsyncLocalDefaultValue]] to _defaultValue_.