@php-wasm/web 0.6.14 → 0.6.16

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
@@ -2,11 +2,11 @@ var K = (e, t, r) => {
2
2
  if (!t.has(e))
3
3
  throw TypeError("Cannot " + r);
4
4
  };
5
- var c = (e, t, r) => (K(e, t, "read from private field"), r ? r.call(e) : t.get(e)), d = (e, t, r) => {
5
+ var u = (e, t, r) => (K(e, t, "read from private field"), r ? r.call(e) : t.get(e)), d = (e, t, r) => {
6
6
  if (t.has(e))
7
7
  throw TypeError("Cannot add the same private member more than once");
8
8
  t instanceof WeakSet ? t.add(e) : t.set(e, r);
9
- }, h = (e, t, r, s) => (K(e, t, "write to private field"), s ? s.call(e, r) : t.set(e, r), r);
9
+ }, p = (e, t, r, s) => (K(e, t, "write to private field"), s ? s.call(e, r) : t.set(e, r), r);
10
10
  var f = (e, t, r) => (K(e, t, "access private method"), r);
11
11
  const currentJsRuntime$1 = function() {
12
12
  var e;
@@ -61,8 +61,8 @@ if (currentJsRuntime$1 === "NODE") {
61
61
  r + o.byteLength
62
62
  ).arrayBuffer(), l = new Uint8Array(a);
63
63
  new Uint8Array(o.buffer).set(l);
64
- const u = l.byteLength;
65
- n.byobRequest.respond(u), r += u, r >= s.size && n.close();
64
+ const c = l.byteLength;
65
+ n.byobRequest.respond(c), r += c, r >= s.size && n.close();
66
66
  }
67
67
  });
68
68
  });
