@ricsam/isolate-fetch 0.1.19 → 0.1.21
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/dist/cjs/index.cjs +95 -62
- package/dist/cjs/index.cjs.map +3 -3
- package/dist/cjs/package.json +1 -1
- package/dist/mjs/index.mjs +95 -62
- package/dist/mjs/index.mjs.map +3 -3
- package/dist/mjs/package.json +1 -1
- package/package.json +2 -2
package/dist/cjs/package.json
CHANGED
package/dist/mjs/index.mjs
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
} from "./stream-state.mjs";
|
|
8
8
|
var instanceStateMap = new WeakMap;
|
|
9
9
|
var passthruBodies = new WeakMap;
|
|
10
|
+
var trackedGlobalHandles = new WeakMap;
|
|
10
11
|
var nextInstanceId = 1;
|
|
11
12
|
function getInstanceStateMapForContext(context) {
|
|
12
13
|
let map = instanceStateMap.get(context);
|
|
@@ -24,6 +25,37 @@ function getPassthruBodiesForContext(context) {
|
|
|
24
25
|
}
|
|
25
26
|
return map;
|
|
26
27
|
}
|
|
28
|
+
function getTrackedGlobalHandlesForContext(context) {
|
|
29
|
+
let handles = trackedGlobalHandles.get(context);
|
|
30
|
+
if (!handles) {
|
|
31
|
+
handles = new Set;
|
|
32
|
+
trackedGlobalHandles.set(context, handles);
|
|
33
|
+
}
|
|
34
|
+
return handles;
|
|
35
|
+
}
|
|
36
|
+
function setTrackedGlobal(context, name, value) {
|
|
37
|
+
if (value instanceof ivm.Callback || value instanceof ivm.Reference) {
|
|
38
|
+
getTrackedGlobalHandlesForContext(context).add(value);
|
|
39
|
+
}
|
|
40
|
+
context.global.setSync(name, value);
|
|
41
|
+
}
|
|
42
|
+
function releaseIfSupported(handle) {
|
|
43
|
+
const maybeHandle = handle;
|
|
44
|
+
if (typeof maybeHandle.release === "function") {
|
|
45
|
+
maybeHandle.release();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function releaseTrackedGlobalHandles(context) {
|
|
49
|
+
const handles = trackedGlobalHandles.get(context);
|
|
50
|
+
if (!handles)
|
|
51
|
+
return;
|
|
52
|
+
for (const handle of handles) {
|
|
53
|
+
try {
|
|
54
|
+
releaseIfSupported(handle);
|
|
55
|
+
} catch {}
|
|
56
|
+
}
|
|
57
|
+
handles.clear();
|
|
58
|
+
}
|
|
27
59
|
var headersCode = `
|
|
28
60
|
(function() {
|
|
29
61
|
class Headers {
|
|
@@ -356,24 +388,23 @@ var multipartCode = `
|
|
|
356
388
|
})();
|
|
357
389
|
`;
|
|
358
390
|
function setupStreamCallbacks(context, streamRegistry) {
|
|
359
|
-
|
|
360
|
-
global.setSync("__Stream_create", new ivm.Callback(() => {
|
|
391
|
+
setTrackedGlobal(context, "__Stream_create", new ivm.Callback(() => {
|
|
361
392
|
return streamRegistry.create();
|
|
362
393
|
}));
|
|
363
|
-
|
|
394
|
+
setTrackedGlobal(context, "__Stream_push", new ivm.Callback((streamId, chunkArray) => {
|
|
364
395
|
const chunk = new Uint8Array(chunkArray);
|
|
365
396
|
return streamRegistry.push(streamId, chunk);
|
|
366
397
|
}));
|
|
367
|
-
|
|
398
|
+
setTrackedGlobal(context, "__Stream_close", new ivm.Callback((streamId) => {
|
|
368
399
|
streamRegistry.close(streamId);
|
|
369
400
|
}));
|
|
370
|
-
|
|
401
|
+
setTrackedGlobal(context, "__Stream_error", new ivm.Callback((streamId, message) => {
|
|
371
402
|
streamRegistry.error(streamId, new Error(message));
|
|
372
403
|
}));
|
|
373
|
-
|
|
404
|
+
setTrackedGlobal(context, "__Stream_isQueueFull", new ivm.Callback((streamId) => {
|
|
374
405
|
return streamRegistry.isQueueFull(streamId);
|
|
375
406
|
}));
|
|
376
|
-
|
|
407
|
+
setTrackedGlobal(context, "__Stream_cancel", new ivm.Callback((streamId) => {
|
|
377
408
|
streamRegistry.cancel(streamId);
|
|
378
409
|
}));
|
|
379
410
|
const pullRef = new ivm.Reference(async (streamId) => {
|
|
@@ -383,7 +414,7 @@ function setupStreamCallbacks(context, streamRegistry) {
|
|
|
383
414
|
}
|
|
384
415
|
return JSON.stringify({ done: false, value: Array.from(result.value) });
|
|
385
416
|
});
|
|
386
|
-
|
|
417
|
+
setTrackedGlobal(context, "__Stream_pull_ref", pullRef);
|
|
387
418
|
}
|
|
388
419
|
var hostBackedStreamCode = `
|
|
389
420
|
(function() {
|
|
@@ -466,8 +497,7 @@ var hostBackedStreamCode = `
|
|
|
466
497
|
})();
|
|
467
498
|
`;
|
|
468
499
|
function setupResponse(context, stateMap, streamRegistry) {
|
|
469
|
-
|
|
470
|
-
global.setSync("__Response_construct", new ivm.Callback((bodyBytes, status, statusText, headers) => {
|
|
500
|
+
setTrackedGlobal(context, "__Response_construct", new ivm.Callback((bodyBytes, status, statusText, headers) => {
|
|
471
501
|
const instanceId = nextInstanceId++;
|
|
472
502
|
const body = bodyBytes ? new Uint8Array(bodyBytes) : null;
|
|
473
503
|
const state = {
|
|
@@ -484,7 +514,7 @@ function setupResponse(context, stateMap, streamRegistry) {
|
|
|
484
514
|
stateMap.set(instanceId, state);
|
|
485
515
|
return instanceId;
|
|
486
516
|
}));
|
|
487
|
-
|
|
517
|
+
setTrackedGlobal(context, "__Response_constructStreaming", new ivm.Callback((streamId, status, statusText, headers) => {
|
|
488
518
|
const instanceId = nextInstanceId++;
|
|
489
519
|
const state = {
|
|
490
520
|
status,
|
|
@@ -500,7 +530,7 @@ function setupResponse(context, stateMap, streamRegistry) {
|
|
|
500
530
|
stateMap.set(instanceId, state);
|
|
501
531
|
return instanceId;
|
|
502
532
|
}));
|
|
503
|
-
|
|
533
|
+
setTrackedGlobal(context, "__Response_constructFromFetch", new ivm.Callback((bodyBytes, status, statusText, headers, url, redirected) => {
|
|
504
534
|
const instanceId = nextInstanceId++;
|
|
505
535
|
const body = bodyBytes ? new Uint8Array(bodyBytes) : null;
|
|
506
536
|
const state = {
|
|
@@ -517,45 +547,45 @@ function setupResponse(context, stateMap, streamRegistry) {
|
|
|
517
547
|
stateMap.set(instanceId, state);
|
|
518
548
|
return instanceId;
|
|
519
549
|
}));
|
|
520
|
-
|
|
550
|
+
setTrackedGlobal(context, "__Response_get_status", new ivm.Callback((instanceId) => {
|
|
521
551
|
const state = stateMap.get(instanceId);
|
|
522
552
|
return state?.status ?? 200;
|
|
523
553
|
}));
|
|
524
|
-
|
|
554
|
+
setTrackedGlobal(context, "__Response_get_statusText", new ivm.Callback((instanceId) => {
|
|
525
555
|
const state = stateMap.get(instanceId);
|
|
526
556
|
return state?.statusText ?? "";
|
|
527
557
|
}));
|
|
528
|
-
|
|
558
|
+
setTrackedGlobal(context, "__Response_get_headers", new ivm.Callback((instanceId) => {
|
|
529
559
|
const state = stateMap.get(instanceId);
|
|
530
560
|
return state?.headers ?? [];
|
|
531
561
|
}));
|
|
532
|
-
|
|
562
|
+
setTrackedGlobal(context, "__Response_get_bodyUsed", new ivm.Callback((instanceId) => {
|
|
533
563
|
const state = stateMap.get(instanceId);
|
|
534
564
|
return state?.bodyUsed ?? false;
|
|
535
565
|
}));
|
|
536
|
-
|
|
566
|
+
setTrackedGlobal(context, "__Response_get_url", new ivm.Callback((instanceId) => {
|
|
537
567
|
const state = stateMap.get(instanceId);
|
|
538
568
|
return state?.url ?? "";
|
|
539
569
|
}));
|
|
540
|
-
|
|
570
|
+
setTrackedGlobal(context, "__Response_get_redirected", new ivm.Callback((instanceId) => {
|
|
541
571
|
const state = stateMap.get(instanceId);
|
|
542
572
|
return state?.redirected ?? false;
|
|
543
573
|
}));
|
|
544
|
-
|
|
574
|
+
setTrackedGlobal(context, "__Response_get_type", new ivm.Callback((instanceId) => {
|
|
545
575
|
const state = stateMap.get(instanceId);
|
|
546
576
|
return state?.type ?? "default";
|
|
547
577
|
}));
|
|
548
|
-
|
|
578
|
+
setTrackedGlobal(context, "__Response_get_nullBody", new ivm.Callback((instanceId) => {
|
|
549
579
|
const state = stateMap.get(instanceId);
|
|
550
580
|
return state?.nullBody ?? false;
|
|
551
581
|
}));
|
|
552
|
-
|
|
582
|
+
setTrackedGlobal(context, "__Response_setType", new ivm.Callback((instanceId, type) => {
|
|
553
583
|
const state = stateMap.get(instanceId);
|
|
554
584
|
if (state) {
|
|
555
585
|
state.type = type;
|
|
556
586
|
}
|
|
557
587
|
}));
|
|
558
|
-
|
|
588
|
+
setTrackedGlobal(context, "__Response_markBodyUsed", new ivm.Callback((instanceId) => {
|
|
559
589
|
const state = stateMap.get(instanceId);
|
|
560
590
|
if (state) {
|
|
561
591
|
if (state.bodyUsed) {
|
|
@@ -564,20 +594,20 @@ function setupResponse(context, stateMap, streamRegistry) {
|
|
|
564
594
|
state.bodyUsed = true;
|
|
565
595
|
}
|
|
566
596
|
}));
|
|
567
|
-
|
|
597
|
+
setTrackedGlobal(context, "__Response_text", new ivm.Callback((instanceId) => {
|
|
568
598
|
const state = stateMap.get(instanceId);
|
|
569
599
|
if (!state || !state.body)
|
|
570
600
|
return "";
|
|
571
601
|
return new TextDecoder().decode(state.body);
|
|
572
602
|
}));
|
|
573
|
-
|
|
603
|
+
setTrackedGlobal(context, "__Response_arrayBuffer", new ivm.Callback((instanceId) => {
|
|
574
604
|
const state = stateMap.get(instanceId);
|
|
575
605
|
if (!state || !state.body) {
|
|
576
606
|
return new ivm.ExternalCopy(new ArrayBuffer(0)).copyInto();
|
|
577
607
|
}
|
|
578
608
|
return new ivm.ExternalCopy(state.body.buffer.slice(state.body.byteOffset, state.body.byteOffset + state.body.byteLength)).copyInto();
|
|
579
609
|
}));
|
|
580
|
-
|
|
610
|
+
setTrackedGlobal(context, "__Response_clone", new ivm.Callback((instanceId) => {
|
|
581
611
|
const state = stateMap.get(instanceId);
|
|
582
612
|
if (!state) {
|
|
583
613
|
throw new Error("[TypeError]Cannot clone invalid Response");
|
|
@@ -623,7 +653,7 @@ function setupResponse(context, stateMap, streamRegistry) {
|
|
|
623
653
|
stateMap.set(newId, newState);
|
|
624
654
|
return newId;
|
|
625
655
|
}));
|
|
626
|
-
|
|
656
|
+
setTrackedGlobal(context, "__Response_getStreamId", new ivm.Callback((instanceId) => {
|
|
627
657
|
const state = stateMap.get(instanceId);
|
|
628
658
|
return state?.streamId ?? null;
|
|
629
659
|
}));
|
|
@@ -1008,8 +1038,7 @@ function setupResponse(context, stateMap, streamRegistry) {
|
|
|
1008
1038
|
context.evalSync(responseCode);
|
|
1009
1039
|
}
|
|
1010
1040
|
function setupRequest(context, stateMap) {
|
|
1011
|
-
|
|
1012
|
-
global.setSync("__Request_construct", new ivm.Callback((url, method, headers, bodyBytes, mode, credentials, cache, redirect, referrer, integrity) => {
|
|
1041
|
+
setTrackedGlobal(context, "__Request_construct", new ivm.Callback((url, method, headers, bodyBytes, mode, credentials, cache, redirect, referrer, integrity) => {
|
|
1013
1042
|
const instanceId = nextInstanceId++;
|
|
1014
1043
|
const body = bodyBytes ? new Uint8Array(bodyBytes) : null;
|
|
1015
1044
|
const state = {
|
|
@@ -1030,47 +1059,47 @@ function setupRequest(context, stateMap) {
|
|
|
1030
1059
|
stateMap.set(instanceId, state);
|
|
1031
1060
|
return instanceId;
|
|
1032
1061
|
}));
|
|
1033
|
-
|
|
1062
|
+
setTrackedGlobal(context, "__Request_get_method", new ivm.Callback((instanceId) => {
|
|
1034
1063
|
const state = stateMap.get(instanceId);
|
|
1035
1064
|
return state?.method ?? "GET";
|
|
1036
1065
|
}));
|
|
1037
|
-
|
|
1066
|
+
setTrackedGlobal(context, "__Request_get_url", new ivm.Callback((instanceId) => {
|
|
1038
1067
|
const state = stateMap.get(instanceId);
|
|
1039
1068
|
return state?.url ?? "";
|
|
1040
1069
|
}));
|
|
1041
|
-
|
|
1070
|
+
setTrackedGlobal(context, "__Request_get_headers", new ivm.Callback((instanceId) => {
|
|
1042
1071
|
const state = stateMap.get(instanceId);
|
|
1043
1072
|
return state?.headers ?? [];
|
|
1044
1073
|
}));
|
|
1045
|
-
|
|
1074
|
+
setTrackedGlobal(context, "__Request_get_bodyUsed", new ivm.Callback((instanceId) => {
|
|
1046
1075
|
const state = stateMap.get(instanceId);
|
|
1047
1076
|
return state?.bodyUsed ?? false;
|
|
1048
1077
|
}));
|
|
1049
|
-
|
|
1078
|
+
setTrackedGlobal(context, "__Request_get_mode", new ivm.Callback((instanceId) => {
|
|
1050
1079
|
const state = stateMap.get(instanceId);
|
|
1051
1080
|
return state?.mode ?? "cors";
|
|
1052
1081
|
}));
|
|
1053
|
-
|
|
1082
|
+
setTrackedGlobal(context, "__Request_get_credentials", new ivm.Callback((instanceId) => {
|
|
1054
1083
|
const state = stateMap.get(instanceId);
|
|
1055
1084
|
return state?.credentials ?? "same-origin";
|
|
1056
1085
|
}));
|
|
1057
|
-
|
|
1086
|
+
setTrackedGlobal(context, "__Request_get_cache", new ivm.Callback((instanceId) => {
|
|
1058
1087
|
const state = stateMap.get(instanceId);
|
|
1059
1088
|
return state?.cache ?? "default";
|
|
1060
1089
|
}));
|
|
1061
|
-
|
|
1090
|
+
setTrackedGlobal(context, "__Request_get_redirect", new ivm.Callback((instanceId) => {
|
|
1062
1091
|
const state = stateMap.get(instanceId);
|
|
1063
1092
|
return state?.redirect ?? "follow";
|
|
1064
1093
|
}));
|
|
1065
|
-
|
|
1094
|
+
setTrackedGlobal(context, "__Request_get_referrer", new ivm.Callback((instanceId) => {
|
|
1066
1095
|
const state = stateMap.get(instanceId);
|
|
1067
1096
|
return state?.referrer ?? "about:client";
|
|
1068
1097
|
}));
|
|
1069
|
-
|
|
1098
|
+
setTrackedGlobal(context, "__Request_get_integrity", new ivm.Callback((instanceId) => {
|
|
1070
1099
|
const state = stateMap.get(instanceId);
|
|
1071
1100
|
return state?.integrity ?? "";
|
|
1072
1101
|
}));
|
|
1073
|
-
|
|
1102
|
+
setTrackedGlobal(context, "__Request_markBodyUsed", new ivm.Callback((instanceId) => {
|
|
1074
1103
|
const state = stateMap.get(instanceId);
|
|
1075
1104
|
if (state) {
|
|
1076
1105
|
if (state.bodyUsed) {
|
|
@@ -1079,26 +1108,26 @@ function setupRequest(context, stateMap) {
|
|
|
1079
1108
|
state.bodyUsed = true;
|
|
1080
1109
|
}
|
|
1081
1110
|
}));
|
|
1082
|
-
|
|
1111
|
+
setTrackedGlobal(context, "__Request_text", new ivm.Callback((instanceId) => {
|
|
1083
1112
|
const state = stateMap.get(instanceId);
|
|
1084
1113
|
if (!state || !state.body)
|
|
1085
1114
|
return "";
|
|
1086
1115
|
return new TextDecoder().decode(state.body);
|
|
1087
1116
|
}));
|
|
1088
|
-
|
|
1117
|
+
setTrackedGlobal(context, "__Request_arrayBuffer", new ivm.Callback((instanceId) => {
|
|
1089
1118
|
const state = stateMap.get(instanceId);
|
|
1090
1119
|
if (!state || !state.body) {
|
|
1091
1120
|
return new ivm.ExternalCopy(new ArrayBuffer(0)).copyInto();
|
|
1092
1121
|
}
|
|
1093
1122
|
return new ivm.ExternalCopy(state.body.buffer.slice(state.body.byteOffset, state.body.byteOffset + state.body.byteLength)).copyInto();
|
|
1094
1123
|
}));
|
|
1095
|
-
|
|
1124
|
+
setTrackedGlobal(context, "__Request_getBodyBytes", new ivm.Callback((instanceId) => {
|
|
1096
1125
|
const state = stateMap.get(instanceId);
|
|
1097
1126
|
if (!state || !state.body)
|
|
1098
1127
|
return null;
|
|
1099
1128
|
return Array.from(state.body);
|
|
1100
1129
|
}));
|
|
1101
|
-
|
|
1130
|
+
setTrackedGlobal(context, "__Request_clone", new ivm.Callback((instanceId) => {
|
|
1102
1131
|
const state = stateMap.get(instanceId);
|
|
1103
1132
|
if (!state) {
|
|
1104
1133
|
throw new Error("[TypeError]Cannot clone invalid Request");
|
|
@@ -1112,11 +1141,11 @@ function setupRequest(context, stateMap) {
|
|
|
1112
1141
|
stateMap.set(newId, newState);
|
|
1113
1142
|
return newId;
|
|
1114
1143
|
}));
|
|
1115
|
-
|
|
1144
|
+
setTrackedGlobal(context, "__Request_getStreamId", new ivm.Callback((instanceId) => {
|
|
1116
1145
|
const state = stateMap.get(instanceId);
|
|
1117
1146
|
return state?.streamId ?? null;
|
|
1118
1147
|
}));
|
|
1119
|
-
|
|
1148
|
+
setTrackedGlobal(context, "__Request_get_signalAborted", new ivm.Callback((instanceId) => {
|
|
1120
1149
|
const state = stateMap.get(instanceId);
|
|
1121
1150
|
return state?.signalAborted ?? false;
|
|
1122
1151
|
}));
|
|
@@ -1462,9 +1491,8 @@ function setupRequest(context, stateMap) {
|
|
|
1462
1491
|
}
|
|
1463
1492
|
var FETCH_STREAM_THRESHOLD = 64 * 1024;
|
|
1464
1493
|
function setupFetchFunction(context, stateMap, streamRegistry, options) {
|
|
1465
|
-
const global = context.global;
|
|
1466
1494
|
const fetchAbortControllers = new Map;
|
|
1467
|
-
|
|
1495
|
+
setTrackedGlobal(context, "__fetch_abort", new ivm.Callback((fetchId) => {
|
|
1468
1496
|
const controller = fetchAbortControllers.get(fetchId);
|
|
1469
1497
|
if (controller) {
|
|
1470
1498
|
setImmediate(() => controller.abort());
|
|
@@ -1559,7 +1587,7 @@ function setupFetchFunction(context, stateMap, streamRegistry, options) {
|
|
|
1559
1587
|
fetchAbortControllers.delete(fetchId);
|
|
1560
1588
|
}
|
|
1561
1589
|
});
|
|
1562
|
-
|
|
1590
|
+
setTrackedGlobal(context, "__fetch_ref", fetchRef);
|
|
1563
1591
|
const fetchCode = `
|
|
1564
1592
|
(function() {
|
|
1565
1593
|
function __decodeError(err) {
|
|
@@ -1644,12 +1672,11 @@ function setupFetchFunction(context, stateMap, streamRegistry, options) {
|
|
|
1644
1672
|
context.evalSync(fetchCode);
|
|
1645
1673
|
}
|
|
1646
1674
|
function setupServer(context, serveState) {
|
|
1647
|
-
const global = context.global;
|
|
1648
1675
|
context.evalSync(`
|
|
1649
1676
|
globalThis.__upgradeRegistry__ = new Map();
|
|
1650
1677
|
globalThis.__upgradeIdCounter__ = 0;
|
|
1651
1678
|
`);
|
|
1652
|
-
|
|
1679
|
+
setTrackedGlobal(context, "__setPendingUpgrade__", new ivm.Callback((connectionId) => {
|
|
1653
1680
|
serveState.pendingUpgrade = { requested: true, connectionId };
|
|
1654
1681
|
}));
|
|
1655
1682
|
context.evalSync(`
|
|
@@ -1668,13 +1695,12 @@ function setupServer(context, serveState) {
|
|
|
1668
1695
|
`);
|
|
1669
1696
|
}
|
|
1670
1697
|
function setupServerWebSocket(context, wsCommandCallbacks) {
|
|
1671
|
-
|
|
1672
|
-
global.setSync("__ServerWebSocket_send", new ivm.Callback((connectionId, data) => {
|
|
1698
|
+
setTrackedGlobal(context, "__ServerWebSocket_send", new ivm.Callback((connectionId, data) => {
|
|
1673
1699
|
const cmd = { type: "message", connectionId, data };
|
|
1674
1700
|
for (const cb of wsCommandCallbacks)
|
|
1675
1701
|
cb(cmd);
|
|
1676
1702
|
}));
|
|
1677
|
-
|
|
1703
|
+
setTrackedGlobal(context, "__ServerWebSocket_close", new ivm.Callback((connectionId, code, reason) => {
|
|
1678
1704
|
const cmd = { type: "close", connectionId, code, reason };
|
|
1679
1705
|
for (const cb of wsCommandCallbacks)
|
|
1680
1706
|
cb(cmd);
|
|
@@ -1727,8 +1753,7 @@ function setupServerWebSocket(context, wsCommandCallbacks) {
|
|
|
1727
1753
|
`);
|
|
1728
1754
|
}
|
|
1729
1755
|
function setupClientWebSocket(context, clientWsCommandCallbacks) {
|
|
1730
|
-
|
|
1731
|
-
global.setSync("__WebSocket_connect", new ivm.Callback((socketId, url, protocols) => {
|
|
1756
|
+
setTrackedGlobal(context, "__WebSocket_connect", new ivm.Callback((socketId, url, protocols) => {
|
|
1732
1757
|
const cmd = {
|
|
1733
1758
|
type: "connect",
|
|
1734
1759
|
socketId,
|
|
@@ -1738,12 +1763,12 @@ function setupClientWebSocket(context, clientWsCommandCallbacks) {
|
|
|
1738
1763
|
for (const cb of clientWsCommandCallbacks)
|
|
1739
1764
|
cb(cmd);
|
|
1740
1765
|
}));
|
|
1741
|
-
|
|
1766
|
+
setTrackedGlobal(context, "__WebSocket_send", new ivm.Callback((socketId, data) => {
|
|
1742
1767
|
const cmd = { type: "send", socketId, data };
|
|
1743
1768
|
for (const cb of clientWsCommandCallbacks)
|
|
1744
1769
|
cb(cmd);
|
|
1745
1770
|
}));
|
|
1746
|
-
|
|
1771
|
+
setTrackedGlobal(context, "__WebSocket_close", new ivm.Callback((socketId, code, reason) => {
|
|
1747
1772
|
const cmd = { type: "close", socketId, code, reason };
|
|
1748
1773
|
for (const cb of clientWsCommandCallbacks)
|
|
1749
1774
|
cb(cmd);
|
|
@@ -2129,7 +2154,7 @@ async function setupFetch(context, options) {
|
|
|
2129
2154
|
setupServe(context);
|
|
2130
2155
|
setupClientWebSocket(context, clientWsCommandCallbacks);
|
|
2131
2156
|
const eventCallbacks = new Set;
|
|
2132
|
-
context
|
|
2157
|
+
setTrackedGlobal(context, "__emit", new ivm.Callback((eventName, payloadJson) => {
|
|
2133
2158
|
const payload = JSON.parse(payloadJson);
|
|
2134
2159
|
for (const cb of eventCallbacks)
|
|
2135
2160
|
cb(eventName, payload);
|
|
@@ -2169,6 +2194,7 @@ async function setupFetch(context, options) {
|
|
|
2169
2194
|
context.evalSync(`globalThis.__upgradeRegistry__.clear()`);
|
|
2170
2195
|
serveState.activeConnections.clear();
|
|
2171
2196
|
serveState.pendingUpgrade = null;
|
|
2197
|
+
releaseTrackedGlobalHandles(context);
|
|
2172
2198
|
try {
|
|
2173
2199
|
requestAbortSignalRef.release();
|
|
2174
2200
|
} catch {}
|
|
@@ -2258,7 +2284,8 @@ async function setupFetch(context, options) {
|
|
|
2258
2284
|
passthruMap.delete(responseState.streamId);
|
|
2259
2285
|
const responseHeaders2 = new Headers(responseState.headers);
|
|
2260
2286
|
const status2 = responseState.status === 101 ? 200 : responseState.status;
|
|
2261
|
-
const
|
|
2287
|
+
const hasNullBodyStatus2 = responseState.status === 101 || responseState.status === 103 || responseState.status === 204 || responseState.status === 205 || responseState.status === 304;
|
|
2288
|
+
const response2 = new Response(hasNullBodyStatus2 ? null : passthruBody, {
|
|
2262
2289
|
status: status2,
|
|
2263
2290
|
statusText: responseState.statusText,
|
|
2264
2291
|
headers: responseHeaders2
|
|
@@ -2308,7 +2335,12 @@ async function setupFetch(context, options) {
|
|
|
2308
2335
|
});
|
|
2309
2336
|
const responseHeaders2 = new Headers(responseState.headers);
|
|
2310
2337
|
const status2 = responseState.status === 101 ? 200 : responseState.status;
|
|
2311
|
-
const
|
|
2338
|
+
const hasNullBodyStatus2 = responseState.status === 101 || responseState.status === 103 || responseState.status === 204 || responseState.status === 205 || responseState.status === 304;
|
|
2339
|
+
if (hasNullBodyStatus2) {
|
|
2340
|
+
streamRegistry.cancel(responseStreamId);
|
|
2341
|
+
streamRegistry.delete(responseStreamId);
|
|
2342
|
+
}
|
|
2343
|
+
const response2 = new Response(hasNullBodyStatus2 ? null : pumpedStream, {
|
|
2312
2344
|
status: status2,
|
|
2313
2345
|
statusText: responseState.statusText,
|
|
2314
2346
|
headers: responseHeaders2
|
|
@@ -2317,7 +2349,8 @@ async function setupFetch(context, options) {
|
|
|
2317
2349
|
return response2;
|
|
2318
2350
|
}
|
|
2319
2351
|
const responseHeaders = new Headers(responseState.headers);
|
|
2320
|
-
const
|
|
2352
|
+
const hasNullBodyStatus = responseState.status === 101 || responseState.status === 103 || responseState.status === 204 || responseState.status === 205 || responseState.status === 304;
|
|
2353
|
+
const responseBody = hasNullBodyStatus ? null : responseState.body;
|
|
2321
2354
|
const status = responseState.status === 101 ? 200 : responseState.status;
|
|
2322
2355
|
const response = new Response(responseBody, {
|
|
2323
2356
|
status,
|
|
@@ -2516,4 +2549,4 @@ export {
|
|
|
2516
2549
|
clearAllInstanceState
|
|
2517
2550
|
};
|
|
2518
2551
|
|
|
2519
|
-
//# debugId=
|
|
2552
|
+
//# debugId=76C34F62F495C17164756E2164756E21
|