@php-wasm/web 0.6.7 → 0.6.8
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 +17 -1
- package/index.js +96 -87
- 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,13 @@ 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
|
+
}
|
|
79
86
|
/**
|
|
80
87
|
* Represents a PHP runtime initialization event.
|
|
81
88
|
*/
|
|
@@ -93,7 +100,7 @@ export interface PHPRuntimeBeforeDestroyEvent {
|
|
|
93
100
|
* This is intentionally not an extension of CustomEvent
|
|
94
101
|
* to make it isomorphic between different JavaScript runtimes.
|
|
95
102
|
*/
|
|
96
|
-
export type PHPEvent = PHPRequestEndEvent | PHPRuntimeInitializedEvent | PHPRuntimeBeforeDestroyEvent;
|
|
103
|
+
export type PHPEvent = PHPRequestEndEvent | PHPRequestErrorEvent | PHPRuntimeInitializedEvent | PHPRuntimeBeforeDestroyEvent;
|
|
97
104
|
/**
|
|
98
105
|
* A callback function that handles PHP events.
|
|
99
106
|
*/
|
|
@@ -570,6 +577,10 @@ declare const SupportedPHPVersions: readonly [
|
|
|
570
577
|
"7.0"
|
|
571
578
|
];
|
|
572
579
|
export type SupportedPHPVersion = (typeof SupportedPHPVersions)[number];
|
|
580
|
+
export type RewriteRule = {
|
|
581
|
+
match: RegExp;
|
|
582
|
+
replacement: string;
|
|
583
|
+
};
|
|
573
584
|
export interface PHPRequestHandlerConfiguration {
|
|
574
585
|
/**
|
|
575
586
|
* The directory in the PHP filesystem where the server will look
|
|
@@ -580,9 +591,14 @@ export interface PHPRequestHandlerConfiguration {
|
|
|
580
591
|
* Request Handler URL. Used to populate $_SERVER details like HTTP_HOST.
|
|
581
592
|
*/
|
|
582
593
|
absoluteUrl?: string;
|
|
594
|
+
/**
|
|
595
|
+
* Rewrite rules
|
|
596
|
+
*/
|
|
597
|
+
rewriteRules?: RewriteRule[];
|
|
583
598
|
}
|
|
584
599
|
declare class PHPRequestHandler implements RequestHandler {
|
|
585
600
|
#private;
|
|
601
|
+
rewriteRules: RewriteRule[];
|
|
586
602
|
/**
|
|
587
603
|
* The PHP instance
|
|
588
604
|
*/
|
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, O, Z, L, X, U, ee;
|
|
547
552
|
class PHPRequestHandler {
|
|
548
553
|
/**
|
|
549
554
|
* @param php - The PHP instance.
|
|
@@ -556,7 +561,7 @@ class PHPRequestHandler {
|
|
|
556
561
|
* @param fsPath - Absolute path of the static file to serve.
|
|
557
562
|
* @returns The response.
|
|
558
563
|
*/
|
|
559
|
-
d(this,
|
|
564
|
+
d(this, O);
|
|
560
565
|
/**
|
|
561
566
|
* Runs the requested PHP file with all the request and $_SERVER
|
|
562
567
|
* superglobals populated.
|
|
@@ -564,7 +569,7 @@ class PHPRequestHandler {
|
|
|
564
569
|
* @param request - The request.
|
|
565
570
|
* @returns The response.
|
|
566
571
|
*/
|
|
567
|
-
d(this,
|
|
572
|
+
d(this, L);
|
|
568
573
|
/**
|
|
569
574
|
* Resolve the requested path to the filesystem path of the requested PHP file.
|
|
570
575
|
*
|
|
@@ -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) {
|
|
@@ -626,14 +632,14 @@ class PHPRequestHandler {
|
|
|
626
632
|
const r = t.url.startsWith("http://") || t.url.startsWith("https://"), s = new URL(
|
|
627
633
|
t.url,
|
|
628
634
|
r ? void 0 : DEFAULT_BASE_URL
|
|
629
|
-
), n =
|
|
630
|
-
s.pathname,
|
|
631
|
-
|
|
635
|
+
), n = applyRewriteRules(
|
|
636
|
+
removePathPrefix(s.pathname, c(this, y)),
|
|
637
|
+
this.rewriteRules
|
|
632
638
|
), o = `${c(this, g)}${n}`;
|
|
633
|
-
return seemsLikeAPHPRequestHandlerPath(o) ? await f(this,
|
|
639
|
+
return seemsLikeAPHPRequestHandlerPath(o) ? await f(this, L, X).call(this, t, s) : f(this, O, Z).call(this, o);
|
|
634
640
|
}
|
|
635
641
|
}
|
|
636
|
-
g = new WeakMap(), H = new WeakMap(), N = new WeakMap(),
|
|
642
|
+
g = new WeakMap(), H = new WeakMap(), N = new WeakMap(), b = new WeakMap(), k = new WeakMap(), y = new WeakMap(), C = new WeakMap(), S = new WeakMap(), O = new WeakSet(), Z = function(t) {
|
|
637
643
|
if (!this.php.fileExists(t))
|
|
638
644
|
return new PHPResponse(
|
|
639
645
|
404,
|
|
@@ -658,8 +664,8 @@ g = new WeakMap(), H = new WeakMap(), N = new WeakMap(), R = new WeakMap(), k =
|
|
|
658
664
|
},
|
|
659
665
|
r
|
|
660
666
|
);
|
|
661
|
-
},
|
|
662
|
-
var n
|
|
667
|
+
}, L = new WeakSet(), X = async function(t, r) {
|
|
668
|
+
var n;
|
|
663
669
|
if (c(this, S).running > 0 && ((n = t.headers) == null ? void 0 : n["x-request-issuer"]) === "php")
|
|
664
670
|
return console.warn(
|
|
665
671
|
"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 +680,20 @@ g = new WeakMap(), H = new WeakMap(), N = new WeakMap(), R = new WeakMap(), k =
|
|
|
674
680
|
"HTTPS",
|
|
675
681
|
c(this, C).startsWith("https://") ? "on" : ""
|
|
676
682
|
);
|
|
677
|
-
let
|
|
678
|
-
const
|
|
683
|
+
let o = "GET";
|
|
684
|
+
const i = {
|
|
679
685
|
host: c(this, k),
|
|
680
686
|
...normalizeHeaders(t.headers || {})
|
|
681
687
|
};
|
|
682
|
-
let
|
|
683
|
-
if (typeof
|
|
684
|
-
|
|
685
|
-
const { bytes:
|
|
686
|
-
|
|
688
|
+
let a = t.body;
|
|
689
|
+
if (typeof a == "object" && !(a instanceof Uint8Array)) {
|
|
690
|
+
o = "POST";
|
|
691
|
+
const { bytes: u, contentType: p } = await encodeAsMultipart(a);
|
|
692
|
+
a = u, i["content-type"] = p;
|
|
687
693
|
}
|
|
688
|
-
let
|
|
694
|
+
let l;
|
|
689
695
|
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);
|
|
696
|
+
l = f(this, U, ee).call(this, r.pathname);
|
|
699
697
|
} catch {
|
|
700
698
|
return new PHPResponse(
|
|
701
699
|
404,
|
|
@@ -709,17 +707,17 @@ g = new WeakMap(), H = new WeakMap(), N = new WeakMap(), R = new WeakMap(), k =
|
|
|
709
707
|
c(this, y)
|
|
710
708
|
),
|
|
711
709
|
protocol: c(this, H),
|
|
712
|
-
method: t.method ||
|
|
713
|
-
body:
|
|
714
|
-
scriptPath:
|
|
715
|
-
headers:
|
|
710
|
+
method: t.method || o,
|
|
711
|
+
body: a,
|
|
712
|
+
scriptPath: l,
|
|
713
|
+
headers: i
|
|
716
714
|
});
|
|
717
715
|
} finally {
|
|
718
716
|
s();
|
|
719
717
|
}
|
|
720
718
|
}, U = new WeakSet(), ee = function(t) {
|
|
721
719
|
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";
|
|
720
|
+
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
721
|
const s = `${c(this, g)}${r}`;
|
|
724
722
|
if (this.php.fileExists(s))
|
|
725
723
|
return s;
|
|
@@ -774,6 +772,12 @@ function seemsLikeAPHPFile(e) {
|
|
|
774
772
|
function seemsLikeADirectoryRoot(e) {
|
|
775
773
|
return !e.split("/").pop().includes(".");
|
|
776
774
|
}
|
|
775
|
+
function applyRewriteRules(e, t) {
|
|
776
|
+
for (const r of t)
|
|
777
|
+
if (new RegExp(r.match).test(e))
|
|
778
|
+
return e.replace(r.match, r.replacement);
|
|
779
|
+
return e;
|
|
780
|
+
}
|
|
777
781
|
const FileErrorCodes = {
|
|
778
782
|
0: "No error occurred. System call completed successfully.",
|
|
779
783
|
1: "Argument list too long.",
|
|
@@ -867,8 +871,8 @@ function rethrowFileSystemError(e = "") {
|
|
|
867
871
|
} catch (a) {
|
|
868
872
|
const l = typeof a == "object" ? a == null ? void 0 : a.errno : null;
|
|
869
873
|
if (l in FileErrorCodes) {
|
|
870
|
-
const u = FileErrorCodes[l],
|
|
871
|
-
throw new Error(`${
|
|
874
|
+
const u = FileErrorCodes[l], p = typeof i[0] == "string" ? i[0] : null, _ = p !== null ? e.replaceAll("{path}", p) : e;
|
|
875
|
+
throw new Error(`${_}: ${u}`, {
|
|
872
876
|
cause: a
|
|
873
877
|
});
|
|
874
878
|
}
|
|
@@ -949,7 +953,7 @@ class BasePHP {
|
|
|
949
953
|
d(this, v, void 0);
|
|
950
954
|
d(this, P, void 0);
|
|
951
955
|
d(this, M, void 0);
|
|
952
|
-
|
|
956
|
+
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
957
|
new PHPRequestHandler(this, t)
|
|
954
958
|
));
|
|
955
959
|
}
|
|
@@ -1005,7 +1009,7 @@ class BasePHP {
|
|
|
1005
1009
|
return n;
|
|
1006
1010
|
}
|
|
1007
1011
|
return "";
|
|
1008
|
-
},
|
|
1012
|
+
}, h(this, E, improveWASMErrorReporting(t)), this.dispatchEvent({
|
|
1009
1013
|
type: "runtime.initialized"
|
|
1010
1014
|
});
|
|
1011
1015
|
}
|
|
@@ -1020,13 +1024,13 @@ class BasePHP {
|
|
|
1020
1024
|
throw new Error(
|
|
1021
1025
|
"Could not set SAPI name. This can only be done before the PHP WASM module is initialized.Did you already dispatch any requests?"
|
|
1022
1026
|
);
|
|
1023
|
-
|
|
1027
|
+
h(this, A, e);
|
|
1024
1028
|
}
|
|
1025
1029
|
/** @inheritDoc */
|
|
1026
1030
|
setPhpIniPath(e) {
|
|
1027
1031
|
if (c(this, w))
|
|
1028
1032
|
throw new Error("Cannot set PHP ini path after calling run().");
|
|
1029
|
-
|
|
1033
|
+
h(this, F, e), this[__private__dont__use].ccall(
|
|
1030
1034
|
"wasm_set_phpini_path",
|
|
1031
1035
|
null,
|
|
1032
1036
|
["string"],
|
|
@@ -1054,7 +1058,7 @@ class BasePHP {
|
|
|
1054
1058
|
const t = await this.semaphore.acquire();
|
|
1055
1059
|
let r;
|
|
1056
1060
|
try {
|
|
1057
|
-
if (c(this, w) || (f(this, W, te).call(this),
|
|
1061
|
+
if (c(this, w) || (f(this, W, te).call(this), h(this, w, !0)), e.scriptPath && !this.fileExists(e.scriptPath))
|
|
1058
1062
|
throw new Error(
|
|
1059
1063
|
`The script path "${e.scriptPath}" does not exist.`
|
|
1060
1064
|
);
|
|
@@ -1077,6 +1081,11 @@ class BasePHP {
|
|
|
1077
1081
|
throw l.output = a, console.error(l), l;
|
|
1078
1082
|
}
|
|
1079
1083
|
return i;
|
|
1084
|
+
} catch (s) {
|
|
1085
|
+
throw this.dispatchEvent({
|
|
1086
|
+
type: "request.error",
|
|
1087
|
+
error: s
|
|
1088
|
+
}), s;
|
|
1080
1089
|
} finally {
|
|
1081
1090
|
try {
|
|
1082
1091
|
r && this[__private__dont__use].free(r);
|
|
@@ -1197,7 +1206,7 @@ class BasePHP {
|
|
|
1197
1206
|
this[__private__dont__use]._exit(e);
|
|
1198
1207
|
} catch {
|
|
1199
1208
|
}
|
|
1200
|
-
|
|
1209
|
+
h(this, w, !1), h(this, E, null), delete this[__private__dont__use].onMessage, delete this[__private__dont__use];
|
|
1201
1210
|
}
|
|
1202
1211
|
}
|
|
1203
1212
|
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() {
|
|
@@ -1366,8 +1375,8 @@ x = new WeakMap(), F = new WeakMap(), A = new WeakMap(), w = new WeakMap(), E =
|
|
|
1366
1375
|
var l;
|
|
1367
1376
|
t = (u) => {
|
|
1368
1377
|
console.error(u), console.error(u.error);
|
|
1369
|
-
const
|
|
1370
|
-
|
|
1378
|
+
const p = new Error("Rethrown");
|
|
1379
|
+
p.cause = u.error, p.betterMessage = u.message, i(p);
|
|
1371
1380
|
}, (l = c(this, E)) == null || l.addEventListener(
|
|
1372
1381
|
"error",
|
|
1373
1382
|
t
|
|
@@ -1392,7 +1401,7 @@ x = new WeakMap(), F = new WeakMap(), A = new WeakMap(), w = new WeakMap(), E =
|
|
|
1392
1401
|
const i = o, a = "betterMessage" in i ? i.betterMessage : i.message, l = new Error(a);
|
|
1393
1402
|
throw l.cause = i, console.error(l), l;
|
|
1394
1403
|
} finally {
|
|
1395
|
-
(n = c(this, E)) == null || n.removeEventListener("error", t),
|
|
1404
|
+
(n = c(this, E)) == null || n.removeEventListener("error", t), h(this, v, {});
|
|
1396
1405
|
}
|
|
1397
1406
|
const { headers: r, httpStatusCode: s } = f(this, B, re).call(this);
|
|
1398
1407
|
return new PHPResponse(
|
|
@@ -1508,27 +1517,27 @@ function expose(e, t = globalThis, r = ["*"]) {
|
|
|
1508
1517
|
const { id: o, type: i, path: a } = Object.assign({ path: [] }, n.data), l = (n.data.argumentList || []).map(fromWireValue);
|
|
1509
1518
|
let u;
|
|
1510
1519
|
try {
|
|
1511
|
-
const
|
|
1520
|
+
const p = a.slice(0, -1).reduce((m, I) => m[I], e), _ = a.reduce((m, I) => m[I], e);
|
|
1512
1521
|
switch (i) {
|
|
1513
1522
|
case "GET":
|
|
1514
|
-
u =
|
|
1523
|
+
u = _;
|
|
1515
1524
|
break;
|
|
1516
1525
|
case "SET":
|
|
1517
|
-
|
|
1526
|
+
p[a.slice(-1)[0]] = fromWireValue(n.data.value), u = !0;
|
|
1518
1527
|
break;
|
|
1519
1528
|
case "APPLY":
|
|
1520
|
-
u =
|
|
1529
|
+
u = _.apply(p, l);
|
|
1521
1530
|
break;
|
|
1522
1531
|
case "CONSTRUCT":
|
|
1523
1532
|
{
|
|
1524
|
-
const
|
|
1525
|
-
u = proxy(
|
|
1533
|
+
const m = new _(...l);
|
|
1534
|
+
u = proxy(m);
|
|
1526
1535
|
}
|
|
1527
1536
|
break;
|
|
1528
1537
|
case "ENDPOINT":
|
|
1529
1538
|
{
|
|
1530
|
-
const { port1:
|
|
1531
|
-
expose(e, I), u = transfer(
|
|
1539
|
+
const { port1: m, port2: I } = new MessageChannel();
|
|
1540
|
+
expose(e, I), u = transfer(m, [m]);
|
|
1532
1541
|
}
|
|
1533
1542
|
break;
|
|
1534
1543
|
case "RELEASE":
|
|
@@ -1537,18 +1546,18 @@ function expose(e, t = globalThis, r = ["*"]) {
|
|
|
1537
1546
|
default:
|
|
1538
1547
|
return;
|
|
1539
1548
|
}
|
|
1540
|
-
} catch (
|
|
1541
|
-
u = { value:
|
|
1549
|
+
} catch (p) {
|
|
1550
|
+
u = { value: p, [throwMarker]: 0 };
|
|
1542
1551
|
}
|
|
1543
|
-
Promise.resolve(u).catch((
|
|
1544
|
-
const [
|
|
1545
|
-
t.postMessage(Object.assign(Object.assign({},
|
|
1546
|
-
}).catch((
|
|
1547
|
-
const [
|
|
1552
|
+
Promise.resolve(u).catch((p) => ({ value: p, [throwMarker]: 0 })).then((p) => {
|
|
1553
|
+
const [_, m] = toWireValue(p);
|
|
1554
|
+
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]());
|
|
1555
|
+
}).catch((p) => {
|
|
1556
|
+
const [_, m] = toWireValue({
|
|
1548
1557
|
value: new TypeError("Unserializable return value"),
|
|
1549
1558
|
[throwMarker]: 0
|
|
1550
1559
|
});
|
|
1551
|
-
t.postMessage(Object.assign(Object.assign({},
|
|
1560
|
+
t.postMessage(Object.assign(Object.assign({}, _), { id: o }), m);
|
|
1552
1561
|
});
|
|
1553
1562
|
}), t.start && t.start();
|
|
1554
1563
|
}
|
|
@@ -1608,7 +1617,7 @@ function createProxy(e, t = [], r = function() {
|
|
|
1608
1617
|
const [l, u] = toWireValue(a);
|
|
1609
1618
|
return requestResponseMessage(e, {
|
|
1610
1619
|
type: "SET",
|
|
1611
|
-
path: [...t, i].map((
|
|
1620
|
+
path: [...t, i].map((p) => p.toString()),
|
|
1612
1621
|
value: l
|
|
1613
1622
|
}, u).then(fromWireValue);
|
|
1614
1623
|
},
|
|
@@ -1621,12 +1630,12 @@ function createProxy(e, t = [], r = function() {
|
|
|
1621
1630
|
}).then(fromWireValue);
|
|
1622
1631
|
if (l === "bind")
|
|
1623
1632
|
return createProxy(e, t.slice(0, -1));
|
|
1624
|
-
const [u,
|
|
1633
|
+
const [u, p] = processArguments(a);
|
|
1625
1634
|
return requestResponseMessage(e, {
|
|
1626
1635
|
type: "APPLY",
|
|
1627
|
-
path: t.map((
|
|
1636
|
+
path: t.map((_) => _.toString()),
|
|
1628
1637
|
argumentList: u
|
|
1629
|
-
},
|
|
1638
|
+
}, p).then(fromWireValue);
|
|
1630
1639
|
},
|
|
1631
1640
|
construct(o, i) {
|
|
1632
1641
|
throwIfProxyReleased(s);
|
|
@@ -1996,10 +2005,10 @@ function responseTo(e, t) {
|
|
|
1996
2005
|
async function registerServiceWorker(e, t, r) {
|
|
1997
2006
|
const s = navigator.serviceWorker;
|
|
1998
2007
|
if (!s)
|
|
1999
|
-
throw
|
|
2000
|
-
"Service workers are not supported in
|
|
2001
|
-
) : new
|
|
2002
|
-
"WordPress Playground
|
|
2008
|
+
throw window.isSecureContext ? new PhpWasmError(
|
|
2009
|
+
"Service workers are not supported in your browser."
|
|
2010
|
+
) : new PhpWasmError(
|
|
2011
|
+
"WordPress Playground uses service workers and may only work on HTTPS and http://localhost/ sites, but the current site is neither."
|
|
2003
2012
|
);
|
|
2004
2013
|
console.debug("[window][sw] Registering a Service Worker"), await (await s.register(r, {
|
|
2005
2014
|
type: "module",
|
|
@@ -2008,7 +2017,7 @@ async function registerServiceWorker(e, t, r) {
|
|
|
2008
2017
|
})).update(), navigator.serviceWorker.addEventListener(
|
|
2009
2018
|
"message",
|
|
2010
2019
|
async function(i) {
|
|
2011
|
-
if (
|
|
2020
|
+
if (t && i.data.scope !== t)
|
|
2012
2021
|
return;
|
|
2013
2022
|
const a = i.data.args || [], l = i.data.method, u = await e[l](...a);
|
|
2014
2023
|
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
|