@n8n/expression-runtime 0.36.1 → 0.37.0

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.
Files changed (29) hide show
  1. package/dist/bundle/runtime.esm.js +1 -1
  2. package/dist/bundle/runtime.esm.js.map +3 -3
  3. package/dist/bundle/runtime.iife.js +1 -1
  4. package/dist/bundle/runtime.iife.js.map +3 -3
  5. package/dist/cjs/bridge/isolated-vm-bridge.d.ts +0 -3
  6. package/dist/cjs/bridge/isolated-vm-bridge.d.ts.map +1 -1
  7. package/dist/cjs/bridge/isolated-vm-bridge.js +21 -14
  8. package/dist/cjs/bridge/isolated-vm-bridge.js.map +1 -1
  9. package/dist/cjs/bridge/quickjs-bridge.d.ts +33 -0
  10. package/dist/cjs/bridge/quickjs-bridge.d.ts.map +1 -1
  11. package/dist/cjs/bridge/quickjs-bridge.js +183 -27
  12. package/dist/cjs/bridge/quickjs-bridge.js.map +1 -1
  13. package/dist/cjs/build.tsbuildinfo +1 -1
  14. package/dist/cjs/extensions/array-extensions.d.ts.map +1 -1
  15. package/dist/cjs/extensions/array-extensions.js +26 -12
  16. package/dist/cjs/extensions/array-extensions.js.map +1 -1
  17. package/dist/esm/bridge/isolated-vm-bridge.d.ts +0 -3
  18. package/dist/esm/bridge/isolated-vm-bridge.d.ts.map +1 -1
  19. package/dist/esm/bridge/isolated-vm-bridge.js +21 -14
  20. package/dist/esm/bridge/isolated-vm-bridge.js.map +1 -1
  21. package/dist/esm/bridge/quickjs-bridge.d.ts +33 -0
  22. package/dist/esm/bridge/quickjs-bridge.d.ts.map +1 -1
  23. package/dist/esm/bridge/quickjs-bridge.js +183 -27
  24. package/dist/esm/bridge/quickjs-bridge.js.map +1 -1
  25. package/dist/esm/build.tsbuildinfo +1 -1
  26. package/dist/esm/extensions/array-extensions.d.ts.map +1 -1
  27. package/dist/esm/extensions/array-extensions.js +26 -12
  28. package/dist/esm/extensions/array-extensions.js.map +1 -1
  29. package/package.json +3 -3
@@ -82,7 +82,6 @@ export declare class IsolatedVmBridge implements RuntimeBridge {
82
82
  * for navigation and guard semantics); errors are caught and returned
83
83
  * as sentinels instead of crossing the isolate boundary.
84
84
  *
85
- * @param data - Current workflow data to use for callback responses
86
85
  * @private
87
86
  */
88
87
  private createGetValueAtPathRef;
@@ -93,7 +92,6 @@ export declare class IsolatedVmBridge implements RuntimeBridge {
93
92
  * for navigation and guard semantics); errors are caught and returned
94
93
  * as sentinels instead of crossing the isolate boundary.
95
94
  *
96
- * @param data - Current workflow data to use for callback responses
97
95
  * @private
98
96
  */
99
97
  private createGetArrayElementRef;
