async-browser-context 0.1.1 → 0.2.1

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.
Files changed (80) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +45 -3
  3. package/dist/babel/name-coroutines.d.ts +25 -0
  4. package/dist/babel/name-coroutines.d.ts.map +1 -0
  5. package/dist/babel/name-coroutines.js +116 -0
  6. package/dist/babel/name-coroutines.js.map +1 -0
  7. package/dist/babel/preset.d.ts +12 -2
  8. package/dist/babel/preset.d.ts.map +1 -1
  9. package/dist/babel/preset.js +8 -2
  10. package/dist/babel/preset.js.map +1 -1
  11. package/dist/core/callback-hook.d.ts +24 -0
  12. package/dist/core/callback-hook.d.ts.map +1 -0
  13. package/dist/core/callback-hook.js +13 -0
  14. package/dist/core/callback-hook.js.map +1 -0
  15. package/dist/core/coroutine.d.ts +2 -12
  16. package/dist/core/coroutine.d.ts.map +1 -1
  17. package/dist/core/coroutine.js +23 -8
  18. package/dist/core/coroutine.js.map +1 -1
  19. package/dist/core/hooks.d.ts +15 -0
  20. package/dist/core/hooks.d.ts.map +1 -0
  21. package/dist/core/hooks.js +28 -0
  22. package/dist/core/hooks.js.map +1 -0
  23. package/dist/core/store.d.ts +28 -3
  24. package/dist/core/store.d.ts.map +1 -1
  25. package/dist/core/store.js +81 -7
  26. package/dist/core/store.js.map +1 -1
  27. package/dist/index.d.ts +1 -0
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +1 -0
  30. package/dist/index.js.map +1 -1
  31. package/dist/node/index.d.ts +10 -0
  32. package/dist/node/index.d.ts.map +1 -1
  33. package/dist/node/index.js +14 -0
  34. package/dist/node/index.js.map +1 -1
  35. package/dist/patches/callbacks.d.ts.map +1 -1
  36. package/dist/patches/callbacks.js +10 -8
  37. package/dist/patches/callbacks.js.map +1 -1
  38. package/dist/patches/events.d.ts.map +1 -1
  39. package/dist/patches/events.js +39 -22
  40. package/dist/patches/events.js.map +1 -1
  41. package/dist/patches/handler-interfaces.d.ts +16 -0
  42. package/dist/patches/handler-interfaces.d.ts.map +1 -0
  43. package/dist/patches/handler-interfaces.js +42 -0
  44. package/dist/patches/handler-interfaces.js.map +1 -0
  45. package/dist/patches/observers.js +1 -1
  46. package/dist/patches/observers.js.map +1 -1
  47. package/dist/patches/patch.d.ts +5 -2
  48. package/dist/patches/patch.d.ts.map +1 -1
  49. package/dist/patches/patch.js +6 -3
  50. package/dist/patches/patch.js.map +1 -1
  51. package/dist/patches/promise.js +1 -1
  52. package/dist/patches/promise.js.map +1 -1
  53. package/dist/patches/streams.d.ts.map +1 -1
  54. package/dist/patches/streams.js +12 -7
  55. package/dist/patches/streams.js.map +1 -1
  56. package/dist/patches/timers.d.ts.map +1 -1
  57. package/dist/patches/timers.js +6 -5
  58. package/dist/patches/timers.js.map +1 -1
  59. package/dist/vite/plugin.d.ts +5 -0
  60. package/dist/vite/plugin.d.ts.map +1 -1
  61. package/dist/vite/plugin.js +1 -1
  62. package/dist/vite/plugin.js.map +1 -1
  63. package/package.json +8 -3
  64. package/src/babel/name-coroutines.ts +128 -0
  65. package/src/babel/preset.ts +16 -3
  66. package/src/core/callback-hook.ts +34 -0
  67. package/src/core/coroutine.ts +27 -8
  68. package/src/core/hooks.ts +30 -0
  69. package/src/core/store.ts +108 -7
  70. package/src/index.ts +1 -0
  71. package/src/node/index.ts +16 -0
  72. package/src/patches/callbacks.ts +10 -8
  73. package/src/patches/events.ts +38 -22
  74. package/src/patches/handler-interfaces.ts +41 -0
  75. package/src/patches/observers.ts +1 -1
  76. package/src/patches/patch.ts +6 -3
  77. package/src/patches/promise.ts +2 -2
  78. package/src/patches/streams.ts +12 -7
  79. package/src/patches/timers.ts +6 -5
  80. package/src/vite/plugin.ts +6 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handler-interfaces.js","sourceRoot":"","sources":["../../src/patches/handler-interfaces.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,MAAM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AmB,EAAE,qBAAqB,EAAE,QAAQ,EAAE,QAAQ,EAAE,YAAY,EAAE,eAAe;IAC7F,wBAAwB,EAAE,0BAA0B,EAAE,2BAA2B,EAAE,YAAY,EAAE,cAAc;IAC/G,yBAAyB,EAAE,cAAc,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,iBAAiB;IACrG,0BAA0B,EAAE,qBAAqB,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,cAAc;IAC1G,eAAe,EAAE,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,gBAAgB;IAC7G,kBAAkB,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,yBAAyB;IAC3F,yBAAyB,EAAE,WAAW,EAAE,QAAQ,EAAE,uBAAuB,EAAE,QAAQ,EAAE,mBAAmB;IACxG,gBAAgB,EAAE,2BAA2B,EAAE,aAAa,EAAE,iBAAiB,EAAE,iBAAiB;IAClG,cAAc,EAAE,aAAa,EAAE,kBAAkB,EAAE,WAAW,EAAE,UAAU;CAC7E,CAAC"}
