@ricsam/isolate 0.1.5 → 0.1.6

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.
@@ -14,6 +14,7 @@ var ASYNC_CONTEXT_BOOTSTRAP = `
14
14
  || !native
15
15
  || typeof native.getContinuationPreservedEmbedderData !== "function"
16
16
  || typeof native.setContinuationPreservedEmbedderData !== "function"
17
+ || typeof native.setPromiseHooks !== "function"
17
18
  ) {
18
19
  throw new Error(
19
20
  "The installed isolated-vm runtime does not expose async context support. " +
@@ -54,17 +55,259 @@ var ASYNC_CONTEXT_BOOTSTRAP = `
54
55
  enumerable: false,
55
56
  value: true,
56
57
  });
57
- const currentAsyncResource = new AsyncContext.Variable({
58
- name: "isolate.asyncResource",
59
- defaultValue: undefined,
58
+
59
+ const topLevelResource = {};
60
+ const topLevelExecutionState = {
61
+ asyncId: 1,
62
+ triggerAsyncId: 0,
63
+ type: "ROOT",
64
+ resource: topLevelResource,
65
+ destroyed: false,
66
+ };
67
+ const currentExecutionState = new AsyncContext.Variable({
68
+ name: "isolate.executionState",
69
+ defaultValue: topLevelExecutionState,
60
70
  });
61
71
 
62
- const wrapCallback = (callback) => {
72
+ const promiseStateByPromise = new WeakMap();
73
+ const activeHooks = new Map();
74
+ const promiseFrameStack = [];
75
+ const kWrappedState = Symbol("isolate.asyncResourceState");
76
+ const kWrappedDestroy = Symbol("isolate.destroyAsyncResource");
77
+ let nextAsyncId = 2;
78
+ let hookDispatchDepth = 0;
79
+ let promiseHooksEnabled = false;
80
+
81
+ function getCurrentExecutionState() {
82
+ return currentExecutionState.get();
83
+ }
84
+
85
+ function normalizeType(type, fallback) {
86
+ if (typeof type === "string" && type.length > 0) {
87
+ return type;
88
+ }
89
+ return fallback;
90
+ }
91
+
92
+ function normalizeTriggerAsyncId(triggerAsyncId) {
93
+ return Number.isSafeInteger(triggerAsyncId) && triggerAsyncId >= 0
94
+ ? triggerAsyncId
95
+ : undefined;
96
+ }
97
+
98
+ function dispatchHook(name, args) {
99
+ if (hookDispatchDepth > 0 || activeHooks.size === 0) {
100
+ return;
101
+ }
102
+
103
+ hookDispatchDepth++;
104
+ try {
105
+ for (const [hook, callbacks] of Array.from(activeHooks.entries())) {
106
+ const callback = callbacks[name];
107
+ if (typeof callback === "function") {
108
+ Reflect.apply(callback, hook, args);
109
+ }
110
+ }
111
+ } finally {
112
+ hookDispatchDepth--;
113
+ }
114
+ }
115
+
116
+ function createResource(type, resource, options = {}) {
117
+ const normalizedOptions =
118
+ options && typeof options === "object" ? options : {};
119
+ const state = {
120
+ asyncId: nextAsyncId++,
121
+ triggerAsyncId:
122
+ normalizeTriggerAsyncId(normalizedOptions.triggerAsyncId)
123
+ ?? getCurrentExecutionState().asyncId,
124
+ type: normalizeType(type, "isolate.resource"),
125
+ resource:
126
+ resource !== undefined && resource !== null ? resource : {},
127
+ destroyed: false,
128
+ };
129
+
130
+ if (normalizedOptions.emitInit !== false) {
131
+ dispatchHook("init", [
132
+ state.asyncId,
133
+ state.type,
134
+ state.triggerAsyncId,
135
+ state.resource,
136
+ ]);
137
+ }
138
+
139
+ return state;
140
+ }
141
+
142
+ function enterResource(resourceState) {
143
+ return AsyncContextFrame.exchange(
144
+ new AsyncContextFrame(currentExecutionState, resourceState),
145
+ );
146
+ }
147
+
148
+ function destroyResource(resourceState) {
149
+ if (!resourceState || resourceState.destroyed) {
150
+ return false;
151
+ }
152
+ resourceState.destroyed = true;
153
+ dispatchHook("destroy", [resourceState.asyncId]);
154
+ return true;
155
+ }
156
+
157
+ function runWithResource(resourceState, fn, thisArg, args) {
158
+ const priorFrame = enterResource(resourceState);
159
+ let didRunBeforeHook = false;
160
+ try {
161
+ dispatchHook("before", [resourceState.asyncId]);
162
+ didRunBeforeHook = true;
163
+ return Reflect.apply(fn, thisArg, args);
164
+ } finally {
165
+ try {
166
+ if (didRunBeforeHook) {
167
+ dispatchHook("after", [resourceState.asyncId]);
168
+ }
169
+ } finally {
170
+ AsyncContextFrame.set(priorFrame);
171
+ }
172
+ }
173
+ }
174
+
175
+ function wrapCallback(callback, options = {}) {
63
176
  if (typeof callback !== "function") {
64
177
  return callback;
65
178
  }
66
- return AsyncContext.Snapshot.wrap(callback);
67
- };
179
+
180
+ const normalizedOptions =
181
+ options && typeof options === "object" ? options : {};
182
+ const snapshot = new AsyncContext.Snapshot();
183
+ const resourceState = createResource(
184
+ normalizedOptions.type,
185
+ normalizedOptions.resource,
186
+ normalizedOptions,
187
+ );
188
+
189
+ function wrapped(...args) {
190
+ const thisArg = normalizedOptions.thisArg === undefined
191
+ ? this
192
+ : normalizedOptions.thisArg;
193
+ return snapshot.run(
194
+ () => runWithResource(resourceState, callback, thisArg, args),
195
+ );
196
+ }
197
+
198
+ try {
199
+ Object.defineProperty(wrapped, "name", {
200
+ configurable: true,
201
+ value: callback.name ? "wrapped " + callback.name : "wrapped",
202
+ });
203
+ } catch {}
204
+
205
+ Object.defineProperty(wrapped, kWrappedState, {
206
+ configurable: false,
207
+ enumerable: false,
208
+ value: resourceState,
209
+ writable: false,
210
+ });
211
+ Object.defineProperty(wrapped, kWrappedDestroy, {
212
+ configurable: false,
213
+ enumerable: false,
214
+ value: () => destroyResource(resourceState),
215
+ writable: false,
216
+ });
217
+
218
+ return wrapped;
219
+ }
220
+
221
+ function releaseCallback(callback) {
222
+ if (typeof callback !== "function") {
223
+ return false;
224
+ }
225
+ const destroy = callback[kWrappedDestroy];
226
+ if (typeof destroy === "function") {
227
+ return destroy();
228
+ }
229
+ return false;
230
+ }
231
+
232
+ function onPromiseInit(promise, parentPromise) {
233
+ const parentState = (
234
+ parentPromise && typeof parentPromise === "object"
235
+ ? promiseStateByPromise.get(parentPromise)
236
+ : undefined
237
+ );
238
+ const promiseState = createResource("PROMISE", promise, {
239
+ triggerAsyncId: parentState?.asyncId ?? getCurrentExecutionState().asyncId,
240
+ });
241
+ promiseStateByPromise.set(promise, promiseState);
242
+ }
243
+
244
+ function onPromiseBefore(promise) {
245
+ const promiseState = promiseStateByPromise.get(promise);
246
+ if (!promiseState) {
247
+ return;
248
+ }
249
+ const priorFrame = enterResource(promiseState);
250
+ promiseFrameStack.push(priorFrame);
251
+ try {
252
+ dispatchHook("before", [promiseState.asyncId]);
253
+ } catch (error) {
254
+ promiseFrameStack.pop();
255
+ AsyncContextFrame.set(priorFrame);
256
+ throw error;
257
+ }
258
+ }
259
+
260
+ function onPromiseAfter(promise) {
261
+ const promiseState = promiseStateByPromise.get(promise);
262
+ if (!promiseState) {
263
+ return;
264
+ }
265
+ const priorFrame = promiseFrameStack.pop();
266
+ try {
267
+ dispatchHook("after", [promiseState.asyncId]);
268
+ } finally {
269
+ AsyncContextFrame.set(priorFrame);
270
+ }
271
+ }
272
+
273
+ function onPromiseResolve(promise) {
274
+ const promiseState = promiseStateByPromise.get(promise);
275
+ if (!promiseState) {
276
+ return;
277
+ }
278
+ dispatchHook("promiseResolve", [promiseState.asyncId]);
279
+ }
280
+
281
+ function refreshPromiseHooks() {
282
+ if (activeHooks.size > 0) {
283
+ if (!promiseHooksEnabled) {
284
+ native.setPromiseHooks(
285
+ onPromiseInit,
286
+ onPromiseBefore,
287
+ onPromiseAfter,
288
+ onPromiseResolve,
289
+ );
290
+ promiseHooksEnabled = true;
291
+ }
292
+ return;
293
+ }
294
+
295
+ if (promiseHooksEnabled) {
296
+ native.setPromiseHooks(undefined, undefined, undefined, undefined);
297
+ promiseFrameStack.length = 0;
298
+ promiseHooksEnabled = false;
299
+ }
300
+ }
301
+
302
+ function enableHook(hook, callbacks) {
303
+ activeHooks.set(hook, callbacks);
304
+ refreshPromiseHooks();
305
+ }
306
+
307
+ function disableHook(hook) {
308
+ activeHooks.delete(hook);
309
+ refreshPromiseHooks();
310
+ }
68
311
 
69
312
  Object.defineProperty(globalThis, "__isolateAsyncContextInternals", {
70
313
  configurable: true,
@@ -72,8 +315,25 @@ var ASYNC_CONTEXT_BOOTSTRAP = `
72
315
  writable: false,
73
316
  value: {
74
317
  AsyncContextFrame,
75
- currentAsyncResource,
318
+ topLevelExecutionState,
319
+ currentExecutionState,
320
+ getCurrentExecutionState,
321
+ executionAsyncId() {
322
+ return getCurrentExecutionState().asyncId;
323
+ },
324
+ triggerAsyncId() {
325
+ return getCurrentExecutionState().triggerAsyncId;
326
+ },
327
+ executionAsyncResource() {
328
+ return getCurrentExecutionState().resource;
329
+ },
330
+ createResource,
331
+ runWithResource,
332
+ destroyResource,
76
333
  wrapCallback,
334
+ releaseCallback,
335
+ enableHook,
336
+ disableHook,
77
337
  },
78
338
  });
79
339
  })();
@@ -86,6 +346,7 @@ async function setupAsyncContext(context) {
86
346
  && typeof globalThis.__ivmAsyncContextInternal === "object"
87
347
  && typeof globalThis.__ivmAsyncContextInternal?.getContinuationPreservedEmbedderData === "function"
88
348
  && typeof globalThis.__ivmAsyncContextInternal?.setContinuationPreservedEmbedderData === "function"
349
+ && typeof globalThis.__ivmAsyncContextInternal?.setPromiseHooks === "function"
89
350
  `);
90
351
  if (!supported) {
91
352
  throw new Error("The installed isolated-vm runtime does not support AsyncContext. " + "Use the async-context-enabled isolate engine build.");
@@ -97,4 +358,4 @@ export {
97
358
  setupAsyncContext
98
359
  };
99
360
 
100
- //# debugId=ABEE91399587999E64756E2164756E21
361
+ //# debugId=8F09A2B6E55A095964756E2164756E21
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/internal/async-context/index.ts"],
4
4
  "sourcesContent": [
5
- "import type ivm from \"@ricsam/isolated-vm\";\n\nconst ASYNC_CONTEXT_BOOTSTRAP = `\n(function() {\n if (globalThis.__isolateAsyncContextInternals) {\n return;\n }\n\n const AsyncContext = globalThis.AsyncContext;\n const native = globalThis.__ivmAsyncContextInternal;\n if (\n !AsyncContext\n || typeof AsyncContext.Variable !== \"function\"\n || typeof AsyncContext.Snapshot !== \"function\"\n || !native\n || typeof native.getContinuationPreservedEmbedderData !== \"function\"\n || typeof native.setContinuationPreservedEmbedderData !== \"function\"\n ) {\n throw new Error(\n \"The installed isolated-vm runtime does not expose async context support. \" +\n \"Install the async-context-enabled isolate engine build.\"\n );\n }\n\n class AsyncContextFrame extends Map {\n constructor(store, value) {\n super(AsyncContextFrame.current() ?? undefined);\n if (arguments.length > 0) {\n this.set(store, value);\n }\n }\n\n static current() {\n return native.getContinuationPreservedEmbedderData();\n }\n\n static set(frame) {\n native.setContinuationPreservedEmbedderData(frame);\n }\n\n static exchange(frame) {\n const prior = this.current();\n this.set(frame);\n return prior;\n }\n\n static disable(store) {\n const frame = this.current();\n frame?.delete(store);\n }\n }\n\n Object.defineProperty(AsyncContextFrame, \"enabled\", {\n configurable: true,\n enumerable: false,\n value: true,\n });\n const currentAsyncResource = new AsyncContext.Variable({\n name: \"isolate.asyncResource\",\n defaultValue: undefined,\n });\n\n const wrapCallback = (callback) => {\n if (typeof callback !== \"function\") {\n return callback;\n }\n return AsyncContext.Snapshot.wrap(callback);\n };\n\n Object.defineProperty(globalThis, \"__isolateAsyncContextInternals\", {\n configurable: true,\n enumerable: false,\n writable: false,\n value: {\n AsyncContextFrame,\n currentAsyncResource,\n wrapCallback,\n },\n });\n})();\n`;\n\nexport interface AsyncContextHandle {\n supported: boolean;\n}\n\nexport async function setupAsyncContext(context: ivm.Context): Promise<AsyncContextHandle> {\n const supported = context.evalSync(`\n typeof globalThis.AsyncContext === \"object\"\n && typeof globalThis.AsyncContext?.Variable === \"function\"\n && typeof globalThis.AsyncContext?.Snapshot === \"function\"\n && typeof globalThis.__ivmAsyncContextInternal === \"object\"\n && typeof globalThis.__ivmAsyncContextInternal?.getContinuationPreservedEmbedderData === \"function\"\n && typeof globalThis.__ivmAsyncContextInternal?.setContinuationPreservedEmbedderData === \"function\"\n `) as boolean;\n\n if (!supported) {\n throw new Error(\n \"The installed isolated-vm runtime does not support AsyncContext. \" +\n \"Use the async-context-enabled isolate engine build.\"\n );\n }\n\n context.evalSync(ASYNC_CONTEXT_BOOTSTRAP);\n return { supported };\n}\n"
5
+ "import type ivm from \"@ricsam/isolated-vm\";\n\nconst ASYNC_CONTEXT_BOOTSTRAP = `\n(function() {\n if (globalThis.__isolateAsyncContextInternals) {\n return;\n }\n\n const AsyncContext = globalThis.AsyncContext;\n const native = globalThis.__ivmAsyncContextInternal;\n if (\n !AsyncContext\n || typeof AsyncContext.Variable !== \"function\"\n || typeof AsyncContext.Snapshot !== \"function\"\n || !native\n || typeof native.getContinuationPreservedEmbedderData !== \"function\"\n || typeof native.setContinuationPreservedEmbedderData !== \"function\"\n || typeof native.setPromiseHooks !== \"function\"\n ) {\n throw new Error(\n \"The installed isolated-vm runtime does not expose async context support. \" +\n \"Install the async-context-enabled isolate engine build.\"\n );\n }\n\n class AsyncContextFrame extends Map {\n constructor(store, value) {\n super(AsyncContextFrame.current() ?? undefined);\n if (arguments.length > 0) {\n this.set(store, value);\n }\n }\n\n static current() {\n return native.getContinuationPreservedEmbedderData();\n }\n\n static set(frame) {\n native.setContinuationPreservedEmbedderData(frame);\n }\n\n static exchange(frame) {\n const prior = this.current();\n this.set(frame);\n return prior;\n }\n\n static disable(store) {\n const frame = this.current();\n frame?.delete(store);\n }\n }\n\n Object.defineProperty(AsyncContextFrame, \"enabled\", {\n configurable: true,\n enumerable: false,\n value: true,\n });\n\n const topLevelResource = {};\n const topLevelExecutionState = {\n asyncId: 1,\n triggerAsyncId: 0,\n type: \"ROOT\",\n resource: topLevelResource,\n destroyed: false,\n };\n const currentExecutionState = new AsyncContext.Variable({\n name: \"isolate.executionState\",\n defaultValue: topLevelExecutionState,\n });\n\n const promiseStateByPromise = new WeakMap();\n const activeHooks = new Map();\n const promiseFrameStack = [];\n const kWrappedState = Symbol(\"isolate.asyncResourceState\");\n const kWrappedDestroy = Symbol(\"isolate.destroyAsyncResource\");\n let nextAsyncId = 2;\n let hookDispatchDepth = 0;\n let promiseHooksEnabled = false;\n\n function getCurrentExecutionState() {\n return currentExecutionState.get();\n }\n\n function normalizeType(type, fallback) {\n if (typeof type === \"string\" && type.length > 0) {\n return type;\n }\n return fallback;\n }\n\n function normalizeTriggerAsyncId(triggerAsyncId) {\n return Number.isSafeInteger(triggerAsyncId) && triggerAsyncId >= 0\n ? triggerAsyncId\n : undefined;\n }\n\n function dispatchHook(name, args) {\n if (hookDispatchDepth > 0 || activeHooks.size === 0) {\n return;\n }\n\n hookDispatchDepth++;\n try {\n for (const [hook, callbacks] of Array.from(activeHooks.entries())) {\n const callback = callbacks[name];\n if (typeof callback === \"function\") {\n Reflect.apply(callback, hook, args);\n }\n }\n } finally {\n hookDispatchDepth--;\n }\n }\n\n function createResource(type, resource, options = {}) {\n const normalizedOptions =\n options && typeof options === \"object\" ? options : {};\n const state = {\n asyncId: nextAsyncId++,\n triggerAsyncId:\n normalizeTriggerAsyncId(normalizedOptions.triggerAsyncId)\n ?? getCurrentExecutionState().asyncId,\n type: normalizeType(type, \"isolate.resource\"),\n resource:\n resource !== undefined && resource !== null ? resource : {},\n destroyed: false,\n };\n\n if (normalizedOptions.emitInit !== false) {\n dispatchHook(\"init\", [\n state.asyncId,\n state.type,\n state.triggerAsyncId,\n state.resource,\n ]);\n }\n\n return state;\n }\n\n function enterResource(resourceState) {\n return AsyncContextFrame.exchange(\n new AsyncContextFrame(currentExecutionState, resourceState),\n );\n }\n\n function destroyResource(resourceState) {\n if (!resourceState || resourceState.destroyed) {\n return false;\n }\n resourceState.destroyed = true;\n dispatchHook(\"destroy\", [resourceState.asyncId]);\n return true;\n }\n\n function runWithResource(resourceState, fn, thisArg, args) {\n const priorFrame = enterResource(resourceState);\n let didRunBeforeHook = false;\n try {\n dispatchHook(\"before\", [resourceState.asyncId]);\n didRunBeforeHook = true;\n return Reflect.apply(fn, thisArg, args);\n } finally {\n try {\n if (didRunBeforeHook) {\n dispatchHook(\"after\", [resourceState.asyncId]);\n }\n } finally {\n AsyncContextFrame.set(priorFrame);\n }\n }\n }\n\n function wrapCallback(callback, options = {}) {\n if (typeof callback !== \"function\") {\n return callback;\n }\n\n const normalizedOptions =\n options && typeof options === \"object\" ? options : {};\n const snapshot = new AsyncContext.Snapshot();\n const resourceState = createResource(\n normalizedOptions.type,\n normalizedOptions.resource,\n normalizedOptions,\n );\n\n function wrapped(...args) {\n const thisArg = normalizedOptions.thisArg === undefined\n ? this\n : normalizedOptions.thisArg;\n return snapshot.run(\n () => runWithResource(resourceState, callback, thisArg, args),\n );\n }\n\n try {\n Object.defineProperty(wrapped, \"name\", {\n configurable: true,\n value: callback.name ? \"wrapped \" + callback.name : \"wrapped\",\n });\n } catch {}\n\n Object.defineProperty(wrapped, kWrappedState, {\n configurable: false,\n enumerable: false,\n value: resourceState,\n writable: false,\n });\n Object.defineProperty(wrapped, kWrappedDestroy, {\n configurable: false,\n enumerable: false,\n value: () => destroyResource(resourceState),\n writable: false,\n });\n\n return wrapped;\n }\n\n function releaseCallback(callback) {\n if (typeof callback !== \"function\") {\n return false;\n }\n const destroy = callback[kWrappedDestroy];\n if (typeof destroy === \"function\") {\n return destroy();\n }\n return false;\n }\n\n function onPromiseInit(promise, parentPromise) {\n const parentState = (\n parentPromise && typeof parentPromise === \"object\"\n ? promiseStateByPromise.get(parentPromise)\n : undefined\n );\n const promiseState = createResource(\"PROMISE\", promise, {\n triggerAsyncId: parentState?.asyncId ?? getCurrentExecutionState().asyncId,\n });\n promiseStateByPromise.set(promise, promiseState);\n }\n\n function onPromiseBefore(promise) {\n const promiseState = promiseStateByPromise.get(promise);\n if (!promiseState) {\n return;\n }\n const priorFrame = enterResource(promiseState);\n promiseFrameStack.push(priorFrame);\n try {\n dispatchHook(\"before\", [promiseState.asyncId]);\n } catch (error) {\n promiseFrameStack.pop();\n AsyncContextFrame.set(priorFrame);\n throw error;\n }\n }\n\n function onPromiseAfter(promise) {\n const promiseState = promiseStateByPromise.get(promise);\n if (!promiseState) {\n return;\n }\n const priorFrame = promiseFrameStack.pop();\n try {\n dispatchHook(\"after\", [promiseState.asyncId]);\n } finally {\n AsyncContextFrame.set(priorFrame);\n }\n }\n\n function onPromiseResolve(promise) {\n const promiseState = promiseStateByPromise.get(promise);\n if (!promiseState) {\n return;\n }\n dispatchHook(\"promiseResolve\", [promiseState.asyncId]);\n }\n\n function refreshPromiseHooks() {\n if (activeHooks.size > 0) {\n if (!promiseHooksEnabled) {\n native.setPromiseHooks(\n onPromiseInit,\n onPromiseBefore,\n onPromiseAfter,\n onPromiseResolve,\n );\n promiseHooksEnabled = true;\n }\n return;\n }\n\n if (promiseHooksEnabled) {\n native.setPromiseHooks(undefined, undefined, undefined, undefined);\n promiseFrameStack.length = 0;\n promiseHooksEnabled = false;\n }\n }\n\n function enableHook(hook, callbacks) {\n activeHooks.set(hook, callbacks);\n refreshPromiseHooks();\n }\n\n function disableHook(hook) {\n activeHooks.delete(hook);\n refreshPromiseHooks();\n }\n\n Object.defineProperty(globalThis, \"__isolateAsyncContextInternals\", {\n configurable: true,\n enumerable: false,\n writable: false,\n value: {\n AsyncContextFrame,\n topLevelExecutionState,\n currentExecutionState,\n getCurrentExecutionState,\n executionAsyncId() {\n return getCurrentExecutionState().asyncId;\n },\n triggerAsyncId() {\n return getCurrentExecutionState().triggerAsyncId;\n },\n executionAsyncResource() {\n return getCurrentExecutionState().resource;\n },\n createResource,\n runWithResource,\n destroyResource,\n wrapCallback,\n releaseCallback,\n enableHook,\n disableHook,\n },\n });\n})();\n`;\n\nexport interface AsyncContextHandle {\n supported: boolean;\n}\n\nexport async function setupAsyncContext(context: ivm.Context): Promise<AsyncContextHandle> {\n const supported = context.evalSync(`\n typeof globalThis.AsyncContext === \"object\"\n && typeof globalThis.AsyncContext?.Variable === \"function\"\n && typeof globalThis.AsyncContext?.Snapshot === \"function\"\n && typeof globalThis.__ivmAsyncContextInternal === \"object\"\n && typeof globalThis.__ivmAsyncContextInternal?.getContinuationPreservedEmbedderData === \"function\"\n && typeof globalThis.__ivmAsyncContextInternal?.setContinuationPreservedEmbedderData === \"function\"\n && typeof globalThis.__ivmAsyncContextInternal?.setPromiseHooks === \"function\"\n `) as boolean;\n\n if (!supported) {\n throw new Error(\n \"The installed isolated-vm runtime does not support AsyncContext. \" +\n \"Use the async-context-enabled isolate engine build.\"\n );\n }\n\n context.evalSync(ASYNC_CONTEXT_BOOTSTRAP);\n return { supported };\n}\n"
6
6
  ],
7
- "mappings": ";AAEA,IAAM,0BAA0B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAoFhC,eAAsB,iBAAiB,CAAC,SAAmD;AAAA,EACzF,MAAM,YAAY,QAAQ,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAOlC;AAAA,EAED,IAAI,CAAC,WAAW;AAAA,IACd,MAAM,IAAI,MACR,sEACA,qDACF;AAAA,EACF;AAAA,EAEA,QAAQ,SAAS,uBAAuB;AAAA,EACxC,OAAO,EAAE,UAAU;AAAA;",
8
- "debugId": "ABEE91399587999E64756E2164756E21",
7
+ "mappings": ";AAEA,IAAM,0BAA0B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAwVhC,eAAsB,iBAAiB,CAAC,SAAmD;AAAA,EACzF,MAAM,YAAY,QAAQ,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAQlC;AAAA,EAED,IAAI,CAAC,WAAW;AAAA,IACd,MAAM,IAAI,MACR,sEACA,qDACF;AAAA,EACF;AAAA,EAEA,QAAQ,SAAS,uBAAuB;AAAA,EACxC,OAAO,EAAE,UAAU;AAAA;",
8
+ "debugId": "8F09A2B6E55A095964756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -1677,10 +1677,15 @@ async function injectAbortController(context) {
1677
1677
  // Use WeakMap for private state (similar to Blob pattern)
1678
1678
  const _abortSignalState = new WeakMap();
1679
1679
  const __wrapAsyncContextCallback = (callback) => (
1680
- typeof callback === 'function' && globalThis.AsyncContext?.Snapshot?.wrap
1681
- ? globalThis.AsyncContext.Snapshot.wrap(callback)
1680
+ typeof callback === 'function' && globalThis.__isolateAsyncContextInternals?.wrapCallback
1681
+ ? globalThis.__isolateAsyncContextInternals.wrapCallback(callback, { type: 'isolate.abort' })
1682
1682
  : callback
1683
1683
  );
1684
+ const __releaseAsyncContextCallback = (callback) => (
1685
+ typeof callback === 'function' && globalThis.__isolateAsyncContextInternals?.releaseCallback
1686
+ ? globalThis.__isolateAsyncContextInternals.releaseCallback(callback)
1687
+ : false
1688
+ );
1684
1689
 
1685
1690
  class AbortSignal {
1686
1691
  constructor() {
@@ -1741,7 +1746,10 @@ async function injectAbortController(context) {
1741
1746
  const idx = state.listeners.findIndex((entry) => (
1742
1747
  entry.original === listener || entry.wrapped === listener
1743
1748
  ));
1744
- if (idx !== -1) state.listeners.splice(idx, 1);
1749
+ if (idx !== -1) {
1750
+ __releaseAsyncContextCallback(state.listeners[idx].wrapped);
1751
+ state.listeners.splice(idx, 1);
1752
+ }
1745
1753
  }
1746
1754
  }
1747
1755
 
@@ -2686,4 +2694,4 @@ export {
2686
2694
  cleanupUnmarshaledHandles
2687
2695
  };
2688
2696
 
2689
- //# debugId=074AB4608F283C7764756E2164756E21
2697
+ //# debugId=10E47F91FBBA287964756E2164756E21