@ricsam/isolate 0.1.10 → 0.1.12
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/README.md +257 -18
- package/dist/cjs/bridge/diagnostics.cjs +37 -2
- package/dist/cjs/bridge/diagnostics.cjs.map +3 -3
- package/dist/cjs/bridge/runtime-bindings.cjs +230 -51
- package/dist/cjs/bridge/runtime-bindings.cjs.map +3 -3
- package/dist/cjs/bridge/sandbox-isolate.cjs +464 -0
- package/dist/cjs/bridge/sandbox-isolate.cjs.map +10 -0
- package/dist/cjs/host/create-isolate-host.cjs +130 -25
- package/dist/cjs/host/create-isolate-host.cjs.map +3 -3
- package/dist/cjs/host/nested-host-controller.cjs +369 -0
- package/dist/cjs/host/nested-host-controller.cjs.map +10 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/internal/browser-source.cjs +102 -0
- package/dist/cjs/internal/browser-source.cjs.map +10 -0
- package/dist/cjs/internal/client/connection.cjs +163 -172
- package/dist/cjs/internal/client/connection.cjs.map +3 -3
- package/dist/cjs/internal/daemon/callback-fs-handler.cjs +3 -3
- package/dist/cjs/internal/daemon/callback-fs-handler.cjs.map +3 -3
- package/dist/cjs/internal/daemon/connection.cjs +156 -13
- package/dist/cjs/internal/daemon/connection.cjs.map +3 -3
- package/dist/cjs/internal/playwright/client.cjs +4 -2
- package/dist/cjs/internal/playwright/client.cjs.map +3 -3
- package/dist/cjs/internal/playwright/handler.cjs +298 -25
- package/dist/cjs/internal/playwright/handler.cjs.map +3 -3
- package/dist/cjs/internal/playwright/index.cjs +54 -8
- package/dist/cjs/internal/playwright/index.cjs.map +3 -3
- package/dist/cjs/internal/playwright/types.cjs +3 -1
- package/dist/cjs/internal/playwright/types.cjs.map +3 -3
- package/dist/cjs/internal/protocol/codec.cjs +16 -5
- package/dist/cjs/internal/protocol/codec.cjs.map +3 -3
- package/dist/cjs/internal/protocol/marshalValue.cjs +37 -6
- package/dist/cjs/internal/protocol/marshalValue.cjs.map +3 -3
- package/dist/cjs/internal/protocol/types.cjs +2 -1
- package/dist/cjs/internal/protocol/types.cjs.map +3 -3
- package/dist/cjs/internal/runtime/index.cjs +377 -22
- package/dist/cjs/internal/runtime/index.cjs.map +3 -3
- package/dist/cjs/internal/typecheck/index.cjs +2 -1
- package/dist/cjs/internal/typecheck/index.cjs.map +3 -3
- package/dist/cjs/internal/typecheck/isolate-types.cjs +218 -13
- package/dist/cjs/internal/typecheck/isolate-types.cjs.map +3 -3
- package/dist/cjs/internal/typecheck/typecheck.cjs +2 -3
- package/dist/cjs/internal/typecheck/typecheck.cjs.map +3 -3
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/playwright.cjs +76 -0
- package/dist/cjs/playwright.cjs.map +10 -0
- package/dist/cjs/runtime/namespaced-runtime.cjs +181 -0
- package/dist/cjs/runtime/namespaced-runtime.cjs.map +10 -0
- package/dist/cjs/runtime/script-runtime.cjs +14 -12
- package/dist/cjs/runtime/script-runtime.cjs.map +3 -3
- package/dist/cjs/runtime/test-runtime.cjs +113 -0
- package/dist/cjs/runtime/test-runtime.cjs.map +10 -0
- package/dist/cjs/server/app-server.cjs +16 -9
- package/dist/cjs/server/app-server.cjs.map +3 -3
- package/dist/cjs/typecheck/index.cjs +2 -1
- package/dist/cjs/typecheck/index.cjs.map +3 -3
- package/dist/mjs/bridge/diagnostics.mjs +37 -2
- package/dist/mjs/bridge/diagnostics.mjs.map +3 -3
- package/dist/mjs/bridge/runtime-bindings.mjs +233 -51
- package/dist/mjs/bridge/runtime-bindings.mjs.map +3 -3
- package/dist/mjs/bridge/sandbox-isolate.mjs +424 -0
- package/dist/mjs/bridge/sandbox-isolate.mjs.map +10 -0
- package/dist/mjs/host/create-isolate-host.mjs +132 -25
- package/dist/mjs/host/create-isolate-host.mjs.map +3 -3
- package/dist/mjs/host/nested-host-controller.mjs +333 -0
- package/dist/mjs/host/nested-host-controller.mjs.map +10 -0
- package/dist/mjs/index.mjs.map +1 -1
- package/dist/mjs/internal/browser-source.mjs +62 -0
- package/dist/mjs/internal/browser-source.mjs.map +10 -0
- package/dist/mjs/internal/client/connection.mjs +165 -173
- package/dist/mjs/internal/client/connection.mjs.map +3 -3
- package/dist/mjs/internal/daemon/callback-fs-handler.mjs +3 -3
- package/dist/mjs/internal/daemon/callback-fs-handler.mjs.map +3 -3
- package/dist/mjs/internal/daemon/connection.mjs +156 -13
- package/dist/mjs/internal/daemon/connection.mjs.map +3 -3
- package/dist/mjs/internal/playwright/client.mjs +7 -3
- package/dist/mjs/internal/playwright/client.mjs.map +3 -3
- package/dist/mjs/internal/playwright/handler.mjs +300 -26
- package/dist/mjs/internal/playwright/handler.mjs.map +3 -3
- package/dist/mjs/internal/playwright/index.mjs +59 -9
- package/dist/mjs/internal/playwright/index.mjs.map +3 -3
- package/dist/mjs/internal/playwright/types.mjs +3 -1
- package/dist/mjs/internal/playwright/types.mjs.map +3 -3
- package/dist/mjs/internal/protocol/codec.mjs +16 -5
- package/dist/mjs/internal/protocol/codec.mjs.map +3 -3
- package/dist/mjs/internal/protocol/marshalValue.mjs +38 -6
- package/dist/mjs/internal/protocol/marshalValue.mjs.map +3 -3
- package/dist/mjs/internal/protocol/types.mjs +2 -1
- package/dist/mjs/internal/protocol/types.mjs.map +3 -3
- package/dist/mjs/internal/runtime/index.mjs +377 -22
- package/dist/mjs/internal/runtime/index.mjs.map +3 -3
- package/dist/mjs/internal/typecheck/index.mjs +3 -1
- package/dist/mjs/internal/typecheck/index.mjs.map +3 -3
- package/dist/mjs/internal/typecheck/isolate-types.mjs +218 -13
- package/dist/mjs/internal/typecheck/isolate-types.mjs.map +3 -3
- package/dist/mjs/internal/typecheck/typecheck.mjs +2 -3
- package/dist/mjs/internal/typecheck/typecheck.mjs.map +3 -3
- package/dist/mjs/package.json +1 -1
- package/dist/mjs/playwright.mjs +47 -0
- package/dist/mjs/playwright.mjs.map +10 -0
- package/dist/mjs/runtime/namespaced-runtime.mjs +143 -0
- package/dist/mjs/runtime/namespaced-runtime.mjs.map +10 -0
- package/dist/mjs/runtime/script-runtime.mjs +16 -12
- package/dist/mjs/runtime/script-runtime.mjs.map +3 -3
- package/dist/mjs/runtime/test-runtime.mjs +78 -0
- package/dist/mjs/runtime/test-runtime.mjs.map +10 -0
- package/dist/mjs/server/app-server.mjs +23 -11
- package/dist/mjs/server/app-server.mjs.map +3 -3
- package/dist/mjs/typecheck/index.mjs +2 -1
- package/dist/mjs/typecheck/index.mjs.map +3 -3
- package/dist/types/bridge/diagnostics.d.ts +6 -1
- package/dist/types/bridge/runtime-bindings.d.ts +5 -1
- package/dist/types/bridge/sandbox-isolate.d.ts +21 -0
- package/dist/types/host/nested-host-controller.d.ts +15 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/internal/browser-source.d.ts +10 -0
- package/dist/types/internal/client/types.d.ts +9 -0
- package/dist/types/internal/daemon/types.d.ts +0 -2
- package/dist/types/internal/playwright/client.d.ts +2 -2
- package/dist/types/internal/playwright/handler.d.ts +27 -4
- package/dist/types/internal/playwright/index.d.ts +2 -2
- package/dist/types/internal/playwright/types.d.ts +33 -1
- package/dist/types/internal/protocol/codec.d.ts +12 -2
- package/dist/types/internal/protocol/marshalValue.d.ts +3 -2
- package/dist/types/internal/protocol/types.d.ts +33 -2
- package/dist/types/internal/runtime/index.d.ts +5 -0
- package/dist/types/internal/typecheck/index.d.ts +1 -1
- package/dist/types/internal/typecheck/isolate-types.d.ts +6 -4
- package/dist/types/internal/typecheck/typecheck.d.ts +1 -1
- package/dist/types/playwright.d.ts +26 -0
- package/dist/types/runtime/namespaced-runtime.d.ts +11 -0
- package/dist/types/runtime/script-runtime.d.ts +2 -1
- package/dist/types/runtime/test-runtime.d.ts +4 -0
- package/dist/types/server/app-server.d.ts +2 -1
- package/dist/types/types.d.ts +75 -33
- package/package.json +8 -3
- package/dist/cjs/browser/browser-runtime.cjs +0 -157
- package/dist/cjs/browser/browser-runtime.cjs.map +0 -10
- package/dist/mjs/browser/browser-runtime.mjs +0 -93
- package/dist/mjs/browser/browser-runtime.mjs.map +0 -10
- package/dist/types/browser/browser-runtime.d.ts +0 -3
|
@@ -233,6 +233,29 @@ var ISOLATE_MARSHAL_CODE = `
|
|
|
233
233
|
);
|
|
234
234
|
let __customFn_nextCallbackId = 1;
|
|
235
235
|
const __customFn_callbacks = new Map();
|
|
236
|
+
let __customFn_nextAsyncRefId = 1;
|
|
237
|
+
const __customFn_promises = new Map();
|
|
238
|
+
const __customFn_iterators = new Map();
|
|
239
|
+
|
|
240
|
+
function __customFn_attachAsyncIterator(resultPromise, label) {
|
|
241
|
+
resultPromise[Symbol.asyncIterator] = async function* () {
|
|
242
|
+
const iterable = await resultPromise;
|
|
243
|
+
if (iterable && typeof iterable[Symbol.asyncIterator] === 'function') {
|
|
244
|
+
yield* iterable;
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
if (iterable && typeof iterable[Symbol.iterator] === 'function') {
|
|
248
|
+
yield* iterable;
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
throw new TypeError(label + '(...) is not async iterable');
|
|
252
|
+
};
|
|
253
|
+
return resultPromise;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
async function __customFn_waitForTurn() {
|
|
257
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
258
|
+
}
|
|
236
259
|
|
|
237
260
|
function __customFn_registerCallback(callback) {
|
|
238
261
|
const callbackId = __customFn_nextCallbackId++;
|
|
@@ -251,7 +274,15 @@ var ISOLATE_MARSHAL_CODE = `
|
|
|
251
274
|
if (type === 'string' || type === 'number' || type === 'boolean') return value;
|
|
252
275
|
if (type === 'bigint') return { __type: 'BigIntRef', value: value.toString() };
|
|
253
276
|
if (type === 'function') {
|
|
254
|
-
return {
|
|
277
|
+
return {
|
|
278
|
+
__type: 'CallbackRef',
|
|
279
|
+
callbackId: __customFn_registerCallback(value),
|
|
280
|
+
callbackKind:
|
|
281
|
+
value.__isolateCallbackKind === 'asyncGenerator' ||
|
|
282
|
+
(value.constructor && value.constructor.name === 'AsyncGeneratorFunction')
|
|
283
|
+
? 'asyncGenerator'
|
|
284
|
+
: undefined,
|
|
285
|
+
};
|
|
255
286
|
}
|
|
256
287
|
if (type === 'symbol') throw new Error('Cannot marshal Symbol values');
|
|
257
288
|
|
|
@@ -265,6 +296,9 @@ var ISOLATE_MARSHAL_CODE = `
|
|
|
265
296
|
if (value instanceof URL) {
|
|
266
297
|
return { __type: 'URLRef', href: value.href };
|
|
267
298
|
}
|
|
299
|
+
if (typeof AbortSignal !== 'undefined' && value instanceof AbortSignal) {
|
|
300
|
+
return { __type: 'AbortSignalRef', aborted: value.aborted };
|
|
301
|
+
}
|
|
268
302
|
if (typeof Headers !== 'undefined' && value instanceof Headers) {
|
|
269
303
|
const pairs = [];
|
|
270
304
|
value.forEach((v, k) => pairs.push([k, v]));
|
|
@@ -304,6 +338,192 @@ var ISOLATE_MARSHAL_CODE = `
|
|
|
304
338
|
return value;
|
|
305
339
|
}
|
|
306
340
|
|
|
341
|
+
async function marshalForHostAsync(value, depth = 0) {
|
|
342
|
+
if (depth > 100) throw new Error('Maximum marshalling depth exceeded');
|
|
343
|
+
|
|
344
|
+
if (value === null || value === undefined) {
|
|
345
|
+
return marshalForHost(value, depth);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
const type = typeof value;
|
|
349
|
+
if (
|
|
350
|
+
type === 'string' ||
|
|
351
|
+
type === 'number' ||
|
|
352
|
+
type === 'boolean' ||
|
|
353
|
+
type === 'bigint' ||
|
|
354
|
+
type === 'function'
|
|
355
|
+
) {
|
|
356
|
+
return marshalForHost(value, depth);
|
|
357
|
+
}
|
|
358
|
+
if (type === 'symbol') {
|
|
359
|
+
throw new Error('Cannot marshal Symbol values');
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
if (value && typeof value.then === 'function') {
|
|
363
|
+
return await marshalForHostAsync(await value, depth);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
if (value && typeof value[Symbol.asyncIterator] === 'function') {
|
|
367
|
+
const iteratorId = __customFn_nextAsyncRefId++;
|
|
368
|
+
const iterator = value[Symbol.asyncIterator]();
|
|
369
|
+
__customFn_iterators.set(iteratorId, iterator);
|
|
370
|
+
|
|
371
|
+
const nextCallbackId = __customFn_registerCallback(async (id) => {
|
|
372
|
+
const target = __customFn_iterators.get(id);
|
|
373
|
+
if (!target) {
|
|
374
|
+
throw new Error('Iterator ' + id + ' not found');
|
|
375
|
+
}
|
|
376
|
+
const result = await target.next();
|
|
377
|
+
if (result.done) {
|
|
378
|
+
__customFn_iterators.delete(id);
|
|
379
|
+
}
|
|
380
|
+
return {
|
|
381
|
+
done: result.done,
|
|
382
|
+
value: await marshalForHostAsync(result.value, depth + 1),
|
|
383
|
+
};
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
const returnCallbackId = __customFn_registerCallback(async (id, returnValue) => {
|
|
387
|
+
const target = __customFn_iterators.get(id);
|
|
388
|
+
__customFn_iterators.delete(id);
|
|
389
|
+
if (!target || typeof target.return !== 'function') {
|
|
390
|
+
return {
|
|
391
|
+
done: true,
|
|
392
|
+
value: marshalForHost(undefined, depth + 1),
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
const result = await target.return(returnValue);
|
|
396
|
+
return {
|
|
397
|
+
done: result.done ?? true,
|
|
398
|
+
value: await marshalForHostAsync(result.value, depth + 1),
|
|
399
|
+
};
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
const throwCallbackId = __customFn_registerCallback(async (id, errorValue) => {
|
|
403
|
+
const target = __customFn_iterators.get(id);
|
|
404
|
+
if (!target) {
|
|
405
|
+
throw new Error('Iterator ' + id + ' not found');
|
|
406
|
+
}
|
|
407
|
+
if (typeof target.throw !== 'function') {
|
|
408
|
+
throw Object.assign(
|
|
409
|
+
new Error(errorValue?.message ?? 'Iterator does not support throw()'),
|
|
410
|
+
{ name: errorValue?.name ?? 'Error', stack: errorValue?.stack }
|
|
411
|
+
);
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
try {
|
|
415
|
+
const thrown = Object.assign(
|
|
416
|
+
new Error(errorValue?.message ?? 'Iterator throw()'),
|
|
417
|
+
{ name: errorValue?.name ?? 'Error', stack: errorValue?.stack }
|
|
418
|
+
);
|
|
419
|
+
const result = await target.throw(thrown);
|
|
420
|
+
if (result.done) {
|
|
421
|
+
__customFn_iterators.delete(id);
|
|
422
|
+
}
|
|
423
|
+
return {
|
|
424
|
+
done: result.done,
|
|
425
|
+
value: await marshalForHostAsync(result.value, depth + 1),
|
|
426
|
+
};
|
|
427
|
+
} catch (error) {
|
|
428
|
+
__customFn_iterators.delete(id);
|
|
429
|
+
throw error;
|
|
430
|
+
}
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
return {
|
|
434
|
+
__type: 'AsyncIteratorRef',
|
|
435
|
+
iteratorId,
|
|
436
|
+
__nextCallbackId: nextCallbackId,
|
|
437
|
+
__returnCallbackId: returnCallbackId,
|
|
438
|
+
__throwCallbackId: throwCallbackId,
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
if (value instanceof Date || value instanceof RegExp || value instanceof URL) {
|
|
443
|
+
return marshalForHost(value, depth);
|
|
444
|
+
}
|
|
445
|
+
if (typeof AbortSignal !== 'undefined' && value instanceof AbortSignal) {
|
|
446
|
+
return marshalForHost(value, depth);
|
|
447
|
+
}
|
|
448
|
+
if (typeof Headers !== 'undefined' && value instanceof Headers) {
|
|
449
|
+
return marshalForHost(value, depth);
|
|
450
|
+
}
|
|
451
|
+
if (value instanceof Uint8Array || value instanceof ArrayBuffer) {
|
|
452
|
+
return marshalForHost(value, depth);
|
|
453
|
+
}
|
|
454
|
+
if (typeof Request !== 'undefined' && value instanceof Request) {
|
|
455
|
+
const headers = [];
|
|
456
|
+
value.headers.forEach((headerValue, key) => headers.push([key, headerValue]));
|
|
457
|
+
const body = value.body
|
|
458
|
+
? Array.from(new Uint8Array(await value.clone().arrayBuffer()))
|
|
459
|
+
: null;
|
|
460
|
+
return {
|
|
461
|
+
__type: 'RequestRef',
|
|
462
|
+
url: value.url,
|
|
463
|
+
method: value.method,
|
|
464
|
+
headers,
|
|
465
|
+
body,
|
|
466
|
+
mode: value.mode,
|
|
467
|
+
credentials: value.credentials,
|
|
468
|
+
cache: value.cache,
|
|
469
|
+
redirect: value.redirect,
|
|
470
|
+
referrer: value.referrer,
|
|
471
|
+
referrerPolicy: value.referrerPolicy,
|
|
472
|
+
integrity: value.integrity,
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
if (typeof Response !== 'undefined' && value instanceof Response) {
|
|
476
|
+
const headers = [];
|
|
477
|
+
value.headers.forEach((headerValue, key) => headers.push([key, headerValue]));
|
|
478
|
+
const body = value.body
|
|
479
|
+
? Array.from(new Uint8Array(await value.clone().arrayBuffer()))
|
|
480
|
+
: null;
|
|
481
|
+
return {
|
|
482
|
+
__type: 'ResponseRef',
|
|
483
|
+
status: value.status,
|
|
484
|
+
statusText: value.statusText,
|
|
485
|
+
headers,
|
|
486
|
+
body,
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
if (typeof File !== 'undefined' && value instanceof File) {
|
|
490
|
+
return {
|
|
491
|
+
__type: 'FileRef',
|
|
492
|
+
name: value.name,
|
|
493
|
+
type: value.type,
|
|
494
|
+
lastModified: value.lastModified,
|
|
495
|
+
data: Array.from(new Uint8Array(await value.arrayBuffer())),
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
if (typeof Blob !== 'undefined' && value instanceof Blob) {
|
|
499
|
+
return {
|
|
500
|
+
__type: 'FileRef',
|
|
501
|
+
type: value.type,
|
|
502
|
+
data: Array.from(new Uint8Array(await value.arrayBuffer())),
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
if (typeof FormData !== 'undefined' && value instanceof FormData) {
|
|
506
|
+
const entries = [];
|
|
507
|
+
for (const [key, entry] of value.entries()) {
|
|
508
|
+
if (typeof entry === 'string') {
|
|
509
|
+
entries.push([key, entry]);
|
|
510
|
+
} else {
|
|
511
|
+
entries.push([key, await marshalForHostAsync(entry, depth + 1)]);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
return { __type: 'FormDataRef', entries };
|
|
515
|
+
}
|
|
516
|
+
if (Array.isArray(value)) {
|
|
517
|
+
return await Promise.all(value.map((item) => marshalForHostAsync(item, depth + 1)));
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
const result = {};
|
|
521
|
+
for (const key of Object.keys(value)) {
|
|
522
|
+
result[key] = await marshalForHostAsync(value[key], depth + 1);
|
|
523
|
+
}
|
|
524
|
+
return result;
|
|
525
|
+
}
|
|
526
|
+
|
|
307
527
|
async function invokeLocalCallback(callbackId, argsJson) {
|
|
308
528
|
const callback = __customFn_callbacks.get(callbackId);
|
|
309
529
|
if (!callback) {
|
|
@@ -319,8 +539,8 @@ var ISOLATE_MARSHAL_CODE = `
|
|
|
319
539
|
try {
|
|
320
540
|
const rawArgs = JSON.parse(argsJson);
|
|
321
541
|
const args = unmarshalFromHost(rawArgs);
|
|
322
|
-
const result =
|
|
323
|
-
return JSON.stringify({ ok: true, value:
|
|
542
|
+
const result = callback(...args);
|
|
543
|
+
return JSON.stringify({ ok: true, value: await marshalForHostAsync(result) });
|
|
324
544
|
} catch (error) {
|
|
325
545
|
const err = error instanceof Error ? error : new Error(String(error));
|
|
326
546
|
return JSON.stringify({
|
|
@@ -347,6 +567,12 @@ var ISOLATE_MARSHAL_CODE = `
|
|
|
347
567
|
case 'RegExpRef': return new RegExp(value.source, value.flags);
|
|
348
568
|
case 'BigIntRef': return BigInt(value.value);
|
|
349
569
|
case 'URLRef': return new URL(value.href);
|
|
570
|
+
case 'AbortSignalRef': {
|
|
571
|
+
if (value.aborted) {
|
|
572
|
+
return AbortSignal.abort();
|
|
573
|
+
}
|
|
574
|
+
return new AbortController().signal;
|
|
575
|
+
}
|
|
350
576
|
case 'HeadersRef': return new Headers(value.pairs);
|
|
351
577
|
case 'Uint8ArrayRef': return new Uint8Array(value.data);
|
|
352
578
|
case 'RequestRef': {
|
|
@@ -450,6 +676,7 @@ var ISOLATE_MARSHAL_CODE = `
|
|
|
450
676
|
error.name = result.error.name;
|
|
451
677
|
throw error;
|
|
452
678
|
}
|
|
679
|
+
await __customFn_waitForTurn();
|
|
453
680
|
return {
|
|
454
681
|
done: result.value.done,
|
|
455
682
|
value: unmarshalFromHost(result.value.value)
|
|
@@ -468,6 +695,7 @@ var ISOLATE_MARSHAL_CODE = `
|
|
|
468
695
|
error.name = result.error.name;
|
|
469
696
|
throw error;
|
|
470
697
|
}
|
|
698
|
+
await __customFn_waitForTurn();
|
|
471
699
|
return {
|
|
472
700
|
done: result.value.done ?? true,
|
|
473
701
|
value: unmarshalFromHost(result.value.value ?? result.value),
|
|
@@ -492,6 +720,7 @@ var ISOLATE_MARSHAL_CODE = `
|
|
|
492
720
|
error.name = result.error.name;
|
|
493
721
|
throw error;
|
|
494
722
|
}
|
|
723
|
+
await __customFn_waitForTurn();
|
|
495
724
|
return {
|
|
496
725
|
done: result.value.done,
|
|
497
726
|
value: unmarshalFromHost(result.value.value),
|
|
@@ -521,6 +750,8 @@ var ISOLATE_MARSHAL_CODE = `
|
|
|
521
750
|
globalThis.__marshalForHost = marshalForHost;
|
|
522
751
|
globalThis.__unmarshalFromHost = unmarshalFromHost;
|
|
523
752
|
globalThis.__customFn_invokeLocalCallback = invokeLocalCallback;
|
|
753
|
+
globalThis.__customFn_attachAsyncIterator = __customFn_attachAsyncIterator;
|
|
754
|
+
globalThis.__customFn_waitForTurn = __customFn_waitForTurn;
|
|
524
755
|
})();
|
|
525
756
|
`;
|
|
526
757
|
async function setupCustomFunctions(context, customFunctions, marshalOptions) {
|
|
@@ -578,6 +809,23 @@ async function setupCustomFunctions(context, customFunctions, marshalOptions) {
|
|
|
578
809
|
global.setSync("__customFn_invoke", invokeCallbackRef);
|
|
579
810
|
context.evalSync(ISOLATE_MARSHAL_CODE);
|
|
580
811
|
const invokeIsolateCallbackRef = context.global.getSync("__customFn_invokeLocalCallback", { reference: true });
|
|
812
|
+
const normalizeIsolateCallbackResult = async (value) => {
|
|
813
|
+
if (typeof Response !== "undefined" && value instanceof Response) {
|
|
814
|
+
const headers = [];
|
|
815
|
+
value.headers.forEach((headerValue, key) => {
|
|
816
|
+
headers.push([key, headerValue]);
|
|
817
|
+
});
|
|
818
|
+
const body = value.body ? Array.from(new Uint8Array(await value.clone().arrayBuffer())) : null;
|
|
819
|
+
return {
|
|
820
|
+
__type: "ResponseRef",
|
|
821
|
+
status: value.status,
|
|
822
|
+
statusText: value.statusText,
|
|
823
|
+
headers,
|
|
824
|
+
body
|
|
825
|
+
};
|
|
826
|
+
}
|
|
827
|
+
return value;
|
|
828
|
+
};
|
|
581
829
|
isolateUnmarshalContext.getCallback = (callbackId) => {
|
|
582
830
|
return async (...args) => {
|
|
583
831
|
let marshalledArgs;
|
|
@@ -591,31 +839,110 @@ async function setupCustomFunctions(context, customFunctions, marshalOptions) {
|
|
|
591
839
|
const resultJson = await invokeIsolateCallbackRef.apply(undefined, [callbackId, JSON.stringify(marshalledArgs)], { result: { promise: true, copy: true } });
|
|
592
840
|
const result = JSON.parse(resultJson);
|
|
593
841
|
if (result.ok) {
|
|
594
|
-
|
|
842
|
+
const unmarshalled = import_protocol3.unmarshalValue(result.value, isolateUnmarshalContext);
|
|
843
|
+
return await normalizeIsolateCallbackResult(unmarshalled);
|
|
595
844
|
}
|
|
596
845
|
const error = new Error(result.error?.message ?? `Callback ${callbackId} failed`);
|
|
597
846
|
error.name = result.error?.name ?? "Error";
|
|
598
847
|
throw error;
|
|
599
848
|
};
|
|
600
849
|
};
|
|
850
|
+
isolateUnmarshalContext.createPromiseProxy = (promiseId, ref) => {
|
|
851
|
+
const resolveCallbackId = ref?.__resolveCallbackId;
|
|
852
|
+
if (typeof resolveCallbackId !== "number") {
|
|
853
|
+
throw new Error(`Promise ${promiseId} is missing a resolve callback`);
|
|
854
|
+
}
|
|
855
|
+
return (async () => {
|
|
856
|
+
const resultJson = await invokeIsolateCallbackRef.apply(undefined, [resolveCallbackId, JSON.stringify([promiseId])], { result: { promise: true, copy: true } });
|
|
857
|
+
const result = JSON.parse(resultJson);
|
|
858
|
+
if (result.ok) {
|
|
859
|
+
return import_protocol3.unmarshalValue(result.value, isolateUnmarshalContext);
|
|
860
|
+
}
|
|
861
|
+
const error = new Error(result.error?.message ?? `Promise ${promiseId} failed`);
|
|
862
|
+
error.name = result.error?.name ?? "Error";
|
|
863
|
+
throw error;
|
|
864
|
+
})();
|
|
865
|
+
};
|
|
866
|
+
isolateUnmarshalContext.createIteratorProxy = (iteratorId, ref) => {
|
|
867
|
+
const nextCallbackId = ref?.__nextCallbackId;
|
|
868
|
+
const returnCallbackId = ref?.__returnCallbackId;
|
|
869
|
+
const throwCallbackId = ref?.__throwCallbackId;
|
|
870
|
+
if (typeof nextCallbackId !== "number") {
|
|
871
|
+
throw new Error(`Iterator ${iteratorId} is missing a next callback`);
|
|
872
|
+
}
|
|
873
|
+
const invokeIteratorCallback = async (callbackId, args, label) => {
|
|
874
|
+
const resultJson = await invokeIsolateCallbackRef.apply(undefined, [callbackId, JSON.stringify(args)], { result: { promise: true, copy: true } });
|
|
875
|
+
const result = JSON.parse(resultJson);
|
|
876
|
+
if (result.ok) {
|
|
877
|
+
return result.value;
|
|
878
|
+
}
|
|
879
|
+
const error = new Error(result.error?.message ?? `${label} failed for iterator ${iteratorId}`);
|
|
880
|
+
error.name = result.error?.name ?? "Error";
|
|
881
|
+
throw error;
|
|
882
|
+
};
|
|
883
|
+
return {
|
|
884
|
+
[Symbol.asyncIterator]() {
|
|
885
|
+
return this;
|
|
886
|
+
},
|
|
887
|
+
async next() {
|
|
888
|
+
const result = await invokeIteratorCallback(nextCallbackId, [iteratorId], "Iterator next()");
|
|
889
|
+
return {
|
|
890
|
+
done: Boolean(result.done),
|
|
891
|
+
value: import_protocol3.unmarshalValue(result.value, isolateUnmarshalContext)
|
|
892
|
+
};
|
|
893
|
+
},
|
|
894
|
+
async return(value) {
|
|
895
|
+
if (typeof returnCallbackId !== "number") {
|
|
896
|
+
return { done: true, value };
|
|
897
|
+
}
|
|
898
|
+
const result = await invokeIteratorCallback(returnCallbackId, [iteratorId, value], "Iterator return()");
|
|
899
|
+
return {
|
|
900
|
+
done: result.done ?? true,
|
|
901
|
+
value: import_protocol3.unmarshalValue(result.value, isolateUnmarshalContext)
|
|
902
|
+
};
|
|
903
|
+
},
|
|
904
|
+
async throw(errorValue) {
|
|
905
|
+
if (typeof throwCallbackId !== "number") {
|
|
906
|
+
throw errorValue;
|
|
907
|
+
}
|
|
908
|
+
const serializedError = errorValue && typeof errorValue === "object" ? {
|
|
909
|
+
message: errorValue.message,
|
|
910
|
+
name: errorValue.name,
|
|
911
|
+
stack: errorValue.stack
|
|
912
|
+
} : {
|
|
913
|
+
message: String(errorValue ?? "Iterator throw()"),
|
|
914
|
+
name: "Error"
|
|
915
|
+
};
|
|
916
|
+
const result = await invokeIteratorCallback(throwCallbackId, [iteratorId, serializedError], "Iterator throw()");
|
|
917
|
+
return {
|
|
918
|
+
done: Boolean(result.done),
|
|
919
|
+
value: import_protocol3.unmarshalValue(result.value, isolateUnmarshalContext)
|
|
920
|
+
};
|
|
921
|
+
}
|
|
922
|
+
};
|
|
923
|
+
};
|
|
601
924
|
for (const name of Object.keys(customFunctions)) {
|
|
602
925
|
const def = customFunctions[name];
|
|
603
926
|
if (def.type === "async") {
|
|
604
927
|
context.evalSync(`
|
|
605
|
-
globalThis.${name} =
|
|
606
|
-
const
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
928
|
+
globalThis.${name} = function(...args) {
|
|
929
|
+
const resultPromise = (async () => {
|
|
930
|
+
const marshalledArgs = __marshalForHost(args);
|
|
931
|
+
const resultJson = await __customFn_invoke.apply(
|
|
932
|
+
undefined,
|
|
933
|
+
["${name}", JSON.stringify(marshalledArgs)],
|
|
934
|
+
{ result: { promise: true, copy: true } }
|
|
935
|
+
);
|
|
936
|
+
const result = JSON.parse(resultJson);
|
|
937
|
+
if (result.ok) {
|
|
938
|
+
await __customFn_waitForTurn();
|
|
939
|
+
return __unmarshalFromHost(result.value);
|
|
940
|
+
}
|
|
941
|
+
const error = new Error(result.error.message);
|
|
942
|
+
error.name = result.error.name;
|
|
943
|
+
throw error;
|
|
944
|
+
})();
|
|
945
|
+
return __customFn_attachAsyncIterator(resultPromise, "${name}");
|
|
619
946
|
};
|
|
620
947
|
`);
|
|
621
948
|
} else if (def.type === "sync") {
|
|
@@ -654,18 +981,38 @@ async function setupCustomFunctions(context, customFunctions, marshalOptions) {
|
|
|
654
981
|
name: result.error.name,
|
|
655
982
|
});
|
|
656
983
|
})();
|
|
984
|
+
let iteratorRef;
|
|
985
|
+
const getIterator = async () => {
|
|
986
|
+
if (!iteratorRef) {
|
|
987
|
+
let iterator = await iteratorPromise;
|
|
988
|
+
for (let depth = 0; depth < 4; depth += 1) {
|
|
989
|
+
if (iterator && typeof iterator.next === 'function') {
|
|
990
|
+
break;
|
|
991
|
+
}
|
|
992
|
+
if (!iterator || typeof iterator[Symbol.asyncIterator] !== 'function') {
|
|
993
|
+
break;
|
|
994
|
+
}
|
|
995
|
+
iterator = iterator[Symbol.asyncIterator]();
|
|
996
|
+
}
|
|
997
|
+
iteratorRef = iterator;
|
|
998
|
+
}
|
|
999
|
+
return iteratorRef;
|
|
1000
|
+
};
|
|
657
1001
|
return {
|
|
658
1002
|
[Symbol.asyncIterator]() { return this; },
|
|
659
1003
|
async next() {
|
|
660
|
-
const iterator = await
|
|
1004
|
+
const iterator = await getIterator();
|
|
1005
|
+
if (!iterator || typeof iterator.next !== 'function') {
|
|
1006
|
+
throw new TypeError('Custom async iterator resolved to a non-iterator');
|
|
1007
|
+
}
|
|
661
1008
|
return iterator.next();
|
|
662
1009
|
},
|
|
663
1010
|
async return(v) {
|
|
664
|
-
const iterator = await
|
|
1011
|
+
const iterator = await getIterator();
|
|
665
1012
|
return iterator.return ? iterator.return(v) : { done: true, value: v };
|
|
666
1013
|
},
|
|
667
1014
|
async throw(e) {
|
|
668
|
-
const iterator = await
|
|
1015
|
+
const iterator = await getIterator();
|
|
669
1016
|
if (!iterator.throw) {
|
|
670
1017
|
throw e;
|
|
671
1018
|
}
|
|
@@ -991,6 +1338,7 @@ async function createRuntime(options) {
|
|
|
991
1338
|
}
|
|
992
1339
|
const playwrightSetupOptions = {
|
|
993
1340
|
handler: opts.playwright.handler,
|
|
1341
|
+
hasDefaultPage: opts.playwright.hasDefaultPage,
|
|
994
1342
|
timeout: opts.playwright.timeout,
|
|
995
1343
|
console: opts.playwright.console && !opts.console?.onEntry,
|
|
996
1344
|
onEvent: eventCallback
|
|
@@ -1182,6 +1530,13 @@ async function createRuntime(options) {
|
|
|
1182
1530
|
requestFailures: state.handles.playwright.getRequestFailures()
|
|
1183
1531
|
};
|
|
1184
1532
|
},
|
|
1533
|
+
getTrackedResources() {
|
|
1534
|
+
ensureRuntimeUsable();
|
|
1535
|
+
if (!state.handles.playwright) {
|
|
1536
|
+
throw new Error("Playwright not configured. Provide playwright.handler in createRuntime options.");
|
|
1537
|
+
}
|
|
1538
|
+
return state.handles.playwright.getTrackedResources();
|
|
1539
|
+
},
|
|
1185
1540
|
clearCollectedData() {
|
|
1186
1541
|
ensureRuntimeUsable();
|
|
1187
1542
|
state.handles.playwright?.clearCollected();
|
|
@@ -1304,4 +1659,4 @@ ${trimmed.map((p) => ` ${p}`).join(`
|
|
|
1304
1659
|
};
|
|
1305
1660
|
}
|
|
1306
1661
|
|
|
1307
|
-
//# debugId=
|
|
1662
|
+
//# debugId=02620CFDF0CE45BE64756E2164756E21
|