@@ -39,7 +39,7 @@ export function installObserverPatches() {
39
39
  construct(target, args, newTarget) {
40
40
  const callback = args[0];
41
41
  if (typeof callback === "function") {
42
- args[0] = bindToFrame(store.current, callback);
42
+ args[0] = bindToFrame(store.current, callback, name);
43
43
  }
44
44
  return Reflect.construct(target, args, newTarget);
45
45
  },
@@ -1 +1 @@
1
- {"version":3,"file":"observers.js","sourceRoot":"","sources":["../../src/patches/observers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnE;;;;GAIG;AACH,MAAM,YAAY,GAAG;IACjB,kBAAkB;IAClB,wBAAwB;IACxB,gBAAgB;IAChB,sBAAsB;IACtB,qBAAqB;IACrB,mBAAmB;IACnB,kBAAkB;IACl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CAAC;QACL,CAAC;QACD,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,IAAI,EAAE,EAAE,GAAG,UAAU,EAAE,KAAK,EAAG,KAAK,EAAE,CAAC,CAAC;IAC9E,CAAC;AACL,CAAC"}
@@ -18,7 +18,10 @@ export declare function replaceFunction<F extends AnyFunction>(owner: object, ke
18
18
  export declare function ownDataValue(owner: object, key: string): unknown;
19
19
  /** This function gives the prototype of the global constructor `name`, if it exists. */
20
20
  export declare function globalPrototype(name: string): object | undefined;
21
- /** This function wraps each function argument with the current frame. Other arguments do not change. */
22
- export declare function wrapFunctionArguments(args: unknown[]): unknown[];
21
+ /**
22
+ * This function wraps each function argument with the current frame. Other arguments do not change.
23
+ * `source` is the name of the API, for the callback hooks.
24
+ */
25
+ export declare function wrapFunctionArguments(args: unknown[], source: string): unknown[];
23
26
  export {};
24
27
  //# sourceMappingURL=patch.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"patch.d.ts","sourceRoot":"","sources":["../../src/patches/patch.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAG,MAAM,GAAI,OAAO,CAM7C;AAED,gIAAgI;AAChI,wBAAgB,gBAAgB,CAAC,WAAW,EAAG,MAAM,EAAE,QAAQ,EAAG,MAAM,GAAI,IAAI,CAE/E;AAkBD,KAAK,WAAW,GAAG,CAAC,IAAI,EAAG,OAAO,EAAE,GAAG,IAAI,EAAG,KAAK,EAAE,KAAK,OAAO,CAAC;AAElE;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,WAAW,EAAE,KAAK,EAAG,MAAM,EAAE,GAAG,EAAG,MAAM,EAAE,MAAM,EAAG,CAAC,QAAQ,EAAG,CAAC,KAAK,CAAC,GAAI,OAAO,CAW3H;AAED,4GAA4G;AAC5G,wBAAgB,YAAY,CAAC,KAAK,EAAG,MAAM,EAAE,GAAG,EAAG,MAAM,GAAI,OAAO,CAGnE;AAED,wFAAwF;AACxF,wBAAgB,eAAe,CAAC,IAAI,EAAG,MAAM,GAAI,MAAM,GAAG,SAAS,CAOlE;AAED,wGAAwG;AACxG,wBAAgB,qBAAqB,CAAC,IAAI,EAAG,OAAO,EAAE,GAAI,OAAO,EAAE,CAUlE"}
1
+ {"version":3,"file":"patch.d.ts","sourceRoot":"","sources":["../../src/patches/patch.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAG,MAAM,GAAI,OAAO,CAM7C;AAED,gIAAgI;AAChI,wBAAgB,gBAAgB,CAAC,WAAW,EAAG,MAAM,EAAE,QAAQ,EAAG,MAAM,GAAI,IAAI,CAE/E;AAkBD,KAAK,WAAW,GAAG,CAAC,IAAI,EAAG,OAAO,EAAE,GAAG,IAAI,EAAG,KAAK,EAAE,KAAK,OAAO,CAAC;AAElE;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,WAAW,EAAE,KAAK,EAAG,MAAM,EAAE,GAAG,EAAG,MAAM,EAAE,MAAM,EAAG,CAAC,QAAQ,EAAG,CAAC,KAAK,CAAC,GAAI,OAAO,CAW3H;AAED,4GAA4G;AAC5G,wBAAgB,YAAY,CAAC,KAAK,EAAG,MAAM,EAAE,GAAG,EAAG,MAAM,GAAI,OAAO,CAGnE;AAED,wFAAwF;AACxF,wBAAgB,eAAe,CAAC,IAAI,EAAG,MAAM,GAAI,MAAM,GAAG,SAAS,CAOlE;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAG,OAAO,EAAE,EAAE,MAAM,EAAG,MAAM,GAAI,OAAO,EAAE,CAUnF"}
@@ -63,14 +63,17 @@ export function globalPrototype(name) {
63
63
  const prototype = constructor.prototype;
64
64
  return typeof prototype === "object" && prototype !== null ? prototype : undefined;
65
65
  }
66
- /** This function wraps each function argument with the current frame. Other arguments do not change. */
67
- export function wrapFunctionArguments(args) {
66
+ /**
67
+ * This function wraps each function argument with the current frame. Other arguments do not change.
68
+ * `source` is the name of the API, for the callback hooks.
69
+ */
70
+ export function wrapFunctionArguments(args, source) {
68
71
  const frame = store.current;
69
72
  let changed;
70
73
  for (const [index, argument] of args.entries()) {
71
74
  if (typeof argument === "function") {
72
75
  changed ??= [...args];
73
- changed[index] = bindToFrame(frame, argument);
76
+ changed[index] = bindToFrame(frame, argument, source);
74
77
  }
75
78
  }
76
79
  return changed ?? args;
@@ -1 +1 @@
1
- {"version":3,"file":"patch.js","sourceRoot":"","sources":["../../src/patches/patch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEtD;;;;GAIG;AACH,MAAM,UAAU,KAAK,CAAC,IAAa;IAC/B,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;QAC1B,OAAO,KAAK,CAAC;IACjB,CAAC;IACD,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACxB,OAAO,IAAI,CAAC;AAChB,CAAC;AAED,gIAAgI;AAChI,MAAM,UAAU,gBAAgB,CAAC,WAAoB,EAAE,QAAiB;IACpE,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,CAAC;AAChF,CAAC;AAED,6GAA6G;AAC7G,SAAS,sBAAsB,CAAC,WAAoB,EAAE,QAAiB;IACnE,KAAK,MAAM,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC1C,iDAAiD;QACjD,IAAI,GAAG,KAAK,WAAW,EAAE,CAAC;YACtB,SAAS;QACb,CAAC;QACD,MAAM,UAAU,GAAG,MAAM,CAAC,wBAAwB,CAAC,QAAQ,EAAE,GAAG,CAAuB,CAAC;QACxF,IAAI,CAAC;YACD,MAAM,CAAC,cAAc,CAAC,WAAW,EAAE,GAAG,EAA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AAY;IACrD,MAAM,UAAU,GAAG,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAC/D,OAAO,UAAU,KAAK,SAAS,IAAI,OAAO,IAAI,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AAC5F,CAAC;AAED,wFAAwF;AACxF,MAAM,UAAU,eAAe,CAAC,IAAa;IACzC,MAAM,WAAW,GAAG,YAAY,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IACnD,IAAI,OAAO,WAAW,KAAK,UAAU,EAAE,CAAC;QACpC,OAAO,SAAS,CAAC;IACrB,CAAC;IACD,MAAM,SAAS,GAAI,WAAwC,CAAC,SAAS,CAAC;IACtE,OAAO,OAAO,SAAS,KAAK,QAAQ,IAAI,SAAS,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;AACvF,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAgB,EAAE,MAAe;IACnE,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC;IAC5B,IAAI,OAA+B,CAAC;IACpC,KAAK,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC;QAC7C,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE,CAAC;YACjC,OAAO,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;YACtB,OAAO,CAAC,KAAK,CAAC,GAAG,WAAW,CAAC,KAAK,EAAE,QAA8C,EAAE,MAAM,CAAC,CAAC;QAChG,CAAC;IACL,CAAC;IACD,OAAO,OAAO,IAAI,IAAI,CAAC;AAC3B,CAAC"}
@@ -18,7 +18,7 @@ export function installPromisePatch() {
18
18
  const nativeThen = store.intrinsics.promiseThen;
19
19
  replaceFunction(Promise.prototype, "then", () => function then(onFulfilled, onRejected) {
20
20
  const frame = store.current;
21
- return nativeThen.call(this, typeof onFulfilled === "function" ? bindOneArgument(frame, onFulfilled) : onFulfilled, typeof onRejected === "function" ? bindOneArgument(frame, onRejected) : onRejected);
21
+ return nativeThen.call(this, typeof onFulfilled === "function" ? bindOneArgument(frame, onFulfilled, "Promise.then") : onFulfilled, typeof onRejected === "function" ? bindOneArgument(frame, onRejected, "Promise.then") : onRejected);
22
22
  });
23
23
  }
24
24
  //# sourceMappingURL=promise.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"promise.js","sourceRoot":"","sources":["../../src/patches/promise.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAIpD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,mBAAmB;IAC/B,IAAI,CAAC,KAAK,CAAC,wBAAwB,CAAC,EAAE,CAAC;QACnC,OAAO;IACX,CAAC;IACD,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC,WAAW,CAAC;IAChD,eAAe,CAAO,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,SAAS,IAAI,CAEhE,WAA2D,EAC3D,UAAiE;QAEjE,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC;QAC5B,OAAO,UAAU,CAAC,IAAI,CAClB,IAAI,EACJ,OAAO,WAAW,KAAK,UAAU,CAAC,CAAC,CAAC,eAAe,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,EACrF,OAAO,UAAU,KAAK,UAAU,CAAC,CAAC,CAAC,eAAe,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CACjE,CAAC;IAC1B,CAAS,CAAC,CAAC;AACf,CAAC"}
1
+ {"version":3,"file":"promise.js","sourceRoot":"","sources":["../../src/patches/promise.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAIpD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,mBAAmB;IAC/B,IAAI,CAAC,KAAK,CAAC,wBAAwB,CAAC,EAAE,CAAC;QACnC,OAAO;IACX,CAAC;IACD,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC,WAAW,CAAC;IAChD,eAAe,CAAO,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,SAAS,IAAI,CAEhE,WAA2D,EAC3D,UAAiE;QAEjE,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC;QAC5B,OAAO,UAAU,CAAC,IAAI,CAClB,IAAI,EACJ,OAAO,WAAW,KAAK,UAAU,CAAC,CAAC,CAAC,eAAe,CAAC,KAAK,EAAE,WAAW,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC,WAAW,EACrG,OAAO,UAAU,KAAK,UAAU,CAAC,CAAC,CAAC,eAAe,CAAC,KAAK,EAAE,UAAU,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC,UAAU,CACjF,CAAC;IAC1B,CAAS,CAAC,CAAC;AACf,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"streams.d.ts","sourceRoot":"","sources":["../../src/patches/streams.ts"],"names":[],"mappings":"AA2CA,qDAAqD;AACrD,wBAAgB,oBAAoB,IAAK,IAAI,CA8B5C"}
1
+ {"version":3,"file":"streams.d.ts","sourceRoot":"","sources":["../../src/patches/streams.ts"],"names":[],"mappings":"AAgDA,qDAAqD;AACrD,wBAAgB,oBAAoB,IAAK,IAAI,CA8B5C"}
@@ -1,4 +1,4 @@
1
- import { store } from "../core/store.js";
1
+ import { applyWithHooks, store } from "../core/store.js";
2
2
  import { claim, ownDataValue, rememberOriginal } from "./patch.js";
3
3
  /**
4
4
  * The stream constructors and the methods of the object that each constructor
@@ -16,19 +16,24 @@ const STREAMS = [
16
16
  * Each method gets `underlying` as its `this` value, as the specification
17
17
  * tells.
18
18
  */
19
- function wrapUnderlying(underlying, methods, frame) {
19
+ function wrapUnderlying(underlying, methods, frame, name) {
20
20
  const wrapped = Object.create(underlying);
21
- const source = underlying;
21
+ const properties = underlying;
22
22
  for (const method of methods) {
23
- const original = source[method];
23
+ const original = properties[method];
24
24
  if (typeof original !== "function") {
25
25
  continue;
26
26
  }
27
- wrapped[method] = function (...args) {
27
+ const source = `${name}.${method}`;
28
+ wrapped[method] = function asyncBrowserContextWrapper(...args) {
28
29
  const previous = store.current;
29
30
  store.current = frame;
30
31
  try {
31
- return original.apply(underlying, args);
32
+ const hooks = store.hooks;
33
+ if (hooks === undefined) {
34
+ return original.apply(underlying, args);
35
+ }
36
+ return applyWithHooks(hooks, original, source, original, underlying, args);
32
37
  }
33
38
  finally {
34
39
  store.current = previous;
@@ -53,7 +58,7 @@ export function installStreamPatches() {
53
58
  construct(target, args, newTarget) {
54
59
  const underlying = args[0];
55
60
  if (typeof underlying === "object" && underlying !== null) {
56
- args[0] = wrapUnderlying(underlying, methods, store.current);
61
+ args[0] = wrapUnderlying(underlying, methods, store.current, name);
57
62
  }
58
63
  return Reflect.construct(target, args, newTarget);
59
64
  },
@@ -1 +1 @@
1
- {"version":3,"file":"streams.js","sourceRoot":"","sources":["../../src/patches/streams.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAc,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnE;;;;GAIG;AACH,MAAM,OAAO,GAAuD;IAChE,CAAC,gBAAgB,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;IAC/C,CAAC,gBAAgB,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IACxD,CAAC,iBAAiB,EAAE,CAAC,OAAO,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,OAAO,SAAS,KAAK,QAAQ,IAAI,SAAS,KAAK,IAAI,EAAE,CAAC;YACtD,MAAM,qBAAqB,GAAG,MAAM,CAAC,wBAAwB,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;YACxF,IAAI,qBAAqB,EAAE,YAAY,KAAK,IAAI,EAAE,CAAC;gBAC/C,MAAM,CAAC,cAAc,CAAC,SAAS,EAAE,aAAa,EAAE,EAAE,GAAG,qBAAqB,EAAE,KAAK,EAAG,KAAK,EAAE,CAAC,CAAC;YACjG,CAAC;QACL,CAAC;QACD,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,IAAI,EAAE,EAAE,GAAG,UAAU,EAAE,KAAK,EAAG,KAAK,EAAE,CAAC,CAAC;IAC9E,CAAC;AACL,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"timers.d.ts","sourceRoot":"","sources":["../../src/patches/timers.ts"],"names":[],"mappings":"AAkCA;;;;GAIG;AACH,wBAAgB,mBAAmB,IAAK,IAAI,CAe3C"}
1
+ {"version":3,"file":"timers.d.ts","sourceRoot":"","sources":["../../src/patches/timers.ts"],"names":[],"mappings":"AAmCA;;;;GAIG;AACH,wBAAgB,mBAAmB,IAAK,IAAI,CAe3C"}
@@ -20,9 +20,10 @@ const PROTOTYPE_SCHEDULERS = [
20
20
  ["XRSession", "requestAnimationFrame"],
21
21
  ];
22
22
  // Stryker restore all
23
- function wrapFirstArgument(original) {
24
- return function (callback, ...rest) {
25
- const wrapped = typeof callback === "function" ? bindToFrame(store.current, callback) : callback;
23
+ /** `source` is the name of the scheduler, for the callback hooks. */
24
+ function wrapFirstArgument(source) {
25
+ return (original) => function (callback, ...rest) {
26
+ const wrapped = typeof callback === "function" ? bindToFrame(store.current, callback, source) : callback;
26
27
  return original.call(this, wrapped, ...rest);
27
28
  };
28
29
  }
@@ -36,13 +37,13 @@ export function installTimerPatches() {
36
37
  return;
37
38
  }
38
39
  for (const name of GLOBAL_SCHEDULERS) {
39
- replaceFunction(globalThis, name, wrapFirstArgument);
40
+ replaceFunction(globalThis, name, wrapFirstArgument(name));
40
41
  }
41
42
  // Stryker disable all: Node.js has none of these classes. The browser tests examine them.
42
43
  for (const [constructorName, method] of PROTOTYPE_SCHEDULERS) {
43
44
  const prototype = globalPrototype(constructorName);
44
45
  if (prototype !== undefined) {
45
- replaceFunction(prototype, method, wrapFirstArgument);
46
+ replaceFunction(prototype, method, wrapFirstArgument(`${constructorName}.${method}`));
46
47
  }
47
48
  }
48
49
  // Stryker restore all
@@ -1 +1 @@
1
- {"version":3,"file":"timers.js","sourceRoot":"","sources":["../../src/patches/timers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAIrE,yFAAyF;AACzF,MAAM,iBAAiB,GAAG;IACtB,YAAY;IACZ,aAAa;IACb,cAAc;IACd,gBAAgB;IAChB,uBAAuB;IACvB,qBAAqB;CACf,CAAC;AAEX;;;GAGG;AACH,6EAA6E;AAC7E,MAAM,oBAAoB,GAA4C;IAClE,CAAC,WAAW,EAAE,UAAU,CAAC;IACzB,CAAC,kBAAkB,EAAE,2BAA2B,CAAC;IACjD,CAAC,WAAW,EAAE,uBAAuB,CAAC;CACzC,CAAC;AACF,sBAAsB;AAEtB,SAAS,iBAAiB,CAAC,QAAoB;IAC3C,OAAO,UAA0B,QAAkB,EAAE,GAAG,IAAgB;QACpE,MAAM,OAAO,GAAG,OAAO,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,QAA4C,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;QACrI,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;IACjD,CAAC,CAAC;AACN,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,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AAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,QAA4C,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;QAC7I,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;IACjD,CAAC,CAAC;AACN,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB;IAC/B,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;QACnB,OAAO;IACX,CAAC;IACD,KAAK,MAAM,IAAI,IAAI,iBAAiB,EAAE,CAAC;QACnC,eAAe,CAAY,UAAU,EAAE,IAAI,EAAE,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC;IAC1E,CAAC;IACD,0FAA0F;IAC1F,KAAK,MAAM,CAAC,eAAe,EAAE,MAAM,CAAC,IAAI,oBAAoB,EAAE,CAAC;QAC3D,MAAM,SAAS,GAAG,eAAe,CAAC,eAAe,CAAC,CAAC;QACnD,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAC1B,eAAe,CAAY,SAAS,EAAE,MAAM,EAAE,iBAAiB,CAAC,GAAG,eAAe,IAAI,MAAM,EAAE,CAAC,CAAC,CAAC;QACrG,CAAC;IACL,CAAC;IACD,sBAAsB;AAC1B,CAAC"}
@@ -12,6 +12,11 @@ export interface AsyncContextPluginOptions {
12
12
  readonly exclude?: ModuleFilter | undefined;
13
13
  /** The runtime module. The default is `async-browser-context/runtime`. */
14
14
  readonly runtime?: string | undefined;
15
+ /**
16
+ * Give the name of each async function to the callback hooks. The default
17
+ * is `true`. Refer to the option `names` of the Babel preset.
18
+ */
19
+ readonly names?: boolean | undefined;
15
20
  /**
16
21
  * Also transform the modules of server-side rendering. The default is
17
22
  * `false`, because on Node.js the native `AsyncLocalStorage` keeps the
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/vite/plugin.ts"],"names":[],"mappings":"AACA,OAAO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G,CAAC,EAAG,OAAO,GAAG,SAAS,CAAC;CACvC;AAYD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,YAAY,CAAC,OAAO,GAAG,yBAA8B,GAAI,MAAM,CA4C9E"}
@@ -58,7 +58,7 @@ export function asyncContext(options = {}) {
58
58
  configFile: false,
59
59
  sourceType: "unambiguous",
60
60
  sourceMaps: true,
61
- presets: [[preset, { runtime }]],
61
+ presets: [[preset, { runtime, names: options.names }]],
62
62
  });
63
63
  const changed = result?.metadata?.[METADATA_KEY] === true;
64
64
  if (result?.code == null || !changed) {
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/vite/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,MAAM,EAAE,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAwB3E,MAAM,MAAM,GAAG,iBAAiB,CAAC;AACjC,oFAAoF;AACpF,MAAM,YAAY,GAAG,mCAAmC,CAAC;AACzD,qEAAqE;AACrE,MAAM,WAAW,GAAG,0CAA0C,CAAC;AAE/D,SAAS,OAAO,CAAC,MAAqB,EAAE,EAAW;IAC/C,OAAO,MAAM,YAAY,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AACnE,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,YAAY,CAAC,UAAsC,EAAE;IACjE,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,eAAe,CAAC;IACnD,OAAO;QACH,IAAI,EAAG,uBAAuB;QAC9B,OAAO,EAAG,MAAM;QAChB,SAAS,EAAG;YACR,MAAM,EAAG,EAAE,IAAI,EAAG,YAAY,EAAE;YAChC,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,EAAE,gBAAgB;gBACp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AAI,MAAM,EAAE,QAAgD,EAAE,CAAC,YAAY,CAAC,KAAK,IAAI,CAAC;gBACnG,IAAI,MAAM,EAAE,IAAI,IAAI,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;oBACnC,OAAO,IAAI,CAAC;gBAChB,CAAC;gBACD,+DAA+D;gBAC/D,OAAO,EAAE,IAAI,EAAG,MAAM,CAAC,IAAI,EAAE,GAAG,EAAG,MAAM,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;YAChG,CAAC;SACJ;KACJ,CAAC;AACN,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "async-browser-context",
3
- "version": "0.1.1",
3
+ "version": "0.2.1",
4
4
  "description": "AsyncLocalStorage and the TC39 AsyncContext API (Variable, Snapshot) for browsers. The context stays through await, promises, timers, events and generators. A Babel preset and a Vite plugin transform async functions. On Node.js, the package uses the native AsyncLocalStorage.",
5
5
  "license": "MIT",
6
6
  "author": "Mark Russell",
@@ -106,18 +106,21 @@
106
106
  "build": "tsc -p tsconfig.build.json",
107
107
  "typecheck": "tsc -p tsconfig.json",
108
108
  "test": "vitest run",
109
- "test:node": "vitest run --project unit --project \"rules (browser runtime, Node.js)\" --project \"rules (node runtime)\" --project \"rules (node runtime, no transform)\"",
109
+ "test:node": "vitest run --project unit --project \"rules (browser runtime, Node.js)\" --project \"rules (browser runtime, SWC ES2016)\" --project \"rules (browser runtime, esbuild ES2016)\" --project \"rules (node runtime)\" --project \"rules (node runtime, no transform)\"",
110
110
  "test:browser": "vitest run --project \"browser (chromium)\" --project \"browser (firefox)\" --project \"browser (webkit)\"",
111
111
  "coverage": "vitest run --coverage --project unit --project \"rules (browser runtime, Node.js)\" --project \"rules (node runtime)\"",
112
112
  "mutation": "stryker run",
113
113
  "bench": "pnpm build && tsx bench/run.ts",
114
114
  "smoke": "pnpm build && tsx test/smoke/run.ts",
115
+ "test:babel": "pnpm build && tsx test/babel/run.ts",
115
116
  "lint:ste": "tsx tools/ste-lint/src/cli.ts",
116
117
  "site:dev": "pnpm --filter ./site dev",
117
118
  "site:build": "pnpm --filter ./site build",
118
119
  "prepublishOnly": "pnpm build && pnpm test",
119
120
  "site:data": "tsx scripts/site-data.ts",
120
- "readme:media": "tsx scripts/readme-media.ts"
121
+ "readme:media": "tsx scripts/readme-media.ts",
122
+ "test:bundlers": "pnpm build && tsx test/bundlers/run.ts",
123
+ "bench:size": "tsx bench/size.ts"
121
124
  },
122
125
  "dependencies": {
123
126
  "@babel/core": "^8.0.7",
@@ -140,10 +143,12 @@
140
143
  "devDependencies": {
141
144
  "@opentelemetry/api": "^1.9.1",
142
145
  "@stryker-mutator/core": "^10.0.0",
146
+ "@swc/core": "^1.16.18",
143
147
  "@types/node": "^25.3.0",
144
148
  "@vitest/browser": "^5.0.3",
145
149
  "@vitest/browser-playwright": "^5.0.3",
146
150
  "@vitest/coverage-v8": "^5.0.3",
151
+ "esbuild": "^0.28.2",
147
152
  "playwright": "^1.64.0",
148
153
  "tinybench": "^6.2.1",
149
154
  "tsx": "^4.23.15",
@@ -0,0 +1,128 @@
1
+ import { types, type NodePath, type PluginObject, type PluginPass } from "@babel/core";
2
+
3
+ /** The options of the plugin. */
4
+ export interface NameCoroutinesOptions {
5
+ /** The module that exports `coroutine`. */
6
+ readonly runtime : string;
7
+ }
8
+
9
+ /** The local names that Babel gives to the import of `coroutine`. */
10
+ const COROUTINE_NAME = /^_coroutine\d*$/;
11
+
12
+ /** The assignment operators that give a name to an anonymous function, as in the specification (NamedEvaluation). */
13
+ const NAMING_OPERATORS = new Set(["=", "&&=", "||=", "??="]);
14
+
15
+ /** This function gives the name of a property key, or `undefined` if the name is known only at run time. */
16
+ function keyName(key : types.Node, computed : boolean) : string | undefined {
17
+ if (types.isStringLiteral(key)) {
18
+ return key.value;
19
+ }
20
+ if (types.isNumericLiteral(key)) {
21
+ return String(key.value);
22
+ }
23
+ if (computed) {
24
+ return undefined;
25
+ }
26
+ if (types.isIdentifier(key)) {
27
+ return key.name;
28
+ }
29
+ return types.isPrivateName(key) ? `#${key.id.name}` : undefined;
30
+ }
31
+
32
+ /**
33
+ * This function gives the `name` that JavaScript gives to the function, or
34
+ * `undefined` if the name is not known before run time.
35
+ */
36
+ export function functionName(path : NodePath<types.Function>) : string | undefined {
37
+ const node = path.node;
38
+ if ((types.isFunctionDeclaration(node) || types.isFunctionExpression(node)) && node.id) {
39
+ return node.id.name;
40
+ }
41
+ if (types.isObjectMethod(node) || types.isClassMethod(node) || types.isClassPrivateMethod(node)) {
42
+ return keyName(node.key, node.computed === true);
43
+ }
44
+ const parent = path.parent;
45
+ if (types.isVariableDeclarator(parent) && parent.init === node && types.isIdentifier(parent.id)) {
46
+ return parent.id.name;
47
+ }
48
+ if (types.isAssignmentExpression(parent) && parent.right === node && NAMING_OPERATORS.has(parent.operator) && types.isIdentifier(parent.left)) {
49
+ return parent.left.name;
50
+ }
51
+ if (types.isAssignmentPattern(parent) && parent.right === node && types.isIdentifier(parent.left)) {
52
+ return parent.left.name;
53
+ }
54
+ if ((types.isObjectProperty(parent) || types.isClassProperty(parent) || types.isClassPrivateProperty(parent)) && parent.value === node) {
55
+ return keyName(parent.key, "computed" in parent && parent.computed === true);
56
+ }
57
+ return types.isExportDefaultDeclaration(parent) ? "default" : undefined;
58
+ }
59
+
60
+ /** This function gives `true` if `callee` is the `coroutine` function of the runtime, also in CommonJS output. */
61
+ function isCoroutineCallee(callee : types.Node, path : NodePath, runtime : string) : boolean {
62
+ if (types.isIdentifier(callee)) {
63
+ return COROUTINE_NAME.test(callee.name) || path.referencesImport(runtime, "coroutine");
64
+ }
65
+ const member = types.isSequenceExpression(callee) ? callee.expressions.at(-1) : callee;
66
+ return types.isMemberExpression(member) && types.isIdentifier(member.property, { name : "coroutine" });
67
+ }
68
+
69
+ /** The key of the names of one file in the plugin state. */
70
+ const NAMES_KEY = "async-browser-context/coroutine-names";
71
+
72
+ /**
73
+ * The Babel plugin that gives the name of each async function to `coroutine`:
74
+ * `_coroutine(function* () {...}, "load")`. The generator function of
75
+ * `@babel/plugin-transform-async-to-generator` has no name, and the callback
76
+ * hooks of the runtime show the name of the async function.
77
+ *
78
+ * In `Program` enter, before the async transform, the plugin records the
79
+ * name of each async function. In `Program` exit, it adds the name to each
80
+ * `coroutine` call. For a plain function, the async transform keeps the
81
+ * function node as the argument of `coroutine`. For a method, the call is in
82
+ * the body of the method.
83
+ */
84
+ export function nameCoroutinesPlugin(_api : unknown, options : object) : PluginObject<PluginPass> {
85
+ const { runtime } = options as NameCoroutinesOptions;
86
+ return {
87
+ name : "async-browser-context/name-coroutines",
88
+ visitor : {
89
+ Program : {
90
+ enter(programPath, state) {
91
+ const names = new WeakMap<types.Node, string>();
92
+ programPath.traverse({
93
+ Function(path) {
94
+ if (!path.node.async || path.node.generator) {
95
+ return;
96
+ }
97
+ const name = functionName(path);
98
+ if (name !== undefined && name !== "") {
99
+ names.set(path.node, name);
100
+ }
101
+ },
102
+ });
103
+ state.set(NAMES_KEY, names);
104
+ },
105
+ exit(programPath, state) {
106
+ const names = state.get(NAMES_KEY) as WeakMap<types.Node, string>;
107
+ programPath.traverse({
108
+ CallExpression(path) {
109
+ const { callee, arguments : args } = path.node;
110
+ const [body] = args;
111
+ if (args.length !== 1 || !types.isFunctionExpression(body) || !body.generator) {
112
+ return;
113
+ }
114
+ if (!isCoroutineCallee(callee, path.get("callee"), runtime)) {
115
+ return;
116
+ }
117
+ const parent = path.getFunctionParent()?.node;
118
+ const name = names.get(body) ?? (types.isMethod(parent) ? names.get(parent) : undefined);
119
+ if (name !== undefined) {
120
+ args.push(types.stringLiteral(name));
121
+ }
122
+ },
123
+ });
124
+ },
125
+ },
126
+ },
127
+ };
128
+ }
@@ -1,7 +1,8 @@
1
- import type { PresetAPI, PresetObject } from "@babel/core";
1
+ import type { PluginItem, PresetAPI, PresetObject } from "@babel/core";
2
2
  import asyncGeneratorFunctions from "@babel/plugin-transform-async-generator-functions";
3
3
  import asyncToGenerator from "@babel/plugin-transform-async-to-generator";
4
4
  import { bindGeneratorsPlugin } from "./bind-generators.js";
5
+ import { nameCoroutinesPlugin } from "./name-coroutines.js";
5
6
 
6
7
  export { METADATA_KEY } from "./bind-generators.js";
7
8
 
@@ -12,6 +13,13 @@ export interface PresetOptions {
12
13
  * `bindGenerator`. The default is `async-browser-context/runtime`.
13
14
  */
14
15
  readonly runtime? : string | undefined;
16
+ /**
17
+ * Give the name of each async function to `coroutine`, for the callback
18
+ * hooks. The default is `true`. With `false`, the hooks get no name for the
19
+ * steps after an `await`. The code is then smaller by 0.1 to 1.6 percent
20
+ * of its gzip size (`pnpm bench:size`).
21
+ */
22
+ readonly names? : boolean | undefined;
15
23
  }
16
24
 
17
25
  /** The default runtime module. */
@@ -23,9 +31,12 @@ export const DEFAULT_RUNTIME = "async-browser-context/runtime";
23
31
  *
24
32
  * 1. A plugin of this library binds each generator to the context of its
25
33
  * creation.
26
- * 2. `@babel/plugin-transform-async-generator-functions` changes async
34
+ * 2. A plugin of this library gives the name of each async function to
35
+ * `coroutine`, for the callback hooks. The option `names: false` removes
36
+ * this step.
37
+ * 3. `@babel/plugin-transform-async-generator-functions` changes async
27
38
  * generators and `for await` loops.
28
- * 3. `@babel/plugin-transform-async-to-generator` changes each async function
39
+ * 4. `@babel/plugin-transform-async-to-generator` changes each async function
29
40
  * into a generator that the `coroutine` function of the runtime operates.
30
41
  *
31
42
  * The preset operates with Babel 7.22 and later and with Babel 8. Put it last
@@ -34,9 +45,11 @@ export const DEFAULT_RUNTIME = "async-browser-context/runtime";
34
45
  export default function asyncBrowserContextPreset(api : PresetAPI, options : PresetOptions = {}) : PresetObject {
35
46
  api.assertVersion("^7.22.0 || ^8.0.0");
36
47
  const runtime = options.runtime ?? DEFAULT_RUNTIME;
48
+ const names : PluginItem[] = options.names === false ? [] : [[nameCoroutinesPlugin, { runtime }]];
37
49
  return {
38
50
  plugins : [
39
51
  [bindGeneratorsPlugin, { runtime }],
52
+ ...names,
40
53
  asyncGeneratorFunctions,
41
54
  [asyncToGenerator, { module : runtime, method : "coroutine" }],
42
55
  ],
@@ -0,0 +1,34 @@
1
+ /**
2
+ * A callback hook. The library starts `before` immediately before each
3
+ * callback that it starts, and `after` immediately after the callback, also
4
+ * after an error. Both methods operate in the context of the callback, so
5
+ * `variable.get()` and `storage.getStore()` give the values of the callback.
6
+ */
7
+ export interface CallbackHook {
8
+ /**
9
+ * The library starts this method before the callback.
10
+ *
11
+ * @param callback - The function that the library starts. For the step
12
+ * of an async function after an `await`, it is the body of the async
13
+ * function, with the name of the async function.
14
+ * @param source - The API that got the callback, for example
15
+ * `"setTimeout"`, `"Promise.then"`, `"addEventListener:click"`,
16
+ * `"onclick"` or `"await"`.
17
+ */
18
+ before?(callback : Function, source : string) : void;
19
+ /** The library starts this method after the callback, also after an error. The arguments are the same as for `before`. */
20
+ after?(callback : Function, source : string) : void;
21
+ }
22
+
23
+ /** This function makes sure that `hook` is an object, and that `before` and `after` are functions or `undefined`. */
24
+ export function assertCallbackHook(hook : CallbackHook) : void {
25
+ if (typeof hook !== "object" || hook === null) {
26
+ throw new TypeError("addCallbackHook: the hook is not an object");
27
+ }
28
+ for (const phase of ["before", "after"] as const) {
29
+ const method : unknown = hook[phase];
30
+ if (method !== undefined && typeof method !== "function") {
31
+ throw new TypeError(`addCallbackHook: hook.${phase} is not a function`);
32
+ }
33
+ }
34
+ }
@@ -1,4 +1,4 @@
1
- import { store, type Frame } from "./store.js";
1
+ import { applyWithHooks, store, type Frame } from "./store.js";
2
2
 
3
3
  /**
4
4
  * The code from the Babel preset uses these runtime functions. Do not use them
@@ -11,25 +11,44 @@ import { store, type Frame } from "./store.js";
11
11
  * also in the same expression, and no other code gets this context.
12
12
  */
13
13
 
14
+ /**
15
+ * This function gives the generator function to the callback hooks, with the name of the
16
+ * async function. The preset gives the name, because the generator function
17
+ * of Babel has no name. The function sets the name only when a hook operates.
18
+ */
19
+ function namedForHooks(generatorFunction : Function, name : string | undefined) : Function {
20
+ if (name !== undefined && generatorFunction.name !== name) {
21
+ Object.defineProperty(generatorFunction, "name", { value : name, configurable : true });
22
+ }
23
+ return generatorFunction;
24
+ }
25
+
14
26
  /**
15
27
  * This function gives an async function that operates `generatorFunction`. The preset gives
16
28
  * this function to `@babel/plugin-transform-async-to-generator` as its
17
- * `method` option.
29
+ * `method` option, and adds `name`, the name of the async function, if it has one.
18
30
  */
19
- export function coroutine<T, A extends unknown[], R>(generatorFunction : (this : T, ...args : A) => Generator<unknown, R, unknown>) : (this : T, ...args : A) => Promise<R> {
31
+ export function coroutine<T, A extends unknown[], R>(
32
+ generatorFunction : (this : T, ...args : A) => Generator<unknown, R, unknown>,
33
+ name? : string,
34
+ ) : (this : T, ...args : A) => Promise<R> {
20
35
  const { Promise : NativePromise, promiseThen, promiseResolve } = store.intrinsics;
21
36
  return function asyncFunction(this : T, ...args : A) : Promise<R> {
22
37
  // The context of the call. The body can change it with AsyncLocalStorage.enterWith.
23
38
  let frame : Frame = store.current;
24
39
  const generator = generatorFunction.apply(this, args);
25
40
  return new NativePromise<R>((resolve, reject) => {
26
- const step = (resume : (argument : unknown) => IteratorResult<unknown, R>, argument : unknown) : void => {
41
+ /** `resumed` is `true` for a step after an `await`. Only these steps start the hook methods. */
42
+ const step = (resume : (argument : unknown) => IteratorResult<unknown, R>, argument : unknown, resumed : boolean) : void => {
27
43
  const previous = store.current;
28
44
  store.current = frame;
29
45
  let result : IteratorResult<unknown, R>;
30
46
  let awaited : Promise<unknown>;
31
47
  try {
32
- result = resume(argument);
48
+ const hooks = resumed ? store.hooks : undefined;
49
+ result = hooks === undefined
50
+ ? resume(argument)
51
+ : applyWithHooks(hooks, namedForHooks(generatorFunction, name), "await", resume, undefined, [argument]);
33
52
  if (result.done) {
34
53
  frame = store.current;
35
54
  store.current = previous;
@@ -49,9 +68,9 @@ export function coroutine<T, A extends unknown[], R>(generatorFunction : (this :
49
68
  };
50
69
  const next = (value : unknown) : IteratorResult<unknown, R> => generator.next(value);
51
70
  const throwInto = (error : unknown) : IteratorResult<unknown, R> => generator.throw(error);
52
- const onFulfilled = (value : unknown) : void => step(next, value);
53
- const onRejected = (error : unknown) : void => step(throwInto, error);
54
- step(next, undefined);
71
+ const onFulfilled = (value : unknown) : void => step(next, value, true);
72
+ const onRejected = (error : unknown) : void => step(throwInto, error, true);
73
+ step(next, undefined, false);
55
74
  });
56
75
  };
57
76
  }
@@ -0,0 +1,30 @@
1
+ import { assertCallbackHook, type CallbackHook } from "./callback-hook.js";
2
+ import { store, type HookEntry } from "./store.js";
3
+
4
+ export type { CallbackHook } from "./callback-hook.js";
5
+
6
+ /**
7
+ * This function adds a hook. The library starts its methods before and after each
8
+ * callback that it starts. These callbacks are the callbacks of the patched
9
+ * APIs and the step of each transformed async function after an `await`. The
10
+ * function gives a function that removes the hook.
11
+ *
12
+ * A tool can use the hook to measure the time of each callback, with the
13
+ * name of the callback and the values of its context. An error in a hook goes
14
+ * to `reportError()`, and the callback operates as usual. A callback that
15
+ * starts synchronously in a hook does not start the hook methods.
16
+ */
17
+ export function addCallbackHook(hook : CallbackHook) : () => void {
18
+ assertCallbackHook(hook);
19
+ const entry : HookEntry = { hook };
20
+ store.hooks = [...(store.hooks ?? []), entry];
21
+ let removed = false;
22
+ return function removeCallbackHook() : void {
23
+ if (removed) {
24
+ return;
25
+ }
26
+ removed = true;
27
+ const remaining = (store.hooks ?? []).filter((other) => other !== entry);
28
+ store.hooks = remaining.length === 0 ? undefined : remaining;
29
+ };
30
+ }