@secure-exec/nodejs 0.2.0-rc.1 → 0.2.0-rc.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/bridge/child-process.js +47 -1
- package/dist/bridge/fs.d.ts +6 -1
- package/dist/bridge/fs.js +12 -3
- package/dist/bridge/index.d.ts +2 -2
- package/dist/bridge/index.js +2 -2
- package/dist/bridge/network.d.ts +35 -1
- package/dist/bridge/network.js +471 -153
- package/dist/bridge/os.js +9 -3
- package/dist/bridge/polyfills.d.ts +6 -9
- package/dist/bridge/polyfills.js +616 -14
- package/dist/bridge/process.d.ts +3 -2
- package/dist/bridge/process.js +288 -61
- package/dist/bridge-contract.d.ts +21 -3
- package/dist/bridge-contract.js +2 -0
- package/dist/bridge-handlers.d.ts +10 -0
- package/dist/bridge-handlers.js +515 -179
- package/dist/bridge.js +1531 -855
- package/dist/builtin-modules.js +6 -0
- package/dist/esm-compiler.d.ts +1 -0
- package/dist/esm-compiler.js +29 -11
- package/dist/execution-driver.js +362 -10
- package/dist/host-network-adapter.js +10 -6
- package/dist/isolate-bootstrap.d.ts +6 -0
- package/dist/kernel-runtime.d.ts +3 -1
- package/dist/kernel-runtime.js +109 -11
- package/dist/module-access.d.ts +3 -0
- package/dist/module-access.js +52 -2
- package/dist/module-resolver.js +3 -3
- package/dist/module-source.d.ts +5 -0
- package/dist/module-source.js +224 -0
- package/dist/polyfills.js +27 -1
- package/package.json +5 -3
package/dist/bridge/process.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type * as nodeProcess from "process";
|
|
2
|
-
import { TextEncoder, TextDecoder } from "./polyfills.js";
|
|
2
|
+
import { TextEncoder, TextDecoder, Event, CustomEvent, EventTarget } from "./polyfills.js";
|
|
3
3
|
import { URL, URLSearchParams } from "./whatwg-url.js";
|
|
4
4
|
/**
|
|
5
5
|
* Process configuration injected by the host before the bridge bundle loads.
|
|
@@ -30,6 +30,7 @@ export interface ProcessConfig {
|
|
|
30
30
|
*/
|
|
31
31
|
export declare class ProcessExitError extends Error {
|
|
32
32
|
code: number;
|
|
33
|
+
_isProcessExit: true;
|
|
33
34
|
constructor(code: number);
|
|
34
35
|
}
|
|
35
36
|
declare const _default: typeof nodeProcess;
|
|
@@ -56,7 +57,7 @@ export declare function clearInterval(timer: TimerHandle | number | undefined):
|
|
|
56
57
|
export declare function setImmediate(callback: (...args: unknown[]) => void, ...args: unknown[]): TimerHandle;
|
|
57
58
|
export declare function clearImmediate(id: TimerHandle | number | undefined): void;
|
|
58
59
|
export { URL, URLSearchParams };
|
|
59
|
-
export { TextEncoder, TextDecoder };
|
|
60
|
+
export { TextEncoder, TextDecoder, Event, CustomEvent, EventTarget };
|
|
60
61
|
export declare const Buffer: BufferConstructor;
|
|
61
62
|
interface SandboxCryptoKeyData {
|
|
62
63
|
type: "public" | "private" | "secret";
|
package/dist/bridge/process.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Process module polyfill for the sandbox
|
|
2
2
|
// Provides Node.js process object and global polyfills for sandbox compatibility
|
|
3
|
-
// Re-export
|
|
4
|
-
import { TextEncoder, TextDecoder } from "./polyfills.js";
|
|
3
|
+
// Re-export WHATWG globals from polyfills (polyfills.ts is imported first in index.ts)
|
|
4
|
+
import { TextEncoder, TextDecoder, Event, CustomEvent, EventTarget, } from "./polyfills.js";
|
|
5
5
|
import { URL, URLSearchParams, installWhatwgUrlGlobals, } from "./whatwg-url.js";
|
|
6
6
|
// Use buffer package for spec-compliant Buffer implementation
|
|
7
7
|
import { Buffer as BufferPolyfill } from "buffer";
|
|
@@ -115,10 +115,12 @@ let _exited = false;
|
|
|
115
115
|
*/
|
|
116
116
|
export class ProcessExitError extends Error {
|
|
117
117
|
code;
|
|
118
|
+
_isProcessExit;
|
|
118
119
|
constructor(code) {
|
|
119
120
|
super("process.exit(" + code + ")");
|
|
120
121
|
this.name = "ProcessExitError";
|
|
121
122
|
this.code = code;
|
|
123
|
+
this._isProcessExit = true;
|
|
122
124
|
}
|
|
123
125
|
}
|
|
124
126
|
// Make available globally
|
|
@@ -132,6 +134,8 @@ const _signalNumbers = {
|
|
|
132
134
|
SIGXCPU: 24, SIGXFSZ: 25, SIGVTALRM: 26, SIGPROF: 27, SIGWINCH: 28,
|
|
133
135
|
SIGIO: 29, SIGPWR: 30, SIGSYS: 31,
|
|
134
136
|
};
|
|
137
|
+
const _signalNamesByNumber = Object.fromEntries(Object.entries(_signalNumbers).map(([name, num]) => [num, name]));
|
|
138
|
+
const _ignoredSelfSignals = new Set(["SIGWINCH", "SIGCHLD", "SIGCONT", "SIGURG"]);
|
|
135
139
|
function _resolveSignal(signal) {
|
|
136
140
|
if (signal === undefined || signal === null)
|
|
137
141
|
return 15; // default SIGTERM
|
|
@@ -199,6 +203,35 @@ function _emit(event, ...args) {
|
|
|
199
203
|
}
|
|
200
204
|
return handled;
|
|
201
205
|
}
|
|
206
|
+
function isProcessExitError(error) {
|
|
207
|
+
return Boolean(error &&
|
|
208
|
+
typeof error === "object" &&
|
|
209
|
+
(error._isProcessExit === true ||
|
|
210
|
+
error.name === "ProcessExitError"));
|
|
211
|
+
}
|
|
212
|
+
function normalizeAsyncError(error) {
|
|
213
|
+
return error instanceof Error ? error : new Error(String(error));
|
|
214
|
+
}
|
|
215
|
+
function routeAsyncCallbackError(error) {
|
|
216
|
+
if (isProcessExitError(error)) {
|
|
217
|
+
return { handled: false, rethrow: error };
|
|
218
|
+
}
|
|
219
|
+
const normalized = normalizeAsyncError(error);
|
|
220
|
+
try {
|
|
221
|
+
if (_emit("uncaughtException", normalized, "uncaughtException")) {
|
|
222
|
+
return { handled: true, rethrow: null };
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
catch (emitError) {
|
|
226
|
+
return { handled: false, rethrow: emitError };
|
|
227
|
+
}
|
|
228
|
+
return { handled: false, rethrow: normalized };
|
|
229
|
+
}
|
|
230
|
+
function scheduleAsyncRethrow(error) {
|
|
231
|
+
setTimeout(() => {
|
|
232
|
+
throw error;
|
|
233
|
+
}, 0);
|
|
234
|
+
}
|
|
202
235
|
function _getStdinIsTTY() {
|
|
203
236
|
return (typeof __runtimeTtyConfig !== "undefined" && __runtimeTtyConfig.stdinIsTTY) || false;
|
|
204
237
|
}
|
|
@@ -208,58 +241,112 @@ function _getStdoutIsTTY() {
|
|
|
208
241
|
function _getStderrIsTTY() {
|
|
209
242
|
return (typeof __runtimeTtyConfig !== "undefined" && __runtimeTtyConfig.stderrIsTTY) || false;
|
|
210
243
|
}
|
|
211
|
-
|
|
212
|
-
|
|
244
|
+
function getWriteCallback(encodingOrCallback, callback) {
|
|
245
|
+
if (typeof encodingOrCallback === "function") {
|
|
246
|
+
return encodingOrCallback;
|
|
247
|
+
}
|
|
248
|
+
if (typeof callback === "function") {
|
|
249
|
+
return callback;
|
|
250
|
+
}
|
|
251
|
+
return undefined;
|
|
252
|
+
}
|
|
253
|
+
function emitListeners(listeners, onceListeners, event, args) {
|
|
254
|
+
const persistent = listeners[event] ? listeners[event].slice() : [];
|
|
255
|
+
const once = onceListeners[event] ? onceListeners[event].slice() : [];
|
|
256
|
+
if (once.length > 0) {
|
|
257
|
+
onceListeners[event] = [];
|
|
258
|
+
}
|
|
259
|
+
for (const listener of persistent) {
|
|
260
|
+
listener(...args);
|
|
261
|
+
}
|
|
262
|
+
for (const listener of once) {
|
|
263
|
+
listener(...args);
|
|
264
|
+
}
|
|
265
|
+
return persistent.length + once.length > 0;
|
|
266
|
+
}
|
|
267
|
+
function createStdioWriteStream(options) {
|
|
268
|
+
const listeners = {};
|
|
269
|
+
const onceListeners = {};
|
|
270
|
+
const remove = (event, listener) => {
|
|
271
|
+
if (listeners[event]) {
|
|
272
|
+
const idx = listeners[event].indexOf(listener);
|
|
273
|
+
if (idx !== -1)
|
|
274
|
+
listeners[event].splice(idx, 1);
|
|
275
|
+
}
|
|
276
|
+
if (onceListeners[event]) {
|
|
277
|
+
const idx = onceListeners[event].indexOf(listener);
|
|
278
|
+
if (idx !== -1)
|
|
279
|
+
onceListeners[event].splice(idx, 1);
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
const stream = {
|
|
283
|
+
write(data, encodingOrCallback, callback) {
|
|
284
|
+
options.write(String(data));
|
|
285
|
+
const done = getWriteCallback(encodingOrCallback, callback);
|
|
286
|
+
if (done) {
|
|
287
|
+
_queueMicrotask(() => done(null));
|
|
288
|
+
}
|
|
289
|
+
return true;
|
|
290
|
+
},
|
|
291
|
+
end() {
|
|
292
|
+
return stream;
|
|
293
|
+
},
|
|
294
|
+
on(event, listener) {
|
|
295
|
+
if (!listeners[event])
|
|
296
|
+
listeners[event] = [];
|
|
297
|
+
listeners[event].push(listener);
|
|
298
|
+
return stream;
|
|
299
|
+
},
|
|
300
|
+
once(event, listener) {
|
|
301
|
+
if (!onceListeners[event])
|
|
302
|
+
onceListeners[event] = [];
|
|
303
|
+
onceListeners[event].push(listener);
|
|
304
|
+
return stream;
|
|
305
|
+
},
|
|
306
|
+
off(event, listener) {
|
|
307
|
+
remove(event, listener);
|
|
308
|
+
return stream;
|
|
309
|
+
},
|
|
310
|
+
removeListener(event, listener) {
|
|
311
|
+
remove(event, listener);
|
|
312
|
+
return stream;
|
|
313
|
+
},
|
|
314
|
+
addListener(event, listener) {
|
|
315
|
+
return stream.on(event, listener);
|
|
316
|
+
},
|
|
317
|
+
emit(event, ...args) {
|
|
318
|
+
return emitListeners(listeners, onceListeners, event, args);
|
|
319
|
+
},
|
|
320
|
+
writable: true,
|
|
321
|
+
get isTTY() { return options.isTTY(); },
|
|
322
|
+
columns: 80,
|
|
323
|
+
rows: 24,
|
|
324
|
+
};
|
|
325
|
+
return stream;
|
|
326
|
+
}
|
|
327
|
+
const _stdout = createStdioWriteStream({
|
|
213
328
|
write(data) {
|
|
214
329
|
if (typeof _log !== "undefined") {
|
|
215
|
-
_log.applySync(undefined, [
|
|
330
|
+
_log.applySync(undefined, [data]);
|
|
216
331
|
}
|
|
217
|
-
return true;
|
|
218
|
-
},
|
|
219
|
-
end() {
|
|
220
|
-
return this;
|
|
221
|
-
},
|
|
222
|
-
on() {
|
|
223
|
-
return this;
|
|
224
|
-
},
|
|
225
|
-
once() {
|
|
226
|
-
return this;
|
|
227
332
|
},
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
writable: true,
|
|
232
|
-
get isTTY() { return _getStdoutIsTTY(); },
|
|
233
|
-
columns: 80,
|
|
234
|
-
rows: 24,
|
|
235
|
-
};
|
|
236
|
-
// Stderr stream
|
|
237
|
-
const _stderr = {
|
|
333
|
+
isTTY: _getStdoutIsTTY,
|
|
334
|
+
});
|
|
335
|
+
const _stderr = createStdioWriteStream({
|
|
238
336
|
write(data) {
|
|
239
337
|
if (typeof _error !== "undefined") {
|
|
240
|
-
_error.applySync(undefined, [
|
|
338
|
+
_error.applySync(undefined, [data]);
|
|
241
339
|
}
|
|
242
|
-
return true;
|
|
243
|
-
},
|
|
244
|
-
end() {
|
|
245
|
-
return this;
|
|
246
|
-
},
|
|
247
|
-
on() {
|
|
248
|
-
return this;
|
|
249
|
-
},
|
|
250
|
-
once() {
|
|
251
|
-
return this;
|
|
252
|
-
},
|
|
253
|
-
emit() {
|
|
254
|
-
return false;
|
|
255
340
|
},
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
columns: 80,
|
|
259
|
-
rows: 24,
|
|
260
|
-
};
|
|
341
|
+
isTTY: _getStderrIsTTY,
|
|
342
|
+
});
|
|
261
343
|
const _stdinListeners = {};
|
|
262
344
|
const _stdinOnceListeners = {};
|
|
345
|
+
const _stdinLiveDecoder = new TextDecoder();
|
|
346
|
+
const STDIN_HANDLE_ID = "process.stdin";
|
|
347
|
+
let _stdinLiveBuffer = "";
|
|
348
|
+
let _stdinLiveStarted = false;
|
|
349
|
+
let _stdinLiveHandleRegistered = false;
|
|
263
350
|
// Initialize stdin state as globals for external access
|
|
264
351
|
exposeMutableRuntimeStateGlobal("_stdinData", (typeof _processConfig !== "undefined" && _processConfig.stdin) || "");
|
|
265
352
|
exposeMutableRuntimeStateGlobal("_stdinPosition", 0);
|
|
@@ -302,11 +389,100 @@ function _emitStdinData() {
|
|
|
302
389
|
}
|
|
303
390
|
}
|
|
304
391
|
}
|
|
392
|
+
function emitStdinListeners(event, value) {
|
|
393
|
+
const listeners = [...(_stdinListeners[event] || []), ...(_stdinOnceListeners[event] || [])];
|
|
394
|
+
_stdinOnceListeners[event] = [];
|
|
395
|
+
for (const listener of listeners) {
|
|
396
|
+
listener(value);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
function syncLiveStdinHandle(active) {
|
|
400
|
+
if (active) {
|
|
401
|
+
if (!_stdinLiveHandleRegistered && typeof _registerHandle === "function") {
|
|
402
|
+
try {
|
|
403
|
+
_registerHandle(STDIN_HANDLE_ID, "process.stdin");
|
|
404
|
+
_stdinLiveHandleRegistered = true;
|
|
405
|
+
}
|
|
406
|
+
catch {
|
|
407
|
+
// Process exit races turn registration into a no-op.
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
if (_stdinLiveHandleRegistered && typeof _unregisterHandle === "function") {
|
|
413
|
+
try {
|
|
414
|
+
_unregisterHandle(STDIN_HANDLE_ID);
|
|
415
|
+
}
|
|
416
|
+
catch {
|
|
417
|
+
// Process exit races turn unregistration into a no-op.
|
|
418
|
+
}
|
|
419
|
+
_stdinLiveHandleRegistered = false;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
function flushLiveStdinBuffer() {
|
|
423
|
+
if (!getStdinFlowMode() || _stdinLiveBuffer.length === 0)
|
|
424
|
+
return;
|
|
425
|
+
const chunk = _stdinLiveBuffer;
|
|
426
|
+
_stdinLiveBuffer = "";
|
|
427
|
+
emitStdinListeners("data", chunk);
|
|
428
|
+
}
|
|
429
|
+
function finishLiveStdin() {
|
|
430
|
+
if (getStdinEnded())
|
|
431
|
+
return;
|
|
432
|
+
setStdinEnded(true);
|
|
433
|
+
flushLiveStdinBuffer();
|
|
434
|
+
emitStdinListeners("end");
|
|
435
|
+
emitStdinListeners("close");
|
|
436
|
+
syncLiveStdinHandle(false);
|
|
437
|
+
}
|
|
438
|
+
function ensureLiveStdinStarted() {
|
|
439
|
+
if (_stdinLiveStarted || !_getStdinIsTTY())
|
|
440
|
+
return;
|
|
441
|
+
_stdinLiveStarted = true;
|
|
442
|
+
syncLiveStdinHandle(!_stdin.paused);
|
|
443
|
+
void (async () => {
|
|
444
|
+
try {
|
|
445
|
+
while (!getStdinEnded()) {
|
|
446
|
+
if (typeof _kernelStdinRead === "undefined") {
|
|
447
|
+
break;
|
|
448
|
+
}
|
|
449
|
+
const next = await _kernelStdinRead.apply(undefined, [], {
|
|
450
|
+
result: { promise: true },
|
|
451
|
+
});
|
|
452
|
+
if (next?.done) {
|
|
453
|
+
break;
|
|
454
|
+
}
|
|
455
|
+
const dataBase64 = String(next?.dataBase64 ?? "");
|
|
456
|
+
if (!dataBase64) {
|
|
457
|
+
continue;
|
|
458
|
+
}
|
|
459
|
+
_stdinLiveBuffer += _stdinLiveDecoder.decode(BufferPolyfill.from(dataBase64, "base64"), { stream: true });
|
|
460
|
+
flushLiveStdinBuffer();
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
catch {
|
|
464
|
+
// Treat bridge-side stdin failures as EOF for sandbox code.
|
|
465
|
+
}
|
|
466
|
+
_stdinLiveBuffer += _stdinLiveDecoder.decode();
|
|
467
|
+
finishLiveStdin();
|
|
468
|
+
})();
|
|
469
|
+
}
|
|
305
470
|
const _stdin = {
|
|
306
471
|
readable: true,
|
|
307
472
|
paused: true,
|
|
308
473
|
encoding: null,
|
|
474
|
+
isRaw: false,
|
|
309
475
|
read(size) {
|
|
476
|
+
if (_stdinLiveBuffer.length > 0) {
|
|
477
|
+
if (!size || size >= _stdinLiveBuffer.length) {
|
|
478
|
+
const chunk = _stdinLiveBuffer;
|
|
479
|
+
_stdinLiveBuffer = "";
|
|
480
|
+
return chunk;
|
|
481
|
+
}
|
|
482
|
+
const chunk = _stdinLiveBuffer.slice(0, size);
|
|
483
|
+
_stdinLiveBuffer = _stdinLiveBuffer.slice(size);
|
|
484
|
+
return chunk;
|
|
485
|
+
}
|
|
310
486
|
if (getStdinPosition() >= getStdinData().length)
|
|
311
487
|
return null;
|
|
312
488
|
const chunk = size ? getStdinData().slice(getStdinPosition(), getStdinPosition() + size) : getStdinData().slice(getStdinPosition());
|
|
@@ -317,6 +493,12 @@ const _stdin = {
|
|
|
317
493
|
if (!_stdinListeners[event])
|
|
318
494
|
_stdinListeners[event] = [];
|
|
319
495
|
_stdinListeners[event].push(listener);
|
|
496
|
+
if (_getStdinIsTTY() && (event === "data" || event === "end" || event === "close")) {
|
|
497
|
+
ensureLiveStdinStarted();
|
|
498
|
+
}
|
|
499
|
+
if (event === "data" && this.paused) {
|
|
500
|
+
this.resume();
|
|
501
|
+
}
|
|
320
502
|
// When 'end' listener is added and we have data, emit everything synchronously
|
|
321
503
|
// This works because typical patterns register 'data' then 'end' listeners
|
|
322
504
|
if (event === "end" && getStdinData() && !getStdinEnded()) {
|
|
@@ -354,11 +536,17 @@ const _stdin = {
|
|
|
354
536
|
pause() {
|
|
355
537
|
this.paused = true;
|
|
356
538
|
setStdinFlowMode(false);
|
|
539
|
+
syncLiveStdinHandle(false);
|
|
357
540
|
return this;
|
|
358
541
|
},
|
|
359
542
|
resume() {
|
|
543
|
+
if (_getStdinIsTTY()) {
|
|
544
|
+
ensureLiveStdinStarted();
|
|
545
|
+
syncLiveStdinHandle(true);
|
|
546
|
+
}
|
|
360
547
|
this.paused = false;
|
|
361
548
|
setStdinFlowMode(true);
|
|
549
|
+
flushLiveStdinBuffer();
|
|
362
550
|
_emitStdinData();
|
|
363
551
|
return this;
|
|
364
552
|
},
|
|
@@ -373,6 +561,7 @@ const _stdin = {
|
|
|
373
561
|
if (typeof _ptySetRawMode !== "undefined") {
|
|
374
562
|
_ptySetRawMode.applySync(undefined, [mode]);
|
|
375
563
|
}
|
|
564
|
+
this.isRaw = mode;
|
|
376
565
|
return this;
|
|
377
566
|
},
|
|
378
567
|
get isTTY() { return _getStdinIsTTY(); },
|
|
@@ -522,12 +711,8 @@ const process = {
|
|
|
522
711
|
return process.exit(1);
|
|
523
712
|
},
|
|
524
713
|
nextTick(callback, ...args) {
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
}
|
|
528
|
-
else {
|
|
529
|
-
Promise.resolve().then(() => callback(...args));
|
|
530
|
-
}
|
|
714
|
+
_nextTickQueue.push({ callback, args });
|
|
715
|
+
scheduleNextTickFlush();
|
|
531
716
|
},
|
|
532
717
|
hrtime: hrtime,
|
|
533
718
|
getuid() {
|
|
@@ -612,7 +797,17 @@ const process = {
|
|
|
612
797
|
}
|
|
613
798
|
// Resolve signal name to number (default SIGTERM)
|
|
614
799
|
const sigNum = _resolveSignal(signal);
|
|
615
|
-
|
|
800
|
+
if (sigNum === 0) {
|
|
801
|
+
return true;
|
|
802
|
+
}
|
|
803
|
+
const sigName = _signalNamesByNumber[sigNum] ?? `SIG${sigNum}`;
|
|
804
|
+
if (_emit(sigName, sigName)) {
|
|
805
|
+
return true;
|
|
806
|
+
}
|
|
807
|
+
if (_ignoredSelfSignals.has(sigName)) {
|
|
808
|
+
return true;
|
|
809
|
+
}
|
|
810
|
+
// Unhandled fatal self-signals exit with 128 + signal number.
|
|
616
811
|
return process.exit(128 + sigNum);
|
|
617
812
|
},
|
|
618
813
|
// EventEmitter methods
|
|
@@ -827,6 +1022,35 @@ class TimerHandle {
|
|
|
827
1022
|
}
|
|
828
1023
|
}
|
|
829
1024
|
const _timerEntries = new Map();
|
|
1025
|
+
const _nextTickQueue = [];
|
|
1026
|
+
let _nextTickScheduled = false;
|
|
1027
|
+
function flushNextTickQueue() {
|
|
1028
|
+
_nextTickScheduled = false;
|
|
1029
|
+
while (_nextTickQueue.length > 0) {
|
|
1030
|
+
const entry = _nextTickQueue.shift();
|
|
1031
|
+
if (!entry) {
|
|
1032
|
+
break;
|
|
1033
|
+
}
|
|
1034
|
+
try {
|
|
1035
|
+
entry.callback(...entry.args);
|
|
1036
|
+
}
|
|
1037
|
+
catch (error) {
|
|
1038
|
+
const outcome = routeAsyncCallbackError(error);
|
|
1039
|
+
if (!outcome.handled && outcome.rethrow !== null) {
|
|
1040
|
+
_nextTickQueue.length = 0;
|
|
1041
|
+
scheduleAsyncRethrow(outcome.rethrow);
|
|
1042
|
+
}
|
|
1043
|
+
return;
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
function scheduleNextTickFlush() {
|
|
1048
|
+
if (_nextTickScheduled) {
|
|
1049
|
+
return;
|
|
1050
|
+
}
|
|
1051
|
+
_nextTickScheduled = true;
|
|
1052
|
+
_queueMicrotask(flushNextTickQueue);
|
|
1053
|
+
}
|
|
830
1054
|
function timerDispatch(_eventType, payload) {
|
|
831
1055
|
const timerId = typeof payload === "number"
|
|
832
1056
|
? payload
|
|
@@ -843,8 +1067,12 @@ function timerDispatch(_eventType, payload) {
|
|
|
843
1067
|
try {
|
|
844
1068
|
entry.callback(...entry.args);
|
|
845
1069
|
}
|
|
846
|
-
catch (
|
|
847
|
-
|
|
1070
|
+
catch (error) {
|
|
1071
|
+
const outcome = routeAsyncCallbackError(error);
|
|
1072
|
+
if (!outcome.handled && outcome.rethrow !== null) {
|
|
1073
|
+
throw outcome.rethrow;
|
|
1074
|
+
}
|
|
1075
|
+
return;
|
|
848
1076
|
}
|
|
849
1077
|
if (entry.repeat && _timerEntries.has(timerId)) {
|
|
850
1078
|
armKernelTimer(timerId);
|
|
@@ -899,7 +1127,7 @@ export function clearImmediate(id) {
|
|
|
899
1127
|
}
|
|
900
1128
|
// TextEncoder and TextDecoder - re-export from polyfills
|
|
901
1129
|
export { URL, URLSearchParams };
|
|
902
|
-
export { TextEncoder, TextDecoder };
|
|
1130
|
+
export { TextEncoder, TextDecoder, Event, CustomEvent, EventTarget };
|
|
903
1131
|
// Buffer - use buffer package polyfill
|
|
904
1132
|
export const Buffer = BufferPolyfill;
|
|
905
1133
|
function throwUnsupportedCryptoApi(api) {
|
|
@@ -1332,13 +1560,12 @@ export function setupGlobals() {
|
|
|
1332
1560
|
}
|
|
1333
1561
|
// URL globals must override bootstrap fallbacks and stay non-enumerable.
|
|
1334
1562
|
installWhatwgUrlGlobals(g);
|
|
1335
|
-
//
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
}
|
|
1563
|
+
// WHATWG encoding and events
|
|
1564
|
+
g.TextEncoder = TextEncoder;
|
|
1565
|
+
g.TextDecoder = TextDecoder;
|
|
1566
|
+
g.Event = Event;
|
|
1567
|
+
g.CustomEvent = CustomEvent;
|
|
1568
|
+
g.EventTarget = EventTarget;
|
|
1342
1569
|
// Buffer
|
|
1343
1570
|
if (typeof g.Buffer === "undefined") {
|
|
1344
1571
|
g.Buffer = Buffer;
|
|
@@ -87,6 +87,7 @@ export declare const HOST_BRIDGE_GLOBAL_KEYS: {
|
|
|
87
87
|
readonly networkHttp2StreamPushStreamRaw: "_networkHttp2StreamPushStreamRaw";
|
|
88
88
|
readonly networkHttp2StreamWriteRaw: "_networkHttp2StreamWriteRaw";
|
|
89
89
|
readonly networkHttp2StreamEndRaw: "_networkHttp2StreamEndRaw";
|
|
90
|
+
readonly networkHttp2StreamCloseRaw: "_networkHttp2StreamCloseRaw";
|
|
90
91
|
readonly networkHttp2StreamPauseRaw: "_networkHttp2StreamPauseRaw";
|
|
91
92
|
readonly networkHttp2StreamResumeRaw: "_networkHttp2StreamResumeRaw";
|
|
92
93
|
readonly networkHttp2StreamRespondWithFileRaw: "_networkHttp2StreamRespondWithFileRaw";
|
|
@@ -120,6 +121,7 @@ export declare const HOST_BRIDGE_GLOBAL_KEYS: {
|
|
|
120
121
|
readonly resolveModuleSync: "_resolveModuleSync";
|
|
121
122
|
readonly loadFileSync: "_loadFileSync";
|
|
122
123
|
readonly ptySetRawMode: "_ptySetRawMode";
|
|
124
|
+
readonly kernelStdinRead: "_kernelStdinRead";
|
|
123
125
|
readonly processConfig: "_processConfig";
|
|
124
126
|
readonly osConfig: "_osConfig";
|
|
125
127
|
readonly log: "_log";
|
|
@@ -241,6 +243,7 @@ export declare const HOST_BRIDGE_GLOBAL_KEY_LIST: ValueOf<{
|
|
|
241
243
|
readonly networkHttp2StreamPushStreamRaw: "_networkHttp2StreamPushStreamRaw";
|
|
242
244
|
readonly networkHttp2StreamWriteRaw: "_networkHttp2StreamWriteRaw";
|
|
243
245
|
readonly networkHttp2StreamEndRaw: "_networkHttp2StreamEndRaw";
|
|
246
|
+
readonly networkHttp2StreamCloseRaw: "_networkHttp2StreamCloseRaw";
|
|
244
247
|
readonly networkHttp2StreamPauseRaw: "_networkHttp2StreamPauseRaw";
|
|
245
248
|
readonly networkHttp2StreamResumeRaw: "_networkHttp2StreamResumeRaw";
|
|
246
249
|
readonly networkHttp2StreamRespondWithFileRaw: "_networkHttp2StreamRespondWithFileRaw";
|
|
@@ -274,6 +277,7 @@ export declare const HOST_BRIDGE_GLOBAL_KEY_LIST: ValueOf<{
|
|
|
274
277
|
readonly resolveModuleSync: "_resolveModuleSync";
|
|
275
278
|
readonly loadFileSync: "_loadFileSync";
|
|
276
279
|
readonly ptySetRawMode: "_ptySetRawMode";
|
|
280
|
+
readonly kernelStdinRead: "_kernelStdinRead";
|
|
277
281
|
readonly processConfig: "_processConfig";
|
|
278
282
|
readonly osConfig: "_osConfig";
|
|
279
283
|
readonly log: "_log";
|
|
@@ -391,6 +395,7 @@ export declare const BRIDGE_GLOBAL_KEY_LIST: readonly (ValueOf<{
|
|
|
391
395
|
readonly networkHttp2StreamPushStreamRaw: "_networkHttp2StreamPushStreamRaw";
|
|
392
396
|
readonly networkHttp2StreamWriteRaw: "_networkHttp2StreamWriteRaw";
|
|
393
397
|
readonly networkHttp2StreamEndRaw: "_networkHttp2StreamEndRaw";
|
|
398
|
+
readonly networkHttp2StreamCloseRaw: "_networkHttp2StreamCloseRaw";
|
|
394
399
|
readonly networkHttp2StreamPauseRaw: "_networkHttp2StreamPauseRaw";
|
|
395
400
|
readonly networkHttp2StreamResumeRaw: "_networkHttp2StreamResumeRaw";
|
|
396
401
|
readonly networkHttp2StreamRespondWithFileRaw: "_networkHttp2StreamRespondWithFileRaw";
|
|
@@ -424,6 +429,7 @@ export declare const BRIDGE_GLOBAL_KEY_LIST: readonly (ValueOf<{
|
|
|
424
429
|
readonly resolveModuleSync: "_resolveModuleSync";
|
|
425
430
|
readonly loadFileSync: "_loadFileSync";
|
|
426
431
|
readonly ptySetRawMode: "_ptySetRawMode";
|
|
432
|
+
readonly kernelStdinRead: "_kernelStdinRead";
|
|
427
433
|
readonly processConfig: "_processConfig";
|
|
428
434
|
readonly osConfig: "_osConfig";
|
|
429
435
|
readonly log: "_log";
|
|
@@ -483,6 +489,7 @@ export interface BridgeApplySyncRef<TArgs extends unknown[], TResult> {
|
|
|
483
489
|
export interface BridgeApplySyncPromiseRef<TArgs extends unknown[], TResult> {
|
|
484
490
|
applySyncPromise(ctx: undefined, args: TArgs): TResult;
|
|
485
491
|
}
|
|
492
|
+
export type ModuleLoadMode = "require" | "import";
|
|
486
493
|
export type DynamicImportBridgeRef = BridgeApplyRef<[
|
|
487
494
|
string,
|
|
488
495
|
string
|
|
@@ -491,13 +498,20 @@ export type LoadPolyfillBridgeRef = BridgeApplyRef<[string], string | null>;
|
|
|
491
498
|
export type ResolveModuleBridgeRef = BridgeApplySyncPromiseRef<[
|
|
492
499
|
string,
|
|
493
500
|
string
|
|
494
|
-
], string | null>;
|
|
495
|
-
export type LoadFileBridgeRef = BridgeApplySyncPromiseRef<[
|
|
501
|
+
] | [string, string, ModuleLoadMode], string | null>;
|
|
502
|
+
export type LoadFileBridgeRef = BridgeApplySyncPromiseRef<[
|
|
503
|
+
string
|
|
504
|
+
] | [string, ModuleLoadMode], string | null>;
|
|
496
505
|
export type RequireFromBridgeFn = (request: string, dirname: string) => unknown;
|
|
497
506
|
export type ModuleCacheBridgeRecord = Record<string, unknown>;
|
|
498
507
|
export type ProcessLogBridgeRef = BridgeApplySyncRef<[string], void>;
|
|
499
508
|
export type ProcessErrorBridgeRef = BridgeApplySyncRef<[string], void>;
|
|
500
509
|
export type ScheduleTimerBridgeRef = BridgeApplyRef<[number], void>;
|
|
510
|
+
export type KernelStdinReadBridgeRef = BridgeApplyRef<[
|
|
511
|
+
], {
|
|
512
|
+
done: boolean;
|
|
513
|
+
dataBase64?: string;
|
|
514
|
+
}>;
|
|
501
515
|
export type CryptoRandomFillBridgeRef = BridgeApplySyncRef<[number], string>;
|
|
502
516
|
export type CryptoRandomUuidBridgeRef = BridgeApplySyncRef<[], string>;
|
|
503
517
|
export type CryptoHashDigestBridgeRef = BridgeApplySyncRef<[string, string], string>;
|
|
@@ -698,7 +712,7 @@ export type NetworkHttp2StreamRespondRawBridgeRef = BridgeApplySyncRef<[
|
|
|
698
712
|
number,
|
|
699
713
|
string
|
|
700
714
|
], void>;
|
|
701
|
-
export type NetworkHttp2StreamPushStreamRawBridgeRef =
|
|
715
|
+
export type NetworkHttp2StreamPushStreamRawBridgeRef = BridgeApplySyncRef<[
|
|
702
716
|
number,
|
|
703
717
|
string,
|
|
704
718
|
string
|
|
@@ -711,6 +725,10 @@ export type NetworkHttp2StreamEndRawBridgeRef = BridgeApplySyncRef<[
|
|
|
711
725
|
number,
|
|
712
726
|
string | null
|
|
713
727
|
], void>;
|
|
728
|
+
export type NetworkHttp2StreamCloseRawBridgeRef = BridgeApplySyncRef<[
|
|
729
|
+
number,
|
|
730
|
+
number | null
|
|
731
|
+
], void>;
|
|
714
732
|
export type NetworkHttp2StreamPauseRawBridgeRef = BridgeApplySyncRef<[number], void>;
|
|
715
733
|
export type NetworkHttp2StreamResumeRawBridgeRef = BridgeApplySyncRef<[number], void>;
|
|
716
734
|
export type NetworkHttp2StreamRespondWithFileRawBridgeRef = BridgeApplySyncRef<[
|
package/dist/bridge-contract.js
CHANGED
|
@@ -89,6 +89,7 @@ export const HOST_BRIDGE_GLOBAL_KEYS = {
|
|
|
89
89
|
networkHttp2StreamPushStreamRaw: "_networkHttp2StreamPushStreamRaw",
|
|
90
90
|
networkHttp2StreamWriteRaw: "_networkHttp2StreamWriteRaw",
|
|
91
91
|
networkHttp2StreamEndRaw: "_networkHttp2StreamEndRaw",
|
|
92
|
+
networkHttp2StreamCloseRaw: "_networkHttp2StreamCloseRaw",
|
|
92
93
|
networkHttp2StreamPauseRaw: "_networkHttp2StreamPauseRaw",
|
|
93
94
|
networkHttp2StreamResumeRaw: "_networkHttp2StreamResumeRaw",
|
|
94
95
|
networkHttp2StreamRespondWithFileRaw: "_networkHttp2StreamRespondWithFileRaw",
|
|
@@ -122,6 +123,7 @@ export const HOST_BRIDGE_GLOBAL_KEYS = {
|
|
|
122
123
|
resolveModuleSync: "_resolveModuleSync",
|
|
123
124
|
loadFileSync: "_loadFileSync",
|
|
124
125
|
ptySetRawMode: "_ptySetRawMode",
|
|
126
|
+
kernelStdinRead: "_kernelStdinRead",
|
|
125
127
|
processConfig: "_processConfig",
|
|
126
128
|
osConfig: "_osConfig",
|
|
127
129
|
log: "_log",
|
|
@@ -89,6 +89,7 @@ export interface TimerBridgeDeps {
|
|
|
89
89
|
}
|
|
90
90
|
/** Build timer bridge handler. */
|
|
91
91
|
export declare function buildTimerBridgeHandlers(deps: TimerBridgeDeps): BridgeHandlers;
|
|
92
|
+
export declare function buildMimeBridgeHandlers(): BridgeHandlers;
|
|
92
93
|
export interface KernelTimerDispatchDeps {
|
|
93
94
|
timerTable: import("@secure-exec/core").TimerTable;
|
|
94
95
|
pid: number;
|
|
@@ -98,6 +99,12 @@ export interface KernelTimerDispatchDeps {
|
|
|
98
99
|
sendStreamEvent(eventType: string, payload: Uint8Array): void;
|
|
99
100
|
}
|
|
100
101
|
export declare function buildKernelTimerDispatchHandlers(deps: KernelTimerDispatchDeps): BridgeHandlers;
|
|
102
|
+
export interface KernelStdinDispatchDeps {
|
|
103
|
+
liveStdinSource?: import("./isolate-bootstrap.js").LiveStdinSource;
|
|
104
|
+
budgetState: BudgetState;
|
|
105
|
+
maxBridgeCalls?: number;
|
|
106
|
+
}
|
|
107
|
+
export declare function buildKernelStdinDispatchHandlers(deps: KernelStdinDispatchDeps): BridgeHandlers;
|
|
101
108
|
export interface KernelHandleDispatchDeps {
|
|
102
109
|
processTable?: import("@secure-exec/core").ProcessTable;
|
|
103
110
|
pid: number;
|
|
@@ -144,6 +151,9 @@ export interface NetworkBridgeDeps {
|
|
|
144
151
|
pendingHttpServerStarts: {
|
|
145
152
|
count: number;
|
|
146
153
|
};
|
|
154
|
+
activeHttpClientRequests: {
|
|
155
|
+
count: number;
|
|
156
|
+
};
|
|
147
157
|
/** Push HTTP server/upgrade events into the V8 isolate. */
|
|
148
158
|
sendStreamEvent: (eventType: string, payload: Uint8Array) => void;
|
|
149
159
|
/** Kernel socket table for all bridge-managed HTTP server routing. */
|