@ricsam/quickjs-core 0.2.0 → 0.2.2
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/blob.cjs +197 -0
- package/dist/cjs/blob.cjs.map +10 -0
- package/dist/cjs/class-builder.cjs +244 -0
- package/dist/cjs/class-builder.cjs.map +10 -0
- package/dist/cjs/dom-exception.cjs +95 -0
- package/dist/cjs/dom-exception.cjs.map +10 -0
- package/dist/cjs/file.cjs +234 -0
- package/dist/cjs/file.cjs.map +10 -0
- package/dist/cjs/function-builder.cjs +70 -0
- package/dist/cjs/function-builder.cjs.map +10 -0
- package/dist/cjs/index.cjs +22 -22
- package/dist/cjs/index.cjs.map +2 -2
- package/dist/cjs/marshal.cjs +191 -0
- package/dist/cjs/marshal.cjs.map +10 -0
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/readable-stream.cjs +588 -0
- package/dist/cjs/readable-stream.cjs.map +10 -0
- package/dist/cjs/scope.cjs +76 -0
- package/dist/cjs/scope.cjs.map +10 -0
- package/dist/cjs/transform-stream.cjs +152 -0
- package/dist/cjs/transform-stream.cjs.map +10 -0
- package/dist/cjs/types.cjs +39 -0
- package/dist/cjs/types.cjs.map +10 -0
- package/dist/cjs/unmarshal.cjs +254 -0
- package/dist/cjs/unmarshal.cjs.map +10 -0
- package/dist/cjs/url-search-params.cjs +165 -0
- package/dist/cjs/url-search-params.cjs.map +10 -0
- package/dist/cjs/url.cjs +183 -0
- package/dist/cjs/url.cjs.map +10 -0
- package/dist/cjs/writable-stream.cjs +513 -0
- package/dist/cjs/writable-stream.cjs.map +10 -0
- package/dist/mjs/blob.mjs +166 -0
- package/dist/mjs/blob.mjs.map +10 -0
- package/dist/mjs/class-builder.mjs +213 -0
- package/dist/mjs/class-builder.mjs.map +10 -0
- package/dist/mjs/dom-exception.mjs +64 -0
- package/dist/mjs/dom-exception.mjs.map +10 -0
- package/dist/mjs/file.mjs +203 -0
- package/dist/mjs/file.mjs.map +10 -0
- package/dist/mjs/function-builder.mjs +39 -0
- package/dist/mjs/function-builder.mjs.map +10 -0
- package/dist/mjs/index.mjs +22 -22
- package/dist/mjs/index.mjs.map +2 -2
- package/dist/mjs/marshal.mjs +160 -0
- package/dist/mjs/marshal.mjs.map +10 -0
- package/dist/mjs/package.json +1 -1
- package/dist/mjs/readable-stream.mjs +557 -0
- package/dist/mjs/readable-stream.mjs.map +10 -0
- package/dist/mjs/scope.mjs +45 -0
- package/dist/mjs/scope.mjs.map +10 -0
- package/dist/mjs/transform-stream.mjs +121 -0
- package/dist/mjs/transform-stream.mjs.map +10 -0
- package/dist/mjs/types.mjs +8 -0
- package/dist/mjs/types.mjs.map +10 -0
- package/dist/mjs/unmarshal.mjs +223 -0
- package/dist/mjs/unmarshal.mjs.map +10 -0
- package/dist/mjs/url-search-params.mjs +134 -0
- package/dist/mjs/url-search-params.mjs.map +10 -0
- package/dist/mjs/url.mjs +152 -0
- package/dist/mjs/url.mjs.map +10 -0
- package/dist/mjs/writable-stream.mjs +482 -0
- package/dist/mjs/writable-stream.mjs.map +10 -0
- package/package.json +1 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/marshal.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import type { QuickJSContext, QuickJSHandle } from \"quickjs-emscripten\";\nimport type { MarshalOptions } from \"./types.cjs\";\n\n/**\n * Check if a value is a QuickJS handle\n */\nexport function isHandle(value: unknown): value is QuickJSHandle {\n return (\n value !== null &&\n typeof value === \"object\" &&\n \"alive\" in value &&\n \"dispose\" in value &&\n typeof (value as QuickJSHandle).dispose === \"function\"\n );\n}\n\n/**\n * Get the type of a QuickJS handle as a string\n */\nexport function getHandleType(\n context: QuickJSContext,\n handle: QuickJSHandle\n): \"undefined\" | \"null\" | \"boolean\" | \"number\" | \"string\" | \"symbol\" | \"object\" | \"function\" {\n return context.typeof(handle) as \"undefined\" | \"null\" | \"boolean\" | \"number\" | \"string\" | \"symbol\" | \"object\" | \"function\";\n}\n\n/**\n * Marshal a JavaScript value to a QuickJS handle\n *\n * Supports:\n * - Primitives (string, number, boolean, null, undefined, bigint)\n * - Arrays\n * - Plain objects\n * - ArrayBuffer / Uint8Array\n * - Date (converted to Date object in QuickJS)\n * - Functions (wrapped as host functions)\n * - Promises (wrapped with context.newPromise)\n *\n * @example\n * const handle = marshal(context, {\n * name: \"test\",\n * values: [1, 2, 3],\n * callback: (x) => x * 2\n * });\n */\nexport function marshal(\n context: QuickJSContext,\n value: unknown,\n options: MarshalOptions = {}\n): QuickJSHandle {\n const maxDepth = options.maxDepth ?? 10;\n const seen = new WeakSet<object>();\n\n function marshalValue(val: unknown, depth: number): QuickJSHandle {\n if (depth > maxDepth) {\n throw new Error(`Maximum marshalling depth of ${maxDepth} exceeded`);\n }\n\n // Pass through existing QuickJS handles\n if (isHandle(val)) {\n return val;\n }\n\n // Try custom marshaller first\n if (options.custom) {\n const customResult = options.custom(val, context);\n if (customResult !== undefined) {\n return customResult;\n }\n }\n\n // Handle primitives\n if (val === undefined) {\n return context.undefined;\n }\n if (val === null) {\n return context.null;\n }\n if (typeof val === \"boolean\") {\n return val ? context.true : context.false;\n }\n if (typeof val === \"number\") {\n return context.newNumber(val);\n }\n if (typeof val === \"string\") {\n return context.newString(val);\n }\n if (typeof val === \"bigint\") {\n return context.newBigInt(val);\n }\n\n // Handle symbols (convert to string representation)\n if (typeof val === \"symbol\") {\n return context.newString(val.toString());\n }\n\n // Handle objects\n if (typeof val === \"object\") {\n // Check for circular references\n if (seen.has(val)) {\n throw new Error(\"Circular reference detected during marshalling\");\n }\n seen.add(val);\n\n try {\n // Handle ArrayBuffer\n if (val instanceof ArrayBuffer) {\n return context.newArrayBuffer(val);\n }\n\n // Handle Uint8Array - create proper Uint8Array in QuickJS (has .length property)\n if (val instanceof Uint8Array) {\n const buffer = val.buffer.slice(\n val.byteOffset,\n val.byteOffset + val.byteLength\n );\n const bufferHandle = context.newArrayBuffer(buffer);\n context.setProp(context.global, \"__tempMarshalBuffer__\", bufferHandle);\n bufferHandle.dispose();\n const result = context.evalCode(\"new Uint8Array(__tempMarshalBuffer__)\");\n const cleanup = context.evalCode(\"delete globalThis.__tempMarshalBuffer__\");\n if (cleanup.error) cleanup.error.dispose();\n else cleanup.value.dispose();\n if (result.error) {\n result.error.dispose();\n // Fallback to ArrayBuffer if Uint8Array creation fails\n return context.newArrayBuffer(buffer);\n }\n return result.value;\n }\n\n // Handle other TypedArrays (Int8Array, Float32Array, etc.) - convert to ArrayBuffer\n if (ArrayBuffer.isView(val)) {\n const buffer = val.buffer.slice(\n val.byteOffset,\n val.byteOffset + val.byteLength\n );\n return context.newArrayBuffer(buffer);\n }\n\n // Handle Date\n if (val instanceof Date) {\n const dateConstructor = context.getProp(context.global, \"Date\");\n const timestamp = context.newNumber(val.getTime());\n const result = context.callFunction(\n dateConstructor,\n context.undefined,\n timestamp\n );\n dateConstructor.dispose();\n timestamp.dispose();\n\n if (result.error) {\n const error = result.error;\n result.error.dispose();\n throw new Error(`Failed to create Date: ${context.dump(error)}`);\n }\n return result.value;\n }\n\n // Handle Promise\n if (val instanceof Promise) {\n const deferred = context.newPromise();\n val\n .then((resolved) => {\n const resolvedHandle = marshalValue(resolved, depth + 1);\n deferred.resolve(resolvedHandle);\n resolvedHandle.dispose();\n context.runtime.executePendingJobs();\n })\n .catch((error) => {\n const errorHandle = marshalValue(\n error instanceof Error\n ? { name: error.name, message: error.message }\n : error,\n depth + 1\n );\n deferred.reject(errorHandle);\n errorHandle.dispose();\n context.runtime.executePendingJobs();\n });\n return deferred.handle;\n }\n\n // Handle Array\n if (Array.isArray(val)) {\n const arr = context.newArray();\n for (let i = 0; i < val.length; i++) {\n const elementHandle = marshalValue(val[i], depth + 1);\n context.setProp(arr, i, elementHandle);\n elementHandle.dispose();\n }\n return arr;\n }\n\n // Handle plain objects\n const obj = context.newObject();\n for (const [key, propVal] of Object.entries(val)) {\n const propHandle = marshalValue(propVal, depth + 1);\n context.setProp(obj, key, propHandle);\n propHandle.dispose();\n }\n return obj;\n } finally {\n seen.delete(val);\n }\n }\n\n // Handle functions\n if (typeof val === \"function\") {\n return context.newFunction(val.name || \"anonymous\", (...argHandles) => {\n const args = argHandles.map((h) => context.dump(h));\n try {\n const result = val(...args);\n if (result instanceof Promise) {\n const deferred = context.newPromise();\n result\n .then((resolved) => {\n const resolvedHandle = marshalValue(resolved, depth + 1);\n deferred.resolve(resolvedHandle);\n resolvedHandle.dispose();\n context.runtime.executePendingJobs();\n })\n .catch((error) => {\n const errorHandle = marshalValue(\n error instanceof Error\n ? { name: error.name, message: error.message }\n : error,\n depth + 1\n );\n deferred.reject(errorHandle);\n errorHandle.dispose();\n context.runtime.executePendingJobs();\n });\n return deferred.handle;\n }\n return marshalValue(result, depth + 1);\n } catch (error) {\n throw context.newError(\n error instanceof Error ? error.message : String(error)\n );\n }\n });\n }\n\n throw new Error(`Cannot marshal value of type ${typeof val}`);\n }\n\n return marshalValue(value, 0);\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMO,SAAS,QAAQ,CAAC,OAAwC;AAAA,EAC/D,OACE,UAAU,QACV,OAAO,UAAU,YACjB,WAAW,SACX,aAAa,SACb,OAAQ,MAAwB,YAAY;AAAA;AAOzC,SAAS,aAAa,CAC3B,SACA,QAC2F;AAAA,EAC3F,OAAO,QAAQ,OAAO,MAAM;AAAA;AAsBvB,SAAS,OAAO,CACrB,SACA,OACA,UAA0B,CAAC,GACZ;AAAA,EACf,MAAM,WAAW,QAAQ,YAAY;AAAA,EACrC,MAAM,OAAO,IAAI;AAAA,EAEjB,SAAS,YAAY,CAAC,KAAc,OAA8B;AAAA,IAChE,IAAI,QAAQ,UAAU;AAAA,MACpB,MAAM,IAAI,MAAM,gCAAgC,mBAAmB;AAAA,IACrE;AAAA,IAGA,IAAI,SAAS,GAAG,GAAG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,OACG,KAAK,CAAC,aAAa;AAAA,cAClB,MAAM,iBAAiB,aAAa,UAAU,QAAQ,CAAC;AAAA,cACvD,SAAS,QAAQ,cAAc;AAAA,cAC/B,eAAe,QAAQ;AAAA,cACvB,QAAQ,QAAQ,mBAAmB;AAAA,aACpC,EACA,MAAM,CAAC,UAAU;AAAA,cAChB,MAAM,cAAc,aAClB,iBAAiB,QACb,EAAE,MAAM,MAAM,MAAM,SAAS,MAAM,QAAQ,IAC3C,OACJ,QAAQ,CACV;AAAA,cACA,SAAS,OAAO,WAAW;AAAA,cAC3B,YAAY,QAAQ;AAAA,cACpB,QAAQ,QAAQ,mBAAmB;AAAA,aACpC;AAAA,YACH,OAAO,SAAS;AAAA,UAClB;AAAA,UACA,OAAO,aAAa,QAAQ,QAAQ,CAAC;AAAA,UACrC,OAAO,OAAO;AAAA,UACd,MAAM,QAAQ,SACZ,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CACvD;AAAA;AAAA,OAEH;AAAA,IACH;AAAA,IAEA,MAAM,IAAI,MAAM,gCAAgC,OAAO,KAAK;AAAA;AAAA,EAG9D,OAAO,aAAa,OAAO,CAAC;AAAA;",
|
|
8
|
+
"debugId": "92FCF047844230B864756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
package/dist/cjs/package.json
CHANGED
|
@@ -0,0 +1,588 @@
|
|
|
1
|
+
// @bun @bun-cjs
|
|
2
|
+
(function(exports, require, module, __filename, __dirname) {var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __moduleCache = /* @__PURE__ */ new WeakMap;
|
|
7
|
+
var __toCommonJS = (from) => {
|
|
8
|
+
var entry = __moduleCache.get(from), desc;
|
|
9
|
+
if (entry)
|
|
10
|
+
return entry;
|
|
11
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function")
|
|
13
|
+
__getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
|
|
14
|
+
get: () => from[key],
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
}));
|
|
17
|
+
__moduleCache.set(from, entry);
|
|
18
|
+
return entry;
|
|
19
|
+
};
|
|
20
|
+
var __export = (target, all) => {
|
|
21
|
+
for (var name in all)
|
|
22
|
+
__defProp(target, name, {
|
|
23
|
+
get: all[name],
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
set: (newValue) => all[name] = () => newValue
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// packages/core/src/streams/readable-stream.ts
|
|
31
|
+
var exports_readable_stream = {};
|
|
32
|
+
__export(exports_readable_stream, {
|
|
33
|
+
createReadableStreamDefaultReaderClass: () => createReadableStreamDefaultReaderClass,
|
|
34
|
+
createReadableStreamClass: () => createReadableStreamClass,
|
|
35
|
+
createReadableStream: () => createReadableStream,
|
|
36
|
+
consumeReadableStream: () => consumeReadableStream
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(exports_readable_stream);
|
|
39
|
+
var import_class_builder = require("../class-builder.cjs");
|
|
40
|
+
var import_marshal = require("../marshal.cjs");
|
|
41
|
+
var import_unmarshal = require("../unmarshal.cjs");
|
|
42
|
+
function createReadableStreamDefaultReaderClass(context, stateMap) {
|
|
43
|
+
return import_class_builder.defineClass(context, stateMap, {
|
|
44
|
+
name: "ReadableStreamDefaultReader",
|
|
45
|
+
construct: () => {
|
|
46
|
+
let resolveClosedPromise;
|
|
47
|
+
let rejectClosedPromise;
|
|
48
|
+
const state = {
|
|
49
|
+
stream: null,
|
|
50
|
+
closed: false,
|
|
51
|
+
closedPromiseResolvers: {
|
|
52
|
+
resolve: () => resolveClosedPromise?.(),
|
|
53
|
+
reject: (e) => rejectClosedPromise?.(e)
|
|
54
|
+
},
|
|
55
|
+
readRequests: []
|
|
56
|
+
};
|
|
57
|
+
Object.defineProperty(state, "_closedPromise", {
|
|
58
|
+
value: undefined,
|
|
59
|
+
writable: true,
|
|
60
|
+
enumerable: false
|
|
61
|
+
});
|
|
62
|
+
Object.defineProperty(state, "getClosedPromise", {
|
|
63
|
+
value: function() {
|
|
64
|
+
if (!this._closedPromise) {
|
|
65
|
+
this._closedPromise = new Promise((resolve, reject) => {
|
|
66
|
+
resolveClosedPromise = resolve;
|
|
67
|
+
rejectClosedPromise = reject;
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
return this._closedPromise;
|
|
71
|
+
},
|
|
72
|
+
enumerable: false
|
|
73
|
+
});
|
|
74
|
+
return state;
|
|
75
|
+
},
|
|
76
|
+
properties: {
|
|
77
|
+
closed: {
|
|
78
|
+
get() {
|
|
79
|
+
return this.getClosedPromise();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
methods: {
|
|
84
|
+
read() {
|
|
85
|
+
if (!this.stream) {
|
|
86
|
+
return Promise.reject(new TypeError("Reader has no stream"));
|
|
87
|
+
}
|
|
88
|
+
if (this.stream.locked === false) {
|
|
89
|
+
return Promise.reject(new TypeError("Stream is not locked"));
|
|
90
|
+
}
|
|
91
|
+
return new Promise((resolve, reject) => {
|
|
92
|
+
if (this.stream.queue.length > 0) {
|
|
93
|
+
const chunk = this.stream.queue.shift();
|
|
94
|
+
resolve({ value: chunk, done: false });
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (this.stream.closed || this.stream.closeRequested) {
|
|
98
|
+
resolve({ value: undefined, done: true });
|
|
99
|
+
this.closedPromiseResolvers.resolve();
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (this.stream.errored) {
|
|
103
|
+
reject(this.stream.errorValue);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
this.readRequests.push({ resolve, reject });
|
|
107
|
+
if (this.stream.source?.pull && this.stream.started) {
|
|
108
|
+
try {
|
|
109
|
+
const pullResult = this.stream.source.pull(this.stream.controller);
|
|
110
|
+
if (pullResult instanceof Promise) {
|
|
111
|
+
pullResult.catch((e) => {
|
|
112
|
+
this.stream.errored = true;
|
|
113
|
+
this.stream.errorValue = e;
|
|
114
|
+
this.readRequests.forEach((req) => req.reject(e));
|
|
115
|
+
this.readRequests = [];
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
} catch (e) {
|
|
119
|
+
this.stream.errored = true;
|
|
120
|
+
this.stream.errorValue = e;
|
|
121
|
+
reject(e);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
},
|
|
126
|
+
cancel(reason) {
|
|
127
|
+
if (!this.stream) {
|
|
128
|
+
return Promise.reject(new TypeError("Reader has no stream"));
|
|
129
|
+
}
|
|
130
|
+
return new Promise((resolve, reject) => {
|
|
131
|
+
try {
|
|
132
|
+
if (this.stream.source?.cancel) {
|
|
133
|
+
const result = this.stream.source.cancel(reason);
|
|
134
|
+
if (result instanceof Promise) {
|
|
135
|
+
result.then(resolve).catch(reject);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
this.stream.closed = true;
|
|
140
|
+
this.closedPromiseResolvers.resolve();
|
|
141
|
+
resolve();
|
|
142
|
+
} catch (e) {
|
|
143
|
+
reject(e);
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
},
|
|
147
|
+
releaseLock() {
|
|
148
|
+
if (!this.stream) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
this.stream.locked = false;
|
|
152
|
+
this.stream.reader = null;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
function createReadableStreamClass(context, stateMap, readerClass) {
|
|
158
|
+
const classHandle = import_class_builder.defineClass(context, stateMap, {
|
|
159
|
+
name: "ReadableStream",
|
|
160
|
+
construct: (args) => {
|
|
161
|
+
const underlyingSource = args[0];
|
|
162
|
+
const state = {
|
|
163
|
+
locked: false,
|
|
164
|
+
controller: null,
|
|
165
|
+
reader: null,
|
|
166
|
+
queue: [],
|
|
167
|
+
closeRequested: false,
|
|
168
|
+
closed: false,
|
|
169
|
+
errored: false,
|
|
170
|
+
errorValue: undefined,
|
|
171
|
+
pullPromise: null,
|
|
172
|
+
started: false,
|
|
173
|
+
source: underlyingSource
|
|
174
|
+
};
|
|
175
|
+
state.controller = {
|
|
176
|
+
enqueue(chunk) {
|
|
177
|
+
if (state.closeRequested || state.closed) {
|
|
178
|
+
throw new TypeError("Stream is closed");
|
|
179
|
+
}
|
|
180
|
+
state.queue.push(chunk);
|
|
181
|
+
if (state.reader && state.reader.readRequests.length > 0) {
|
|
182
|
+
const request = state.reader.readRequests.shift();
|
|
183
|
+
const value = state.queue.shift();
|
|
184
|
+
request.resolve({ value, done: false });
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
close() {
|
|
188
|
+
if (state.closeRequested || state.closed) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
state.closeRequested = true;
|
|
192
|
+
if (state.queue.length === 0) {
|
|
193
|
+
state.closed = true;
|
|
194
|
+
if (state.reader) {
|
|
195
|
+
state.reader.closedPromiseResolvers.resolve();
|
|
196
|
+
state.reader.readRequests.forEach((req) => {
|
|
197
|
+
req.resolve({ value: undefined, done: true });
|
|
198
|
+
});
|
|
199
|
+
state.reader.readRequests = [];
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
error(e) {
|
|
204
|
+
if (state.errored || state.closed) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
state.errored = true;
|
|
208
|
+
state.errorValue = e;
|
|
209
|
+
if (state.reader) {
|
|
210
|
+
state.reader.closedPromiseResolvers.reject(e);
|
|
211
|
+
state.reader.readRequests.forEach((req) => req.reject(e));
|
|
212
|
+
state.reader.readRequests = [];
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
get desiredSize() {
|
|
216
|
+
if (state.errored)
|
|
217
|
+
return null;
|
|
218
|
+
if (state.closeRequested)
|
|
219
|
+
return 0;
|
|
220
|
+
return 1 - state.queue.length;
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
if (underlyingSource?.start) {
|
|
224
|
+
try {
|
|
225
|
+
const startResult = underlyingSource.start(state.controller);
|
|
226
|
+
if (startResult instanceof Promise) {
|
|
227
|
+
startResult.then(() => {
|
|
228
|
+
state.started = true;
|
|
229
|
+
}).catch((e) => {
|
|
230
|
+
state.errored = true;
|
|
231
|
+
state.errorValue = e;
|
|
232
|
+
});
|
|
233
|
+
} else {
|
|
234
|
+
state.started = true;
|
|
235
|
+
}
|
|
236
|
+
} catch (e) {
|
|
237
|
+
state.errored = true;
|
|
238
|
+
state.errorValue = e;
|
|
239
|
+
}
|
|
240
|
+
} else {
|
|
241
|
+
state.started = true;
|
|
242
|
+
}
|
|
243
|
+
return state;
|
|
244
|
+
},
|
|
245
|
+
properties: {
|
|
246
|
+
locked: {
|
|
247
|
+
get() {
|
|
248
|
+
return this.locked;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
},
|
|
252
|
+
methods: {
|
|
253
|
+
__linkReader__(readerObj) {
|
|
254
|
+
if (this.locked) {
|
|
255
|
+
throw new TypeError("ReadableStream is locked");
|
|
256
|
+
}
|
|
257
|
+
this.locked = true;
|
|
258
|
+
const readerId = readerObj.__instanceId__;
|
|
259
|
+
const readerState = import_class_builder.getInstanceStateById(readerId);
|
|
260
|
+
if (!readerState) {
|
|
261
|
+
throw new Error("Reader instance state not found");
|
|
262
|
+
}
|
|
263
|
+
readerState.stream = this;
|
|
264
|
+
this.reader = readerState;
|
|
265
|
+
},
|
|
266
|
+
cancel(reason) {
|
|
267
|
+
if (this.locked) {
|
|
268
|
+
return Promise.reject(new TypeError("Cannot cancel a locked stream"));
|
|
269
|
+
}
|
|
270
|
+
return new Promise((resolve, reject) => {
|
|
271
|
+
try {
|
|
272
|
+
if (this.source?.cancel) {
|
|
273
|
+
const result = this.source.cancel(reason);
|
|
274
|
+
if (result instanceof Promise) {
|
|
275
|
+
result.then(resolve).catch(reject);
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
this.closed = true;
|
|
280
|
+
resolve();
|
|
281
|
+
} catch (e) {
|
|
282
|
+
reject(e);
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
const prototypeHandle = context.getProp(classHandle, "prototype");
|
|
289
|
+
const getReaderCode = `(function() {
|
|
290
|
+
// Create a reader instance
|
|
291
|
+
const reader = new ReadableStreamDefaultReader();
|
|
292
|
+
// Link it to this stream's internal state
|
|
293
|
+
this.__linkReader__(reader);
|
|
294
|
+
return reader;
|
|
295
|
+
})`;
|
|
296
|
+
const getReaderResult = context.evalCode(getReaderCode);
|
|
297
|
+
if (!getReaderResult.error) {
|
|
298
|
+
context.setProp(prototypeHandle, "getReader", getReaderResult.value);
|
|
299
|
+
getReaderResult.value.dispose();
|
|
300
|
+
} else {
|
|
301
|
+
getReaderResult.error.dispose();
|
|
302
|
+
}
|
|
303
|
+
const pipeToCode = `(async function(destination, options = {}) {
|
|
304
|
+
if (this.locked) throw new TypeError("ReadableStream is locked");
|
|
305
|
+
if (destination.locked) throw new TypeError("WritableStream is locked");
|
|
306
|
+
|
|
307
|
+
const reader = this.getReader();
|
|
308
|
+
const writer = destination.getWriter();
|
|
309
|
+
|
|
310
|
+
try {
|
|
311
|
+
while (true) {
|
|
312
|
+
const { value, done } = await reader.read();
|
|
313
|
+
if (done) break;
|
|
314
|
+
await writer.write(value);
|
|
315
|
+
}
|
|
316
|
+
if (!options.preventClose) await writer.close();
|
|
317
|
+
} catch (error) {
|
|
318
|
+
if (!options.preventAbort) await writer.abort(error);
|
|
319
|
+
if (!options.preventCancel) await reader.cancel(error);
|
|
320
|
+
throw error;
|
|
321
|
+
} finally {
|
|
322
|
+
reader.releaseLock();
|
|
323
|
+
writer.releaseLock();
|
|
324
|
+
}
|
|
325
|
+
})`;
|
|
326
|
+
const pipeToResult = context.evalCode(pipeToCode);
|
|
327
|
+
if (!pipeToResult.error) {
|
|
328
|
+
context.setProp(prototypeHandle, "pipeTo", pipeToResult.value);
|
|
329
|
+
pipeToResult.value.dispose();
|
|
330
|
+
} else {
|
|
331
|
+
pipeToResult.error.dispose();
|
|
332
|
+
}
|
|
333
|
+
const pipeThroughCode = `(function(transform, options = {}) {
|
|
334
|
+
if (this.locked) throw new TypeError("ReadableStream is locked");
|
|
335
|
+
if (transform.writable.locked) throw new TypeError("WritableStream is locked");
|
|
336
|
+
|
|
337
|
+
// Start piping in background
|
|
338
|
+
this.pipeTo(transform.writable, {
|
|
339
|
+
preventClose: options.preventClose,
|
|
340
|
+
preventAbort: options.preventAbort,
|
|
341
|
+
preventCancel: options.preventCancel,
|
|
342
|
+
signal: options.signal
|
|
343
|
+
}).catch(() => {}); // Errors handled internally
|
|
344
|
+
|
|
345
|
+
return transform.readable;
|
|
346
|
+
})`;
|
|
347
|
+
const pipeThroughResult = context.evalCode(pipeThroughCode);
|
|
348
|
+
if (!pipeThroughResult.error) {
|
|
349
|
+
context.setProp(prototypeHandle, "pipeThrough", pipeThroughResult.value);
|
|
350
|
+
pipeThroughResult.value.dispose();
|
|
351
|
+
} else {
|
|
352
|
+
pipeThroughResult.error.dispose();
|
|
353
|
+
}
|
|
354
|
+
const teeCode = `(function() {
|
|
355
|
+
if (this.locked) throw new TypeError("ReadableStream is locked");
|
|
356
|
+
|
|
357
|
+
const reader = this.getReader();
|
|
358
|
+
let reading = false;
|
|
359
|
+
let readAgain = false;
|
|
360
|
+
let canceled1 = false, canceled2 = false;
|
|
361
|
+
let reason1, reason2;
|
|
362
|
+
let branch1Controller, branch2Controller;
|
|
363
|
+
|
|
364
|
+
function pullAlgorithm() {
|
|
365
|
+
if (reading) {
|
|
366
|
+
readAgain = true;
|
|
367
|
+
return Promise.resolve();
|
|
368
|
+
}
|
|
369
|
+
reading = true;
|
|
370
|
+
|
|
371
|
+
return reader.read().then(({ value, done }) => {
|
|
372
|
+
reading = false;
|
|
373
|
+
if (done) {
|
|
374
|
+
if (!canceled1 && branch1Controller) branch1Controller.close();
|
|
375
|
+
if (!canceled2 && branch2Controller) branch2Controller.close();
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
if (!canceled1 && branch1Controller) branch1Controller.enqueue(value);
|
|
379
|
+
if (!canceled2 && branch2Controller) branch2Controller.enqueue(value);
|
|
380
|
+
if (readAgain) {
|
|
381
|
+
readAgain = false;
|
|
382
|
+
return pullAlgorithm();
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
const branch1 = new ReadableStream({
|
|
388
|
+
start(controller) { branch1Controller = controller; },
|
|
389
|
+
pull: pullAlgorithm,
|
|
390
|
+
cancel(reason) {
|
|
391
|
+
canceled1 = true;
|
|
392
|
+
reason1 = reason;
|
|
393
|
+
if (canceled2) reader.cancel(reason1);
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
const branch2 = new ReadableStream({
|
|
398
|
+
start(controller) { branch2Controller = controller; },
|
|
399
|
+
pull: pullAlgorithm,
|
|
400
|
+
cancel(reason) {
|
|
401
|
+
canceled2 = true;
|
|
402
|
+
reason2 = reason;
|
|
403
|
+
if (canceled1) reader.cancel(reason2);
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
return [branch1, branch2];
|
|
408
|
+
})`;
|
|
409
|
+
const teeResult = context.evalCode(teeCode);
|
|
410
|
+
if (!teeResult.error) {
|
|
411
|
+
context.setProp(prototypeHandle, "tee", teeResult.value);
|
|
412
|
+
teeResult.value.dispose();
|
|
413
|
+
} else {
|
|
414
|
+
teeResult.error.dispose();
|
|
415
|
+
}
|
|
416
|
+
prototypeHandle.dispose();
|
|
417
|
+
return classHandle;
|
|
418
|
+
}
|
|
419
|
+
function createReadableStream(context, stateMap, source) {
|
|
420
|
+
const sourceObj = context.newObject();
|
|
421
|
+
if (source.start) {
|
|
422
|
+
const startFn = context.newFunction("start", (controllerHandle) => {
|
|
423
|
+
const controller = {
|
|
424
|
+
enqueue: (chunk) => {
|
|
425
|
+
const enqueueFn = context.getProp(controllerHandle, "enqueue");
|
|
426
|
+
const chunkHandle = import_marshal.marshal(context, chunk);
|
|
427
|
+
context.callFunction(enqueueFn, controllerHandle, chunkHandle);
|
|
428
|
+
chunkHandle.dispose();
|
|
429
|
+
enqueueFn.dispose();
|
|
430
|
+
},
|
|
431
|
+
close: () => {
|
|
432
|
+
const closeFn = context.getProp(controllerHandle, "close");
|
|
433
|
+
context.callFunction(closeFn, controllerHandle);
|
|
434
|
+
closeFn.dispose();
|
|
435
|
+
},
|
|
436
|
+
error: (e) => {
|
|
437
|
+
const errorFn = context.getProp(controllerHandle, "error");
|
|
438
|
+
const errorHandle = import_marshal.marshal(context, e);
|
|
439
|
+
context.callFunction(errorFn, controllerHandle, errorHandle);
|
|
440
|
+
errorHandle.dispose();
|
|
441
|
+
errorFn.dispose();
|
|
442
|
+
}
|
|
443
|
+
};
|
|
444
|
+
const result2 = source.start(controller);
|
|
445
|
+
if (result2 instanceof Promise) {
|
|
446
|
+
const deferred = context.newPromise();
|
|
447
|
+
result2.then(() => {
|
|
448
|
+
deferred.resolve(context.undefined);
|
|
449
|
+
context.runtime.executePendingJobs();
|
|
450
|
+
}).catch((e) => {
|
|
451
|
+
deferred.reject(import_marshal.marshal(context, e));
|
|
452
|
+
context.runtime.executePendingJobs();
|
|
453
|
+
});
|
|
454
|
+
return deferred.handle;
|
|
455
|
+
}
|
|
456
|
+
return context.undefined;
|
|
457
|
+
});
|
|
458
|
+
context.setProp(sourceObj, "start", startFn);
|
|
459
|
+
startFn.dispose();
|
|
460
|
+
}
|
|
461
|
+
if (source.pull) {
|
|
462
|
+
const pullFn = context.newFunction("pull", (controllerHandle) => {
|
|
463
|
+
const controller = {
|
|
464
|
+
enqueue: (chunk) => {
|
|
465
|
+
const enqueueFn = context.getProp(controllerHandle, "enqueue");
|
|
466
|
+
const chunkHandle = import_marshal.marshal(context, chunk);
|
|
467
|
+
context.callFunction(enqueueFn, controllerHandle, chunkHandle);
|
|
468
|
+
chunkHandle.dispose();
|
|
469
|
+
enqueueFn.dispose();
|
|
470
|
+
},
|
|
471
|
+
close: () => {
|
|
472
|
+
const closeFn = context.getProp(controllerHandle, "close");
|
|
473
|
+
context.callFunction(closeFn, controllerHandle);
|
|
474
|
+
closeFn.dispose();
|
|
475
|
+
},
|
|
476
|
+
error: (e) => {
|
|
477
|
+
const errorFn = context.getProp(controllerHandle, "error");
|
|
478
|
+
const errorHandle = import_marshal.marshal(context, e);
|
|
479
|
+
context.callFunction(errorFn, controllerHandle, errorHandle);
|
|
480
|
+
errorHandle.dispose();
|
|
481
|
+
errorFn.dispose();
|
|
482
|
+
}
|
|
483
|
+
};
|
|
484
|
+
const result2 = source.pull(controller);
|
|
485
|
+
if (result2 instanceof Promise) {
|
|
486
|
+
const deferred = context.newPromise();
|
|
487
|
+
result2.then(() => {
|
|
488
|
+
deferred.resolve(context.undefined);
|
|
489
|
+
context.runtime.executePendingJobs();
|
|
490
|
+
}).catch((e) => {
|
|
491
|
+
deferred.reject(import_marshal.marshal(context, e));
|
|
492
|
+
context.runtime.executePendingJobs();
|
|
493
|
+
});
|
|
494
|
+
return deferred.handle;
|
|
495
|
+
}
|
|
496
|
+
return context.undefined;
|
|
497
|
+
});
|
|
498
|
+
context.setProp(sourceObj, "pull", pullFn);
|
|
499
|
+
pullFn.dispose();
|
|
500
|
+
}
|
|
501
|
+
if (source.cancel) {
|
|
502
|
+
const cancelFn = context.newFunction("cancel", (reasonHandle) => {
|
|
503
|
+
const reason = import_unmarshal.unmarshal(context, reasonHandle);
|
|
504
|
+
const result2 = source.cancel(reason);
|
|
505
|
+
if (result2 instanceof Promise) {
|
|
506
|
+
const deferred = context.newPromise();
|
|
507
|
+
result2.then(() => {
|
|
508
|
+
deferred.resolve(context.undefined);
|
|
509
|
+
context.runtime.executePendingJobs();
|
|
510
|
+
}).catch((e) => {
|
|
511
|
+
deferred.reject(import_marshal.marshal(context, e));
|
|
512
|
+
context.runtime.executePendingJobs();
|
|
513
|
+
});
|
|
514
|
+
return deferred.handle;
|
|
515
|
+
}
|
|
516
|
+
return context.undefined;
|
|
517
|
+
});
|
|
518
|
+
context.setProp(sourceObj, "cancel", cancelFn);
|
|
519
|
+
cancelFn.dispose();
|
|
520
|
+
}
|
|
521
|
+
context.setProp(context.global, "__tempReadableStreamSource__", sourceObj);
|
|
522
|
+
sourceObj.dispose();
|
|
523
|
+
const result = context.evalCode(`
|
|
524
|
+
(function() {
|
|
525
|
+
const stream = new ReadableStream(__tempReadableStreamSource__);
|
|
526
|
+
stream.__source__ = __tempReadableStreamSource__;
|
|
527
|
+
return stream;
|
|
528
|
+
})()
|
|
529
|
+
`);
|
|
530
|
+
const cleanupResult = context.evalCode("delete __tempReadableStreamSource__");
|
|
531
|
+
if (cleanupResult.error)
|
|
532
|
+
cleanupResult.error.dispose();
|
|
533
|
+
else
|
|
534
|
+
cleanupResult.value.dispose();
|
|
535
|
+
if (result.error) {
|
|
536
|
+
const msgHandle = context.getProp(result.error, "message");
|
|
537
|
+
const errorMsg = context.dump(msgHandle);
|
|
538
|
+
msgHandle.dispose();
|
|
539
|
+
result.error.dispose();
|
|
540
|
+
throw new Error(`Failed to create ReadableStream: ${errorMsg}`);
|
|
541
|
+
}
|
|
542
|
+
return result.value;
|
|
543
|
+
}
|
|
544
|
+
async function* consumeReadableStream(context, stateMap, streamHandle) {
|
|
545
|
+
const getReaderFn = context.getProp(streamHandle, "getReader");
|
|
546
|
+
const readerResult = context.callFunction(getReaderFn, streamHandle);
|
|
547
|
+
getReaderFn.dispose();
|
|
548
|
+
if (readerResult.error) {
|
|
549
|
+
const error = context.dump(readerResult.error);
|
|
550
|
+
readerResult.error.dispose();
|
|
551
|
+
throw new Error(`Failed to get reader: ${error}`);
|
|
552
|
+
}
|
|
553
|
+
const reader = readerResult.value;
|
|
554
|
+
try {
|
|
555
|
+
while (true) {
|
|
556
|
+
const readFn = context.getProp(reader, "read");
|
|
557
|
+
const readResult = context.callFunction(readFn, reader);
|
|
558
|
+
readFn.dispose();
|
|
559
|
+
if (readResult.error) {
|
|
560
|
+
const error = context.dump(readResult.error);
|
|
561
|
+
readResult.error.dispose();
|
|
562
|
+
throw new Error(`Read failed: ${error}`);
|
|
563
|
+
}
|
|
564
|
+
const resolved = await context.resolvePromise(readResult.value);
|
|
565
|
+
readResult.value.dispose();
|
|
566
|
+
context.runtime.executePendingJobs();
|
|
567
|
+
if (resolved.error) {
|
|
568
|
+
const error = context.dump(resolved.error);
|
|
569
|
+
resolved.error.dispose();
|
|
570
|
+
throw new Error(`Read failed: ${error}`);
|
|
571
|
+
}
|
|
572
|
+
const result = import_unmarshal.unmarshal(context, resolved.value);
|
|
573
|
+
resolved.value.dispose();
|
|
574
|
+
if (result.done) {
|
|
575
|
+
break;
|
|
576
|
+
}
|
|
577
|
+
yield result.value;
|
|
578
|
+
}
|
|
579
|
+
} finally {
|
|
580
|
+
const releaseLockFn = context.getProp(reader, "releaseLock");
|
|
581
|
+
context.callFunction(releaseLockFn, reader);
|
|
582
|
+
releaseLockFn.dispose();
|
|
583
|
+
reader.dispose();
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
})
|
|
587
|
+
|
|
588
|
+
//# debugId=824583274BA2456864756E2164756E21
|