@@ -111,7 +109,6 @@ export declare class IsolatedVmBridge implements RuntimeBridge {
111
109
  * not isolated-vm objects (`Reference`/`ExternalCopy`) or other
112
110
  * non-cloneable values.
113
111
  *
114
- * @param data - Current workflow data
115
112
  * @private
116
113
  */
117
114
  private createCallHostRef;
@@ -1 +1 @@
1
- {"version":3,"file":"isolated-vm-bridge.d.ts","sourceRoot":"","sources":["../../../src/bridge/isolated-vm-bridge.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AA8G1F;;;;;;;;;;GAUG;AACH,qBAAa,gBAAiB,YAAW,aAAa;IACrD,OAAO,CAAC,OAAO,CAAc;IAC7B,OAAO,CAAC,OAAO,CAAC,CAAc;IAC9B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,MAAM,CAAyB;IACvC,OAAO,CAAC,MAAM,CAAmC;IAEjD,YAAY,MAAM,GAAE,YAAiB,EAUpC;IAED;;;;;;;;;;OAUG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAyBhC;IAED;;;;;;;;;;;OAWG;YACW,mBAAmB;IA8BjC;;;;;;;;;;;;;;;;;;;;;;OAsBG;YACW,kBAAkB;IAUhC;;;;;;OAMG;IACH,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AAO,CAAC,wBAAwB;IAUhC;;;;;;;;;;;;;;;OAeG;IACH,OAAO,CAAC,iBAAiB;IAUzB;;;;;;;;;;;;;;;;;;;OAmBG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAkH3E;IAED;;;OAGG;IACH,OAAO,CAAC,YAAY;IASpB;;;;OAIG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAc7B;IAED;;;;OAIG;IACH,UAAU,IAAI,OAAO,CAEpB;CACD"}
@@ -121,6 +121,11 @@ function loadRuntimeBundle() {
121
121
  }
122
122
  throw new Error(`Could not find runtime bundle (${BUNDLE_RELATIVE_PATH}) in any parent of ${__dirname}`);
123
123
  }
124
+ function heldData(holder) {
125
+ if (!holder.data)
126
+ throw new Error('Host callback called after its expression finished');
127
+ return holder.data;
128
+ }
124
129
  /**
125
130
  * IsolatedVmBridge - Runtime bridge using isolated-vm for secure expression evaluation.
126
131
  *
@@ -290,13 +295,12 @@ class IsolatedVmBridge {
290
295
  * for navigation and guard semantics); errors are caught and returned
291
296
  * as sentinels instead of crossing the isolate boundary.
292
297
  *
293
- * @param data - Current workflow data to use for callback responses
294
298
  * @private
295
299
  */
296
- createGetValueAtPathRef(data) {
300
+ createGetValueAtPathRef(holder) {
297
301
  return new (getIvm().Callback)((pathArr) => {
298
302
  try {
299
- return (0, host_functions_1.getValueAtPath)(data, pathArr);
303
+ return (0, host_functions_1.getValueAtPath)(heldData(holder), pathArr);
300
304
  }
301
305
  catch (err) {
302
306
  return (0, host_functions_1.serializeError)(err);
@@ -310,13 +314,12 @@ class IsolatedVmBridge {
310
314
  * for navigation and guard semantics); errors are caught and returned
311
315
  * as sentinels instead of crossing the isolate boundary.
312
316
  *
313
- * @param data - Current workflow data to use for callback responses
314
317
  * @private
315
318
  */
316
- createGetArrayElementRef(data) {
319
+ createGetArrayElementRef(holder) {
317
320
  return new (getIvm().Callback)((pathArr, index) => {
318
321
  try {
319
- return (0, host_functions_1.getArrayElement)(data, pathArr, index);
322
+ return (0, host_functions_1.getArrayElement)(heldData(holder), pathArr, index);
320
323
  }
321
324
  catch (err) {
322
325
  return (0, host_functions_1.serializeError)(err);
@@ -337,13 +340,12 @@ class IsolatedVmBridge {
337
340
  * not isolated-vm objects (`Reference`/`ExternalCopy`) or other
338
341
  * non-cloneable values.
339
342
  *
340
- * @param data - Current workflow data
341
343
  * @private
342
344
  */
343
- createCallHostRef(data) {
345
+ createCallHostRef(holder) {
344
346
  return new (getIvm().Callback)((rawMsg) => {
345
347
  try {
346
- return (0, host_functions_1.dispatchHostCall)(rawMsg, data);
348
+ return (0, host_functions_1.dispatchHostCall)(rawMsg, heldData(holder));
347
349
  }
348
350
  catch (err) {
349
351
  return (0, host_functions_1.serializeError)(err);
@@ -393,11 +395,13 @@ class IsolatedVmBridge {
393
395
  }
394
396
  // Host callbacks are ivm.Callback instances: inside the isolate they
395
397
  // arrive as plain functions with structured-clone marshaling, so the
396
- // runtime invokes them directly. Callbacks are GC-managed; there is no
397
- // release() to call in `finally`.
398
- const getValueAtPath = this.createGetValueAtPathRef(data);
399
- const getArrayElement = this.createGetArrayElementRef(data);
400
- const callHost = this.createCallHostRef(data);
398
+ // runtime invokes them directly. isolated-vm frees a callback only at the
399
+ // next isolated-vm call in the process, even after the isolate is disposed.
400
+ // So the callbacks read the data from a holder that `finally` clears.
401
+ const holder = { data };
402
+ const getValueAtPath = this.createGetValueAtPathRef(holder);
403
+ const getArrayElement = this.createGetArrayElementRef(holder);
404
+ const callHost = this.createCallHostRef(holder);
401
405
  try {
402
406
  const timezone = options?.timezone ? safeStringify(options.timezone) : 'undefined';
403
407
  // Wrap transformed code so 'this' === the closure-scoped context.
@@ -465,6 +469,9 @@ try {
465
469
  }
466
470
  throw new Error(`Expression evaluation failed: ${errorMessage}`);
467
471
  }
472
+ finally {
473
+ holder.data = undefined;
474
+ }
468
475
  }
469
476
  /**
470
477
  * Always names the configured limit, never the reduced budget a nested call
@@ -1 +1 @@
1
- {"version":3,"file":"isolated-vm-bridge.js","sourceRoot":"","sources":["../../../src/bridge/isolated-vm-bridge.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,qCAAuC;AACvC,MAAY,IAAI,sCAAkB;AAElC,oCAAiF;AAEjF,8DAA8D;AAC9D,qDAO0B;AAM1B,IAAI,IAAI,GAAsB,IAAI,CAAC;AACnC,2EAA2E;AAC3E,IAAI,cAAc,GAAkB,IAAI,CAAC;AAEzC,SAAS,MAAM;IACd,IAAI,CAAC,IAAI,EAAE,CAAC;QACX,iEAAiE;QACjE,IAAI,GAAG,OAAO,CAAC,aAAa,CAAe,CAAC;IAC7C,CAAC;IACD,OAAO,IAAI,CAAC;AACb,CAAC;AAED,MAAM,oBAAoB,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE,iBAAiB,CAAC,CAAC;AAE5E,6EAA6E;AAC7E,wCAAwC;AACxC,MAAM,aAAa,GAAG,IAAI,CAAC,SAAS,CAAC;AAErC,2EAA2E;AAC3E,qEAAqE;AACrE,qEAAqE;AACrE,IAAI,iBAAiB,GAAyC,IAAI,CAAC;AAEnE,2EAA2E;AAC3E,wEAAwE;AACxE,SAAS,kBAAkB,CAAC,MAAkB;IAC7C,MAAM,IAAI,GAAY,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACxD,OAAO,IAAI,YAAY,MAAM,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;AAC5D,CAAC;AAED,gFAAgF;AAChF,MAAM,eAAe,GAAG;IACvB,UAAU;IACV,QAAQ;IACR,qBAAqB;IACrB,YAAY;IACZ,WAAW;IACX,cAAc;CACd,CAAC;AAEF,4FAA4F;AAC5F,MAAM,8BAA8B,GAAG,kBAAkB,IAAI,CAAC,SAAS,CAAC,eAAe,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AAE,CAAC,CAAC;QAClE,CAAC;gBAAS,CAAC;YACV,MAAM,CAAC,IAAI,GAAG,SAAS,CAAC;QACzB,CAAC;IACF,CAAC;IAED;;;OAGG;IACK,YAAY,CAAC,MAAe;QACnC,OAAO,IAAI,oBAAY,CACtB,MAAM;YACL,CAAC,CAAC,kDAAkD,IAAI,CAAC,MAAM,CAAC,OAAO,UAAU;YACjF,CAAC,CAAC,8BAA8B,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,EACxD,EAAE,CACF,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,OAAO;QACZ,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnB,OAAO;QACR,CAAC;QAED,sEAAsE;QACtE,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC;YAC9B,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;QACxB,CAAC;QAED,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;QAEzB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,6BAA6B,CAAC,CAAC;IAClD,CAAC;IAED;;;;OAIG;IACH,UAAU;QACT,OAAO,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC;IACjD,CAAC;CACD"}
@@ -14,10 +14,21 @@ import type { RuntimeBridge, BridgeConfig, ExecuteOptions, WorkflowData } from '
14
14
  * the host callback functions directly.
15
15
  */
16
16
  export declare class QuickJsBridge implements RuntimeBridge {
17
+ private wasm;
17
18
  private runtime;
18
19
  private vm;
19
20
  private initialized;
20
21
  private disposed;
22
+ /**
23
+ * Set when a host error escapes a call into the runtime, for example V8
24
+ * running out of native stack in deep recursion. QuickJS reports its own
25
+ * errors as results, so an escaped error means that the unwind skipped
26
+ * QuickJS cleanup. The runtime is not used again, and execute() builds a new
27
+ * one on a new module.
28
+ */
29
+ private broken;
30
+ /** The bundle that the runtime loaded. A rebuild loads it again. */
31
+ private runtimeBundle;
21
32
  private config;
22
33
  private logger;
23
34
  private intlHandles;
@@ -103,6 +114,28 @@ export declare class QuickJsBridge implements RuntimeBridge {
103
114
  * 4. Reconstruct error sentinels into real Errors
104
115
  */
105
116
  execute(code: string, data: WorkflowData, options?: ExecuteOptions): unknown;
117
+ /**
118
+ * Run the wrapped code and give back its outcome as host values. QuickJS
119
+ * reports guest errors as results, so a throw from here is a host error.
120
+ */
121
+ private runInGuest;
122
+ /**
123
+ * Build a new runtime in place of a broken one, so that the caller that holds
124
+ * this bridge can go on. The runtime goes on the current module, which is
125
+ * never the retired one.
126
+ */
127
+ private rebuildRuntime;
128
+ /**
129
+ * Free the runtime of a failed rebuild. It ran no guest call, so it can
130
+ * usually be freed. If the free aborts, the module is unusable.
131
+ */
132
+ private discardFailedRuntime;
133
+ /**
134
+ * Drop a broken runtime without freeing it. JS_FreeRuntime asserts that no
135
+ * objects are left, and the unwind left some, so a free aborts the module.
136
+ * The memory is released when the module is garbage collected.
137
+ */
138
+ private abandonRuntime;
106
139
  /**
107
140
  * Always names the configured limit, never the reduced budget a nested call
108
141
  * ran on — reporting "timed out after 137ms" would misstate the limit.
@@ -1 +1 @@
1
- {"version":3,"file":"quickjs-bridge.d.ts","sourceRoot":"","sources":["../../../src/bridge/quickjs-bridge.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAyb1F;;;;;;;;;;;;;GAaG;AACH,qBAAa,aAAc,YAAW,aAAa;IAClD,OAAO,CAAC,OAAO,CAA0D;IACzE,OAAO,CAAC,EAAE,CAA0D;IACpE,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,MAAM,CAAyB;IACvC,OAAO,CAAC,MAAM,CAAmC;IAGjD,OAAO,CAAC,WAAW,CAAyD;IAM5E,OAA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AEpB;CACD"}
@@ -43,11 +43,13 @@ const transfer_1 = require("../runtime/transfer");
43
43
  const host_functions_1 = require("./host-functions");
44
44
  let _quickjs = null;
45
45
  /**
46
- * The instantiated WASM module, cached after the first async initialize().
47
- * Creating runtimes/contexts from it is synchronous, so once it is cached
48
- * (pool warmup does this) initializeSync() can build a bridge on demand.
46
+ * The instantiated WASM module that new bridges use, cached after the first
47
+ * async initialize(). Creating runtimes/contexts from it is synchronous, so
48
+ * once it is cached (pool warmup does this) initializeSync() can build a
49
+ * bridge on demand. retireQuickJSWasm() replaces it.
49
50
  */
50
51
  let _quickjsWasm = null;
52
+ let _quickjsWasmLoading = null;
51
53
  /** Runtime bundle source, read once per process by loadRuntimeBundle(). */
52
54
  let _runtimeBundle = null;
53
55
  async function getQuickJSModule() {
@@ -56,6 +58,40 @@ async function getQuickJSModule() {
56
58
  }
57
59
  return _quickjs;
58
60
  }
61
+ /**
62
+ * Our own module instance, not the library's getQuickJS() singleton: that one
63
+ * cannot be replaced after it is retired.
64
+ */
65
+ async function loadQuickJSWasm() {
66
+ if (_quickjsWasm)
67
+ return _quickjsWasm;
68
+ _quickjsWasmLoading ??= getQuickJSModule()
69
+ .then(async ({ newQuickJSWASMModule }) => await newQuickJSWASMModule())
70
+ .then((wasm) => {
71
+ _quickjsWasm = wasm;
72
+ return wasm;
73
+ })
74
+ .finally(() => {
75
+ _quickjsWasmLoading = null;
76
+ });
77
+ return await _quickjsWasmLoading;
78
+ }
79
+ /**
80
+ * Stop building runtimes on a module that a host error unwound through. The
81
+ * unwind skips the code that restores the module's stack pointer, and all
82
+ * runtimes in the module share that stack. Runtimes that already exist keep
83
+ * their stack limit, but a new one would take its limit from the lowered
84
+ * pointer and could write past the end of the stack.
85
+ */
86
+ function retireQuickJSWasm(wasm, logger) {
87
+ if (_quickjsWasm !== wasm)
88
+ return;
89
+ _quickjsWasm = null;
90
+ // Load the replacement now, so that the next initializeSync() finds it.
91
+ loadQuickJSWasm().catch((error) => {
92
+ logger.error('[QuickJsBridge] Failed to load a replacement WASM module', { error });
93
+ });
94
+ }
59
95
  // Joined by hand, not with `path.join`. This runs at module load, and a browser
60
96
  // build resolves `node:path` to an empty module, so `path.join` is undefined there.
61
97
  const BUNDLE_RELATIVE_PATH = ['dist', 'bundle', 'runtime.iife.js'].join('/');
@@ -411,10 +447,21 @@ const INTL_DISPATCH = {
411
447
  * the host callback functions directly.
412
448
  */
413
449
  class QuickJsBridge {
450
+ wasm;
414
451
  runtime;
415
452
  vm;
416
453
  initialized = false;
417
454
  disposed = false;
455
+ /**
456
+ * Set when a host error escapes a call into the runtime, for example V8
457
+ * running out of native stack in deep recursion. QuickJS reports its own
458
+ * errors as results, so an escaped error means that the unwind skipped
459
+ * QuickJS cleanup. The runtime is not used again, and execute() builds a new
460
+ * one on a new module.
461
+ */
462
+ broken = false;
463
+ /** The bundle that the runtime loaded. A rebuild loads it again. */
464
+ runtimeBundle;
418
465
  config;
419
466
  logger;
420
467
  // Long-lived host-callback handles (Intl polyfills) — disposed on dispose()
@@ -442,9 +489,7 @@ class QuickJsBridge {
442
489
  throw new Error('Bridge has been disposed and cannot be reinitialized.');
443
490
  if (this.initialized)
444
491
  return;
445
- const { getQuickJS } = await getQuickJSModule();
446
- const QuickJS = await getQuickJS();
447
- _quickjsWasm = QuickJS;
492
+ const QuickJS = await loadQuickJSWasm();
448
493
  // A host without a filesystem (the browser) passes the bundle in, so
449
494
  // loadRuntimeBundle() — the only Node-only code here — is never reached.
450
495
  const runtimeBundle = this.config.runtimeBundle || _runtimeBundle || loadRuntimeBundle();
@@ -466,15 +511,17 @@ class QuickJsBridge {
466
511
  return;
467
512
  // Both caches are populated by the same async initialize() (pool
468
513
  // warmup), so the sync path never touches the filesystem or the
469
- // event loop beyond the context setup itself.
514
+ // event loop beyond the context setup itself. The module is also empty
515
+ // while a replacement for a retired one loads.
470
516
  if (_quickjsWasm === null || _runtimeBundle === null) {
471
517
  throw new Error('QuickJS WASM module and runtime bundle are not loaded yet: an async initialize() ' +
472
- 'must run once (pool warmup) before bridges can be created synchronously');
518
+ 'must load them before bridges can be created synchronously');
473
519
  }
474
520
  this.setupContext(_quickjsWasm, _runtimeBundle);
475
521
  }
476
522
  /** Everything after module/bundle acquisition is synchronous and shared. */
477
523
  setupContext(QuickJS, runtimeBundle) {
524
+ this.wasm = QuickJS;
478
525
  // Create runtime with memory limit (MB → bytes)
479
526
  this.runtime = QuickJS.newRuntime();
480
527
  this.runtime.setMemoryLimit(this.config.memoryLimit * 1024 * 1024);
@@ -482,7 +529,8 @@ class QuickJsBridge {
482
529
  // Install the interrupt handler once. It reads the live deadline stack, so
483
530
  // nested execute() calls share one budget: the earliest deadline wins.
484
531
  // Math.min() of an empty stack is Infinity, so an idle runtime never fires.
485
- this.runtime.setInterruptHandler(() => Date.now() > Math.min(...this.deadlines));
532
+ // A broken runtime also stops the outer call that a nested call broke it in.
533
+ this.runtime.setInterruptHandler(() => (this.broken && this.deadlines.length > 0) || Date.now() > Math.min(...this.deadlines));
486
534
  // Set up 'global' / 'globalThis' self-reference
487
535
  const globalHandle = this.vm.global;
488
536
  this.vm.setProp(globalHandle, 'global', globalHandle);
@@ -491,12 +539,14 @@ class QuickJsBridge {
491
539
  this.injectIntlPolyfill();
492
540
  // Load runtime bundle (DateTime, extend, SafeObject, proxy system, buildContext)
493
541
  this.loadRuntimeBundle(runtimeBundle);
542
+ this.runtimeBundle = runtimeBundle;
494
543
  // Wrap __prepareForTransfer to mark Date/NaN/Map/Set/Error so they survive vm.dump()
495
544
  this.injectTransferWrapper();
496
545
  // Inject E() error handler matching IsolatedVmBridge's E() semantics
497
546
  this.injectErrorHandler();
498
547
  this.verifyProxySystem();
499
548
  this.initialized = true;
549
+ this.broken = false;
500
550
  this.logger.info('[QuickJsBridge] Initialized successfully');
501
551
  }
502
552
  /**
@@ -1025,7 +1075,8 @@ class QuickJsBridge {
1025
1075
  hostValueToQuickJSHandle(value) {
1026
1076
  if (!this.vm)
1027
1077
  throw new Error('Context not initialized');
1028
- if (value === undefined)
1078
+ // Building a value runs guest code, which a broken runtime must not do.
1079
+ if (value === undefined || this.broken)
1029
1080
  return this.vm.undefined;
1030
1081
  if (value === null)
1031
1082
  return this.vm.null;
@@ -1067,9 +1118,12 @@ class QuickJsBridge {
1067
1118
  * 4. Reconstruct error sentinels into real Errors
1068
1119
  */
1069
1120
  execute(code, data, options) {
1121
+ if (this.broken && !this.disposed)
1122
+ this.rebuildRuntime();
1070
1123
  if (!this.initialized || !this.vm || !this.runtime) {
1071
1124
  throw new Error('Bridge not initialized. Call initialize() first.');
1072
1125
  }
1126
+ const vm = this.vm;
1073
1127
  // A nested call runs on what is left of the configured timeout, so the
1074
1128
  // chain shares one budget (mirrors IsolatedVmBridge). A configured
1075
1129
  // timeout of 0 means "no limit", so there is nothing to share.
@@ -1082,7 +1136,6 @@ class QuickJsBridge {
1082
1136
  throw this.timeoutError(true);
1083
1137
  }
1084
1138
  const callbackHandles = this.createCallbackHandles(data);
1085
- let wrapperFn;
1086
1139
  // Push this call's deadline; the interrupt handler (set in initialize)
1087
1140
  // interrupts on the earliest in-flight deadline. Popped in finally so a
1088
1141
  // nested call can't leave the outer budget extended.
@@ -1121,17 +1174,19 @@ class QuickJsBridge {
1121
1174
  };
1122
1175
  }
1123
1176
  })`;
1124
- const wrapperResult = this.vm.evalCode(wrappedCode);
1125
- if (wrapperResult.error) {
1126
- const errDump = this.vm.dump(wrapperResult.error);
1127
- wrapperResult.error.dispose();
1128
- throw new Error(`Expression compilation failed: ${String(errDump)}`);
1177
+ let outcome;
1178
+ try {
1179
+ outcome = this.runInGuest(vm, wrappedCode, callbackHandles);
1180
+ }
1181
+ catch (error) {
1182
+ this.broken = true;
1183
+ throw error;
1129
1184
  }
1130
- wrapperFn = wrapperResult.value;
1131
- const execResult = this.vm.callFunction(wrapperFn, this.vm.undefined, ...callbackHandles);
1132
- if (execResult.error) {
1133
- const errDump = this.vm.dump(execResult.error);
1134
- execResult.error.dispose();
1185
+ if (outcome.kind === 'compileError') {
1186
+ throw new Error(`Expression compilation failed: ${String(outcome.dump)}`);
1187
+ }
1188
+ if (outcome.kind === 'error') {
1189
+ const errDump = outcome.dump;
1135
1190
  // buildContext throws on invalid timezone — propagate the original message
1136
1191
  const errStr = String(typeof errDump === 'object' && errDump !== null
1137
1192
  ? (errDump.message ?? errDump)
@@ -1146,9 +1201,7 @@ class QuickJsBridge {
1146
1201
  }
1147
1202
  throw new Error(`Expression evaluation failed: ${errStr}`);
1148
1203
  }
1149
- const rawResult = this.vm.dump(execResult.value);
1150
- execResult.value.dispose();
1151
- const result = unwrapSentinels(rawResult);
1204
+ const result = unwrapSentinels(outcome.dump);
1152
1205
  if ((0, host_functions_1.isErrorSentinel)(result)) {
1153
1206
  throw (0, host_functions_1.reconstructError)(result);
1154
1207
  }
@@ -1164,6 +1217,10 @@ class QuickJsBridge {
1164
1217
  throw error;
1165
1218
  }
1166
1219
  const errorMessage = error instanceof Error ? error.message : String(error);
1220
+ // A host error, for example a WASM trap, can name memory without the
1221
+ // guest reaching its memory limit.
1222
+ if (this.broken)
1223
+ throw new Error(`Expression evaluation failed: ${errorMessage}`);
1167
1224
  if (errorMessage.includes('interrupted')) {
1168
1225
  throw this.timeoutError(nested);
1169
1226
  }
@@ -1174,11 +1231,108 @@ class QuickJsBridge {
1174
1231
  }
1175
1232
  finally {
1176
1233
  this.deadlines.pop();
1177
- wrapperFn?.dispose();
1178
- for (const handle of callbackHandles) {
1179
- handle.dispose();
1234
+ if (!this.broken) {
1235
+ for (const handle of callbackHandles) {
1236
+ handle.dispose();
1237
+ }
1180
1238
  }
1239
+ else if (this.deadlines.length === 0) {
1240
+ // Only the outermost call drops the runtime. A nested call returns
1241
+ // into the frames of the outer call, which still use the runtime.
1242
+ this.abandonRuntime();
1243
+ }
1244
+ }
1245
+ }
1246
+ /**
1247
+ * Run the wrapped code and give back its outcome as host values. QuickJS
1248
+ * reports guest errors as results, so a throw from here is a host error.
1249
+ */
1250
+ runInGuest(vm, wrappedCode, callbackHandles) {
1251
+ const wrapperResult = vm.evalCode(wrappedCode);
1252
+ if (wrapperResult.error) {
1253
+ const dump = vm.dump(wrapperResult.error);
1254
+ wrapperResult.error.dispose();
1255
+ return { kind: 'compileError', dump };
1256
+ }
1257
+ const wrapperFn = wrapperResult.value;
1258
+ const execResult = vm.callFunction(wrapperFn, vm.undefined, ...callbackHandles);
1259
+ // A nested execute() that broke the runtime returned into this call.
1260
+ if (this.broken)
1261
+ throw new Error('A nested expression stopped the expression engine');
1262
+ wrapperFn.dispose();
1263
+ if (execResult.error) {
1264
+ const dump = vm.dump(execResult.error);
1265
+ execResult.error.dispose();
1266
+ return { kind: 'error', dump };
1181
1267
  }
1268
+ const dump = vm.dump(execResult.value);
1269
+ execResult.value.dispose();
1270
+ return { kind: 'value', dump };
1271
+ }
1272
+ /**
1273
+ * Build a new runtime in place of a broken one, so that the caller that holds
1274
+ * this bridge can go on. The runtime goes on the current module, which is
1275
+ * never the retired one.
1276
+ */
1277
+ rebuildRuntime() {
1278
+ // A nested call must not enter a runtime that an inner call has broken.
1279
+ if (this.vm || _quickjsWasm === null) {
1280
+ // Retries a failed load. A load that is in progress is reused.
1281
+ loadQuickJSWasm().catch((error) => {
1282
+ this.logger.error('[QuickJsBridge] Failed to load a replacement WASM module', { error });
1283
+ });
1284
+ throw new Error('Expression evaluation failed: the expression engine is restarting after an earlier error. Try again.');
1285
+ }
1286
+ if (this.runtimeBundle === undefined) {
1287
+ throw new Error('Bridge not initialized. Call initialize() first.');
1288
+ }
1289
+ // The process-wide bundle cache holds the bundle of the bridge that
1290
+ // initialized last, which can differ from the bundle of this bridge.
1291
+ try {
1292
+ this.setupContext(_quickjsWasm, this.runtimeBundle);
1293
+ }
1294
+ catch (error) {
1295
+ // Clears this.vm, so the next execute() tries the rebuild again.
1296
+ this.discardFailedRuntime();
1297
+ throw error;
1298
+ }
1299
+ }
1300
+ /**
1301
+ * Free the runtime of a failed rebuild. It ran no guest call, so it can
1302
+ * usually be freed. If the free aborts, the module is unusable.
1303
+ */
1304
+ discardFailedRuntime() {
1305
+ try {
1306
+ for (const handle of this.intlHandles)
1307
+ handle.dispose();
1308
+ this.vm?.dispose();
1309
+ this.runtime?.dispose();
1310
+ }
1311
+ catch {
1312
+ if (this.wasm)
1313
+ retireQuickJSWasm(this.wasm, this.logger);
1314
+ }
1315
+ finally {
1316
+ this.intlHandles = [];
1317
+ this.vm = undefined;
1318
+ this.runtime = undefined;
1319
+ this.wasm = undefined;
1320
+ }
1321
+ }
1322
+ /**
1323
+ * Drop a broken runtime without freeing it. JS_FreeRuntime asserts that no
1324
+ * objects are left, and the unwind left some, so a free aborts the module.
1325
+ * The memory is released when the module is garbage collected.
1326
+ */
1327
+ abandonRuntime() {
1328
+ if (this.wasm)
1329
+ retireQuickJSWasm(this.wasm, this.logger);
1330
+ this.wasm = undefined;
1331
+ this.vm = undefined;
1332
+ this.runtime = undefined;
1333
+ this.intlHandles = [];
1334
+ this.initialized = false;
1335
+ this.logger.warn('[QuickJsBridge] Discarded the runtime after a host error in a guest call');
1182
1336
  }
1183
1337
  /**
1184
1338
  * Always names the configured limit, never the reduced budget a nested call
@@ -1205,6 +1359,8 @@ class QuickJsBridge {
1205
1359
  async dispose() {
1206
1360
  if (this.disposed)
1207
1361
  return;
1362
+ if (this.broken && this.vm)
1363
+ this.abandonRuntime();
1208
1364
  for (const handle of this.intlHandles) {
1209
1365
  handle.dispose();
1210
1366
  }