@php-wasm/universal 3.0.4 → 3.0.6

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/index.js CHANGED
@@ -1,8 +1,8 @@
1
- var B = (t) => {
1
+ var z = (t) => {
2
2
  throw TypeError(t);
3
3
  };
4
- var O = (t, e, r) => e.has(t) || B("Cannot " + r);
5
- var u = (t, e, r) => (O(t, e, "read from private field"), r ? r.call(t) : e.get(t)), m = (t, e, r) => e.has(t) ? B("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, r), w = (t, e, r, s) => (O(t, e, "write to private field"), s ? s.call(t, r) : e.set(t, r), r), y = (t, e, r) => (O(t, e, "access private method"), r);
4
+ var O = (t, e, r) => e.has(t) || z("Cannot " + r);
5
+ var u = (t, e, r) => (O(t, e, "read from private field"), r ? r.call(t) : e.get(t)), m = (t, e, r) => e.has(t) ? z("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, r), g = (t, e, r, s) => (O(t, e, "write to private field"), s ? s.call(t, r) : e.set(t, r), r), y = (t, e, r) => (O(t, e, "access private method"), r);
6
6
  import "@php-wasm/node-polyfills";
7
7
  import { logger } from "@php-wasm/logger";
8
8
  import { dirname, joinPaths, Semaphore, createSpawnHandler, normalizePath, AcquireTimeoutError } from "@php-wasm/util";
@@ -368,7 +368,7 @@ class PHPWorker {
368
368
  /** @inheritDoc */
369
369
  constructor(e, r) {
370
370
  m(this, P);
371
- this.absoluteUrl = "", this.documentRoot = "", w(this, P, /* @__PURE__ */ new Map()), this.onMessageListeners = [], _private.set(this, {
371
+ this.absoluteUrl = "", this.documentRoot = "", g(this, P, /* @__PURE__ */ new Map()), this.onMessageListeners = [], _private.set(this, {
372
372
  monitor: r
373
373
  }), e && this.__internal_setRequestHandler(e);
374
374
  }
@@ -937,7 +937,7 @@ class PHPExecutionFailureError extends Error {
937
937
  }
938
938
  }
939
939
  const PHP_INI_PATH = "/internal/shared/php.ini", AUTO_PREPEND_SCRIPT = "/internal/shared/auto_prepend_file.php", OPCACHE_FILE_FOLDER = "/internal/shared/opcache";
940
- var C, b, T, E, F, M, _, h, z, $, V, G, J, Y, K, X, U, Q, j, q;
940
+ var C, b, T, E, F, M, _, h, B, $, V, G, J, Y, K, X, U, Q, j, q;
941
941
  class PHP {
942
942
  /**
943
943
  * Initializes a PHP runtime.
@@ -1035,7 +1035,7 @@ class PHP {
1035
1035
  */
1036
1036
  onMessage(t) {
1037
1037
  return u(this, F).push(t), async () => {
1038
- w(this, F, u(this, F).filter(
1038
+ g(this, F, u(this, F).filter(
1039
1039
  (e) => e !== t
1040
1040
  ));
1041
1041
  };
@@ -1135,7 +1135,7 @@ class PHP {
1135
1135
  return n;
1136
1136
  }
1137
1137
  return "";
1138
- }, w(this, T, improveWASMErrorReporting(e)), this.dispatchEvent({
1138
+ }, g(this, T, improveWASMErrorReporting(e)), this.dispatchEvent({
1139
1139
  type: "runtime.initialized"
1140
1140
  });
1141
1141
  }
@@ -1150,7 +1150,7 @@ class PHP {
1150
1150
  throw new Error(
1151
1151
  "Could not set SAPI name. This can only be done before the PHP WASM module is initialized.Did you already dispatch any requests?"
1152
1152
  );
1153
- w(this, C, t);
1153
+ g(this, C, t);
1154
1154
  }
1155
1155
  /**
1156
1156
  * Changes the current working directory in the PHP filesystem.
@@ -1375,7 +1375,7 @@ class PHP {
1375
1375
  {
1376
1376
  isAsync: !0
1377
1377
  }
1378
- ), w(this, b, !0)), t.scriptPath && !this.fileExists(t.scriptPath))
1378
+ ), g(this, b, !0)), t.scriptPath && !this.fileExists(t.scriptPath))
1379
1379
  throw new Error(
1380
1380
  `The script path "${t.scriptPath}" does not exist.`
1381
1381
  );
@@ -1389,12 +1389,12 @@ class PHP {
1389
1389
  throw new TypeError(
1390
1390
  "The request object must have either a `code` or a `scriptPath` property."
1391
1391
  );
1392
- const c = y(this, h, z).call(this, t.$_SERVER, i, a);
1393
- for (const p in c)
1394
- y(this, h, Q).call(this, p, c[p]);
1392
+ const c = y(this, h, B).call(this, t.$_SERVER, i, a);
1393
+ for (const d in c)
1394
+ y(this, h, Q).call(this, d, c[d]);
1395
1395
  const l = t.env || {};
1396
- for (const p in l)
1397
- y(this, h, j).call(this, p, l[p]);
1396
+ for (const d in l)
1397
+ y(this, h, j).call(this, d, l[d]);
1398
1398
  return await this[__private__dont__use].ccall(
1399
1399
  "wasm_sapi_handle_request",
1400
1400
  NUMBER,
@@ -1600,7 +1600,7 @@ class PHP {
1600
1600
  * or an internal crash.
1601
1601
  */
1602
1602
  enableRuntimeRotation(t) {
1603
- w(this, _, {
1603
+ g(this, _, {
1604
1604
  ...u(this, _),
1605
1605
  enabled: !0,
1606
1606
  recreateRuntime: t.recreateRuntime,
@@ -1711,7 +1711,7 @@ class PHP {
1711
1711
  this[__private__dont__use]._exit(t);
1712
1712
  } catch {
1713
1713
  }
1714
- w(this, b, !1), w(this, T, null), this[__private__dont__use] && (delete this[__private__dont__use].onMessage, delete this[__private__dont__use]);
1714
+ g(this, b, !1), g(this, T, null), this[__private__dont__use] && (delete this[__private__dont__use].onMessage, delete this[__private__dont__use]);
1715
1715
  }
1716
1716
  [Symbol.dispose]() {
1717
1717
  this.exit(0);
@@ -1726,7 +1726,7 @@ C = new WeakMap(), b = new WeakMap(), T = new WeakMap(), E = new WeakMap(), F =
1726
1726
  * was provided.
1727
1727
  * @returns Computed $_SERVER entries.
1728
1728
  */
1729
- z = function(t, e, r) {
1729
+ B = function(t, e, r) {
1730
1730
  const s = {
1731
1731
  ...t || {}
1732
1732
  };
@@ -1842,27 +1842,27 @@ z = function(t, e, r) {
1842
1842
  }, q = async function(t) {
1843
1843
  u(this, _).enabled && u(this, _).needsRotating && await this.rotateRuntime(), ++u(this, _).requestsMade, u(this, _).requestsMade >= u(this, _).maxRequests && (u(this, _).needsRotating = !0);
1844
1844
  const e = this[__private__dont__use], r = await createInvertedReadableStream();
1845
- e.onHeaders = (d) => {
1846
- a || s || r.controller.enqueue(d.slice());
1845
+ e.onHeaders = (p) => {
1846
+ a || s || r.controller.enqueue(p.slice());
1847
1847
  };
1848
1848
  let s = !1;
1849
1849
  const n = () => {
1850
1850
  s || (s = !0, r.controller.close());
1851
1851
  }, i = await createInvertedReadableStream();
1852
- e.onStdout = (d) => {
1853
- n(), !a && i.controller.enqueue(d.slice());
1852
+ e.onStdout = (p) => {
1853
+ n(), !a && i.controller.enqueue(p.slice());
1854
1854
  };
1855
1855
  const o = await createInvertedReadableStream();
1856
- e.onStderr = (d) => {
1857
- a || o.controller.enqueue(d.slice());
1856
+ e.onStderr = (p) => {
1857
+ a || o.controller.enqueue(p.slice());
1858
1858
  };
1859
1859
  let a = !1, c;
1860
- const p = (async () => {
1861
- var d;
1860
+ const d = (async () => {
1861
+ var p;
1862
1862
  try {
1863
1863
  return await Promise.race([
1864
1864
  t(),
1865
- new Promise((g, H) => {
1865
+ new Promise((w, H) => {
1866
1866
  var D;
1867
1867
  c = (W) => {
1868
1868
  isExitCode(W.error) || H(W.error);
@@ -1877,42 +1877,42 @@ z = function(t, e, r) {
1877
1877
  if (isExitCode(f))
1878
1878
  return f.status;
1879
1879
  i.controller.error(f), o.controller.error(f), r.controller.error(f), a = !0;
1880
- for (const g in this)
1881
- typeof this[g] == "function" && (this[g] = () => {
1880
+ for (const w in this)
1881
+ typeof this[w] == "function" && (this[w] = () => {
1882
1882
  throw new Error(
1883
1883
  "PHP runtime has crashed – see the earlier error for details."
1884
1884
  );
1885
1885
  });
1886
1886
  throw this.functionsMaybeMissingFromAsyncify = getFunctionsMaybeMissingFromAsyncify(), f;
1887
1887
  } finally {
1888
- a || (i.controller.close(), o.controller.close(), n(), a = !0), (d = u(this, T)) == null || d.removeEventListener(
1888
+ a || (i.controller.close(), o.controller.close(), n(), a = !0), (p = u(this, T)) == null || p.removeEventListener(
1889
1889
  "error",
1890
1890
  c
1891
1891
  );
1892
1892
  }
1893
1893
  })().then(
1894
- (d) => (d !== 0 && this.dispatchEvent({
1894
+ (p) => (p !== 0 && this.dispatchEvent({
1895
1895
  type: "request.error",
1896
1896
  error: new Error(
1897
- `PHP.run() failed with exit code ${d}.`
1897
+ `PHP.run() failed with exit code ${p}.`
1898
1898
  ),
1899
1899
  // Distinguish between PHP request and PHP-wasm errors
1900
1900
  source: "php-wasm"
1901
- }), d),
1902
- (d) => {
1903
- const f = d.source ?? "php-wasm";
1901
+ }), p),
1902
+ (p) => {
1903
+ const f = p.source ?? "php-wasm";
1904
1904
  throw this.dispatchEvent({
1905
1905
  type: "request.error",
1906
- error: d,
1906
+ error: p,
1907
1907
  source: f
1908
- }), d;
1908
+ }), p;
1909
1909
  }
1910
1910
  );
1911
1911
  return new StreamedPHPResponse(
1912
1912
  r.stream,
1913
1913
  i.stream,
1914
1914
  o.stream,
1915
- p
1915
+ d
1916
1916
  );
1917
1917
  };
1918
1918
  function normalizeHeaders(t) {
@@ -2407,14 +2407,14 @@ class PHPRequestHandler {
2407
2407
  return l.isDir(r) || l.mkdir(r), l.chdir(r), l.requestHandler = this, l;
2408
2408
  },
2409
2409
  maxPhpInstances: e.maxPhpInstances
2410
- }), w(this, v, e.cookieStore === void 0 ? new HttpCookieStore() : e.cookieStore), w(this, S, r);
2410
+ }), g(this, v, e.cookieStore === void 0 ? new HttpCookieStore() : e.cookieStore), g(this, S, r);
2411
2411
  const o = new URL(s);
2412
- w(this, L, o.hostname), w(this, k, o.port ? Number(o.port) : o.protocol === "https:" ? 443 : 80), w(this, I, (o.protocol || "").replace(":", ""));
2412
+ g(this, L, o.hostname), g(this, k, o.port ? Number(o.port) : o.protocol === "https:" ? 443 : 80), g(this, I, (o.protocol || "").replace(":", ""));
2413
2413
  const a = u(this, k) !== 443 && u(this, k) !== 80;
2414
- w(this, A, [
2414
+ g(this, A, [
2415
2415
  u(this, L),
2416
2416
  a ? `:${u(this, k)}` : ""
2417
- ].join("")), w(this, x, o.pathname.replace(/\/+$/, "")), w(this, N, [
2417
+ ].join("")), g(this, x, o.pathname.replace(/\/+$/, "")), g(this, N, [
2418
2418
  `${u(this, I)}://`,
2419
2419
  u(this, A),
2420
2420
  u(this, x)
@@ -2838,10 +2838,10 @@ class NodeSABSyncReceiveMessageTransport {
2838
2838
  ), Atomics.wait(i, 0, 0, 5e3) === "timed-out")
2839
2839
  throw new Error("Timeout waiting for response");
2840
2840
  for (; ; ) {
2841
- const p = NodeSABSyncReceiveMessageTransport.receiveMessageOnPort(e);
2842
- if (((l = p.message) == null ? void 0 : l.id) === o)
2843
- return p.message;
2844
- if (!p)
2841
+ const d = NodeSABSyncReceiveMessageTransport.receiveMessageOnPort(e);
2842
+ if (((l = d.message) == null ? void 0 : l.id) === o)
2843
+ return d.message;
2844
+ if (!d)
2845
2845
  throw new Error("No response received");
2846
2846
  }
2847
2847
  }
@@ -2919,51 +2919,51 @@ function expose(t, e = globalThis, r = ["*"], s) {
2919
2919
  path: [],
2920
2920
  ...i.data
2921
2921
  }, l = (i.data.argumentList || []).map(fromWireValue);
2922
- let p;
2922
+ let d;
2923
2923
  try {
2924
- const d = c.slice(0, -1).reduce((g, H) => g[H], t), f = c.reduce((g, H) => g[H], t);
2924
+ const p = c.slice(0, -1).reduce((w, H) => w[H], t), f = c.reduce((w, H) => w[H], t);
2925
2925
  switch (a) {
2926
2926
  case MessageType.GET:
2927
- p = f;
2927
+ d = f;
2928
2928
  break;
2929
2929
  case MessageType.SET:
2930
- d[c.slice(-1)[0]] = fromWireValue(
2930
+ p[c.slice(-1)[0]] = fromWireValue(
2931
2931
  i.data.value
2932
- ), p = !0;
2932
+ ), d = !0;
2933
2933
  break;
2934
2934
  case MessageType.APPLY:
2935
- p = f.apply(d, l);
2935
+ d = f.apply(p, l);
2936
2936
  break;
2937
2937
  case MessageType.CONSTRUCT:
2938
2938
  {
2939
- const g = new f(...l);
2940
- p = proxy(g);
2939
+ const w = new f(...l);
2940
+ d = proxy(w);
2941
2941
  }
2942
2942
  break;
2943
2943
  case MessageType.ENDPOINT:
2944
2944
  {
2945
- const { port1: g, port2: H } = new MessageChannel();
2946
- expose(t, H), p = transfer(g, [g]);
2945
+ const { port1: w, port2: H } = new MessageChannel();
2946
+ expose(t, H), d = transfer(w, [w]);
2947
2947
  }
2948
2948
  break;
2949
2949
  case MessageType.RELEASE:
2950
- p = void 0;
2950
+ d = void 0;
2951
2951
  break;
2952
2952
  default:
2953
2953
  return;
2954
2954
  }
2955
- } catch (d) {
2956
- p = { value: d, [throwMarker]: 0 };
2955
+ } catch (p) {
2956
+ d = { value: p, [throwMarker]: 0 };
2957
2957
  }
2958
- Promise.resolve(p).catch((d) => ({ value: d, [throwMarker]: 0 })).then((d) => {
2959
- const [f, g] = toWireValue(d);
2960
- e.postMessage({ ...f, id: o }, g), a === MessageType.RELEASE && (e.removeEventListener("message", n), closeEndPoint(e), finalizer in t && typeof t[finalizer] == "function" && t[finalizer]());
2958
+ Promise.resolve(d).catch((p) => ({ value: p, [throwMarker]: 0 })).then((p) => {
2959
+ const [f, w] = toWireValue(p);
2960
+ e.postMessage({ ...f, id: o }, w), a === MessageType.RELEASE && (e.removeEventListener("message", n), closeEndPoint(e), finalizer in t && typeof t[finalizer] == "function" && t[finalizer]());
2961
2961
  }).catch(() => {
2962
- const [d, f] = toWireValue({
2962
+ const [p, f] = toWireValue({
2963
2963
  value: new TypeError("Unserializable return value"),
2964
2964
  [throwMarker]: 0
2965
2965
  });
2966
- e.postMessage({ ...d, id: o }, f);
2966
+ e.postMessage({ ...p, id: o }, f);
2967
2967
  }).finally(() => {
2968
2968
  s == null || s(i);
2969
2969
  });
@@ -3034,16 +3034,16 @@ function createProxy(t, e, r = [], s = function() {
3034
3034
  },
3035
3035
  set(o, a, c) {
3036
3036
  throwIfProxyReleased(n);
3037
- const [l, p] = toWireValue(c);
3037
+ const [l, d] = toWireValue(c);
3038
3038
  return requestResponseMessage(
3039
3039
  t,
3040
3040
  e,
3041
3041
  {
3042
3042
  type: MessageType.SET,
3043
- path: [...r, a].map((d) => d.toString()),
3043
+ path: [...r, a].map((p) => p.toString()),
3044
3044
  value: l
3045
3045
  },
3046
- p
3046
+ d
3047
3047
  ).then(fromWireValue);
3048
3048
  },
3049
3049
  apply(o, a, c) {
@@ -3055,16 +3055,16 @@ function createProxy(t, e, r = [], s = function() {
3055
3055
  }).then(fromWireValue);
3056
3056
  if (l === "bind")
3057
3057
  return createProxy(t, e, r.slice(0, -1));
3058
- const [p, d] = processArguments(c);
3058
+ const [d, p] = processArguments(c);
3059
3059
  return requestResponseMessage(
3060
3060
  t,
3061
3061
  e,
3062
3062
  {
3063
3063
  type: MessageType.APPLY,
3064
3064
  path: r.map((f) => f.toString()),
3065
- argumentList: p
3065
+ argumentList: d
3066
3066
  },
3067
- d
3067
+ p
3068
3068
  ).then(fromWireValue);
3069
3069
  },
3070
3070
  construct(o, a) {
@@ -3075,7 +3075,7 @@ function createProxy(t, e, r = [], s = function() {
3075
3075
  e,
3076
3076
  {
3077
3077
  type: MessageType.CONSTRUCT,
3078
- path: r.map((p) => p.toString()),
3078
+ path: r.map((d) => d.toString()),
3079
3079
  argumentList: c
3080
3080
  },
3081
3081
  l
@@ -3246,19 +3246,19 @@ const errorProperties = [
3246
3246
  useToJSON: o,
3247
3247
  serialize: a
3248
3248
  });
3249
- for (const [l, p] of Object.entries(t)) {
3250
- if (p && p instanceof Uint8Array && p.constructor.name === "Buffer") {
3249
+ for (const [l, d] of Object.entries(t)) {
3250
+ if (d && d instanceof Uint8Array && d.constructor.name === "Buffer") {
3251
3251
  r[l] = "[object Buffer]";
3252
3252
  continue;
3253
3253
  }
3254
- if (p !== null && typeof p == "object" && typeof p.pipe == "function") {
3254
+ if (d !== null && typeof d == "object" && typeof d.pipe == "function") {
3255
3255
  r[l] = "[object Stream]";
3256
3256
  continue;
3257
3257
  }
3258
- if (typeof p != "function") {
3259
- if (!p || typeof p != "object") {
3258
+ if (typeof d != "function") {
3259
+ if (!d || typeof d != "object") {
3260
3260
  try {
3261
- r[l] = p;
3261
+ r[l] = d;
3262
3262
  } catch {
3263
3263
  }
3264
3264
  continue;
@@ -3271,10 +3271,10 @@ const errorProperties = [
3271
3271
  }
3272
3272
  }
3273
3273
  if (a || r instanceof Error)
3274
- for (const { property: l, enumerable: p } of errorProperties)
3274
+ for (const { property: l, enumerable: d } of errorProperties)
3275
3275
  t[l] !== void 0 && t[l] !== null && Object.defineProperty(r, l, {
3276
3276
  value: isErrorLike(t[l]) || Array.isArray(t[l]) ? c(t[l]) : t[l],
3277
- enumerable: s ? !0 : p,
3277
+ enumerable: s ? !0 : d,
3278
3278
  configurable: !0,
3279
3279
  writable: !0
3280
3280
  });
@@ -3403,7 +3403,198 @@ function setupTransferHandlers() {
3403
3403
  t.serialize = ({ value: r }) => {
3404
3404
  const s = e({ value: r });
3405
3405
  return r.response && (s[0].value.response = r.response), r.source && (s[0].value.source = r.source), s;
3406
- };
3406
+ }, transferHandlers.set("StreamedPHPResponse", {
3407
+ canHandle: (r) => r instanceof StreamedPHPResponse,
3408
+ serialize(r) {
3409
+ const s = supportsTransferableStreams(), n = promiseToPort(r.exitCode);
3410
+ if (s)
3411
+ return [{
3412
+ __type: "StreamedPHPResponse",
3413
+ headers: r.headersStream,
3414
+ stdout: r.stdout,
3415
+ stderr: r.stderr,
3416
+ exitCodePort: n
3417
+ }, [n]];
3418
+ const i = streamToPort(r.headersStream), o = streamToPort(r.stdout), a = streamToPort(r.stderr);
3419
+ return [
3420
+ {
3421
+ __type: "StreamedPHPResponse",
3422
+ headersPort: i,
3423
+ stdoutPort: o,
3424
+ stderrPort: a,
3425
+ exitCodePort: n
3426
+ },
3427
+ [i, o, a, n]
3428
+ ];
3429
+ },
3430
+ deserialize(r) {
3431
+ if (r.headers && r.stdout && r.stderr) {
3432
+ const a = portToPromise(
3433
+ r.exitCodePort
3434
+ );
3435
+ return new StreamedPHPResponse(
3436
+ r.headers,
3437
+ r.stdout,
3438
+ r.stderr,
3439
+ a
3440
+ );
3441
+ }
3442
+ const s = portToStream(r.headersPort), n = portToStream(r.stdoutPort), i = portToStream(r.stderrPort), o = portToPromise(r.exitCodePort);
3443
+ return new StreamedPHPResponse(s, n, i, o);
3444
+ }
3445
+ });
3446
+ }
3447
+ function supportsTransferableStreams() {
3448
+ try {
3449
+ if (typeof ReadableStream > "u") return !1;
3450
+ const { port1: t } = new MessageChannel(), e = new ReadableStream();
3451
+ t.postMessage(e);
3452
+ try {
3453
+ t.close();
3454
+ } catch {
3455
+ }
3456
+ return !0;
3457
+ } catch {
3458
+ return !1;
3459
+ }
3460
+ }
3461
+ function streamToPort(t) {
3462
+ const { port1: e, port2: r } = new MessageChannel();
3463
+ return (async () => {
3464
+ const s = t.getReader();
3465
+ try {
3466
+ for (; ; ) {
3467
+ const { done: n, value: i } = await s.read();
3468
+ if (n) {
3469
+ try {
3470
+ e.postMessage({ t: "close" });
3471
+ } catch {
3472
+ }
3473
+ try {
3474
+ e.close();
3475
+ } catch {
3476
+ }
3477
+ break;
3478
+ }
3479
+ if (i) {
3480
+ const o = i.byteOffset === 0 && i.byteLength === i.buffer.byteLength ? i : i.slice(), a = o.buffer;
3481
+ try {
3482
+ e.postMessage({ t: "chunk", b: a }, [
3483
+ a
3484
+ ]);
3485
+ } catch {
3486
+ e.postMessage({
3487
+ t: "chunk",
3488
+ b: o.buffer.slice(0)
3489
+ });
3490
+ }
3491
+ }
3492
+ }
3493
+ } catch (n) {
3494
+ try {
3495
+ e.postMessage({ t: "error", m: (n == null ? void 0 : n.message) || String(n) });
3496
+ } catch {
3497
+ }
3498
+ } finally {
3499
+ try {
3500
+ e.close();
3501
+ } catch {
3502
+ }
3503
+ }
3504
+ })(), r;
3505
+ }
3506
+ function portToStream(t) {
3507
+ return new ReadableStream({
3508
+ start(e) {
3509
+ const r = (n) => {
3510
+ const i = n.data;
3511
+ if (i)
3512
+ switch (i.t) {
3513
+ case "chunk":
3514
+ e.enqueue(new Uint8Array(i.b));
3515
+ break;
3516
+ case "close":
3517
+ e.close(), s();
3518
+ break;
3519
+ case "error":
3520
+ e.error(new Error(i.m || "Stream error")), s();
3521
+ break;
3522
+ }
3523
+ }, s = () => {
3524
+ var n;
3525
+ try {
3526
+ (n = t.removeEventListener) == null || n.call(t, "message", r);
3527
+ } catch {
3528
+ }
3529
+ try {
3530
+ t.onmessage = null;
3531
+ } catch {
3532
+ }
3533
+ try {
3534
+ t.close();
3535
+ } catch {
3536
+ }
3537
+ };
3538
+ t.addEventListener ? t.addEventListener("message", r) : t.on ? t.on(
3539
+ "message",
3540
+ (n) => r({ data: n })
3541
+ ) : t.onmessage = r, typeof t.start == "function" && t.start();
3542
+ },
3543
+ cancel() {
3544
+ try {
3545
+ t.close();
3546
+ } catch {
3547
+ }
3548
+ }
3549
+ });
3550
+ }
3551
+ function promiseToPort(t) {
3552
+ const { port1: e, port2: r } = new MessageChannel();
3553
+ return t.then((s) => {
3554
+ try {
3555
+ e.postMessage({ t: "resolve", v: s });
3556
+ } catch {
3557
+ }
3558
+ }).catch((s) => {
3559
+ try {
3560
+ e.postMessage({
3561
+ t: "reject",
3562
+ m: (s == null ? void 0 : s.message) || String(s)
3563
+ });
3564
+ } catch {
3565
+ }
3566
+ }).finally(() => {
3567
+ try {
3568
+ e.close();
3569
+ } catch {
3570
+ }
3571
+ }), r;
3572
+ }
3573
+ function portToPromise(t) {
3574
+ return new Promise((e, r) => {
3575
+ const s = (i) => {
3576
+ const o = i.data;
3577
+ o && (o.t === "resolve" ? (n(), e(o.v)) : o.t === "reject" && (n(), r(new Error(o.m || ""))));
3578
+ }, n = () => {
3579
+ var i;
3580
+ try {
3581
+ (i = t.removeEventListener) == null || i.call(t, "message", s);
3582
+ } catch {
3583
+ }
3584
+ try {
3585
+ t.onmessage = null;
3586
+ } catch {
3587
+ }
3588
+ try {
3589
+ t.close();
3590
+ } catch {
3591
+ }
3592
+ };
3593
+ t.addEventListener ? t.addEventListener("message", s) : t.on ? t.on(
3594
+ "message",
3595
+ (i) => s({ data: i })
3596
+ ) : t.onmessage = s, typeof t.start == "function" && t.start();
3597
+ });
3407
3598
  }
3408
3599
  const throwTransferHandler = transferHandlers.get(
3409
3600
  "throw"