@php-wasm/web 0.6.7 → 0.6.9
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.d.ts +18 -6
- package/index.js +104 -92
- package/kitchen-sink/7_0_33/php_7_0.wasm +0 -0
- package/kitchen-sink/7_1_30/php_7_1.wasm +0 -0
- package/kitchen-sink/7_2_34/php_7_2.wasm +0 -0
- package/kitchen-sink/7_3_33/php_7_3.wasm +0 -0
- package/kitchen-sink/7_4_33/php_7_4.wasm +0 -0
- package/kitchen-sink/8_0_30/php_8_0.wasm +0 -0
- package/kitchen-sink/8_1_23/php_8_1.wasm +0 -0
- package/kitchen-sink/8_2_10/php_8_2.wasm +0 -0
- package/kitchen-sink/8_3_0/php_8_3.wasm +0 -0
- package/kitchen-sink/php_7_0.js +2 -2
- package/kitchen-sink/php_7_1.js +2 -2
- package/kitchen-sink/php_7_2.js +2 -2
- package/kitchen-sink/php_7_3.js +2 -2
- package/kitchen-sink/php_7_4.js +2 -2
- package/kitchen-sink/php_8_0.js +2 -2
- package/kitchen-sink/php_8_1.js +2 -2
- package/kitchen-sink/php_8_2.js +2 -2
- package/kitchen-sink/php_8_3.js +2 -2
- package/light/7_0_33/php_7_0.wasm +0 -0
- package/light/7_1_30/php_7_1.wasm +0 -0
- package/light/7_2_34/php_7_2.wasm +0 -0
- package/light/7_3_33/php_7_3.wasm +0 -0
- package/light/7_4_33/php_7_4.wasm +0 -0
- package/light/8_0_30/php_8_0.wasm +0 -0
- package/light/8_1_23/php_8_1.wasm +0 -0
- package/light/8_2_10/php_8_2.wasm +0 -0
- package/light/8_3_0/php_8_3.wasm +0 -0
- package/light/php_7_0.js +2 -2
- package/light/php_7_1.js +2 -2
- package/light/php_7_2.js +2 -2
- package/light/php_7_3.js +2 -2
- package/light/php_7_4.js +2 -2
- package/light/php_8_0.js +2 -2
- package/light/php_8_1.js +2 -2
- package/light/php_8_2.js +2 -2
- package/light/php_8_3.js +2 -2
- package/package.json +6 -5
package/index.d.ts
CHANGED
|
@@ -76,6 +76,14 @@ declare class PHPResponse implements PHPResponseData {
|
|
|
76
76
|
export interface PHPRequestEndEvent {
|
|
77
77
|
type: "request.end";
|
|
78
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Represents an error event related to the PHP request.
|
|
81
|
+
*/
|
|
82
|
+
export interface PHPRequestErrorEvent {
|
|
83
|
+
type: "request.error";
|
|
84
|
+
error: Error;
|
|
85
|
+
source?: "request" | "php-wasm";
|
|
86
|
+
}
|
|
79
87
|
/**
|
|
80
88
|
* Represents a PHP runtime initialization event.
|
|
81
89
|
*/
|
|
@@ -93,7 +101,7 @@ export interface PHPRuntimeBeforeDestroyEvent {
|
|
|
93
101
|
* This is intentionally not an extension of CustomEvent
|
|
94
102
|
* to make it isomorphic between different JavaScript runtimes.
|
|
95
103
|
*/
|
|
96
|
-
export type PHPEvent = PHPRequestEndEvent | PHPRuntimeInitializedEvent | PHPRuntimeBeforeDestroyEvent;
|
|
104
|
+
export type PHPEvent = PHPRequestEndEvent | PHPRequestErrorEvent | PHPRuntimeInitializedEvent | PHPRuntimeBeforeDestroyEvent;
|
|
97
105
|
/**
|
|
98
106
|
* A callback function that handles PHP events.
|
|
99
107
|
*/
|
|
@@ -538,11 +546,6 @@ export interface PHPRunOptions {
|
|
|
538
546
|
* The code snippet to eval instead of a php file.
|
|
539
547
|
*/
|
|
540
548
|
code?: string;
|
|
541
|
-
/**
|
|
542
|
-
* Whether to throw an error if the PHP process exits with a non-zero code
|
|
543
|
-
* or outputs to stderr.
|
|
544
|
-
*/
|
|
545
|
-
throwOnError?: boolean;
|
|
546
549
|
}
|
|
547
550
|
export interface RmDirOptions {
|
|
548
551
|
/**
|
|
@@ -570,6 +573,10 @@ declare const SupportedPHPVersions: readonly [
|
|
|
570
573
|
"7.0"
|
|
571
574
|
];
|
|
572
575
|
export type SupportedPHPVersion = (typeof SupportedPHPVersions)[number];
|
|
576
|
+
export type RewriteRule = {
|
|
577
|
+
match: RegExp;
|
|
578
|
+
replacement: string;
|
|
579
|
+
};
|
|
573
580
|
export interface PHPRequestHandlerConfiguration {
|
|
574
581
|
/**
|
|
575
582
|
* The directory in the PHP filesystem where the server will look
|
|
@@ -580,9 +587,14 @@ export interface PHPRequestHandlerConfiguration {
|
|
|
580
587
|
* Request Handler URL. Used to populate $_SERVER details like HTTP_HOST.
|
|
581
588
|
*/
|
|
582
589
|
absoluteUrl?: string;
|
|
590
|
+
/**
|
|
591
|
+
* Rewrite rules
|
|
592
|
+
*/
|
|
593
|
+
rewriteRules?: RewriteRule[];
|
|
583
594
|
}
|
|
584
595
|
declare class PHPRequestHandler implements RequestHandler {
|
|
585
596
|
#private;
|
|
597
|
+
rewriteRules: RewriteRule[];
|
|
586
598
|
/**
|
|
587
599
|
* The PHP instance
|
|
588
600
|
*/
|
package/index.js
CHANGED
|
@@ -6,7 +6,7 @@ var c = (e, t, r) => (K(e, t, "read from private field"), r ? r.call(e) : t.get(
|
|
|
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
|
-
},
|
|
9
|
+
}, h = (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;
|
|
@@ -254,6 +254,11 @@ class Semaphore {
|
|
|
254
254
|
}
|
|
255
255
|
}
|
|
256
256
|
}
|
|
257
|
+
class PhpWasmError extends Error {
|
|
258
|
+
constructor(t, r) {
|
|
259
|
+
super(t), this.userFriendlyMessage = r, this.userFriendlyMessage || (this.userFriendlyMessage = t);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
257
262
|
function joinPaths(...e) {
|
|
258
263
|
let t = e.join("/");
|
|
259
264
|
const r = t[0] === "/", s = t.substring(t.length - 1) === "/";
|
|
@@ -417,16 +422,16 @@ const SupportedPHPVersions = [
|
|
|
417
422
|
"7.1",
|
|
418
423
|
"7.0"
|
|
419
424
|
], LatestSupportedPHPVersion = SupportedPHPVersions[0];
|
|
420
|
-
var
|
|
425
|
+
var R, T;
|
|
421
426
|
class PHPBrowser {
|
|
422
427
|
/**
|
|
423
428
|
* @param server - The PHP server to browse.
|
|
424
429
|
* @param config - The browser configuration.
|
|
425
430
|
*/
|
|
426
431
|
constructor(t, r = {}) {
|
|
427
|
-
d(this,
|
|
432
|
+
d(this, R, void 0);
|
|
428
433
|
d(this, T, void 0);
|
|
429
|
-
this.requestHandler = t,
|
|
434
|
+
this.requestHandler = t, h(this, R, {}), h(this, T, {
|
|
430
435
|
handleRedirects: !1,
|
|
431
436
|
maxRedirects: 4,
|
|
432
437
|
...r
|
|
@@ -492,19 +497,19 @@ class PHPBrowser {
|
|
|
492
497
|
if (!r.includes("="))
|
|
493
498
|
continue;
|
|
494
499
|
const s = r.indexOf("="), n = r.substring(0, s), o = r.substring(s + 1).split(";")[0];
|
|
495
|
-
c(this,
|
|
500
|
+
c(this, R)[n] = o;
|
|
496
501
|
} catch (s) {
|
|
497
502
|
console.error(s);
|
|
498
503
|
}
|
|
499
504
|
}
|
|
500
505
|
serializeCookies() {
|
|
501
506
|
const t = [];
|
|
502
|
-
for (const r in c(this,
|
|
503
|
-
t.push(`${r}=${c(this,
|
|
507
|
+
for (const r in c(this, R))
|
|
508
|
+
t.push(`${r}=${c(this, R)[r]}`);
|
|
504
509
|
return t.join("; ");
|
|
505
510
|
}
|
|
506
511
|
}
|
|
507
|
-
|
|
512
|
+
R = new WeakMap(), T = new WeakMap();
|
|
508
513
|
const DEFAULT_BASE_URL = "http://example.com";
|
|
509
514
|
function toRelativeUrl(e) {
|
|
510
515
|
return e.toString().substring(e.origin.length);
|
|
@@ -543,7 +548,7 @@ function fileToUint8Array(e) {
|
|
|
543
548
|
}, r.readAsArrayBuffer(e);
|
|
544
549
|
});
|
|
545
550
|
}
|
|
546
|
-
var g, H, N,
|
|
551
|
+
var g, H, N, b, k, y, C, S, L, Z, O, X, U, ee;
|
|
547
552
|
class PHPRequestHandler {
|
|
548
553
|
/**
|
|
549
554
|
* @param php - The PHP instance.
|
|
@@ -578,28 +583,29 @@ class PHPRequestHandler {
|
|
|
578
583
|
d(this, g, void 0);
|
|
579
584
|
d(this, H, void 0);
|
|
580
585
|
d(this, N, void 0);
|
|
581
|
-
d(this,
|
|
586
|
+
d(this, b, void 0);
|
|
582
587
|
d(this, k, void 0);
|
|
583
588
|
d(this, y, void 0);
|
|
584
589
|
d(this, C, void 0);
|
|
585
590
|
d(this, S, void 0);
|
|
586
|
-
|
|
591
|
+
h(this, S, new Semaphore({ concurrency: 1 }));
|
|
587
592
|
const {
|
|
588
593
|
documentRoot: s = "/www/",
|
|
589
|
-
absoluteUrl: n = typeof location == "object" ? location == null ? void 0 : location.href : ""
|
|
594
|
+
absoluteUrl: n = typeof location == "object" ? location == null ? void 0 : location.href : "",
|
|
595
|
+
rewriteRules: o = []
|
|
590
596
|
} = r;
|
|
591
|
-
this.php = t,
|
|
592
|
-
const
|
|
593
|
-
|
|
594
|
-
const
|
|
595
|
-
|
|
597
|
+
this.php = t, h(this, g, s);
|
|
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, [
|
|
596
602
|
c(this, N),
|
|
597
|
-
|
|
598
|
-
].join("")),
|
|
603
|
+
a ? `:${c(this, b)}` : ""
|
|
604
|
+
].join("")), h(this, y, i.pathname.replace(/\/+$/, "")), h(this, C, [
|
|
599
605
|
`${c(this, H)}://`,
|
|
600
606
|
c(this, k),
|
|
601
607
|
c(this, y)
|
|
602
|
-
].join(""));
|
|
608
|
+
].join("")), this.rewriteRules = o;
|
|
603
609
|
}
|
|
604
610
|
/** @inheritDoc */
|
|
605
611
|
pathToInternalUrl(t) {
|
|
@@ -624,16 +630,17 @@ class PHPRequestHandler {
|
|
|
624
630
|
/** @inheritDoc */
|
|
625
631
|
async request(t) {
|
|
626
632
|
const r = t.url.startsWith("http://") || t.url.startsWith("https://"), s = new URL(
|
|
627
|
-
|
|
633
|
+
// Remove the hash part of the URL as it's not meant for the server.
|
|
634
|
+
t.url.split("#")[0],
|
|
628
635
|
r ? void 0 : DEFAULT_BASE_URL
|
|
629
|
-
), n =
|
|
630
|
-
s.pathname,
|
|
631
|
-
|
|
636
|
+
), n = applyRewriteRules(
|
|
637
|
+
removePathPrefix(s.pathname, c(this, y)),
|
|
638
|
+
this.rewriteRules
|
|
632
639
|
), o = `${c(this, g)}${n}`;
|
|
633
640
|
return seemsLikeAPHPRequestHandlerPath(o) ? await f(this, O, X).call(this, t, s) : f(this, L, Z).call(this, o);
|
|
634
641
|
}
|
|
635
642
|
}
|
|
636
|
-
g = new WeakMap(), H = new WeakMap(), N = new WeakMap(),
|
|
643
|
+
g = new WeakMap(), H = new WeakMap(), N = new WeakMap(), b = new WeakMap(), k = new WeakMap(), y = new WeakMap(), C = new WeakMap(), S = new WeakMap(), L = new WeakSet(), Z = function(t) {
|
|
637
644
|
if (!this.php.fileExists(t))
|
|
638
645
|
return new PHPResponse(
|
|
639
646
|
404,
|
|
@@ -659,7 +666,7 @@ g = new WeakMap(), H = new WeakMap(), N = new WeakMap(), R = new WeakMap(), k =
|
|
|
659
666
|
r
|
|
660
667
|
);
|
|
661
668
|
}, O = new WeakSet(), X = async function(t, r) {
|
|
662
|
-
var n
|
|
669
|
+
var n;
|
|
663
670
|
if (c(this, S).running > 0 && ((n = t.headers) == null ? void 0 : n["x-request-issuer"]) === "php")
|
|
664
671
|
return console.warn(
|
|
665
672
|
"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."
|
|
@@ -674,28 +681,20 @@ g = new WeakMap(), H = new WeakMap(), N = new WeakMap(), R = new WeakMap(), k =
|
|
|
674
681
|
"HTTPS",
|
|
675
682
|
c(this, C).startsWith("https://") ? "on" : ""
|
|
676
683
|
);
|
|
677
|
-
let
|
|
678
|
-
const
|
|
684
|
+
let o = "GET";
|
|
685
|
+
const i = {
|
|
679
686
|
host: c(this, k),
|
|
680
687
|
...normalizeHeaders(t.headers || {})
|
|
681
688
|
};
|
|
682
|
-
let
|
|
683
|
-
if (typeof
|
|
684
|
-
|
|
685
|
-
const { bytes:
|
|
686
|
-
|
|
689
|
+
let a = t.body;
|
|
690
|
+
if (typeof a == "object" && !(a instanceof Uint8Array)) {
|
|
691
|
+
o = "POST";
|
|
692
|
+
const { bytes: u, contentType: p } = await encodeAsMultipart(a);
|
|
693
|
+
a = u, i["content-type"] = p;
|
|
687
694
|
}
|
|
688
|
-
let
|
|
695
|
+
let l;
|
|
689
696
|
try {
|
|
690
|
-
|
|
691
|
-
if ((o = t.headers) != null && o["x-rewrite-url"])
|
|
692
|
-
try {
|
|
693
|
-
h = new URL(
|
|
694
|
-
t.headers["x-rewrite-url"]
|
|
695
|
-
).pathname;
|
|
696
|
-
} catch {
|
|
697
|
-
}
|
|
698
|
-
u = f(this, U, ee).call(this, h);
|
|
697
|
+
l = f(this, U, ee).call(this, r.pathname);
|
|
699
698
|
} catch {
|
|
700
699
|
return new PHPResponse(
|
|
701
700
|
404,
|
|
@@ -709,17 +708,17 @@ g = new WeakMap(), H = new WeakMap(), N = new WeakMap(), R = new WeakMap(), k =
|
|
|
709
708
|
c(this, y)
|
|
710
709
|
),
|
|
711
710
|
protocol: c(this, H),
|
|
712
|
-
method: t.method ||
|
|
713
|
-
body:
|
|
714
|
-
scriptPath:
|
|
715
|
-
headers:
|
|
711
|
+
method: t.method || o,
|
|
712
|
+
body: a,
|
|
713
|
+
scriptPath: l,
|
|
714
|
+
headers: i
|
|
716
715
|
});
|
|
717
716
|
} finally {
|
|
718
717
|
s();
|
|
719
718
|
}
|
|
720
719
|
}, U = new WeakSet(), ee = function(t) {
|
|
721
720
|
let r = removePathPrefix(t, c(this, y));
|
|
722
|
-
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";
|
|
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";
|
|
723
722
|
const s = `${c(this, g)}${r}`;
|
|
724
723
|
if (this.php.fileExists(s))
|
|
725
724
|
return s;
|
|
@@ -774,6 +773,12 @@ function seemsLikeAPHPFile(e) {
|
|
|
774
773
|
function seemsLikeADirectoryRoot(e) {
|
|
775
774
|
return !e.split("/").pop().includes(".");
|
|
776
775
|
}
|
|
776
|
+
function applyRewriteRules(e, t) {
|
|
777
|
+
for (const r of t)
|
|
778
|
+
if (new RegExp(r.match).test(e))
|
|
779
|
+
return e.replace(r.match, r.replacement);
|
|
780
|
+
return e;
|
|
781
|
+
}
|
|
777
782
|
const FileErrorCodes = {
|
|
778
783
|
0: "No error occurred. System call completed successfully.",
|
|
779
784
|
1: "Argument list too long.",
|
|
@@ -867,8 +872,8 @@ function rethrowFileSystemError(e = "") {
|
|
|
867
872
|
} catch (a) {
|
|
868
873
|
const l = typeof a == "object" ? a == null ? void 0 : a.errno : null;
|
|
869
874
|
if (l in FileErrorCodes) {
|
|
870
|
-
const u = FileErrorCodes[l],
|
|
871
|
-
throw new Error(`${
|
|
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}`, {
|
|
872
877
|
cause: a
|
|
873
878
|
});
|
|
874
879
|
}
|
|
@@ -919,7 +924,7 @@ var __defProp = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyD
|
|
|
919
924
|
return s && n && __defProp(t, r, n), n;
|
|
920
925
|
};
|
|
921
926
|
const STRING = "string", NUMBER = "number", __private__dont__use = Symbol("__private__dont__use");
|
|
922
|
-
var x, F, A, w, E, v, P, M, W, te,
|
|
927
|
+
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;
|
|
923
928
|
class BasePHP {
|
|
924
929
|
/**
|
|
925
930
|
* Initializes a PHP runtime.
|
|
@@ -930,8 +935,8 @@ class BasePHP {
|
|
|
930
935
|
*/
|
|
931
936
|
constructor(e, t) {
|
|
932
937
|
d(this, W);
|
|
933
|
-
d(this, B);
|
|
934
938
|
d(this, q);
|
|
939
|
+
d(this, B);
|
|
935
940
|
d(this, D);
|
|
936
941
|
d(this, $);
|
|
937
942
|
d(this, z);
|
|
@@ -949,7 +954,7 @@ class BasePHP {
|
|
|
949
954
|
d(this, v, void 0);
|
|
950
955
|
d(this, P, void 0);
|
|
951
956
|
d(this, M, void 0);
|
|
952
|
-
|
|
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(
|
|
953
958
|
new PHPRequestHandler(this, t)
|
|
954
959
|
));
|
|
955
960
|
}
|
|
@@ -1005,7 +1010,7 @@ class BasePHP {
|
|
|
1005
1010
|
return n;
|
|
1006
1011
|
}
|
|
1007
1012
|
return "";
|
|
1008
|
-
},
|
|
1013
|
+
}, h(this, E, improveWASMErrorReporting(t)), this.dispatchEvent({
|
|
1009
1014
|
type: "runtime.initialized"
|
|
1010
1015
|
});
|
|
1011
1016
|
}
|
|
@@ -1020,13 +1025,13 @@ class BasePHP {
|
|
|
1020
1025
|
throw new Error(
|
|
1021
1026
|
"Could not set SAPI name. This can only be done before the PHP WASM module is initialized.Did you already dispatch any requests?"
|
|
1022
1027
|
);
|
|
1023
|
-
|
|
1028
|
+
h(this, A, e);
|
|
1024
1029
|
}
|
|
1025
1030
|
/** @inheritDoc */
|
|
1026
1031
|
setPhpIniPath(e) {
|
|
1027
1032
|
if (c(this, w))
|
|
1028
1033
|
throw new Error("Cannot set PHP ini path after calling run().");
|
|
1029
|
-
|
|
1034
|
+
h(this, F, e), this[__private__dont__use].ccall(
|
|
1030
1035
|
"wasm_set_phpini_path",
|
|
1031
1036
|
null,
|
|
1032
1037
|
["string"],
|
|
@@ -1054,18 +1059,18 @@ class BasePHP {
|
|
|
1054
1059
|
const t = await this.semaphore.acquire();
|
|
1055
1060
|
let r;
|
|
1056
1061
|
try {
|
|
1057
|
-
if (c(this, w) || (f(this, W, te).call(this),
|
|
1062
|
+
if (c(this, w) || (f(this, W, te).call(this), h(this, w, !0)), e.scriptPath && !this.fileExists(e.scriptPath))
|
|
1058
1063
|
throw new Error(
|
|
1059
1064
|
`The script path "${e.scriptPath}" does not exist.`
|
|
1060
1065
|
);
|
|
1061
|
-
f(this, G, le).call(this, e.scriptPath || ""), f(this,
|
|
1066
|
+
f(this, G, le).call(this, e.scriptPath || ""), f(this, B, se).call(this, e.relativeUri || ""), f(this, $, ie).call(this, e.method || "GET");
|
|
1062
1067
|
const s = normalizeHeaders(e.headers || {}), n = s.host || "example.com:443";
|
|
1063
1068
|
f(this, D, ne).call(this, n, e.protocol || "http"), f(this, z, oe).call(this, s), e.body && (r = f(this, j, ae).call(this, e.body)), typeof e.code == "string" && f(this, Q, de).call(this, " ?>" + e.code), f(this, V, ce).call(this);
|
|
1064
1069
|
const o = e.env || {};
|
|
1065
1070
|
for (const a in o)
|
|
1066
1071
|
f(this, J, ue).call(this, a, o[a]);
|
|
1067
1072
|
const i = await f(this, Y, he).call(this);
|
|
1068
|
-
if (
|
|
1073
|
+
if (i.exitCode !== 0) {
|
|
1069
1074
|
const a = {
|
|
1070
1075
|
stdout: i.text,
|
|
1071
1076
|
stderr: i.errors
|
|
@@ -1074,9 +1079,16 @@ class BasePHP {
|
|
|
1074
1079
|
const l = new Error(
|
|
1075
1080
|
`PHP.run() failed with exit code ${i.exitCode} and the following output: ` + i.errors
|
|
1076
1081
|
);
|
|
1077
|
-
throw l.output = a, console.error(l), l;
|
|
1082
|
+
throw l.output = a, l.source = "request", console.error(l), l;
|
|
1078
1083
|
}
|
|
1079
1084
|
return i;
|
|
1085
|
+
} catch (s) {
|
|
1086
|
+
throw this.dispatchEvent({
|
|
1087
|
+
type: "request.error",
|
|
1088
|
+
error: s,
|
|
1089
|
+
// Distinguish between PHP request and PHP-wasm errors
|
|
1090
|
+
source: s.source ?? "php-wasm"
|
|
1091
|
+
}), s;
|
|
1080
1092
|
} finally {
|
|
1081
1093
|
try {
|
|
1082
1094
|
r && this[__private__dont__use].free(r);
|
|
@@ -1197,7 +1209,7 @@ class BasePHP {
|
|
|
1197
1209
|
this[__private__dont__use]._exit(e);
|
|
1198
1210
|
} catch {
|
|
1199
1211
|
}
|
|
1200
|
-
|
|
1212
|
+
h(this, w, !1), h(this, E, null), delete this[__private__dont__use].onMessage, delete this[__private__dont__use];
|
|
1201
1213
|
}
|
|
1202
1214
|
}
|
|
1203
1215
|
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() {
|
|
@@ -1225,7 +1237,7 @@ x = new WeakMap(), F = new WeakMap(), A = new WeakMap(), w = new WeakMap(), E =
|
|
|
1225
1237
|
);
|
|
1226
1238
|
}
|
|
1227
1239
|
this[__private__dont__use].ccall("php_wasm_init", null, [], []);
|
|
1228
|
-
},
|
|
1240
|
+
}, q = new WeakSet(), re = function() {
|
|
1229
1241
|
const e = "/internal/headers.json";
|
|
1230
1242
|
if (!this.fileExists(e))
|
|
1231
1243
|
throw new Error(
|
|
@@ -1242,7 +1254,7 @@ x = new WeakMap(), F = new WeakMap(), A = new WeakMap(), w = new WeakMap(), E =
|
|
|
1242
1254
|
headers: r,
|
|
1243
1255
|
httpStatusCode: t.status
|
|
1244
1256
|
};
|
|
1245
|
-
},
|
|
1257
|
+
}, B = new WeakSet(), se = function(e) {
|
|
1246
1258
|
if (this[__private__dont__use].ccall(
|
|
1247
1259
|
"wasm_set_request_uri",
|
|
1248
1260
|
null,
|
|
@@ -1366,8 +1378,8 @@ x = new WeakMap(), F = new WeakMap(), A = new WeakMap(), w = new WeakMap(), E =
|
|
|
1366
1378
|
var l;
|
|
1367
1379
|
t = (u) => {
|
|
1368
1380
|
console.error(u), console.error(u.error);
|
|
1369
|
-
const
|
|
1370
|
-
|
|
1381
|
+
const p = new Error("Rethrown");
|
|
1382
|
+
p.cause = u.error, p.betterMessage = u.message, i(p);
|
|
1371
1383
|
}, (l = c(this, E)) == null || l.addEventListener(
|
|
1372
1384
|
"error",
|
|
1373
1385
|
t
|
|
@@ -1392,9 +1404,9 @@ x = new WeakMap(), F = new WeakMap(), A = new WeakMap(), w = new WeakMap(), E =
|
|
|
1392
1404
|
const i = o, a = "betterMessage" in i ? i.betterMessage : i.message, l = new Error(a);
|
|
1393
1405
|
throw l.cause = i, console.error(l), l;
|
|
1394
1406
|
} finally {
|
|
1395
|
-
(n = c(this, E)) == null || n.removeEventListener("error", t),
|
|
1407
|
+
(n = c(this, E)) == null || n.removeEventListener("error", t), h(this, v, {});
|
|
1396
1408
|
}
|
|
1397
|
-
const { headers: r, httpStatusCode: s } = f(this,
|
|
1409
|
+
const { headers: r, httpStatusCode: s } = f(this, q, re).call(this);
|
|
1398
1410
|
return new PHPResponse(
|
|
1399
1411
|
s,
|
|
1400
1412
|
r,
|
|
@@ -1508,27 +1520,27 @@ function expose(e, t = globalThis, r = ["*"]) {
|
|
|
1508
1520
|
const { id: o, type: i, path: a } = Object.assign({ path: [] }, n.data), l = (n.data.argumentList || []).map(fromWireValue);
|
|
1509
1521
|
let u;
|
|
1510
1522
|
try {
|
|
1511
|
-
const
|
|
1523
|
+
const p = a.slice(0, -1).reduce((m, I) => m[I], e), _ = a.reduce((m, I) => m[I], e);
|
|
1512
1524
|
switch (i) {
|
|
1513
1525
|
case "GET":
|
|
1514
|
-
u =
|
|
1526
|
+
u = _;
|
|
1515
1527
|
break;
|
|
1516
1528
|
case "SET":
|
|
1517
|
-
|
|
1529
|
+
p[a.slice(-1)[0]] = fromWireValue(n.data.value), u = !0;
|
|
1518
1530
|
break;
|
|
1519
1531
|
case "APPLY":
|
|
1520
|
-
u =
|
|
1532
|
+
u = _.apply(p, l);
|
|
1521
1533
|
break;
|
|
1522
1534
|
case "CONSTRUCT":
|
|
1523
1535
|
{
|
|
1524
|
-
const
|
|
1525
|
-
u = proxy(
|
|
1536
|
+
const m = new _(...l);
|
|
1537
|
+
u = proxy(m);
|
|
1526
1538
|
}
|
|
1527
1539
|
break;
|
|
1528
1540
|
case "ENDPOINT":
|
|
1529
1541
|
{
|
|
1530
|
-
const { port1:
|
|
1531
|
-
expose(e, I), u = transfer(
|
|
1542
|
+
const { port1: m, port2: I } = new MessageChannel();
|
|
1543
|
+
expose(e, I), u = transfer(m, [m]);
|
|
1532
1544
|
}
|
|
1533
1545
|
break;
|
|
1534
1546
|
case "RELEASE":
|
|
@@ -1537,18 +1549,18 @@ function expose(e, t = globalThis, r = ["*"]) {
|
|
|
1537
1549
|
default:
|
|
1538
1550
|
return;
|
|
1539
1551
|
}
|
|
1540
|
-
} catch (
|
|
1541
|
-
u = { value:
|
|
1552
|
+
} catch (p) {
|
|
1553
|
+
u = { value: p, [throwMarker]: 0 };
|
|
1542
1554
|
}
|
|
1543
|
-
Promise.resolve(u).catch((
|
|
1544
|
-
const [
|
|
1545
|
-
t.postMessage(Object.assign(Object.assign({},
|
|
1546
|
-
}).catch((
|
|
1547
|
-
const [
|
|
1555
|
+
Promise.resolve(u).catch((p) => ({ value: p, [throwMarker]: 0 })).then((p) => {
|
|
1556
|
+
const [_, m] = toWireValue(p);
|
|
1557
|
+
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) => {
|
|
1559
|
+
const [_, m] = toWireValue({
|
|
1548
1560
|
value: new TypeError("Unserializable return value"),
|
|
1549
1561
|
[throwMarker]: 0
|
|
1550
1562
|
});
|
|
1551
|
-
t.postMessage(Object.assign(Object.assign({},
|
|
1563
|
+
t.postMessage(Object.assign(Object.assign({}, _), { id: o }), m);
|
|
1552
1564
|
});
|
|
1553
1565
|
}), t.start && t.start();
|
|
1554
1566
|
}
|
|
@@ -1608,7 +1620,7 @@ function createProxy(e, t = [], r = function() {
|
|
|
1608
1620
|
const [l, u] = toWireValue(a);
|
|
1609
1621
|
return requestResponseMessage(e, {
|
|
1610
1622
|
type: "SET",
|
|
1611
|
-
path: [...t, i].map((
|
|
1623
|
+
path: [...t, i].map((p) => p.toString()),
|
|
1612
1624
|
value: l
|
|
1613
1625
|
}, u).then(fromWireValue);
|
|
1614
1626
|
},
|
|
@@ -1621,12 +1633,12 @@ function createProxy(e, t = [], r = function() {
|
|
|
1621
1633
|
}).then(fromWireValue);
|
|
1622
1634
|
if (l === "bind")
|
|
1623
1635
|
return createProxy(e, t.slice(0, -1));
|
|
1624
|
-
const [u,
|
|
1636
|
+
const [u, p] = processArguments(a);
|
|
1625
1637
|
return requestResponseMessage(e, {
|
|
1626
1638
|
type: "APPLY",
|
|
1627
|
-
path: t.map((
|
|
1639
|
+
path: t.map((_) => _.toString()),
|
|
1628
1640
|
argumentList: u
|
|
1629
|
-
},
|
|
1641
|
+
}, p).then(fromWireValue);
|
|
1630
1642
|
},
|
|
1631
1643
|
construct(o, i) {
|
|
1632
1644
|
throwIfProxyReleased(s);
|
|
@@ -1996,10 +2008,10 @@ function responseTo(e, t) {
|
|
|
1996
2008
|
async function registerServiceWorker(e, t, r) {
|
|
1997
2009
|
const s = navigator.serviceWorker;
|
|
1998
2010
|
if (!s)
|
|
1999
|
-
throw
|
|
2000
|
-
"Service workers are not supported in
|
|
2001
|
-
) : new
|
|
2002
|
-
"WordPress Playground
|
|
2011
|
+
throw window.isSecureContext ? new PhpWasmError(
|
|
2012
|
+
"Service workers are not supported in your browser."
|
|
2013
|
+
) : new PhpWasmError(
|
|
2014
|
+
"WordPress Playground uses service workers and may only work on HTTPS and http://localhost/ sites, but the current site is neither."
|
|
2003
2015
|
);
|
|
2004
2016
|
console.debug("[window][sw] Registering a Service Worker"), await (await s.register(r, {
|
|
2005
2017
|
type: "module",
|
|
@@ -2008,7 +2020,7 @@ async function registerServiceWorker(e, t, r) {
|
|
|
2008
2020
|
})).update(), navigator.serviceWorker.addEventListener(
|
|
2009
2021
|
"message",
|
|
2010
2022
|
async function(i) {
|
|
2011
|
-
if (
|
|
2023
|
+
if (t && i.data.scope !== t)
|
|
2012
2024
|
return;
|
|
2013
2025
|
const a = i.data.args || [], l = i.data.method, u = await e[l](...a);
|
|
2014
2026
|
i.source.postMessage(responseTo(i.data.requestId, u));
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|