async-browser-context 0.2.3 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +102 -0
- package/README.md +45 -30
- package/dist/babel/async-generator-helpers.d.ts +6 -6
- package/dist/babel/async-generator-helpers.d.ts.map +1 -1
- package/dist/babel/async-generator-helpers.js +33 -22
- package/dist/babel/async-generator-helpers.js.map +1 -1
- package/dist/babel/async-generator-resources.d.ts +14 -0
- package/dist/babel/async-generator-resources.d.ts.map +1 -0
- package/dist/babel/async-generator-resources.js +38 -0
- package/dist/babel/async-generator-resources.js.map +1 -0
- package/dist/babel/bind-generators.d.ts +1 -1
- package/dist/babel/bind-generators.d.ts.map +1 -1
- package/dist/babel/bind-generators.js +88 -44
- package/dist/babel/bind-generators.js.map +1 -1
- package/dist/babel/name-coroutines.d.ts +14 -8
- package/dist/babel/name-coroutines.d.ts.map +1 -1
- package/dist/babel/name-coroutines.js +160 -39
- package/dist/babel/name-coroutines.js.map +1 -1
- package/dist/babel/preset.d.ts +24 -13
- package/dist/babel/preset.d.ts.map +1 -1
- package/dist/babel/preset.js +37 -9
- package/dist/babel/preset.js.map +1 -1
- package/dist/babel/runtime-calls.d.ts +22 -0
- package/dist/babel/runtime-calls.d.ts.map +1 -0
- package/dist/babel/runtime-calls.js +69 -0
- package/dist/babel/runtime-calls.js.map +1 -0
- package/dist/babel/skip-runtime.d.ts +18 -11
- package/dist/babel/skip-runtime.d.ts.map +1 -1
- package/dist/babel/skip-runtime.js +52 -16
- package/dist/babel/skip-runtime.js.map +1 -1
- package/dist/babel/static-members.d.ts +4 -0
- package/dist/babel/static-members.d.ts.map +1 -0
- package/dist/babel/static-members.js +112 -0
- package/dist/babel/static-members.js.map +1 -0
- package/dist/core/async-generator.d.ts +51 -13
- package/dist/core/async-generator.d.ts.map +1 -1
- package/dist/core/async-generator.js +255 -58
- package/dist/core/async-generator.js.map +1 -1
- package/dist/core/async-local-storage.d.ts +3 -0
- package/dist/core/async-local-storage.d.ts.map +1 -1
- package/dist/core/async-local-storage.js +3 -0
- package/dist/core/async-local-storage.js.map +1 -1
- package/dist/core/callback-hook.d.ts +3 -3
- package/dist/core/coroutine.d.ts +6 -2
- package/dist/core/coroutine.d.ts.map +1 -1
- package/dist/core/coroutine.js +106 -44
- package/dist/core/coroutine.js.map +1 -1
- package/dist/core/function-name.d.ts +9 -0
- package/dist/core/function-name.d.ts.map +1 -0
- package/dist/core/function-name.js +12 -0
- package/dist/core/function-name.js.map +1 -0
- package/dist/core/hooks.d.ts +2 -1
- package/dist/core/hooks.d.ts.map +1 -1
- package/dist/core/hooks.js +21 -6
- package/dist/core/hooks.js.map +1 -1
- package/dist/core/snapshot.d.ts +2 -1
- package/dist/core/snapshot.d.ts.map +1 -1
- package/dist/core/snapshot.js +7 -3
- package/dist/core/snapshot.js.map +1 -1
- package/dist/core/store.d.ts +28 -0
- package/dist/core/store.d.ts.map +1 -1
- package/dist/core/store.js +90 -20
- package/dist/core/store.js.map +1 -1
- package/dist/core/variable.d.ts +2 -1
- package/dist/core/variable.d.ts.map +1 -1
- package/dist/core/variable.js +5 -2
- package/dist/core/variable.js.map +1 -1
- package/dist/node/index.d.ts +10 -4
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +51 -16
- package/dist/node/index.js.map +1 -1
- package/dist/node/runtime.d.ts +7 -6
- package/dist/node/runtime.d.ts.map +1 -1
- package/dist/node/runtime.js +29 -16
- package/dist/node/runtime.js.map +1 -1
- package/dist/opentelemetry/context-manager.d.ts.map +1 -1
- package/dist/opentelemetry/context-manager.js +172 -13
- package/dist/opentelemetry/context-manager.js.map +1 -1
- package/dist/patches/callbacks.d.ts.map +1 -1
- package/dist/patches/callbacks.js +84 -29
- package/dist/patches/callbacks.js.map +1 -1
- package/dist/patches/events.d.ts.map +1 -1
- package/dist/patches/events.js +203 -91
- package/dist/patches/events.js.map +1 -1
- package/dist/patches/handler-interfaces.d.ts +3 -2
- package/dist/patches/handler-interfaces.d.ts.map +1 -1
- package/dist/patches/handler-interfaces.js +3 -2
- package/dist/patches/handler-interfaces.js.map +1 -1
- package/dist/patches/promise.d.ts +3 -0
- package/dist/patches/promise.d.ts.map +1 -1
- package/dist/patches/promise.js +13 -5
- package/dist/patches/promise.js.map +1 -1
- package/dist/patches/streams.d.ts.map +1 -1
- package/dist/patches/streams.js +36 -16
- package/dist/patches/streams.js.map +1 -1
- package/dist/patches/timers.d.ts.map +1 -1
- package/dist/patches/timers.js +17 -5
- package/dist/patches/timers.js.map +1 -1
- package/dist/patches/to-string.d.ts +4 -0
- package/dist/patches/to-string.d.ts.map +1 -1
- package/dist/patches/to-string.js +12 -6
- package/dist/patches/to-string.js.map +1 -1
- package/dist/runtime.d.ts +3 -3
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +3 -3
- package/dist/runtime.js.map +1 -1
- package/dist/vite/plugin.d.ts +7 -2
- package/dist/vite/plugin.d.ts.map +1 -1
- package/dist/vite/plugin.js +30 -6
- package/dist/vite/plugin.js.map +1 -1
- package/package.json +49 -25
- package/src/babel/async-generator-helpers.ts +34 -23
- package/src/babel/async-generator-resources.ts +40 -0
- package/src/babel/bind-generators.ts +91 -47
- package/src/babel/name-coroutines.ts +170 -41
- package/src/babel/preset.ts +47 -15
- package/src/babel/runtime-calls.ts +73 -0
- package/src/babel/skip-runtime.ts +58 -18
- package/src/babel/static-members.ts +117 -0
- package/src/core/async-generator.ts +273 -62
- package/src/core/async-local-storage.ts +3 -0
- package/src/core/callback-hook.ts +3 -3
- package/src/core/coroutine.ts +104 -43
- package/src/core/function-name.ts +11 -0
- package/src/core/hooks.ts +23 -6
- package/src/core/snapshot.ts +8 -3
- package/src/core/store.ts +107 -21
- package/src/core/variable.ts +6 -2
- package/src/node/index.ts +62 -19
- package/src/node/runtime.ts +33 -15
- package/src/opentelemetry/context-manager.ts +188 -13
- package/src/patches/callbacks.ts +87 -30
- package/src/patches/events.ts +249 -103
- package/src/patches/handler-interfaces.ts +3 -2
- package/src/patches/promise.ts +17 -13
- package/src/patches/streams.ts +36 -16
- package/src/patches/timers.ts +17 -5
- package/src/patches/to-string.ts +12 -6
- package/src/runtime.ts +3 -3
- package/src/vite/plugin.ts +38 -8
|
@@ -2,17 +2,23 @@
|
|
|
2
2
|
* The async generators of transformed code. `@babel/plugin-transform-async-generator-functions`
|
|
3
3
|
* changes each async generator into a sync generator and its helper `wrapAsyncGenerator`.
|
|
4
4
|
* The helper continued each step in a `then` callback, and a `then` callback is slow in
|
|
5
|
-
* Firefox. The preset replaces the helper with `asyncGenerator` of the runtime
|
|
6
|
-
*
|
|
7
|
-
* continues each step with a native `await`.
|
|
5
|
+
* Firefox. The preset replaces the helper with `asyncGenerator` of the runtime. It also takes
|
|
6
|
+
* the helpers `OverloadYield`, `awaitAsyncGenerator` and `asyncGeneratorDelegate` from this
|
|
7
|
+
* module. The driver in this module then continues each step with a native `await`.
|
|
8
8
|
*
|
|
9
9
|
* The protocol is the protocol of the Babel 8 helper: the body gives
|
|
10
10
|
* `new OverloadYield(value, 0)` for an `await`, and `new OverloadYield(promise, 1)` for a
|
|
11
|
-
* step of `yield*`. Each other value is a `yield`.
|
|
11
|
+
* step of `yield*`. Each other value is a `yield`. Where the helper differs from a native async
|
|
12
|
+
* generator, the driver does as the native generator. Thus `return()` at a `yield` awaits its
|
|
13
|
+
* value first, and a request on a complete generator settles at once. The delegate of this
|
|
14
|
+
* module also gives kind 2 for a step of `yield*` after `return()`.
|
|
12
15
|
*/
|
|
16
|
+
/** The Promise of the time when the module loads, for the rejections of the methods. */
|
|
17
|
+
const NativePromise = Promise;
|
|
13
18
|
/**
|
|
14
|
-
* The value that the body gives for an `await` (kind 0)
|
|
15
|
-
*
|
|
19
|
+
* The value that the body gives for an `await` (kind 0), for a step of `yield*` (kind 1), or
|
|
20
|
+
* for a step of `yield*` after `return()` (kind 2). The helpers `awaitAsyncGenerator` and
|
|
21
|
+
* `asyncGeneratorDelegate` make it with `new`.
|
|
16
22
|
*/
|
|
17
23
|
export class OverloadYield {
|
|
18
24
|
v;
|
|
@@ -22,90 +28,281 @@ export class OverloadYield {
|
|
|
22
28
|
this.k = kind;
|
|
23
29
|
}
|
|
24
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* The error of a step of `yield*` that was rejected. The driver gives it back to the delegate,
|
|
33
|
+
* and the delegate throws the error. Thus the error goes into the body at the `yield*`, also
|
|
34
|
+
* when the delegate has no `throw` method.
|
|
35
|
+
*/
|
|
36
|
+
class DelegateRejection {
|
|
37
|
+
error;
|
|
38
|
+
constructor(error) {
|
|
39
|
+
this.error = error;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The helper `awaitAsyncGenerator` of Babel: the body gives its value for an `await`. The preset
|
|
44
|
+
* gives this function in place of the helper of Babel. Thus the marker is always the class of this
|
|
45
|
+
* module, also when `@babel/plugin-transform-runtime` gives the other helpers.
|
|
46
|
+
*/
|
|
47
|
+
export function awaitAsyncGenerator(value) {
|
|
48
|
+
return new OverloadYield(value, 0);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The helper `asyncGeneratorDelegate` of Babel 8: a sync iterator for `yield*` in an async
|
|
52
|
+
* generator. Each step of the inner async iterator becomes `new OverloadYield(promise, 1)`, or
|
|
53
|
+
* kind 2 after `return()`. The driver awaits the promise, and gives a copy of its result back to
|
|
54
|
+
* the iterator. After kind 2, the driver gives it back with `return()`. Thus a complete inner
|
|
55
|
+
* iterator ends the body, as with a native `yield*`.
|
|
56
|
+
*/
|
|
57
|
+
export function asyncGeneratorDelegate(inner) {
|
|
58
|
+
const iterator = inner;
|
|
59
|
+
let waiting = false;
|
|
60
|
+
const pump = (key, value) => {
|
|
61
|
+
waiting = true;
|
|
62
|
+
const promise = new NativePromise((resolve) => {
|
|
63
|
+
resolve(Reflect.apply(iterator[key], inner, [value]));
|
|
64
|
+
});
|
|
65
|
+
return { done: false, value: new OverloadYield(promise, key === "return" ? 2 : 1) };
|
|
66
|
+
};
|
|
67
|
+
const delegate = {
|
|
68
|
+
[Symbol.iterator]() { return this; },
|
|
69
|
+
next(value) {
|
|
70
|
+
if (!waiting) {
|
|
71
|
+
return pump("next", value);
|
|
72
|
+
}
|
|
73
|
+
waiting = false;
|
|
74
|
+
if (value instanceof DelegateRejection) {
|
|
75
|
+
throw value.error;
|
|
76
|
+
}
|
|
77
|
+
return value;
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
delegate["throw"] = (value) => {
|
|
81
|
+
if (typeof iterator.throw === "function") {
|
|
82
|
+
return pump("throw", value);
|
|
83
|
+
}
|
|
84
|
+
// Without a throw method, a native yield* closes the inner iterator and awaits its return()
|
|
85
|
+
// (AsyncIteratorClose). An error of return() goes into the body, else a TypeError.
|
|
86
|
+
waiting = true;
|
|
87
|
+
const closed = new NativePromise((resolve) => {
|
|
88
|
+
resolve(typeof iterator.return === "function" ? Reflect.apply(iterator.return, inner, []) : undefined);
|
|
89
|
+
}).then((result) => {
|
|
90
|
+
if (typeof iterator.return === "function" && !isObject(result)) {
|
|
91
|
+
throw new TypeError("The result of return() of the iterator of yield* is not an object");
|
|
92
|
+
}
|
|
93
|
+
throw new TypeError("The iterator of yield* has no throw method");
|
|
94
|
+
});
|
|
95
|
+
return { done: false, value: new OverloadYield(closed, 1) };
|
|
96
|
+
};
|
|
97
|
+
if (typeof iterator.return === "function") {
|
|
98
|
+
delegate["return"] = (value) => {
|
|
99
|
+
if (waiting) {
|
|
100
|
+
waiting = false;
|
|
101
|
+
return value;
|
|
102
|
+
}
|
|
103
|
+
return pump("return", value);
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
return delegate;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* A value that is not a thenable, in a box. The browser runtime reads the `then` property of an
|
|
110
|
+
* awaited object one time, in the context of the body. When the object has no `then` method,
|
|
111
|
+
* the driver awaits the box. Thus the engine does not read `then` a second time, and the
|
|
112
|
+
* `await` takes the same microtask turns.
|
|
113
|
+
*/
|
|
114
|
+
export class PlainValue {
|
|
115
|
+
value;
|
|
116
|
+
constructor(value) {
|
|
117
|
+
this.value = value;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/** This function gives the value in a box, or the value itself. */
|
|
121
|
+
export function unbox(value) {
|
|
122
|
+
return value instanceof PlainValue ? value.value : value;
|
|
123
|
+
}
|
|
124
|
+
/** This function gives `true` for a value that can have properties: an object or a function. */
|
|
125
|
+
export function isObject(value) {
|
|
126
|
+
return (typeof value === "object" && value !== null) || typeof value === "function";
|
|
127
|
+
}
|
|
25
128
|
/** The key of the request function of each async generator object. */
|
|
26
129
|
const INVOKE = Symbol("async-browser-context/invoke");
|
|
27
|
-
function
|
|
28
|
-
|
|
130
|
+
/** This function starts a request. For an object that is not an async generator of the runtime, it gives a rejected promise, as a native method does. */
|
|
131
|
+
function request(target, key, argument) {
|
|
132
|
+
const invoke = typeof target === "object" && target !== null ? target[INVOKE] : undefined;
|
|
29
133
|
if (invoke === undefined) {
|
|
30
|
-
|
|
134
|
+
return NativePromise.reject(new TypeError(`AsyncGenerator.prototype.${key} started on an object that is not an async generator`));
|
|
135
|
+
}
|
|
136
|
+
return invoke(key, argument);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* This function gives %AsyncIteratorPrototype% of the engine from an async generator function.
|
|
140
|
+
* The prototype gives `Symbol.asyncIterator`, `Symbol.asyncDispose` and the async iterator
|
|
141
|
+
* helpers. If a compiler changed the async generator function, the function gives `undefined`.
|
|
142
|
+
*
|
|
143
|
+
* @internal
|
|
144
|
+
*/
|
|
145
|
+
export function asyncIteratorPrototypeOf(generatorFunction) {
|
|
146
|
+
let prototype;
|
|
147
|
+
try {
|
|
148
|
+
prototype = Object.getPrototypeOf(Object.getPrototypeOf(generatorFunction.prototype));
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
// A function without a prototype object, for example an arrow function
|
|
152
|
+
return undefined;
|
|
153
|
+
}
|
|
154
|
+
return prototype !== null && typeof prototype[Symbol.asyncIterator] === "function" ? prototype : undefined;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* This function makes the prototype of the async generator objects of transformed code. Its
|
|
158
|
+
* methods are not enumerable, as native methods. Without `parent`, the prototype inherits from
|
|
159
|
+
* `Object.prototype` and gets its own `Symbol.asyncIterator` method.
|
|
160
|
+
*
|
|
161
|
+
* @internal
|
|
162
|
+
*/
|
|
163
|
+
export function makeAsyncGeneratorPrototype(parent) {
|
|
164
|
+
const prototype = Object.create(parent ?? Object.prototype);
|
|
165
|
+
const methods = {
|
|
166
|
+
next(value) { return request(this, "next", value); },
|
|
167
|
+
throw(error) { return request(this, "throw", error); },
|
|
168
|
+
return(value) { return request(this, "return", value); },
|
|
169
|
+
};
|
|
170
|
+
for (const key of ["next", "throw", "return"]) {
|
|
171
|
+
Object.defineProperty(prototype, key, { value: methods[key], writable: true, configurable: true });
|
|
172
|
+
}
|
|
173
|
+
if (parent === undefined) {
|
|
174
|
+
Object.defineProperty(prototype, Symbol.asyncIterator, { value: function asyncIterator() { return this; }, writable: true, configurable: true });
|
|
175
|
+
}
|
|
176
|
+
Object.defineProperty(prototype, Symbol.toStringTag, { value: "AsyncGenerator", configurable: true });
|
|
177
|
+
return prototype;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* This function gives %AsyncIteratorPrototype% of the engine, or `undefined`. Another preset in
|
|
181
|
+
* the same Babel configuration, for example `next/babel` with its preset-env, can change the
|
|
182
|
+
* async generator below in the runtime itself. Its helper is then a module that loads at this
|
|
183
|
+
* time, and the call can throw. The catch keeps the runtime available, with a prototype
|
|
184
|
+
* without the parent of the engine.
|
|
185
|
+
*/
|
|
186
|
+
function engineAsyncIteratorPrototype() {
|
|
187
|
+
try {
|
|
188
|
+
return asyncIteratorPrototypeOf(async function* () {
|
|
189
|
+
// The directive tells the Babel preset not to change this function (src/babel/skip-runtime.ts)
|
|
190
|
+
// Stryker disable next-line all: the directive matters only when a bundler applies the preset to the runtime
|
|
191
|
+
"async-browser-context runtime";
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
catch {
|
|
195
|
+
return undefined;
|
|
31
196
|
}
|
|
32
|
-
return invoke;
|
|
33
197
|
}
|
|
34
198
|
/** The prototype of the async generator objects of transformed code. */
|
|
35
|
-
const AsyncGeneratorPrototype =
|
|
36
|
-
next(value) {
|
|
37
|
-
return invokeOf(this)("next", value);
|
|
38
|
-
},
|
|
39
|
-
throw(error) {
|
|
40
|
-
return invokeOf(this)("throw", error);
|
|
41
|
-
},
|
|
42
|
-
return(value) {
|
|
43
|
-
return invokeOf(this)("return", value);
|
|
44
|
-
},
|
|
45
|
-
[Symbol.asyncIterator]() {
|
|
46
|
-
return this;
|
|
47
|
-
},
|
|
48
|
-
[Symbol.toStringTag]: "AsyncGenerator",
|
|
49
|
-
};
|
|
199
|
+
const AsyncGeneratorPrototype = makeAsyncGeneratorPrototype(engineAsyncIteratorPrototype());
|
|
50
200
|
/**
|
|
51
201
|
* This function makes an async generator object. The object queues the requests of the
|
|
52
|
-
* consumer, and starts one request at a time, as
|
|
53
|
-
* driver: the Node.js runtime starts it in the context of the generator.
|
|
202
|
+
* consumer, and starts one request at a time, as a native async generator does. `enter`
|
|
203
|
+
* starts the driver: the Node.js runtime starts it in the context of the generator.
|
|
54
204
|
*/
|
|
55
|
-
export function createAsyncGenerator(step,
|
|
205
|
+
export function createAsyncGenerator(step, PromiseConstructor, enter = (start) => start(), prepare = (value) => value) {
|
|
56
206
|
let first;
|
|
57
207
|
let last;
|
|
208
|
+
/** `true` after the first step of the body. While a step operates, the requests wait in the queue. */
|
|
209
|
+
let started = false;
|
|
210
|
+
/** `true` when the body is complete. */
|
|
211
|
+
let complete = false;
|
|
58
212
|
/** This function starts the requests in the queue, one after the other, until the queue is empty. */
|
|
59
213
|
const run = async (key, argument) => {
|
|
60
214
|
// The directive tells the Babel preset not to change this function (src/babel/skip-runtime.ts)
|
|
215
|
+
// Stryker disable next-line all: the directive matters only when a bundler applies the preset to the runtime
|
|
61
216
|
"async-browser-context runtime";
|
|
62
217
|
let resumed = false;
|
|
63
218
|
for (;;) {
|
|
64
219
|
let failed = false;
|
|
65
220
|
let settled;
|
|
66
|
-
let done = false;
|
|
67
221
|
try {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
try {
|
|
74
|
-
value = await (overloaded ? yielded.v : yielded);
|
|
222
|
+
if (complete || (!started && key !== "next")) {
|
|
223
|
+
// The body does not operate: it is complete, or return() or throw() came before the start
|
|
224
|
+
complete = true;
|
|
225
|
+
if (key === "throw") {
|
|
226
|
+
throw argument;
|
|
75
227
|
}
|
|
76
|
-
|
|
228
|
+
if (key === "return") {
|
|
229
|
+
// As AsyncGeneratorAwaitReturn, return() awaits its value
|
|
230
|
+
settled = await argument;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
started = true;
|
|
235
|
+
if (key === "return") {
|
|
236
|
+
// At a yield, return() awaits its value first. A rejection goes into the body at the yield.
|
|
237
|
+
try {
|
|
238
|
+
argument = unbox(await prepare(argument));
|
|
239
|
+
}
|
|
240
|
+
catch (error) {
|
|
241
|
+
key = "throw";
|
|
242
|
+
argument = error;
|
|
243
|
+
}
|
|
77
244
|
resumed = true;
|
|
78
|
-
key = "throw";
|
|
79
|
-
result = step("throw", error, true);
|
|
80
|
-
continue;
|
|
81
245
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
246
|
+
let result = step(key, argument, resumed);
|
|
247
|
+
// return() at a yield already awaited its value. If the body completes with that value, a native generator does not await it again.
|
|
248
|
+
if (key === "return" && result.done === true && result.value === argument) {
|
|
249
|
+
settled = argument;
|
|
250
|
+
complete = true;
|
|
251
|
+
result = { done: true, value: undefined };
|
|
252
|
+
}
|
|
253
|
+
for (;;) {
|
|
254
|
+
if (complete) {
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
const yielded = result.value;
|
|
258
|
+
const overloaded = yielded instanceof OverloadYield;
|
|
259
|
+
let value;
|
|
260
|
+
try {
|
|
261
|
+
value = unbox(await prepare(overloaded ? yielded.v : yielded));
|
|
262
|
+
}
|
|
263
|
+
catch (error) {
|
|
264
|
+
// The error goes into the body at the await or the yield. The delegate of a yield* throws it.
|
|
265
|
+
result = overloaded && yielded.k !== 0 ? step("next", new DelegateRejection(error), true) : step("throw", error, true);
|
|
88
266
|
continue;
|
|
89
267
|
}
|
|
90
|
-
|
|
268
|
+
resumed = true;
|
|
269
|
+
if (overloaded) {
|
|
270
|
+
const resumeKey = yielded.k === 2 ? "return" : "next";
|
|
271
|
+
if (yielded.k === 0 || !isObject(value)) {
|
|
272
|
+
// The value of an await. For a result of yield* that is not an object, the body throws a TypeError.
|
|
273
|
+
result = step(resumeKey, value, true);
|
|
274
|
+
continue;
|
|
275
|
+
}
|
|
276
|
+
// A step of yield*. As a native yield*, the driver reads done and value one time, and the body gets a copy.
|
|
277
|
+
// The driver does not compare the result of the body with the copy, because the yield* of WebKit makes a new object.
|
|
278
|
+
const done = Boolean(value.done);
|
|
279
|
+
const item = value.value;
|
|
280
|
+
result = step(resumeKey, { value: item, done }, true);
|
|
281
|
+
if (done) {
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
// The body gives the result back. Its value is not awaited, as with a native yield*.
|
|
285
|
+
value = item;
|
|
286
|
+
}
|
|
287
|
+
settled = value;
|
|
288
|
+
complete = result.done === true;
|
|
289
|
+
break;
|
|
91
290
|
}
|
|
92
|
-
settled = value;
|
|
93
|
-
done = result.done === true;
|
|
94
|
-
break;
|
|
95
291
|
}
|
|
96
292
|
}
|
|
97
293
|
catch (error) {
|
|
294
|
+
complete = true;
|
|
98
295
|
failed = true;
|
|
99
296
|
settled = error;
|
|
100
297
|
}
|
|
101
298
|
// A request always waits in the queue while the driver runs
|
|
102
|
-
const
|
|
103
|
-
first =
|
|
299
|
+
const current = first;
|
|
300
|
+
first = current.next;
|
|
104
301
|
if (failed) {
|
|
105
|
-
|
|
302
|
+
current.reject(settled);
|
|
106
303
|
}
|
|
107
304
|
else {
|
|
108
|
-
|
|
305
|
+
current.resolve({ value: settled, done: complete });
|
|
109
306
|
}
|
|
110
307
|
if (first === undefined) {
|
|
111
308
|
last = undefined;
|
|
@@ -115,14 +312,14 @@ export function createAsyncGenerator(step, NativePromise, enter = (start) => sta
|
|
|
115
312
|
argument = first.argument;
|
|
116
313
|
}
|
|
117
314
|
};
|
|
118
|
-
const invoke = (key, argument) => new
|
|
119
|
-
const
|
|
315
|
+
const invoke = (key, argument) => new PromiseConstructor((resolve, reject) => {
|
|
316
|
+
const added = { key, argument, resolve, reject, next: undefined };
|
|
120
317
|
if (last === undefined) {
|
|
121
|
-
first = last =
|
|
318
|
+
first = last = added;
|
|
122
319
|
void enter(() => run(key, argument));
|
|
123
320
|
}
|
|
124
321
|
else {
|
|
125
|
-
last = last.next =
|
|
322
|
+
last = last.next = added;
|
|
126
323
|
}
|
|
127
324
|
});
|
|
128
325
|
const generator = Object.create(AsyncGeneratorPrototype);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"async-generator.js","sourceRoot":"","sources":["../../src/core/async-generator.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"async-generator.js","sourceRoot":"","sources":["../../src/core/async-generator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,wFAAwF;AACxF,MAAM,aAAa,GAAwB,OAAO,CAAC;AAEnD;;;;GAIG;AACH,MAAM,OAAO,aAAa;IACb,CAAC,CAAW;IACZ,CAAC,CAAa;IACvB,YAAY,KAAe,EAAE,IAAgB;QACzC,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC;QACf,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC;IAClB,CAAC;CACJ;AAED;;;;GAIG;AACH,MAAM,iBAAiB;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M,CAAC,MAAM,CAAC,uBAAuB,CAA8C,CAAC;IACtG,MAAM,CAAC,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,KAAK,EAAG,MAAM,EAAE,CAAC,CAAC;IAC7D,OAAO,SAAS,CAAC;AACrB,CAAC"}
|
|
@@ -41,6 +41,9 @@ export declare class AsyncLocalStorage<T> {
|
|
|
41
41
|
* This method sets `store` for the rest of the current synchronous step, and for the
|
|
42
42
|
* code that this step starts later. Prefer `run()`: `enterWith()` can also
|
|
43
43
|
* change the store of the code that called the current function.
|
|
44
|
+
*
|
|
45
|
+
* Outside all steps, for example at the top level of a module, the store stays after the
|
|
46
|
+
* task as a default store, as on Node.js. No code sets the root context again.
|
|
44
47
|
*/
|
|
45
48
|
enterWith(store: T): void;
|
|
46
49
|
/** This method disables the storage. `getStore()` gives `undefined` until the next `run()` or `enterWith()`. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"async-local-storage.d.ts","sourceRoot":"","sources":["../../src/core/async-local-storage.ts"],"names":[],"mappings":"AAGA,6FAA6F;AAC7F,MAAM,WAAW,wBAAwB,CAAC,CAAC;IACvC,yDAAyD;IACzD,QAAQ,CAAC,YAAY,CAAC,EAAG,CAAC,GAAG,SAAS,CAAC;IACvC,2DAA2D;IAC3D,QAAQ,CAAC,IAAI,CAAC,EAAG,MAAM,GAAG,SAAS,CAAC;CACvC;AAED;;;;;;;;;;;;;GAaG;AACH,qBAAa,iBAAiB,CAAC,CAAC;;gBAIhB,OAAO,GAAG,wBAAwB,CAAC,CAAC,CAAM;IAItD,+BAA+B;IAC/B,IAAI,IAAI,IAAK,MAAM,CAElB;IAED;;;OAGG;IACH,QAAQ,IAAK,CAAC,GAAG,SAAS;IAI1B;;;;OAIG;IACH,GAAG,CAAC,CAAC,EAAE,CAAC,SAAS,OAAO,EAAE,EAAE,KAAK,EAAG,CAAC,EAAE,QAAQ,EAAG,CAAC,GAAG,IAAI,EAAG,CAAC,KAAK,CAAC,EA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AM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,SAAS,OAAO,EAAE,EAAE,CAAC,EAAE,EAAE,EAAG,CAAC,IAAI,EAAG,CAAC,EAAE,GAAG,IAAI,EAAG,CAAC,KAAK,CAAC,GAAI,CAAC,IAAI,EAAG,CAAC,EAAE,GAAG,IAAI,EAAG,CAAC,KAAK,CAAC;IAIxG,gHAAgH;IAChH,MAAM,CAAC,QAAQ,IAAK,CAAC,CAAC,EAAE,CAAC,SAAS,OAAO,EAAE,EAAE,EAAE,EAAG,CAAC,GAAG,IAAI,EAAG,CAAC,KAAK,CAAC,EAAE,GAAG,IAAI,EAAG,CAAC,KAAK,CAAC;CAI1F"}
|
|
@@ -48,6 +48,9 @@ export class AsyncLocalStorage {
|
|
|
48
48
|
* This method sets `store` for the rest of the current synchronous step, and for the
|
|
49
49
|
* code that this step starts later. Prefer `run()`: `enterWith()` can also
|
|
50
50
|
* change the store of the code that called the current function.
|
|
51
|
+
*
|
|
52
|
+
* Outside all steps, for example at the top level of a module, the store stays after the
|
|
53
|
+
* task as a default store, as on Node.js. No code sets the root context again.
|
|
51
54
|
*/
|
|
52
55
|
enterWith(store) {
|
|
53
56
|
this.#enabled = true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"async-local-storage.js","sourceRoot":"","sources":["../../src/core/async-local-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAUrD;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,iBAAiB;IACjB,SAAS,CAAe;IACjC,QAAQ,GAAG,IAAI,CAAC;IAEhB,YAAY,UAAwC,EAAE;QAClD,IAAI,CAAC,SAAS,GAAG,IAAI,QAAQ,CAAI,EAAE,IAAI,EAAG,OAAO,CAAC,IAAI,EAAE,YAAY,EAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC;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
|
|
11
|
-
* @param callback - The function that the library starts. For
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* @param callback - The function that the library starts. For a step
|
|
12
|
+
* after an `await`, it is the body of the async function or the async
|
|
13
|
+
* generator. It has the name of that function.
|
|
14
14
|
* @param source - The API that got the callback, for example
|
|
15
15
|
* `"setTimeout"`, `"Promise.then"`, `"addEventListener:click"`,
|
|
16
16
|
* `"onclick"` or `"await"`.
|
package/dist/core/coroutine.d.ts
CHANGED
|
@@ -2,17 +2,21 @@
|
|
|
2
2
|
* This function gives an async function that operates `generatorFunction`. The preset gives
|
|
3
3
|
* this function to `@babel/plugin-transform-async-to-generator` as its
|
|
4
4
|
* `method` option, and adds `name`, the name of the async function, if it has one.
|
|
5
|
+
*
|
|
6
|
+
* The first step of the body operates in the step of the caller. Thus an `enterWith()` of that
|
|
7
|
+
* step stays for the caller, as on Node.js.
|
|
5
8
|
*/
|
|
6
9
|
export declare function coroutine<T, A extends unknown[], R>(generatorFunction: (this: T, ...args: A) => Generator<unknown, R, unknown>, name?: string): (this: T, ...args: A) => Promise<R>;
|
|
7
10
|
/**
|
|
8
11
|
* This function gives a function that makes an async generator object, which operates
|
|
9
12
|
* `generatorFunction`. The preset gives this function in place of the helper
|
|
10
|
-
* `wrapAsyncGenerator` of `@babel/plugin-transform-async-generator-functions`.
|
|
13
|
+
* `wrapAsyncGenerator` of `@babel/plugin-transform-async-generator-functions`. It adds `name`,
|
|
14
|
+
* the name of the async generator, if it has one.
|
|
11
15
|
*
|
|
12
16
|
* Each step of the body operates in the context of the call that made the generator
|
|
13
17
|
* (rule C5). The driver continues each step with a native `await` (`async-generator.ts`).
|
|
14
18
|
*/
|
|
15
|
-
export declare function asyncGenerator<T, A extends unknown[]>(generatorFunction: (this: T, ...args: A) => Generator<unknown, unknown, unknown
|
|
19
|
+
export declare function asyncGenerator<T, A extends unknown[]>(generatorFunction: (this: T, ...args: A) => Generator<unknown, unknown, unknown>, name?: string): (this: T, ...args: A) => AsyncGenerator<unknown, unknown, unknown>;
|
|
16
20
|
type AnyIterator = Iterator<unknown, unknown, unknown> | AsyncIterator<unknown, unknown, unknown>;
|
|
17
21
|
/**
|
|
18
22
|
* This function binds a generator object to the current context. The body of
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coroutine.d.ts","sourceRoot":"","sources":["../../src/core/coroutine.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"coroutine.d.ts","sourceRoot":"","sources":["../../src/core/coroutine.ts"],"names":[],"mappings":"AAyEA;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,CAAC,SAAS,OAAO,EAAE,EAAE,CAAC,EAC/C,iBAAiB,EAAG,CAAC,IAAI,EAAG,CAAC,EAAE,GAAG,IAAI,EAAG,CAAC,KAAK,SAAS,CAAC,OAAO,EAAE,CAAC,EAAE,OAAO,CAAC,EAC7E,IAAI,CAAC,EAAG,MAAM,GACd,CAAC,IAAI,EAAG,CAAC,EAAE,GAAG,IAAI,EAAG,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAkExC;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,CAAC,SAAS,OAAO,EAAE,EACjD,iBAAiB,EAAG,CAAC,IAAI,EAAG,CAAC,EAAE,GAAG,IAAI,EAAG,CAAC,KAAK,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,EACnF,IAAI,CAAC,EAAG,MAAM,GACd,CAAC,IAAI,EAAG,CAAC,EAAE,GAAG,IAAI,EAAG,CAAC,KAAK,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CA2CvE;AAED,KAAK,WAAW,GAAG,QAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,GAAG,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AAGlG;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,WAAW,EAAE,SAAS,EAAG,CAAC,GAAI,CAAC,CA2BtE"}
|