@@ -431,7 +431,7 @@ class PHPBrowser {
431
431
  constructor(t, r = {}) {
432
432
  d(this, R, void 0);
433
433
  d(this, T, void 0);
434
- this.requestHandler = t, h(this, R, {}), h(this, T, {
434
+ this.requestHandler = t, p(this, R, {}), p(this, T, {
435
435
  handleRedirects: !1,
436
436
  maxRedirects: 4,
437
437
  ...r
@@ -459,7 +459,7 @@ class PHPBrowser {
459
459
  cookie: this.serializeCookies()
460
460
  }
461
461
  });
462
- if (s.headers["set-cookie"] && this.setCookies(s.headers["set-cookie"]), c(this, T).handleRedirects && s.headers.location && r < c(this, T).maxRedirects) {
462
+ if (s.headers["set-cookie"] && this.setCookies(s.headers["set-cookie"]), u(this, T).handleRedirects && s.headers.location && r < u(this, T).maxRedirects) {
463
463
  const n = new URL(
464
464
  s.headers.location[0],
465
465
  this.requestHandler.absoluteUrl
@@ -497,15 +497,15 @@ class PHPBrowser {
497
497
  if (!r.includes("="))
498
498
  continue;
499
499
  const s = r.indexOf("="), n = r.substring(0, s), o = r.substring(s + 1).split(";")[0];
500
- c(this, R)[n] = o;
500
+ u(this, R)[n] = o;
501
501
  } catch (s) {
502
502
  console.error(s);
503
503
  }
504
504
  }
505
505
  serializeCookies() {
506
506
  const t = [];
507
- for (const r in c(this, R))
508
- t.push(`${r}=${c(this, R)[r]}`);
507
+ for (const r in u(this, R))
508
+ t.push(`${r}=${u(this, R)[r]}`);
509
509
  return t.join("; ");
510
510
  }
511
511
  }
@@ -522,16 +522,16 @@ function ensurePathPrefix(e, t) {
522
522
  }
523
523
  async function encodeAsMultipart(e) {
524
524
  const t = `----${Math.random().toString(36).slice(2)}`, r = `multipart/form-data; boundary=${t}`, s = new TextEncoder(), n = [];
525
- for (const [l, u] of Object.entries(e))
525
+ for (const [l, c] of Object.entries(e))
526
526
  n.push(`--${t}\r
527
- `), n.push(`Content-Disposition: form-data; name="${l}"`), u instanceof File && n.push(`; filename="${u.name}"`), n.push(`\r
528
- `), u instanceof File && (n.push("Content-Type: application/octet-stream"), n.push(`\r
527
+ `), n.push(`Content-Disposition: form-data; name="${l}"`), c instanceof File && n.push(`; filename="${c.name}"`), n.push(`\r
528
+ `), c instanceof File && (n.push("Content-Type: application/octet-stream"), n.push(`\r
529
529
  `)), n.push(`\r
530
- `), u instanceof File ? n.push(await fileToUint8Array(u)) : n.push(u), n.push(`\r
530
+ `), c instanceof File ? n.push(await fileToUint8Array(c)) : n.push(c), n.push(`\r
531
531
  `);
532
532
  n.push(`--${t}--\r
533
533
  `);
534
- const o = n.reduce((l, u) => l + u.length, 0), i = new Uint8Array(o);
534
+ const o = n.reduce((l, c) => l + c.length, 0), i = new Uint8Array(o);
535
535
  let a = 0;
536
536
  for (const l of n)
537
537
  i.set(
@@ -588,23 +588,23 @@ class PHPRequestHandler {
588
588
  d(this, y, void 0);
589
589
  d(this, C, void 0);
590
590
  d(this, S, void 0);
591
- h(this, S, new Semaphore({ concurrency: 1 }));
591
+ p(this, S, new Semaphore({ concurrency: 1 }));
592
592
  const {
593
593
  documentRoot: s = "/www/",
594
594
  absoluteUrl: n = typeof location == "object" ? location == null ? void 0 : location.href : "",
595
595
  rewriteRules: o = []
596
596
  } = r;
597
- this.php = t, h(this, g, s);
597
+ this.php = t, p(this, g, s);
598
598
  const i = new URL(n);
599
- h(this, N, i.hostname), h(this, b, i.port ? Number(i.port) : i.protocol === "https:" ? 443 : 80), h(this, H, (i.protocol || "").replace(":", ""));
600
- const a = c(this, b) !== 443 && c(this, b) !== 80;
601
- h(this, k, [
602
- c(this, N),
603
- a ? `:${c(this, b)}` : ""
604
- ].join("")), h(this, y, i.pathname.replace(/\/+$/, "")), h(this, C, [
605
- `${c(this, H)}://`,
606
- c(this, k),
607
- c(this, y)
599
+ p(this, N, i.hostname), p(this, b, i.port ? Number(i.port) : i.protocol === "https:" ? 443 : 80), p(this, H, (i.protocol || "").replace(":", ""));
600
+ const a = u(this, b) !== 443 && u(this, b) !== 80;
601
+ p(this, k, [
602
+ u(this, N),
603
+ a ? `:${u(this, b)}` : ""
604
+ ].join("")), p(this, y, i.pathname.replace(/\/+$/, "")), p(this, C, [
605
+ `${u(this, H)}://`,
606
+ u(this, k),
607
+ u(this, y)
608
608
  ].join("")), this.rewriteRules = o;
609
609
  }
610
610
  /** @inheritDoc */
@@ -614,18 +614,18 @@ class PHPRequestHandler {
614
614
  /** @inheritDoc */
615
615
  internalUrlToPath(t) {
616
616
  const r = new URL(t);
617
- return r.pathname.startsWith(c(this, y)) && (r.pathname = r.pathname.slice(c(this, y).length)), toRelativeUrl(r);
617
+ return r.pathname.startsWith(u(this, y)) && (r.pathname = r.pathname.slice(u(this, y).length)), toRelativeUrl(r);
618
618
  }
619
619
  get isRequestRunning() {
620
- return c(this, S).running > 0;
620
+ return u(this, S).running > 0;
621
621
  }
622
622
  /** @inheritDoc */
623
623
  get absoluteUrl() {
624
- return c(this, C);
624
+ return u(this, C);
625
625
  }
626
626
  /** @inheritDoc */
627
627
  get documentRoot() {
628
- return c(this, g);
628
+ return u(this, g);
629
629
  }
630
630
  /** @inheritDoc */
631
631
  async request(t) {
@@ -634,9 +634,12 @@ class PHPRequestHandler {
634
634
  t.url.split("#")[0],
635
635
  r ? void 0 : DEFAULT_BASE_URL
636
636
  ), n = applyRewriteRules(
637
- removePathPrefix(s.pathname, c(this, y)),
637
+ removePathPrefix(
638
+ decodeURIComponent(s.pathname),
639
+ u(this, y)
640
+ ),
638
641
  this.rewriteRules
639
- ), o = `${c(this, g)}${n}`;
642
+ ), o = joinPaths(u(this, g), n);
640
643
  return seemsLikeAPHPRequestHandlerPath(o) ? await f(this, O, X).call(this, t, s) : f(this, L, Z).call(this, o);
641
644
  }
642
645
  }
@@ -667,7 +670,7 @@ g = new WeakMap(), H = new WeakMap(), N = new WeakMap(), b = new WeakMap(), k =
667
670
  );
668
671
  }, O = new WeakSet(), X = async function(t, r) {
669
672
  var n;
670
- if (c(this, S).running > 0 && ((n = t.headers) == null ? void 0 : n["x-request-issuer"]) === "php")
673
+ if (u(this, S).running > 0 && ((n = t.headers) == null ? void 0 : n["x-request-issuer"]) === "php")
671
674
  return console.warn(
672
675
  "Possible deadlock: Called request() before the previous request() have finished. PHP likely issued an HTTP call to itself. Normally this would lead to infinite waiting as Request 1 holds the lock that the Request 2 is waiting to acquire. That's not useful, so PHPRequestHandler will return error 502 instead."
673
676
  ), new PHPResponse(
@@ -675,26 +678,26 @@ g = new WeakMap(), H = new WeakMap(), N = new WeakMap(), b = new WeakMap(), k =
675
678
  {},
676
679
  new TextEncoder().encode("502 Bad Gateway")
677
680
  );
678
- const s = await c(this, S).acquire();
681
+ const s = await u(this, S).acquire();
679
682
  try {
680
- this.php.addServerGlobalEntry("REMOTE_ADDR", "127.0.0.1"), this.php.addServerGlobalEntry("DOCUMENT_ROOT", c(this, g)), this.php.addServerGlobalEntry(
683
+ this.php.addServerGlobalEntry("REMOTE_ADDR", "127.0.0.1"), this.php.addServerGlobalEntry("DOCUMENT_ROOT", u(this, g)), this.php.addServerGlobalEntry(
681
684
  "HTTPS",
682
- c(this, C).startsWith("https://") ? "on" : ""
685
+ u(this, C).startsWith("https://") ? "on" : ""
683
686
  );
684
687
  let o = "GET";
685
688
  const i = {
686
- host: c(this, k),
689
+ host: u(this, k),
687
690
  ...normalizeHeaders(t.headers || {})
688
691
  };
689
692
  let a = t.body;
690
693
  if (typeof a == "object" && !(a instanceof Uint8Array)) {
691
694
  o = "POST";
692
- const { bytes: u, contentType: p } = await encodeAsMultipart(a);
693
- a = u, i["content-type"] = p;
695
+ const { bytes: c, contentType: h } = await encodeAsMultipart(a);
696
+ a = c, i["content-type"] = h;
694
697
  }
695
698
  let l;
696
699
  try {
697
- l = f(this, U, ee).call(this, r.pathname);
700
+ l = f(this, U, ee).call(this, decodeURIComponent(r.pathname));
698
701
  } catch {
699
702
  return new PHPResponse(
700
703
  404,
@@ -702,24 +705,31 @@ g = new WeakMap(), H = new WeakMap(), N = new WeakMap(), b = new WeakMap(), k =
702
705
  new TextEncoder().encode("404 File not found")
703
706
  );
704
707
  }
705
- return await this.php.run({
706
- relativeUri: ensurePathPrefix(
707
- toRelativeUrl(r),
708
- c(this, y)
709
- ),
710
- protocol: c(this, H),
711
- method: t.method || o,
712
- body: a,
713
- scriptPath: l,
714
- headers: i
715
- });
708
+ try {
709
+ return await this.php.run({
710
+ relativeUri: ensurePathPrefix(
711
+ toRelativeUrl(r),
712
+ u(this, y)
713
+ ),
714
+ protocol: u(this, H),
715
+ method: t.method || o,
716
+ body: a,
717
+ scriptPath: l,
718
+ headers: i
719
+ });
720
+ } catch (c) {
721
+ const h = c;
722
+ if (h != null && h.response)
723
+ return h.response;
724
+ throw c;
725
+ }
716
726
  } finally {
717
727
  s();
718
728
  }
719
729
  }, U = new WeakSet(), ee = function(t) {
720
- let r = removePathPrefix(t, c(this, y));
721
- r = applyRewriteRules(r, this.rewriteRules), r.includes(".php") ? r = r.split(".php")[0] + ".php" : this.php.isDir(`${c(this, g)}${r}`) ? (r.endsWith("/") || (r = `${r}/`), r = `${r}index.php`) : r = "/index.php";
722
- const s = `${c(this, g)}${r}`;
730
+ let r = removePathPrefix(t, u(this, y));
731
+ r = applyRewriteRules(r, this.rewriteRules), r.includes(".php") ? r = r.split(".php")[0] + ".php" : this.php.isDir(`${u(this, g)}${r}`) ? (r.endsWith("/") || (r = `${r}/`), r = `${r}index.php`) : r = "/index.php";
732
+ const s = `${u(this, g)}${r}`;
723
733
  if (this.php.fileExists(s))
724
734
  return s;
725
735
  throw new Error(`File not found: ${s}`);
@@ -872,8 +882,8 @@ function rethrowFileSystemError(e = "") {
872
882
  } catch (a) {
873
883
  const l = typeof a == "object" ? a == null ? void 0 : a.errno : null;
874
884
  if (l in FileErrorCodes) {
875
- const u = FileErrorCodes[l], p = typeof i[0] == "string" ? i[0] : null, _ = p !== null ? e.replaceAll("{path}", p) : e;
876
- throw new Error(`${_}: ${u}`, {
885
+ const c = FileErrorCodes[l], h = typeof i[0] == "string" ? i[0] : null, _ = h !== null ? e.replaceAll("{path}", h) : e;
886
+ throw new Error(`${_}: ${c}`, {
877
887
  cause: a
878
888
  });
879
889
  }
@@ -924,6 +934,11 @@ var __defProp = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyD
924
934
  return s && n && __defProp(t, r, n), n;
925
935
  };
926
936
  const STRING = "string", NUMBER = "number", __private__dont__use = Symbol("__private__dont__use");
937
+ class PHPExecutionFailureError extends Error {
938
+ constructor(t, r, s) {
939
+ super(t), this.response = r, this.source = s;
940
+ }
941
+ }
927
942
  var x, F, A, w, E, v, P, M, W, te, q, re, B, se, D, ne, $, ie, z, oe, j, ae, G, le, V, ce, J, ue, Q, de, Y, he;
928
943
  class BasePHP {
929
944
  /**
@@ -954,26 +969,26 @@ class BasePHP {
954
969
  d(this, v, void 0);
955
970
  d(this, P, void 0);
956
971
  d(this, M, void 0);
957
- h(this, x, []), h(this, w, !1), h(this, E, null), h(this, v, {}), h(this, P, /* @__PURE__ */ new Map()), h(this, M, []), this.semaphore = new Semaphore({ concurrency: 1 }), e !== void 0 && this.initializeRuntime(e), t && (this.requestHandler = new PHPBrowser(
972
+ p(this, x, []), p(this, w, !1), p(this, E, null), p(this, v, {}), p(this, P, /* @__PURE__ */ new Map()), p(this, M, []), this.semaphore = new Semaphore({ concurrency: 1 }), e !== void 0 && this.initializeRuntime(e), t && (this.requestHandler = new PHPBrowser(
958
973
  new PHPRequestHandler(this, t)
959
974
  ));
960
975
  }
961
976
  addEventListener(e, t) {
962
- c(this, P).has(e) || c(this, P).set(e, /* @__PURE__ */ new Set()), c(this, P).get(e).add(t);
977
+ u(this, P).has(e) || u(this, P).set(e, /* @__PURE__ */ new Set()), u(this, P).get(e).add(t);
963
978
  }
964
979
  removeEventListener(e, t) {
965
980
  var r;
966
- (r = c(this, P).get(e)) == null || r.delete(t);
981
+ (r = u(this, P).get(e)) == null || r.delete(t);
967
982
  }
968
983
  dispatchEvent(e) {
969
- const t = c(this, P).get(e.type);
984
+ const t = u(this, P).get(e.type);
970
985
  if (t)
971
986
  for (const r of t)
972
987
  r(e);
973
988
  }
974
989
  /** @inheritDoc */
975
990
  async onMessage(e) {
976
- c(this, M).push(e);
991
+ u(this, M).push(e);
977
992
  }
978
993
  /** @inheritDoc */
979
994
  async setSpawnHandler(handler) {
@@ -1004,13 +1019,13 @@ class BasePHP {
1004
1019
  if (!t)
1005
1020
  throw new Error("Invalid PHP runtime id.");
1006
1021
  this[__private__dont__use] = t, t.onMessage = async (r) => {
1007
- for (const s of c(this, M)) {
1022
+ for (const s of u(this, M)) {
1008
1023
  const n = await s(r);
1009
1024
  if (n)
1010
1025
  return n;
1011
1026
  }
1012
1027
  return "";
1013
- }, h(this, E, improveWASMErrorReporting(t)), this.dispatchEvent({
1028
+ }, p(this, E, improveWASMErrorReporting(t)), this.dispatchEvent({
1014
1029
  type: "runtime.initialized"
1015
1030
  });
1016
1031
  }
@@ -1025,13 +1040,13 @@ class BasePHP {
1025
1040
  throw new Error(
1026
1041
  "Could not set SAPI name. This can only be done before the PHP WASM module is initialized.Did you already dispatch any requests?"
1027
1042
  );
1028
- h(this, A, e);
1043
+ p(this, A, e);
1029
1044
  }
1030
1045
  /** @inheritDoc */
1031
1046
  setPhpIniPath(e) {
1032
- if (c(this, w))
1047
+ if (u(this, w))
1033
1048
  throw new Error("Cannot set PHP ini path after calling run().");
1034
- h(this, F, e), this[__private__dont__use].ccall(
1049
+ p(this, F, e), this[__private__dont__use].ccall(
1035
1050
  "wasm_set_phpini_path",
1036
1051
  null,
1037
1052
  ["string"],
@@ -1040,9 +1055,9 @@ class BasePHP {
1040
1055
  }
1041
1056
  /** @inheritDoc */
1042
1057
  setPhpIniEntry(e, t) {
1043
- if (c(this, w))
1058
+ if (u(this, w))
1044
1059
  throw new Error("Cannot set PHP ini entries after calling run().");
1045
- c(this, x).push([e, t]);
1060
+ u(this, x).push([e, t]);
1046
1061
  }
1047
1062
  /** @inheritDoc */
1048
1063
  chdir(e) {
@@ -1059,7 +1074,7 @@ class BasePHP {
1059
1074
  const t = await this.semaphore.acquire();
1060
1075
  let r;
1061
1076
  try {
1062
- if (c(this, w) || (f(this, W, te).call(this), h(this, w, !0)), e.scriptPath && !this.fileExists(e.scriptPath))
1077
+ if (u(this, w) || (f(this, W, te).call(this), p(this, w, !0)), e.scriptPath && !this.fileExists(e.scriptPath))
1063
1078
  throw new Error(
1064
1079
  `The script path "${e.scriptPath}" does not exist.`
1065
1080
  );
@@ -1071,15 +1086,13 @@ class BasePHP {
1071
1086
  f(this, J, ue).call(this, a, o[a]);
1072
1087
  const i = await f(this, Y, he).call(this);
1073
1088
  if (i.exitCode !== 0) {
1074
- const a = {
1075
- stdout: i.text,
1076
- stderr: i.errors
1077
- };
1078
- console.warn("PHP.run() output was:", a);
1079
- const l = new Error(
1080
- `PHP.run() failed with exit code ${i.exitCode} and the following output: ` + i.errors
1089
+ console.warn("PHP.run() output was:", i.text);
1090
+ const a = new PHPExecutionFailureError(
1091
+ `PHP.run() failed with exit code ${i.exitCode} and the following output: ` + i.errors,
1092
+ i,
1093
+ "request"
1081
1094
  );
1082
- throw l.output = a, l.source = "request", console.error(l), l;
1095
+ throw console.error(a), a;
1083
1096
  }
1084
1097
  return i;
1085
1098
  } catch (s) {
@@ -1100,7 +1113,7 @@ class BasePHP {
1100
1113
  }
1101
1114
  }
1102
1115
  addServerGlobalEntry(e, t) {
1103
- c(this, v)[e] = t;
1116
+ u(this, v)[e] = t;
1104
1117
  }
1105
1118
  defineConstant(e, t) {
1106
1119
  let r = {};
@@ -1196,7 +1209,7 @@ class BasePHP {
1196
1209
  this.exit();
1197
1210
  } catch {
1198
1211
  }
1199
- if (this.initializeRuntime(e), c(this, F) && this.setPhpIniPath(c(this, F)), c(this, A) && this.setSapiName(c(this, A)), this.requestHandler) {
1212
+ if (this.initializeRuntime(e), u(this, F) && this.setPhpIniPath(u(this, F)), u(this, A) && this.setSapiName(u(this, A)), this.requestHandler) {
1200
1213
  const r = this.documentRoot;
1201
1214
  copyFS(t, this[__private__dont__use].FS, r);
1202
1215
  }
@@ -1209,7 +1222,7 @@ class BasePHP {
1209
1222
  this[__private__dont__use]._exit(e);
1210
1223
  } catch {
1211
1224
  }
1212
- h(this, w, !1), h(this, E, null), delete this[__private__dont__use].onMessage, delete this[__private__dont__use];
1225
+ p(this, w, !1), p(this, E, null), delete this[__private__dont__use].onMessage, delete this[__private__dont__use];
1213
1226
  }
1214
1227
  }
1215
1228
  x = new WeakMap(), F = new WeakMap(), A = new WeakMap(), w = new WeakMap(), E = new WeakMap(), v = new WeakMap(), P = new WeakMap(), M = new WeakMap(), W = new WeakSet(), te = function() {
@@ -1224,8 +1237,8 @@ x = new WeakMap(), F = new WeakMap(), A = new WeakMap(), w = new WeakMap(), E =
1224
1237
  }
1225
1238
  }
1226
1239
  }`
1227
- ), c(this, x).length > 0) {
1228
- const e = c(this, x).map(([t, r]) => `${t}=${r}`).join(`
1240
+ ), u(this, x).length > 0) {
1241
+ const e = u(this, x).map(([t, r]) => `${t}=${r}`).join(`
1229
1242
  `) + `
1230
1243
 
1231
1244
  `;
@@ -1349,12 +1362,12 @@ x = new WeakMap(), F = new WeakMap(), A = new WeakMap(), w = new WeakMap(), E =
1349
1362
  [e]
1350
1363
  );
1351
1364
  }, V = new WeakSet(), ce = function() {
1352
- for (const e in c(this, v))
1365
+ for (const e in u(this, v))
1353
1366
  this[__private__dont__use].ccall(
1354
1367
  "wasm_add_SERVER_entry",
1355
1368
  null,
1356
1369
  [STRING, STRING],
1357
- [e, c(this, v)[e]]
1370
+ [e, u(this, v)[e]]
1358
1371
  );
1359
1372
  }, J = new WeakSet(), ue = function(e, t) {
1360
1373
  this[__private__dont__use].ccall(
@@ -1376,11 +1389,11 @@ x = new WeakMap(), F = new WeakMap(), A = new WeakMap(), w = new WeakMap(), E =
1376
1389
  try {
1377
1390
  e = await new Promise((o, i) => {
1378
1391
  var l;
1379
- t = (u) => {
1380
- console.error(u), console.error(u.error);
1381
- const p = new Error("Rethrown");
1382
- p.cause = u.error, p.betterMessage = u.message, i(p);
1383
- }, (l = c(this, E)) == null || l.addEventListener(
1392
+ t = (c) => {
1393
+ console.error(c), console.error(c.error);
1394
+ const h = new Error("Rethrown");
1395
+ h.cause = c.error, h.betterMessage = c.message, i(h);
1396
+ }, (l = u(this, E)) == null || l.addEventListener(
1384
1397
  "error",
1385
1398
  t
1386
1399
  );
@@ -1394,8 +1407,8 @@ x = new WeakMap(), F = new WeakMap(), A = new WeakMap(), w = new WeakMap(), E =
1394
1407
  return a instanceof Promise ? a.then(o, i) : o(a);
1395
1408
  });
1396
1409
  } catch (o) {
1397
- for (const u in this)
1398
- typeof this[u] == "function" && (this[u] = () => {
1410
+ for (const c in this)
1411
+ typeof this[c] == "function" && (this[c] = () => {
1399
1412
  throw new Error(
1400
1413
  "PHP runtime has crashed – see the earlier error for details."
1401
1414
  );
@@ -1404,11 +1417,11 @@ x = new WeakMap(), F = new WeakMap(), A = new WeakMap(), w = new WeakMap(), E =
1404
1417
  const i = o, a = "betterMessage" in i ? i.betterMessage : i.message, l = new Error(a);
1405
1418
  throw l.cause = i, console.error(l), l;
1406
1419
  } finally {
1407
- (n = c(this, E)) == null || n.removeEventListener("error", t), h(this, v, {});
1420
+ (n = u(this, E)) == null || n.removeEventListener("error", t), p(this, v, {});
1408
1421
  }
1409
1422
  const { headers: r, httpStatusCode: s } = f(this, q, re).call(this);
1410
1423
  return new PHPResponse(
1411
- s,
1424
+ e === 0 ? s : 500,
1412
1425
  r,
1413
1426
  this.readFileAsBuffer("/internal/stdout"),
1414
1427
  this.readFileAsText("/internal/stderr"),
@@ -1518,44 +1531,44 @@ function expose(e, t = globalThis, r = ["*"]) {
1518
1531
  return;
1519
1532
  }
1520
1533
  const { id: o, type: i, path: a } = Object.assign({ path: [] }, n.data), l = (n.data.argumentList || []).map(fromWireValue);
1521
- let u;
1534
+ let c;
1522
1535
  try {
1523
- const p = a.slice(0, -1).reduce((m, I) => m[I], e), _ = a.reduce((m, I) => m[I], e);
1536
+ const h = a.slice(0, -1).reduce((m, I) => m[I], e), _ = a.reduce((m, I) => m[I], e);
1524
1537
  switch (i) {
1525
1538
  case "GET":
1526
- u = _;
1539
+ c = _;
1527
1540
  break;
1528
1541
  case "SET":
1529
- p[a.slice(-1)[0]] = fromWireValue(n.data.value), u = !0;
1542
+ h[a.slice(-1)[0]] = fromWireValue(n.data.value), c = !0;
1530
1543
  break;
1531
1544
  case "APPLY":
1532
- u = _.apply(p, l);
1545
+ c = _.apply(h, l);
1533
1546
  break;
1534
1547
  case "CONSTRUCT":
1535
1548
  {
1536
1549
  const m = new _(...l);
1537
- u = proxy(m);
1550
+ c = proxy(m);
1538
1551
  }
1539
1552
  break;
1540
1553
  case "ENDPOINT":
1541
1554
  {
1542
1555
  const { port1: m, port2: I } = new MessageChannel();
1543
- expose(e, I), u = transfer(m, [m]);
1556
+ expose(e, I), c = transfer(m, [m]);
1544
1557
  }
1545
1558
  break;
1546
1559
  case "RELEASE":
1547
- u = void 0;
1560
+ c = void 0;
1548
1561
  break;
1549
1562
  default:
1550
1563
  return;
1551
1564
  }
1552
- } catch (p) {
1553
- u = { value: p, [throwMarker]: 0 };
1565
+ } catch (h) {
1566
+ c = { value: h, [throwMarker]: 0 };
1554
1567
  }
1555
- Promise.resolve(u).catch((p) => ({ value: p, [throwMarker]: 0 })).then((p) => {
1556
- const [_, m] = toWireValue(p);
1568
+ Promise.resolve(c).catch((h) => ({ value: h, [throwMarker]: 0 })).then((h) => {
1569
+ const [_, m] = toWireValue(h);
1557
1570
  t.postMessage(Object.assign(Object.assign({}, _), { id: o }), m), i === "RELEASE" && (t.removeEventListener("message", s), closeEndPoint(t), finalizer in e && typeof e[finalizer] == "function" && e[finalizer]());
1558
- }).catch((p) => {
1571
+ }).catch((h) => {
1559
1572
  const [_, m] = toWireValue({
1560
1573
  value: new TypeError("Unserializable return value"),
1561
1574
  [throwMarker]: 0
@@ -1617,12 +1630,12 @@ function createProxy(e, t = [], r = function() {
1617
1630
  },
1618
1631
  set(o, i, a) {
1619
1632
  throwIfProxyReleased(s);
1620
- const [l, u] = toWireValue(a);
1633
+ const [l, c] = toWireValue(a);
1621
1634
  return requestResponseMessage(e, {
1622
1635
  type: "SET",
1623
- path: [...t, i].map((p) => p.toString()),
1636
+ path: [...t, i].map((h) => h.toString()),
1624
1637
  value: l
1625
- }, u).then(fromWireValue);
1638
+ }, c).then(fromWireValue);
1626
1639
  },
1627
1640
  apply(o, i, a) {
1628
1641
  throwIfProxyReleased(s);
@@ -1633,19 +1646,19 @@ function createProxy(e, t = [], r = function() {
1633
1646
  }).then(fromWireValue);
1634
1647
  if (l === "bind")
1635
1648
  return createProxy(e, t.slice(0, -1));
1636
- const [u, p] = processArguments(a);
1649
+ const [c, h] = processArguments(a);
1637
1650
  return requestResponseMessage(e, {
1638
1651
  type: "APPLY",
1639
1652
  path: t.map((_) => _.toString()),
1640
- argumentList: u
1641
- }, p).then(fromWireValue);
1653
+ argumentList: c
1654
+ }, h).then(fromWireValue);
1642
1655
  },
1643
1656
  construct(o, i) {
1644
1657
  throwIfProxyReleased(s);
1645
1658
  const [a, l] = processArguments(i);
1646
1659
  return requestResponseMessage(e, {
1647
1660
  type: "CONSTRUCT",
1648
- path: t.map((u) => u.toString()),
1661
+ path: t.map((c) => c.toString()),
1649
1662
  argumentList: a
1650
1663
  }, l).then(fromWireValue);
1651
1664
  }
@@ -1736,10 +1749,10 @@ function exposeAPI(e, t) {
1736
1749
  setupTransferHandlers();
1737
1750
  const r = Promise.resolve();
1738
1751
  let s, n;
1739
- const o = new Promise((l, u) => {
1740
- s = l, n = u;
1752
+ const o = new Promise((l, c) => {
1753
+ s = l, n = c;
1741
1754
  }), i = proxyClone(e), a = new Proxy(i, {
1742
- get: (l, u) => u === "isConnected" ? () => r : u === "isReady" ? () => o : u in l ? l[u] : t == null ? void 0 : t[u]
1755
+ get: (l, c) => c === "isConnected" ? () => r : c === "isReady" ? () => o : c in l ? l[c] : t == null ? void 0 : t[c]
1743
1756
  });
1744
1757
  return expose(
1745
1758
  a,
@@ -1748,34 +1761,41 @@ function exposeAPI(e, t) {
1748
1761
  }
1749
1762
  let isTransferHandlersSetup = !1;
1750
1763
  function setupTransferHandlers() {
1751
- isTransferHandlersSetup || (isTransferHandlersSetup = !0, transferHandlers.set("EVENT", {
1752
- canHandle: (e) => e instanceof CustomEvent,
1753
- serialize: (e) => [
1764
+ if (isTransferHandlersSetup)
1765
+ return;
1766
+ isTransferHandlersSetup = !0, transferHandlers.set("EVENT", {
1767
+ canHandle: (r) => r instanceof CustomEvent,
1768
+ serialize: (r) => [
1754
1769
  {
1755
- detail: e.detail
1770
+ detail: r.detail
1756
1771
  },
1757
1772
  []
1758
1773
  ],
1759
- deserialize: (e) => e
1774
+ deserialize: (r) => r
1760
1775
  }), transferHandlers.set("FUNCTION", {
1761
- canHandle: (e) => typeof e == "function",
1762
- serialize(e) {
1776
+ canHandle: (r) => typeof r == "function",
1777
+ serialize(r) {
1763
1778
  console.debug("[Comlink][Performance] Proxying a function");
1764
- const { port1: t, port2: r } = new MessageChannel();
1765
- return expose(e, t), [r, [r]];
1779
+ const { port1: s, port2: n } = new MessageChannel();
1780
+ return expose(r, s), [n, [n]];
1766
1781
  },
1767
- deserialize(e) {
1768
- return e.start(), wrap(e);
1782
+ deserialize(r) {
1783
+ return r.start(), wrap(r);
1769
1784
  }
1770
1785
  }), transferHandlers.set("PHPResponse", {
1771
- canHandle: (e) => typeof e == "object" && e !== null && "headers" in e && "bytes" in e && "errors" in e && "exitCode" in e && "httpStatusCode" in e,
1772
- serialize(e) {
1773
- return [e.toRawData(), []];
1786
+ canHandle: (r) => typeof r == "object" && r !== null && "headers" in r && "bytes" in r && "errors" in r && "exitCode" in r && "httpStatusCode" in r,
1787
+ serialize(r) {
1788
+ return [r.toRawData(), []];
1774
1789
  },
1775
- deserialize(e) {
1776
- return PHPResponse.fromRawData(e);
1790
+ deserialize(r) {
1791
+ return PHPResponse.fromRawData(r);
1777
1792
  }
1778
- }));
1793
+ });
1794
+ const e = transferHandlers.get("throw"), t = e == null ? void 0 : e.serialize;
1795
+ e.serialize = ({ value: r }) => {
1796
+ const s = t({ value: r });
1797
+ return r.response && (s[0].value.response = r.response), r.source && (s[0].value.source = r.source), s;
1798
+ };
1779
1799
  }
1780
1800
  function proxyClone(e) {
1781
1801
  return new Proxy(e, {
@@ -2022,8 +2042,8 @@ async function registerServiceWorker(e, t, r) {
2022
2042
  async function(i) {
2023
2043
  if (t && i.data.scope !== t)
2024
2044
  return;
2025
- const a = i.data.args || [], l = i.data.method, u = await e[l](...a);
2026
- i.source.postMessage(responseTo(i.data.requestId, u));
2045
+ const a = i.data.args || [], l = i.data.method, c = await e[l](...a);
2046
+ i.source.postMessage(responseTo(i.data.requestId, c));
2027
2047
  }
2028
2048
  ), s.startMessages();
2029
2049
  }
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -1,6 +1,6 @@
1
1
  import dependencyFilename from './7_0_33/php_7_0.wasm';
2
2
  export { dependencyFilename };
3
- export const dependenciesTotalSize = 10638342;
3
+ export const dependenciesTotalSize = 10638709;
4
4
  export function init(RuntimeName, PHPLoader) {
5
5
  /**
6
6
  * Overrides Emscripten's default ExitStatus object which gets
@@ -1,6 +1,6 @@
1
1
  import dependencyFilename from './7_1_30/php_7_1.wasm';
2
2
  export { dependencyFilename };
3
- export const dependenciesTotalSize = 11078540;
3
+ export const dependenciesTotalSize = 11078277;
4
4
  export function init(RuntimeName, PHPLoader) {
5
5
  /**
6
6
  * Overrides Emscripten's default ExitStatus object which gets
@@ -1,6 +1,6 @@
1
1
  import dependencyFilename from './7_2_34/php_7_2.wasm';
2
2
  export { dependencyFilename };
3
- export const dependenciesTotalSize = 11712677;
3
+ export const dependenciesTotalSize = 11712687;
4
4
  export function init(RuntimeName, PHPLoader) {
5
5
  /**
6
6
  * Overrides Emscripten's default ExitStatus object which gets
@@ -1,6 +1,6 @@
1
1
  import dependencyFilename from './7_3_33/php_7_3.wasm';
2
2
  export { dependencyFilename };
3
- export const dependenciesTotalSize = 11775223;
3
+ export const dependenciesTotalSize = 11775233;
4
4
  export function init(RuntimeName, PHPLoader) {
5
5
  /**
6
6
  * Overrides Emscripten's default ExitStatus object which gets
@@ -1,6 +1,6 @@
1
1
  import dependencyFilename from './7_4_33/php_7_4.wasm';
2
2
  export { dependencyFilename };
3
- export const dependenciesTotalSize = 11945559;
3
+ export const dependenciesTotalSize = 11945564;
4
4
  export function init(RuntimeName, PHPLoader) {
5
5
  /**
6
6
  * Overrides Emscripten's default ExitStatus object which gets
@@ -1,6 +1,6 @@
1
1
  import dependencyFilename from './8_0_30/php_8_0.wasm';
2
2
  export { dependencyFilename };
3
- export const dependenciesTotalSize = 11611332;
3
+ export const dependenciesTotalSize = 11611342;
4
4
  export function init(RuntimeName, PHPLoader) {
5
5
  /**
6
6
  * Overrides Emscripten's default ExitStatus object which gets
@@ -1,6 +1,6 @@
1
1
  import dependencyFilename from './8_1_23/php_8_1.wasm';
2
2
  export { dependencyFilename };
3
- export const dependenciesTotalSize = 11541668;
3
+ export const dependenciesTotalSize = 11541678;
4
4
  export function init(RuntimeName, PHPLoader) {
5
5
  /**
6
6
  * Overrides Emscripten's default ExitStatus object which gets
@@ -1,6 +1,6 @@
1
1
  import dependencyFilename from './8_2_10/php_8_2.wasm';
2
2
  export { dependencyFilename };
3
- export const dependenciesTotalSize = 11787163;
3
+ export const dependenciesTotalSize = 11787173;
4
4
  export function init(RuntimeName, PHPLoader) {
5
5
  /**
6
6
  * Overrides Emscripten's default ExitStatus object which gets
@@ -1,6 +1,6 @@
1
1
  import dependencyFilename from './8_3_0/php_8_3.wasm';
2
2
  export { dependencyFilename };
3
- export const dependenciesTotalSize = 12043963;
3
+ export const dependenciesTotalSize = 12043974;
4
4
  export function init(RuntimeName, PHPLoader) {
5
5
  /**
6
6
  * Overrides Emscripten's default ExitStatus object which gets
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/light/php_7_0.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import dependencyFilename from './7_0_33/php_7_0.wasm';
2
2
  export { dependencyFilename };
3
- export const dependenciesTotalSize = 5285560;
3
+ export const dependenciesTotalSize = 5285931;
4
4
  export function init(RuntimeName, PHPLoader) {
5
5
  /**
6
6
  * Overrides Emscripten's default ExitStatus object which gets
package/light/php_7_1.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import dependencyFilename from './7_1_30/php_7_1.wasm';
2
2
  export { dependencyFilename };
3
- export const dependenciesTotalSize = 5429825;
3
+ export const dependenciesTotalSize = 5429562;
4
4
  export function init(RuntimeName, PHPLoader) {
5
5
  /**
6
6
  * Overrides Emscripten's default ExitStatus object which gets
package/light/php_7_2.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import dependencyFilename from './7_2_34/php_7_2.wasm';
2
2
  export { dependencyFilename };
3
- export const dependenciesTotalSize = 5772770;
3
+ export const dependenciesTotalSize = 5772780;
4
4
  export function init(RuntimeName, PHPLoader) {
5
5
  /**
6
6
  * Overrides Emscripten's default ExitStatus object which gets
package/light/php_7_3.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import dependencyFilename from './7_3_33/php_7_3.wasm';
2
2
  export { dependencyFilename };
3
- export const dependenciesTotalSize = 5700746;
3
+ export const dependenciesTotalSize = 5700756;
4
4
  export function init(RuntimeName, PHPLoader) {
5
5
  /**
6
6
  * Overrides Emscripten's default ExitStatus object which gets
package/light/php_7_4.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import dependencyFilename from './7_4_33/php_7_4.wasm';
2
2
  export { dependencyFilename };
3
- export const dependenciesTotalSize = 5783238;
3
+ export const dependenciesTotalSize = 5783248;
4
4
  export function init(RuntimeName, PHPLoader) {
5
5
  /**
6
6
  * Overrides Emscripten's default ExitStatus object which gets
package/light/php_8_0.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import dependencyFilename from './8_0_30/php_8_0.wasm';
2
2
  export { dependencyFilename };
3
- export const dependenciesTotalSize = 5579505;
3
+ export const dependenciesTotalSize = 5579515;
4
4
  export function init(RuntimeName, PHPLoader) {
5
5
  /**
6
6
  * Overrides Emscripten's default ExitStatus object which gets
package/light/php_8_1.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import dependencyFilename from './8_1_23/php_8_1.wasm';
2
2
  export { dependencyFilename };
3
- export const dependenciesTotalSize = 5382805;
3
+ export const dependenciesTotalSize = 5382815;
4
4
  export function init(RuntimeName, PHPLoader) {
5
5
  /**
6
6
  * Overrides Emscripten's default ExitStatus object which gets
package/light/php_8_2.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import dependencyFilename from './8_2_10/php_8_2.wasm';
2
2
  export { dependencyFilename };
3
- export const dependenciesTotalSize = 5496649;
3
+ export const dependenciesTotalSize = 5496659;
4
4
  export function init(RuntimeName, PHPLoader) {
5
5
  /**
6
6
  * Overrides Emscripten's default ExitStatus object which gets
package/light/php_8_3.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import dependencyFilename from './8_3_0/php_8_3.wasm';
2
2
  export { dependencyFilename };
3
- export const dependenciesTotalSize = 5587869;
3
+ export const dependenciesTotalSize = 5587879;
4
4
  export function init(RuntimeName, PHPLoader) {
5
5
  /**
6
6
  * Overrides Emscripten's default ExitStatus object which gets
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@php-wasm/web",
3
- "version": "0.6.14",
3
+ "version": "0.6.16",
4
4
  "description": "PHP.wasm for the web",
5
5
  "repository": {
6
6
  "type": "git",
@@ -29,16 +29,16 @@
29
29
  "type": "module",
30
30
  "main": "index.js",
31
31
  "types": "index.d.ts",
32
- "gitHead": "83b6f8542937a9bea9ee6562887a511c20ac9442",
32
+ "gitHead": "1981567e7eacecbc4a18c870267c20bf489afd8f",
33
33
  "engines": {
34
34
  "node": ">=16.15.1",
35
35
  "npm": ">=8.11.0"
36
36
  },
37
37
  "dependencies": {
38
38
  "comlink": "^4.4.1",
39
- "@php-wasm/universal": "0.6.14",
40
- "@php-wasm/util": "0.6.14",
41
- "@php-wasm/web-service-worker": "0.6.14",
42
- "@php-wasm/progress": "0.6.14"
39
+ "@php-wasm/universal": "0.6.16",
40
+ "@php-wasm/util": "0.6.16",
41
+ "@php-wasm/web-service-worker": "0.6.16",
42
+ "@php-wasm/progress": "0.6.16"
43
43
  }
44
44
  }