@ricsam/isolate 0.1.10 → 0.1.11
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 +172 -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 +203 -51
- package/dist/cjs/bridge/runtime-bindings.cjs.map +3 -3
- package/dist/cjs/bridge/sandbox-isolate.cjs +365 -0
- package/dist/cjs/bridge/sandbox-isolate.cjs.map +10 -0
- package/dist/cjs/host/create-isolate-host.cjs +51 -25
- package/dist/cjs/host/create-isolate-host.cjs.map +3 -3
- package/dist/cjs/host/nested-host-controller.cjs +311 -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 +91 -0
- package/dist/cjs/internal/browser-source.cjs.map +10 -0
- package/dist/cjs/internal/client/connection.cjs +152 -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 +129 -4
- 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.map +2 -2
- 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 +186 -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/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 +206 -51
- package/dist/mjs/bridge/runtime-bindings.mjs.map +3 -3
- package/dist/mjs/bridge/sandbox-isolate.mjs +325 -0
- package/dist/mjs/bridge/sandbox-isolate.mjs.map +10 -0
- package/dist/mjs/host/create-isolate-host.mjs +53 -25
- package/dist/mjs/host/create-isolate-host.mjs.map +3 -3
- package/dist/mjs/host/nested-host-controller.mjs +275 -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 +51 -0
- package/dist/mjs/internal/browser-source.mjs.map +10 -0
- package/dist/mjs/internal/client/connection.mjs +154 -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 +129 -4
- 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.map +2 -2
- 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 +186 -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/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 +15 -0
- package/dist/types/host/nested-host-controller.d.ts +11 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/internal/browser-source.d.ts +11 -0
- package/dist/types/internal/client/types.d.ts +5 -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 +25 -1
- 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/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 +33 -33
- package/package.json +3 -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
|
@@ -94,8 +94,13 @@ async function connect(options = {}) {
|
|
|
94
94
|
callbackStreamReaders: new Map,
|
|
95
95
|
activeCallbackInvocations: new Map,
|
|
96
96
|
callbackAbortControllers: new Map,
|
|
97
|
+
clientIteratorSessions: new Map,
|
|
98
|
+
returnedPromiseRegistry: new Map,
|
|
99
|
+
returnedIteratorRegistry: new Map,
|
|
97
100
|
closing: false,
|
|
98
|
-
namespacedRuntimes: new Map
|
|
101
|
+
namespacedRuntimes: new Map,
|
|
102
|
+
nextClientIteratorId: 1,
|
|
103
|
+
nextReturnedRefId: 1
|
|
99
104
|
};
|
|
100
105
|
function setupSocket(sock) {
|
|
101
106
|
const parser = import_protocol.createFrameParser();
|
|
@@ -139,6 +144,9 @@ async function connect(options = {}) {
|
|
|
139
144
|
}
|
|
140
145
|
state.callbackAbortControllers.clear();
|
|
141
146
|
state.activeCallbackInvocations.clear();
|
|
147
|
+
state.clientIteratorSessions.clear();
|
|
148
|
+
state.returnedPromiseRegistry.clear();
|
|
149
|
+
state.returnedIteratorRegistry.clear();
|
|
142
150
|
if (!state.closing && state.namespacedRuntimes.size > 0) {
|
|
143
151
|
state.reconnecting = reconnect(state, options).catch(() => {
|
|
144
152
|
state.namespacedRuntimes.clear();
|
|
@@ -659,145 +667,57 @@ async function createRuntime(state, options = {}, namespaceId) {
|
|
|
659
667
|
callbacks.custom = registerCustomFunctions(state, options.customFunctions);
|
|
660
668
|
}
|
|
661
669
|
let playwrightHandler;
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
670
|
+
let getCollectedData = () => ({
|
|
671
|
+
browserConsoleLogs: [],
|
|
672
|
+
pageErrors: [],
|
|
673
|
+
networkRequests: [],
|
|
674
|
+
networkResponses: [],
|
|
675
|
+
requestFailures: []
|
|
676
|
+
});
|
|
677
|
+
let getTrackedResources = () => ({
|
|
678
|
+
contexts: [],
|
|
679
|
+
pages: []
|
|
680
|
+
});
|
|
681
|
+
let clearCollectedData = () => {};
|
|
682
|
+
const playwrightListenerCleanups = [];
|
|
668
683
|
if (normalizedPlaywrightOptions) {
|
|
669
684
|
playwrightHandler = normalizedPlaywrightOptions.handler;
|
|
670
685
|
if (!playwrightHandler) {
|
|
671
686
|
throw new Error("playwright.handler is required when using playwright options");
|
|
672
687
|
}
|
|
673
|
-
const
|
|
688
|
+
const handlerMetadata = import_client.getPlaywrightHandlerMetadata(playwrightHandler);
|
|
689
|
+
if (handlerMetadata) {
|
|
690
|
+
getCollectedData = () => handlerMetadata.collector.getCollectedData();
|
|
691
|
+
getTrackedResources = () => handlerMetadata.collector.getTrackedResources();
|
|
692
|
+
clearCollectedData = () => {
|
|
693
|
+
handlerMetadata.collector.clearCollectedData();
|
|
694
|
+
};
|
|
695
|
+
playwrightListenerCleanups.push(handlerMetadata.collector.onEvent((event) => {
|
|
696
|
+
if (normalizedPlaywrightOptions.onEvent) {
|
|
697
|
+
normalizedPlaywrightOptions.onEvent(event);
|
|
698
|
+
}
|
|
699
|
+
if (event.type === "browserConsoleLog") {
|
|
700
|
+
if (normalizedPlaywrightOptions.console && options.console?.onEntry) {
|
|
701
|
+
options.console.onEntry({
|
|
702
|
+
type: "browserOutput",
|
|
703
|
+
level: event.level,
|
|
704
|
+
stdout: event.stdout,
|
|
705
|
+
location: event.location,
|
|
706
|
+
timestamp: event.timestamp
|
|
707
|
+
});
|
|
708
|
+
} else if (normalizedPlaywrightOptions.console) {
|
|
709
|
+
const prefix = event.level === "error" ? "[browser:error]" : "[browser]";
|
|
710
|
+
console.log(prefix, event.stdout);
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
}));
|
|
714
|
+
}
|
|
674
715
|
const handlerCallbackId = state.nextCallbackId++;
|
|
675
716
|
state.callbacks.set(handlerCallbackId, async (opJson) => {
|
|
676
717
|
const op = JSON.parse(opJson);
|
|
677
718
|
const result2 = await playwrightHandler(op);
|
|
678
719
|
return JSON.stringify(result2);
|
|
679
720
|
});
|
|
680
|
-
if (page) {
|
|
681
|
-
const requestIds = new WeakMap;
|
|
682
|
-
let nextRequestId = 1;
|
|
683
|
-
const getRequestId = (request2) => {
|
|
684
|
-
let requestId2 = requestIds.get(request2);
|
|
685
|
-
if (!requestId2) {
|
|
686
|
-
requestId2 = `req_${nextRequestId++}`;
|
|
687
|
-
requestIds.set(request2, requestId2);
|
|
688
|
-
}
|
|
689
|
-
return requestId2;
|
|
690
|
-
};
|
|
691
|
-
const toLocation = (location) => {
|
|
692
|
-
if (!location || !location.url && location.lineNumber == null && location.columnNumber == null) {
|
|
693
|
-
return;
|
|
694
|
-
}
|
|
695
|
-
return {
|
|
696
|
-
url: location.url || undefined,
|
|
697
|
-
lineNumber: location.lineNumber != null ? location.lineNumber + 1 : undefined,
|
|
698
|
-
columnNumber: location.columnNumber != null ? location.columnNumber + 1 : undefined
|
|
699
|
-
};
|
|
700
|
-
};
|
|
701
|
-
const onConsole = (msg) => {
|
|
702
|
-
const entry = {
|
|
703
|
-
level: msg.type(),
|
|
704
|
-
stdout: msg.text(),
|
|
705
|
-
location: toLocation(msg.location()),
|
|
706
|
-
timestamp: Date.now()
|
|
707
|
-
};
|
|
708
|
-
browserConsoleLogs.push(entry);
|
|
709
|
-
if (normalizedPlaywrightOptions.onEvent) {
|
|
710
|
-
normalizedPlaywrightOptions.onEvent({
|
|
711
|
-
type: "browserConsoleLog",
|
|
712
|
-
...entry
|
|
713
|
-
});
|
|
714
|
-
}
|
|
715
|
-
if (normalizedPlaywrightOptions.console && options.console?.onEntry) {
|
|
716
|
-
options.console.onEntry({
|
|
717
|
-
type: "browserOutput",
|
|
718
|
-
...entry
|
|
719
|
-
});
|
|
720
|
-
} else if (normalizedPlaywrightOptions.console) {
|
|
721
|
-
const prefix = entry.level === "error" ? "[browser:error]" : "[browser]";
|
|
722
|
-
console.log(prefix, entry.stdout);
|
|
723
|
-
}
|
|
724
|
-
};
|
|
725
|
-
const onRequest = (request2) => {
|
|
726
|
-
const info = {
|
|
727
|
-
requestId: getRequestId(request2),
|
|
728
|
-
url: request2.url(),
|
|
729
|
-
method: request2.method(),
|
|
730
|
-
headers: request2.headers(),
|
|
731
|
-
postData: request2.postData() ?? undefined,
|
|
732
|
-
resourceType: request2.resourceType(),
|
|
733
|
-
timestamp: Date.now()
|
|
734
|
-
};
|
|
735
|
-
networkRequests.push(info);
|
|
736
|
-
if (normalizedPlaywrightOptions.onEvent) {
|
|
737
|
-
normalizedPlaywrightOptions.onEvent({
|
|
738
|
-
type: "networkRequest",
|
|
739
|
-
...info
|
|
740
|
-
});
|
|
741
|
-
}
|
|
742
|
-
};
|
|
743
|
-
const onResponse = (response) => {
|
|
744
|
-
const request2 = response.request();
|
|
745
|
-
const info = {
|
|
746
|
-
requestId: getRequestId(request2),
|
|
747
|
-
url: response.url(),
|
|
748
|
-
status: response.status(),
|
|
749
|
-
statusText: response.statusText(),
|
|
750
|
-
headers: response.headers(),
|
|
751
|
-
resourceType: request2.resourceType(),
|
|
752
|
-
timestamp: Date.now()
|
|
753
|
-
};
|
|
754
|
-
networkResponses.push(info);
|
|
755
|
-
if (normalizedPlaywrightOptions.onEvent) {
|
|
756
|
-
normalizedPlaywrightOptions.onEvent({
|
|
757
|
-
type: "networkResponse",
|
|
758
|
-
...info
|
|
759
|
-
});
|
|
760
|
-
}
|
|
761
|
-
};
|
|
762
|
-
const onRequestFailed = (request2) => {
|
|
763
|
-
const info = {
|
|
764
|
-
requestId: getRequestId(request2),
|
|
765
|
-
url: request2.url(),
|
|
766
|
-
method: request2.method(),
|
|
767
|
-
failureText: request2.failure()?.errorText || "request failed",
|
|
768
|
-
resourceType: request2.resourceType(),
|
|
769
|
-
timestamp: Date.now()
|
|
770
|
-
};
|
|
771
|
-
requestFailures.push(info);
|
|
772
|
-
if (normalizedPlaywrightOptions.onEvent) {
|
|
773
|
-
normalizedPlaywrightOptions.onEvent({
|
|
774
|
-
type: "requestFailure",
|
|
775
|
-
...info
|
|
776
|
-
});
|
|
777
|
-
}
|
|
778
|
-
};
|
|
779
|
-
const onPageError = (error) => {
|
|
780
|
-
const entry = {
|
|
781
|
-
name: error.name,
|
|
782
|
-
message: error.message,
|
|
783
|
-
stack: error.stack,
|
|
784
|
-
timestamp: Date.now()
|
|
785
|
-
};
|
|
786
|
-
pageErrors.push(entry);
|
|
787
|
-
if (normalizedPlaywrightOptions.onEvent) {
|
|
788
|
-
normalizedPlaywrightOptions.onEvent({
|
|
789
|
-
type: "pageError",
|
|
790
|
-
...entry
|
|
791
|
-
});
|
|
792
|
-
}
|
|
793
|
-
};
|
|
794
|
-
page.on("console", onConsole);
|
|
795
|
-
page.on("request", onRequest);
|
|
796
|
-
page.on("response", onResponse);
|
|
797
|
-
page.on("requestfailed", onRequestFailed);
|
|
798
|
-
page.on("pageerror", onPageError);
|
|
799
|
-
pageListenerCleanups.push(() => page.removeListener("console", onConsole), () => page.removeListener("request", onRequest), () => page.removeListener("response", onResponse), () => page.removeListener("requestfailed", onRequestFailed), () => page.removeListener("pageerror", onPageError));
|
|
800
|
-
}
|
|
801
721
|
callbacks.playwright = {
|
|
802
722
|
handlerCallbackId,
|
|
803
723
|
console: normalizedPlaywrightOptions.console && !options.console?.onEntry
|
|
@@ -828,7 +748,10 @@ async function createRuntime(state, options = {}, namespaceId) {
|
|
|
828
748
|
testEnvironmentOption = true;
|
|
829
749
|
}
|
|
830
750
|
}
|
|
831
|
-
const playwrightOption = normalizedPlaywrightOptions
|
|
751
|
+
const playwrightOption = normalizedPlaywrightOptions ? {
|
|
752
|
+
timeout: normalizedPlaywrightOptions.timeout,
|
|
753
|
+
hasDefaultPage: normalizedPlaywrightOptions.hasDefaultPage
|
|
754
|
+
} : undefined;
|
|
832
755
|
const requestId = state.nextRequestId++;
|
|
833
756
|
const request = {
|
|
834
757
|
type: import_protocol.MessageType.CREATE_RUNTIME,
|
|
@@ -1139,23 +1062,19 @@ async function createRuntime(state, options = {}, namespaceId) {
|
|
|
1139
1062
|
if (!playwrightEnabled) {
|
|
1140
1063
|
throw new Error("Playwright not configured. Provide playwright.handler in createRuntime options.");
|
|
1141
1064
|
}
|
|
1142
|
-
return
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1065
|
+
return getCollectedData();
|
|
1066
|
+
},
|
|
1067
|
+
getTrackedResources() {
|
|
1068
|
+
if (!playwrightEnabled) {
|
|
1069
|
+
throw new Error("Playwright not configured. Provide playwright.handler in createRuntime options.");
|
|
1070
|
+
}
|
|
1071
|
+
return getTrackedResources();
|
|
1149
1072
|
},
|
|
1150
1073
|
clearCollectedData() {
|
|
1151
1074
|
if (!playwrightEnabled) {
|
|
1152
1075
|
throw new Error("Playwright not configured. Provide playwright.handler in createRuntime options.");
|
|
1153
1076
|
}
|
|
1154
|
-
|
|
1155
|
-
pageErrors.length = 0;
|
|
1156
|
-
networkRequests.length = 0;
|
|
1157
|
-
networkResponses.length = 0;
|
|
1158
|
-
requestFailures.length = 0;
|
|
1077
|
+
clearCollectedData();
|
|
1159
1078
|
}
|
|
1160
1079
|
};
|
|
1161
1080
|
return {
|
|
@@ -1210,7 +1129,7 @@ async function createRuntime(state, options = {}, namespaceId) {
|
|
|
1210
1129
|
});
|
|
1211
1130
|
},
|
|
1212
1131
|
dispose: async (options2) => {
|
|
1213
|
-
for (const cleanup of
|
|
1132
|
+
for (const cleanup of playwrightListenerCleanups) {
|
|
1214
1133
|
cleanup();
|
|
1215
1134
|
}
|
|
1216
1135
|
isolateWsCallbacks.delete(isolateId);
|
|
@@ -1454,10 +1373,6 @@ function registerModuleLoaderCallback(state, callback) {
|
|
|
1454
1373
|
});
|
|
1455
1374
|
return { callbackId, name: "moduleLoader", type: "async" };
|
|
1456
1375
|
}
|
|
1457
|
-
var clientIteratorSessions = new Map;
|
|
1458
|
-
var nextClientIteratorId = 1;
|
|
1459
|
-
var returnedPromiseRegistry = new Map;
|
|
1460
|
-
var returnedIteratorRegistry = new Map;
|
|
1461
1376
|
function registerCustomFunctions(state, customFunctions) {
|
|
1462
1377
|
const registrations = {};
|
|
1463
1378
|
const addCallbackIdsToRefs = (value) => {
|
|
@@ -1468,12 +1383,12 @@ function registerCustomFunctions(state, customFunctions) {
|
|
|
1468
1383
|
const resolveCallbackId = state.nextCallbackId++;
|
|
1469
1384
|
state.callbacks.set(resolveCallbackId, async (...args) => {
|
|
1470
1385
|
const promiseId = args[0];
|
|
1471
|
-
const promise = returnedPromiseRegistry.get(promiseId);
|
|
1386
|
+
const promise = state.returnedPromiseRegistry.get(promiseId);
|
|
1472
1387
|
if (!promise) {
|
|
1473
1388
|
throw new Error(`Promise ${promiseId} not found`);
|
|
1474
1389
|
}
|
|
1475
1390
|
const promiseResult = await promise;
|
|
1476
|
-
returnedPromiseRegistry.delete(promiseId);
|
|
1391
|
+
state.returnedPromiseRegistry.delete(promiseId);
|
|
1477
1392
|
const marshalledResult = await import_protocol.marshalValue(promiseResult, marshalCtx);
|
|
1478
1393
|
return addCallbackIdsToRefs(marshalledResult);
|
|
1479
1394
|
});
|
|
@@ -1486,13 +1401,13 @@ function registerCustomFunctions(state, customFunctions) {
|
|
|
1486
1401
|
const nextCallbackId = state.nextCallbackId++;
|
|
1487
1402
|
state.callbacks.set(nextCallbackId, async (...args) => {
|
|
1488
1403
|
const iteratorId = args[0];
|
|
1489
|
-
const iterator = returnedIteratorRegistry.get(iteratorId);
|
|
1404
|
+
const iterator = state.returnedIteratorRegistry.get(iteratorId);
|
|
1490
1405
|
if (!iterator) {
|
|
1491
1406
|
throw new Error(`Iterator ${iteratorId} not found`);
|
|
1492
1407
|
}
|
|
1493
1408
|
const iterResult = await iterator.next();
|
|
1494
1409
|
if (iterResult.done) {
|
|
1495
|
-
returnedIteratorRegistry.delete(iteratorId);
|
|
1410
|
+
state.returnedIteratorRegistry.delete(iteratorId);
|
|
1496
1411
|
}
|
|
1497
1412
|
const marshalledValue = await import_protocol.marshalValue(iterResult.value, marshalCtx);
|
|
1498
1413
|
return {
|
|
@@ -1504,8 +1419,8 @@ function registerCustomFunctions(state, customFunctions) {
|
|
|
1504
1419
|
state.callbacks.set(returnCallbackId, async (...args) => {
|
|
1505
1420
|
const iteratorId = args[0];
|
|
1506
1421
|
const returnValue = args[1];
|
|
1507
|
-
const iterator = returnedIteratorRegistry.get(iteratorId);
|
|
1508
|
-
returnedIteratorRegistry.delete(iteratorId);
|
|
1422
|
+
const iterator = state.returnedIteratorRegistry.get(iteratorId);
|
|
1423
|
+
state.returnedIteratorRegistry.delete(iteratorId);
|
|
1509
1424
|
if (!iterator || !iterator.return) {
|
|
1510
1425
|
return { done: true, value: undefined };
|
|
1511
1426
|
}
|
|
@@ -1520,7 +1435,7 @@ function registerCustomFunctions(state, customFunctions) {
|
|
|
1520
1435
|
state.callbacks.set(throwCallbackId, async (...args) => {
|
|
1521
1436
|
const iteratorId = args[0];
|
|
1522
1437
|
const errorValue = args[1];
|
|
1523
|
-
const iterator = returnedIteratorRegistry.get(iteratorId);
|
|
1438
|
+
const iterator = state.returnedIteratorRegistry.get(iteratorId);
|
|
1524
1439
|
if (!iterator) {
|
|
1525
1440
|
throw new Error(`Iterator ${iteratorId} not found`);
|
|
1526
1441
|
}
|
|
@@ -1531,7 +1446,7 @@ function registerCustomFunctions(state, customFunctions) {
|
|
|
1531
1446
|
const thrownError = Object.assign(new Error(errorValue?.message ?? "Iterator throw()"), { name: errorValue?.name ?? "Error", stack: errorValue?.stack });
|
|
1532
1447
|
const iterResult = await iterator.throw(thrownError);
|
|
1533
1448
|
if (iterResult.done) {
|
|
1534
|
-
returnedIteratorRegistry.delete(iteratorId);
|
|
1449
|
+
state.returnedIteratorRegistry.delete(iteratorId);
|
|
1535
1450
|
}
|
|
1536
1451
|
const marshalledValue = await import_protocol.marshalValue(iterResult.value, marshalCtx);
|
|
1537
1452
|
return {
|
|
@@ -1539,7 +1454,7 @@ function registerCustomFunctions(state, customFunctions) {
|
|
|
1539
1454
|
value: addCallbackIdsToRefs(marshalledValue)
|
|
1540
1455
|
};
|
|
1541
1456
|
} catch (error) {
|
|
1542
|
-
returnedIteratorRegistry.delete(iteratorId);
|
|
1457
|
+
state.returnedIteratorRegistry.delete(iteratorId);
|
|
1543
1458
|
throw error;
|
|
1544
1459
|
}
|
|
1545
1460
|
});
|
|
@@ -1570,13 +1485,13 @@ function registerCustomFunctions(state, customFunctions) {
|
|
|
1570
1485
|
return returnedCallbackId;
|
|
1571
1486
|
},
|
|
1572
1487
|
registerPromise: (promise) => {
|
|
1573
|
-
const promiseId = state.
|
|
1574
|
-
returnedPromiseRegistry.set(promiseId, promise);
|
|
1488
|
+
const promiseId = state.nextReturnedRefId++;
|
|
1489
|
+
state.returnedPromiseRegistry.set(promiseId, promise);
|
|
1575
1490
|
return promiseId;
|
|
1576
1491
|
},
|
|
1577
1492
|
registerIterator: (iterator) => {
|
|
1578
|
-
const iteratorId = state.
|
|
1579
|
-
returnedIteratorRegistry.set(iteratorId, iterator);
|
|
1493
|
+
const iteratorId = state.nextReturnedRefId++;
|
|
1494
|
+
state.returnedIteratorRegistry.set(iteratorId, iterator);
|
|
1580
1495
|
return iteratorId;
|
|
1581
1496
|
}
|
|
1582
1497
|
};
|
|
@@ -1588,6 +1503,71 @@ function registerCustomFunctions(state, customFunctions) {
|
|
|
1588
1503
|
return import_protocol.unmarshalValue(result, unmarshalCtx);
|
|
1589
1504
|
};
|
|
1590
1505
|
};
|
|
1506
|
+
unmarshalCtx.createPromiseProxy = (promiseId, ref) => {
|
|
1507
|
+
const resolveCallbackId = ref?.__resolveCallbackId;
|
|
1508
|
+
if (typeof resolveCallbackId !== "number") {
|
|
1509
|
+
throw new Error(`Promise ${promiseId} is missing a resolve callback`);
|
|
1510
|
+
}
|
|
1511
|
+
return (async () => {
|
|
1512
|
+
const result = await invokeDaemonCallback(state, resolveCallbackId, [promiseId]);
|
|
1513
|
+
return import_protocol.unmarshalValue(result, unmarshalCtx);
|
|
1514
|
+
})();
|
|
1515
|
+
};
|
|
1516
|
+
unmarshalCtx.createIteratorProxy = (iteratorId, ref) => {
|
|
1517
|
+
const nextCallbackId = ref?.__nextCallbackId;
|
|
1518
|
+
const returnCallbackId = ref?.__returnCallbackId;
|
|
1519
|
+
const throwCallbackId = ref?.__throwCallbackId;
|
|
1520
|
+
if (typeof nextCallbackId !== "number") {
|
|
1521
|
+
throw new Error(`Iterator ${iteratorId} is missing a next callback`);
|
|
1522
|
+
}
|
|
1523
|
+
const invokeIteratorCallback = async (callbackId, args, label) => {
|
|
1524
|
+
const result = await invokeDaemonCallback(state, callbackId, args);
|
|
1525
|
+
if (!result || typeof result !== "object" || !("done" in result)) {
|
|
1526
|
+
throw new Error(`${label} returned an invalid iterator result`);
|
|
1527
|
+
}
|
|
1528
|
+
return result;
|
|
1529
|
+
};
|
|
1530
|
+
return {
|
|
1531
|
+
[Symbol.asyncIterator]() {
|
|
1532
|
+
return this;
|
|
1533
|
+
},
|
|
1534
|
+
async next() {
|
|
1535
|
+
const result = await invokeIteratorCallback(nextCallbackId, [iteratorId], "Iterator next()");
|
|
1536
|
+
return {
|
|
1537
|
+
done: Boolean(result.done),
|
|
1538
|
+
value: import_protocol.unmarshalValue(result.value, unmarshalCtx)
|
|
1539
|
+
};
|
|
1540
|
+
},
|
|
1541
|
+
async return(value) {
|
|
1542
|
+
if (typeof returnCallbackId !== "number") {
|
|
1543
|
+
return { done: true, value };
|
|
1544
|
+
}
|
|
1545
|
+
const result = await invokeIteratorCallback(returnCallbackId, [iteratorId, value], "Iterator return()");
|
|
1546
|
+
return {
|
|
1547
|
+
done: result.done ?? true,
|
|
1548
|
+
value: import_protocol.unmarshalValue(result.value, unmarshalCtx)
|
|
1549
|
+
};
|
|
1550
|
+
},
|
|
1551
|
+
async throw(errorValue) {
|
|
1552
|
+
if (typeof throwCallbackId !== "number") {
|
|
1553
|
+
throw errorValue;
|
|
1554
|
+
}
|
|
1555
|
+
const serializedError = errorValue && typeof errorValue === "object" ? {
|
|
1556
|
+
message: errorValue.message,
|
|
1557
|
+
name: errorValue.name,
|
|
1558
|
+
stack: errorValue.stack
|
|
1559
|
+
} : {
|
|
1560
|
+
message: String(errorValue ?? "Iterator throw()"),
|
|
1561
|
+
name: "Error"
|
|
1562
|
+
};
|
|
1563
|
+
const result = await invokeIteratorCallback(throwCallbackId, [iteratorId, serializedError], "Iterator throw()");
|
|
1564
|
+
return {
|
|
1565
|
+
done: Boolean(result.done),
|
|
1566
|
+
value: import_protocol.unmarshalValue(result.value, unmarshalCtx)
|
|
1567
|
+
};
|
|
1568
|
+
}
|
|
1569
|
+
};
|
|
1570
|
+
};
|
|
1591
1571
|
for (const [name, def] of Object.entries(customFunctions)) {
|
|
1592
1572
|
if (def.type === "asyncIterator") {
|
|
1593
1573
|
const startCallbackId = state.nextCallbackId++;
|
|
@@ -1595,8 +1575,8 @@ function registerCustomFunctions(state, customFunctions) {
|
|
|
1595
1575
|
try {
|
|
1596
1576
|
const fn = def.fn;
|
|
1597
1577
|
const iterator = fn(...import_protocol.unmarshalValue(args, unmarshalCtx));
|
|
1598
|
-
const iteratorId = nextClientIteratorId++;
|
|
1599
|
-
clientIteratorSessions.set(iteratorId, { iterator });
|
|
1578
|
+
const iteratorId = state.nextClientIteratorId++;
|
|
1579
|
+
state.clientIteratorSessions.set(iteratorId, { iterator });
|
|
1600
1580
|
return { iteratorId };
|
|
1601
1581
|
} catch (error) {
|
|
1602
1582
|
throw error;
|
|
@@ -1604,39 +1584,39 @@ function registerCustomFunctions(state, customFunctions) {
|
|
|
1604
1584
|
});
|
|
1605
1585
|
const nextCallbackId = state.nextCallbackId++;
|
|
1606
1586
|
state.callbacks.set(nextCallbackId, async (iteratorId) => {
|
|
1607
|
-
const session = clientIteratorSessions.get(iteratorId);
|
|
1587
|
+
const session = state.clientIteratorSessions.get(iteratorId);
|
|
1608
1588
|
if (!session) {
|
|
1609
1589
|
throw new Error(`Iterator session ${iteratorId} not found`);
|
|
1610
1590
|
}
|
|
1611
1591
|
try {
|
|
1612
1592
|
const result = await session.iterator.next();
|
|
1613
1593
|
if (result.done) {
|
|
1614
|
-
clientIteratorSessions.delete(iteratorId);
|
|
1594
|
+
state.clientIteratorSessions.delete(iteratorId);
|
|
1615
1595
|
}
|
|
1616
1596
|
return { done: result.done, value: await import_protocol.marshalValue(result.value) };
|
|
1617
1597
|
} catch (error) {
|
|
1618
|
-
clientIteratorSessions.delete(iteratorId);
|
|
1598
|
+
state.clientIteratorSessions.delete(iteratorId);
|
|
1619
1599
|
throw error;
|
|
1620
1600
|
}
|
|
1621
1601
|
});
|
|
1622
1602
|
const returnCallbackId = state.nextCallbackId++;
|
|
1623
1603
|
state.callbacks.set(returnCallbackId, async (iteratorId, value) => {
|
|
1624
|
-
const session = clientIteratorSessions.get(iteratorId);
|
|
1604
|
+
const session = state.clientIteratorSessions.get(iteratorId);
|
|
1625
1605
|
if (!session) {
|
|
1626
1606
|
return { done: true, value: await import_protocol.marshalValue(undefined) };
|
|
1627
1607
|
}
|
|
1628
1608
|
try {
|
|
1629
1609
|
const result = await session.iterator.return?.(value);
|
|
1630
|
-
clientIteratorSessions.delete(iteratorId);
|
|
1610
|
+
state.clientIteratorSessions.delete(iteratorId);
|
|
1631
1611
|
return { done: true, value: await import_protocol.marshalValue(result?.value) };
|
|
1632
1612
|
} catch (error) {
|
|
1633
|
-
clientIteratorSessions.delete(iteratorId);
|
|
1613
|
+
state.clientIteratorSessions.delete(iteratorId);
|
|
1634
1614
|
throw error;
|
|
1635
1615
|
}
|
|
1636
1616
|
});
|
|
1637
1617
|
const throwCallbackId = state.nextCallbackId++;
|
|
1638
1618
|
state.callbacks.set(throwCallbackId, async (iteratorId, errorData) => {
|
|
1639
|
-
const session = clientIteratorSessions.get(iteratorId);
|
|
1619
|
+
const session = state.clientIteratorSessions.get(iteratorId);
|
|
1640
1620
|
if (!session) {
|
|
1641
1621
|
throw new Error(`Iterator session ${iteratorId} not found`);
|
|
1642
1622
|
}
|
|
@@ -1644,10 +1624,10 @@ function registerCustomFunctions(state, customFunctions) {
|
|
|
1644
1624
|
const errInfo = errorData;
|
|
1645
1625
|
const error = Object.assign(new Error(errInfo.message), { name: errInfo.name });
|
|
1646
1626
|
const result = await session.iterator.throw?.(error);
|
|
1647
|
-
clientIteratorSessions.delete(iteratorId);
|
|
1627
|
+
state.clientIteratorSessions.delete(iteratorId);
|
|
1648
1628
|
return { done: result?.done ?? true, value: await import_protocol.marshalValue(result?.value) };
|
|
1649
1629
|
} catch (error) {
|
|
1650
|
-
clientIteratorSessions.delete(iteratorId);
|
|
1630
|
+
state.clientIteratorSessions.delete(iteratorId);
|
|
1651
1631
|
throw error;
|
|
1652
1632
|
}
|
|
1653
1633
|
});
|
|
@@ -1968,4 +1948,4 @@ function handleClientWsClose(isolateId, payload, state) {
|
|
|
1968
1948
|
}
|
|
1969
1949
|
}
|
|
1970
1950
|
|
|
1971
|
-
//# debugId=
|
|
1951
|
+
//# debugId=D2E0738CC59A08A764756E2164756E21
|