@php-wasm/web 0.6.6 → 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 +169 -150
- 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.js
CHANGED
|
@@ -6,58 +6,68 @@ 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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
const currentJsRuntime$1 = function() {
|
|
12
|
+
var e;
|
|
13
|
+
return typeof process < "u" && ((e = process.release) == null ? void 0 : e.name) === "node" ? "NODE" : typeof window < "u" ? "WEB" : (
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
typeof WorkerGlobalScope < "u" && // @ts-ignore
|
|
16
|
+
self instanceof WorkerGlobalScope ? "WORKER" : "NODE"
|
|
17
|
+
);
|
|
18
|
+
}();
|
|
19
|
+
if (currentJsRuntime$1 === "NODE") {
|
|
20
|
+
let e = function(r) {
|
|
21
|
+
return new Promise(function(s, n) {
|
|
22
|
+
r.onload = r.onerror = function(o) {
|
|
23
|
+
r.onload = r.onerror = null, o.type === "load" ? s(r.result) : n(new Error("Failed to read the blob/file"));
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
}, t = function() {
|
|
27
|
+
const r = new Uint8Array([1, 2, 3, 4]), n = new File([r], "test").stream();
|
|
28
|
+
try {
|
|
29
|
+
return n.getReader({ mode: "byob" }), !0;
|
|
30
|
+
} catch {
|
|
31
|
+
return !1;
|
|
17
32
|
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
typeof Blob.prototype.arrayBuffer > "u" && (Blob.prototype.arrayBuffer = function() {
|
|
29
|
-
const t = new FileReader();
|
|
30
|
-
return t.readAsArrayBuffer(this), asPromise(t);
|
|
31
|
-
});
|
|
32
|
-
typeof Blob.prototype.text > "u" && (Blob.prototype.text = function() {
|
|
33
|
-
const t = new FileReader();
|
|
34
|
-
return t.readAsText(this), asPromise(t);
|
|
35
|
-
});
|
|
36
|
-
function isByobSupported() {
|
|
37
|
-
const e = new Uint8Array([1, 2, 3, 4]), r = new File([e], "test").stream();
|
|
38
|
-
try {
|
|
39
|
-
return r.getReader({ mode: "byob" }), !0;
|
|
40
|
-
} catch {
|
|
41
|
-
return !1;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
(typeof Blob.prototype.stream > "u" || !isByobSupported()) && (Blob.prototype.stream = function() {
|
|
45
|
-
let e = 0;
|
|
46
|
-
const t = this;
|
|
47
|
-
return new ReadableStream({
|
|
48
|
-
type: "bytes",
|
|
49
|
-
// 0.5 MB seems like a reasonable chunk size, let's adjust
|
|
50
|
-
// this if needed.
|
|
51
|
-
autoAllocateChunkSize: 512 * 1024,
|
|
52
|
-
async pull(r) {
|
|
53
|
-
const s = r.byobRequest.view, o = await t.slice(e, e + s.byteLength).arrayBuffer(), i = new Uint8Array(o);
|
|
54
|
-
new Uint8Array(s.buffer).set(i);
|
|
55
|
-
const a = i.byteLength;
|
|
56
|
-
r.byobRequest.respond(a), e += a, e >= t.size && r.close();
|
|
33
|
+
};
|
|
34
|
+
if (typeof File > "u") {
|
|
35
|
+
class r extends Blob {
|
|
36
|
+
constructor(n, o, i) {
|
|
37
|
+
super(n);
|
|
38
|
+
let a;
|
|
39
|
+
i != null && i.lastModified && (a = /* @__PURE__ */ new Date()), (!a || isNaN(a.getFullYear())) && (a = /* @__PURE__ */ new Date()), this.lastModifiedDate = a, this.lastModified = a.getMilliseconds(), this.name = o || "";
|
|
40
|
+
}
|
|
57
41
|
}
|
|
42
|
+
global.File = r;
|
|
43
|
+
}
|
|
44
|
+
typeof Blob.prototype.arrayBuffer > "u" && (Blob.prototype.arrayBuffer = function() {
|
|
45
|
+
const s = new FileReader();
|
|
46
|
+
return s.readAsArrayBuffer(this), e(s);
|
|
47
|
+
}), typeof Blob.prototype.text > "u" && (Blob.prototype.text = function() {
|
|
48
|
+
const s = new FileReader();
|
|
49
|
+
return s.readAsText(this), e(s);
|
|
50
|
+
}), (typeof Blob.prototype.stream > "u" || !t()) && (Blob.prototype.stream = function() {
|
|
51
|
+
let r = 0;
|
|
52
|
+
const s = this;
|
|
53
|
+
return new ReadableStream({
|
|
54
|
+
type: "bytes",
|
|
55
|
+
// 0.5 MB seems like a reasonable chunk size, let's adjust
|
|
56
|
+
// this if needed.
|
|
57
|
+
autoAllocateChunkSize: 512 * 1024,
|
|
58
|
+
async pull(n) {
|
|
59
|
+
const o = n.byobRequest.view, a = await s.slice(
|
|
60
|
+
r,
|
|
61
|
+
r + o.byteLength
|
|
62
|
+
).arrayBuffer(), l = new Uint8Array(a);
|
|
63
|
+
new Uint8Array(o.buffer).set(l);
|
|
64
|
+
const u = l.byteLength;
|
|
65
|
+
n.byobRequest.respond(u), r += u, r >= s.size && n.close();
|
|
66
|
+
}
|
|
67
|
+
});
|
|
58
68
|
});
|
|
59
|
-
}
|
|
60
|
-
if (typeof CustomEvent > "u") {
|
|
69
|
+
}
|
|
70
|
+
if (currentJsRuntime$1 === "NODE" && typeof CustomEvent > "u") {
|
|
61
71
|
class e extends Event {
|
|
62
72
|
constructor(r, s = {}) {
|
|
63
73
|
super(r, s), this.detail = s.detail;
|
|
@@ -244,6 +254,11 @@ class Semaphore {
|
|
|
244
254
|
}
|
|
245
255
|
}
|
|
246
256
|
}
|
|
257
|
+
class PhpWasmError extends Error {
|
|
258
|
+
constructor(t, r) {
|
|
259
|
+
super(t), this.userFriendlyMessage = r, this.userFriendlyMessage || (this.userFriendlyMessage = t);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
247
262
|
function joinPaths(...e) {
|
|
248
263
|
let t = e.join("/");
|
|
249
264
|
const r = t[0] === "/", s = t.substring(t.length - 1) === "/";
|
|
@@ -407,16 +422,16 @@ const SupportedPHPVersions = [
|
|
|
407
422
|
"7.1",
|
|
408
423
|
"7.0"
|
|
409
424
|
], LatestSupportedPHPVersion = SupportedPHPVersions[0];
|
|
410
|
-
var
|
|
425
|
+
var R, T;
|
|
411
426
|
class PHPBrowser {
|
|
412
427
|
/**
|
|
413
428
|
* @param server - The PHP server to browse.
|
|
414
429
|
* @param config - The browser configuration.
|
|
415
430
|
*/
|
|
416
431
|
constructor(t, r = {}) {
|
|
417
|
-
d(this,
|
|
432
|
+
d(this, R, void 0);
|
|
418
433
|
d(this, T, void 0);
|
|
419
|
-
this.requestHandler = t,
|
|
434
|
+
this.requestHandler = t, h(this, R, {}), h(this, T, {
|
|
420
435
|
handleRedirects: !1,
|
|
421
436
|
maxRedirects: 4,
|
|
422
437
|
...r
|
|
@@ -482,19 +497,19 @@ class PHPBrowser {
|
|
|
482
497
|
if (!r.includes("="))
|
|
483
498
|
continue;
|
|
484
499
|
const s = r.indexOf("="), n = r.substring(0, s), o = r.substring(s + 1).split(";")[0];
|
|
485
|
-
c(this,
|
|
500
|
+
c(this, R)[n] = o;
|
|
486
501
|
} catch (s) {
|
|
487
502
|
console.error(s);
|
|
488
503
|
}
|
|
489
504
|
}
|
|
490
505
|
serializeCookies() {
|
|
491
506
|
const t = [];
|
|
492
|
-
for (const r in c(this,
|
|
493
|
-
t.push(`${r}=${c(this,
|
|
507
|
+
for (const r in c(this, R))
|
|
508
|
+
t.push(`${r}=${c(this, R)[r]}`);
|
|
494
509
|
return t.join("; ");
|
|
495
510
|
}
|
|
496
511
|
}
|
|
497
|
-
|
|
512
|
+
R = new WeakMap(), T = new WeakMap();
|
|
498
513
|
const DEFAULT_BASE_URL = "http://example.com";
|
|
499
514
|
function toRelativeUrl(e) {
|
|
500
515
|
return e.toString().substring(e.origin.length);
|
|
@@ -533,7 +548,7 @@ function fileToUint8Array(e) {
|
|
|
533
548
|
}, r.readAsArrayBuffer(e);
|
|
534
549
|
});
|
|
535
550
|
}
|
|
536
|
-
var g, H,
|
|
551
|
+
var g, H, N, b, k, y, C, S, O, Z, L, X, U, ee;
|
|
537
552
|
class PHPRequestHandler {
|
|
538
553
|
/**
|
|
539
554
|
* @param php - The PHP instance.
|
|
@@ -546,7 +561,7 @@ class PHPRequestHandler {
|
|
|
546
561
|
* @param fsPath - Absolute path of the static file to serve.
|
|
547
562
|
* @returns The response.
|
|
548
563
|
*/
|
|
549
|
-
d(this,
|
|
564
|
+
d(this, O);
|
|
550
565
|
/**
|
|
551
566
|
* Runs the requested PHP file with all the request and $_SERVER
|
|
552
567
|
* superglobals populated.
|
|
@@ -554,7 +569,7 @@ class PHPRequestHandler {
|
|
|
554
569
|
* @param request - The request.
|
|
555
570
|
* @returns The response.
|
|
556
571
|
*/
|
|
557
|
-
d(this,
|
|
572
|
+
d(this, L);
|
|
558
573
|
/**
|
|
559
574
|
* Resolve the requested path to the filesystem path of the requested PHP file.
|
|
560
575
|
*
|
|
@@ -564,32 +579,33 @@ class PHPRequestHandler {
|
|
|
564
579
|
* @throws {Error} If the requested path doesn't exist.
|
|
565
580
|
* @returns The resolved filesystem path.
|
|
566
581
|
*/
|
|
567
|
-
d(this,
|
|
582
|
+
d(this, U);
|
|
568
583
|
d(this, g, void 0);
|
|
569
584
|
d(this, H, void 0);
|
|
570
|
-
d(this,
|
|
571
|
-
d(this,
|
|
585
|
+
d(this, N, void 0);
|
|
586
|
+
d(this, b, void 0);
|
|
572
587
|
d(this, k, void 0);
|
|
573
588
|
d(this, y, void 0);
|
|
574
589
|
d(this, C, void 0);
|
|
575
590
|
d(this, S, void 0);
|
|
576
|
-
|
|
591
|
+
h(this, S, new Semaphore({ concurrency: 1 }));
|
|
577
592
|
const {
|
|
578
593
|
documentRoot: s = "/www/",
|
|
579
|
-
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 = []
|
|
580
596
|
} = r;
|
|
581
|
-
this.php = t,
|
|
582
|
-
const
|
|
583
|
-
|
|
584
|
-
const
|
|
585
|
-
|
|
586
|
-
c(this,
|
|
587
|
-
|
|
588
|
-
].join("")),
|
|
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, [
|
|
602
|
+
c(this, N),
|
|
603
|
+
a ? `:${c(this, b)}` : ""
|
|
604
|
+
].join("")), h(this, y, i.pathname.replace(/\/+$/, "")), h(this, C, [
|
|
589
605
|
`${c(this, H)}://`,
|
|
590
606
|
c(this, k),
|
|
591
607
|
c(this, y)
|
|
592
|
-
].join(""));
|
|
608
|
+
].join("")), this.rewriteRules = o;
|
|
593
609
|
}
|
|
594
610
|
/** @inheritDoc */
|
|
595
611
|
pathToInternalUrl(t) {
|
|
@@ -616,14 +632,14 @@ class PHPRequestHandler {
|
|
|
616
632
|
const r = t.url.startsWith("http://") || t.url.startsWith("https://"), s = new URL(
|
|
617
633
|
t.url,
|
|
618
634
|
r ? void 0 : DEFAULT_BASE_URL
|
|
619
|
-
), n =
|
|
620
|
-
s.pathname,
|
|
621
|
-
|
|
635
|
+
), n = applyRewriteRules(
|
|
636
|
+
removePathPrefix(s.pathname, c(this, y)),
|
|
637
|
+
this.rewriteRules
|
|
622
638
|
), o = `${c(this, g)}${n}`;
|
|
623
|
-
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);
|
|
624
640
|
}
|
|
625
641
|
}
|
|
626
|
-
g = new WeakMap(), H = 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) {
|
|
627
643
|
if (!this.php.fileExists(t))
|
|
628
644
|
return new PHPResponse(
|
|
629
645
|
404,
|
|
@@ -648,8 +664,8 @@ g = new WeakMap(), H = new WeakMap(), L = new WeakMap(), R = new WeakMap(), k =
|
|
|
648
664
|
},
|
|
649
665
|
r
|
|
650
666
|
);
|
|
651
|
-
},
|
|
652
|
-
var n
|
|
667
|
+
}, L = new WeakSet(), X = async function(t, r) {
|
|
668
|
+
var n;
|
|
653
669
|
if (c(this, S).running > 0 && ((n = t.headers) == null ? void 0 : n["x-request-issuer"]) === "php")
|
|
654
670
|
return console.warn(
|
|
655
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."
|
|
@@ -664,28 +680,20 @@ g = new WeakMap(), H = new WeakMap(), L = new WeakMap(), R = new WeakMap(), k =
|
|
|
664
680
|
"HTTPS",
|
|
665
681
|
c(this, C).startsWith("https://") ? "on" : ""
|
|
666
682
|
);
|
|
667
|
-
let
|
|
668
|
-
const
|
|
683
|
+
let o = "GET";
|
|
684
|
+
const i = {
|
|
669
685
|
host: c(this, k),
|
|
670
686
|
...normalizeHeaders(t.headers || {})
|
|
671
687
|
};
|
|
672
|
-
let
|
|
673
|
-
if (typeof
|
|
674
|
-
|
|
675
|
-
const { bytes:
|
|
676
|
-
|
|
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;
|
|
677
693
|
}
|
|
678
|
-
let
|
|
694
|
+
let l;
|
|
679
695
|
try {
|
|
680
|
-
|
|
681
|
-
if ((o = t.headers) != null && o["x-rewrite-url"])
|
|
682
|
-
try {
|
|
683
|
-
h = new URL(
|
|
684
|
-
t.headers["x-rewrite-url"]
|
|
685
|
-
).pathname;
|
|
686
|
-
} catch {
|
|
687
|
-
}
|
|
688
|
-
u = f(this, O, ee).call(this, h);
|
|
696
|
+
l = f(this, U, ee).call(this, r.pathname);
|
|
689
697
|
} catch {
|
|
690
698
|
return new PHPResponse(
|
|
691
699
|
404,
|
|
@@ -699,17 +707,17 @@ g = new WeakMap(), H = new WeakMap(), L = new WeakMap(), R = new WeakMap(), k =
|
|
|
699
707
|
c(this, y)
|
|
700
708
|
),
|
|
701
709
|
protocol: c(this, H),
|
|
702
|
-
method: t.method ||
|
|
703
|
-
body:
|
|
704
|
-
scriptPath:
|
|
705
|
-
headers:
|
|
710
|
+
method: t.method || o,
|
|
711
|
+
body: a,
|
|
712
|
+
scriptPath: l,
|
|
713
|
+
headers: i
|
|
706
714
|
});
|
|
707
715
|
} finally {
|
|
708
716
|
s();
|
|
709
717
|
}
|
|
710
|
-
},
|
|
718
|
+
}, U = new WeakSet(), ee = function(t) {
|
|
711
719
|
let r = removePathPrefix(t, c(this, y));
|
|
712
|
-
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";
|
|
713
721
|
const s = `${c(this, g)}${r}`;
|
|
714
722
|
if (this.php.fileExists(s))
|
|
715
723
|
return s;
|
|
@@ -764,6 +772,12 @@ function seemsLikeAPHPFile(e) {
|
|
|
764
772
|
function seemsLikeADirectoryRoot(e) {
|
|
765
773
|
return !e.split("/").pop().includes(".");
|
|
766
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
|
+
}
|
|
767
781
|
const FileErrorCodes = {
|
|
768
782
|
0: "No error occurred. System call completed successfully.",
|
|
769
783
|
1: "Argument list too long.",
|
|
@@ -857,8 +871,8 @@ function rethrowFileSystemError(e = "") {
|
|
|
857
871
|
} catch (a) {
|
|
858
872
|
const l = typeof a == "object" ? a == null ? void 0 : a.errno : null;
|
|
859
873
|
if (l in FileErrorCodes) {
|
|
860
|
-
const u = FileErrorCodes[l],
|
|
861
|
-
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}`, {
|
|
862
876
|
cause: a
|
|
863
877
|
});
|
|
864
878
|
}
|
|
@@ -909,7 +923,7 @@ var __defProp = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyD
|
|
|
909
923
|
return s && n && __defProp(t, r, n), n;
|
|
910
924
|
};
|
|
911
925
|
const STRING = "string", NUMBER = "number", __private__dont__use = Symbol("__private__dont__use");
|
|
912
|
-
var x, F, A, w, E, v, P, M,
|
|
926
|
+
var x, F, A, w, E, v, P, M, W, te, B, re, q, se, D, ne, $, ie, z, oe, j, ae, G, le, V, ce, J, ue, Q, de, Y, he;
|
|
913
927
|
class BasePHP {
|
|
914
928
|
/**
|
|
915
929
|
* Initializes a PHP runtime.
|
|
@@ -919,8 +933,8 @@ class BasePHP {
|
|
|
919
933
|
* @param serverOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
|
|
920
934
|
*/
|
|
921
935
|
constructor(e, t) {
|
|
922
|
-
d(this, B);
|
|
923
936
|
d(this, W);
|
|
937
|
+
d(this, B);
|
|
924
938
|
d(this, q);
|
|
925
939
|
d(this, D);
|
|
926
940
|
d(this, $);
|
|
@@ -928,9 +942,9 @@ class BasePHP {
|
|
|
928
942
|
d(this, j);
|
|
929
943
|
d(this, G);
|
|
930
944
|
d(this, V);
|
|
945
|
+
d(this, J);
|
|
931
946
|
d(this, Q);
|
|
932
947
|
d(this, Y);
|
|
933
|
-
d(this, J);
|
|
934
948
|
d(this, x, void 0);
|
|
935
949
|
d(this, F, void 0);
|
|
936
950
|
d(this, A, void 0);
|
|
@@ -939,7 +953,7 @@ class BasePHP {
|
|
|
939
953
|
d(this, v, void 0);
|
|
940
954
|
d(this, P, void 0);
|
|
941
955
|
d(this, M, void 0);
|
|
942
|
-
|
|
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(
|
|
943
957
|
new PHPRequestHandler(this, t)
|
|
944
958
|
));
|
|
945
959
|
}
|
|
@@ -995,7 +1009,7 @@ class BasePHP {
|
|
|
995
1009
|
return n;
|
|
996
1010
|
}
|
|
997
1011
|
return "";
|
|
998
|
-
},
|
|
1012
|
+
}, h(this, E, improveWASMErrorReporting(t)), this.dispatchEvent({
|
|
999
1013
|
type: "runtime.initialized"
|
|
1000
1014
|
});
|
|
1001
1015
|
}
|
|
@@ -1010,13 +1024,13 @@ class BasePHP {
|
|
|
1010
1024
|
throw new Error(
|
|
1011
1025
|
"Could not set SAPI name. This can only be done before the PHP WASM module is initialized.Did you already dispatch any requests?"
|
|
1012
1026
|
);
|
|
1013
|
-
|
|
1027
|
+
h(this, A, e);
|
|
1014
1028
|
}
|
|
1015
1029
|
/** @inheritDoc */
|
|
1016
1030
|
setPhpIniPath(e) {
|
|
1017
1031
|
if (c(this, w))
|
|
1018
1032
|
throw new Error("Cannot set PHP ini path after calling run().");
|
|
1019
|
-
|
|
1033
|
+
h(this, F, e), this[__private__dont__use].ccall(
|
|
1020
1034
|
"wasm_set_phpini_path",
|
|
1021
1035
|
null,
|
|
1022
1036
|
["string"],
|
|
@@ -1044,17 +1058,17 @@ class BasePHP {
|
|
|
1044
1058
|
const t = await this.semaphore.acquire();
|
|
1045
1059
|
let r;
|
|
1046
1060
|
try {
|
|
1047
|
-
if (c(this, w) || (f(this,
|
|
1061
|
+
if (c(this, w) || (f(this, W, te).call(this), h(this, w, !0)), e.scriptPath && !this.fileExists(e.scriptPath))
|
|
1048
1062
|
throw new Error(
|
|
1049
1063
|
`The script path "${e.scriptPath}" does not exist.`
|
|
1050
1064
|
);
|
|
1051
1065
|
f(this, G, le).call(this, e.scriptPath || ""), f(this, q, se).call(this, e.relativeUri || ""), f(this, $, ie).call(this, e.method || "GET");
|
|
1052
1066
|
const s = normalizeHeaders(e.headers || {}), n = s.host || "example.com:443";
|
|
1053
|
-
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,
|
|
1067
|
+
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);
|
|
1054
1068
|
const o = e.env || {};
|
|
1055
1069
|
for (const a in o)
|
|
1056
|
-
f(this,
|
|
1057
|
-
const i = await f(this,
|
|
1070
|
+
f(this, J, ue).call(this, a, o[a]);
|
|
1071
|
+
const i = await f(this, Y, he).call(this);
|
|
1058
1072
|
if (e.throwOnError && i.exitCode !== 0) {
|
|
1059
1073
|
const a = {
|
|
1060
1074
|
stdout: i.text,
|
|
@@ -1067,6 +1081,11 @@ class BasePHP {
|
|
|
1067
1081
|
throw l.output = a, console.error(l), l;
|
|
1068
1082
|
}
|
|
1069
1083
|
return i;
|
|
1084
|
+
} catch (s) {
|
|
1085
|
+
throw this.dispatchEvent({
|
|
1086
|
+
type: "request.error",
|
|
1087
|
+
error: s
|
|
1088
|
+
}), s;
|
|
1070
1089
|
} finally {
|
|
1071
1090
|
try {
|
|
1072
1091
|
r && this[__private__dont__use].free(r);
|
|
@@ -1187,10 +1206,10 @@ class BasePHP {
|
|
|
1187
1206
|
this[__private__dont__use]._exit(e);
|
|
1188
1207
|
} catch {
|
|
1189
1208
|
}
|
|
1190
|
-
|
|
1209
|
+
h(this, w, !1), h(this, E, null), delete this[__private__dont__use].onMessage, delete this[__private__dont__use];
|
|
1191
1210
|
}
|
|
1192
1211
|
}
|
|
1193
|
-
x = new WeakMap(), F = new WeakMap(), A = new WeakMap(), w = new WeakMap(), E = new WeakMap(), v = new WeakMap(), P = new WeakMap(), M = new WeakMap(),
|
|
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() {
|
|
1194
1213
|
if (this.setPhpIniEntry("auto_prepend_file", "/internal/consts.php"), this.fileExists("/internal/consts.php") || this.writeFile(
|
|
1195
1214
|
"/internal/consts.php",
|
|
1196
1215
|
`<?php
|
|
@@ -1215,7 +1234,7 @@ x = new WeakMap(), F = new WeakMap(), A = new WeakMap(), w = new WeakMap(), E =
|
|
|
1215
1234
|
);
|
|
1216
1235
|
}
|
|
1217
1236
|
this[__private__dont__use].ccall("php_wasm_init", null, [], []);
|
|
1218
|
-
},
|
|
1237
|
+
}, B = new WeakSet(), re = function() {
|
|
1219
1238
|
const e = "/internal/headers.json";
|
|
1220
1239
|
if (!this.fileExists(e))
|
|
1221
1240
|
throw new Error(
|
|
@@ -1334,21 +1353,21 @@ x = new WeakMap(), F = new WeakMap(), A = new WeakMap(), w = new WeakMap(), E =
|
|
|
1334
1353
|
[STRING, STRING],
|
|
1335
1354
|
[e, c(this, v)[e]]
|
|
1336
1355
|
);
|
|
1337
|
-
},
|
|
1356
|
+
}, J = new WeakSet(), ue = function(e, t) {
|
|
1338
1357
|
this[__private__dont__use].ccall(
|
|
1339
1358
|
"wasm_add_ENV_entry",
|
|
1340
1359
|
null,
|
|
1341
1360
|
[STRING, STRING],
|
|
1342
1361
|
[e, t]
|
|
1343
1362
|
);
|
|
1344
|
-
},
|
|
1363
|
+
}, Q = new WeakSet(), de = function(e) {
|
|
1345
1364
|
this[__private__dont__use].ccall(
|
|
1346
1365
|
"wasm_set_php_code",
|
|
1347
1366
|
null,
|
|
1348
1367
|
[STRING],
|
|
1349
1368
|
[e]
|
|
1350
1369
|
);
|
|
1351
|
-
},
|
|
1370
|
+
}, Y = new WeakSet(), he = async function() {
|
|
1352
1371
|
var n;
|
|
1353
1372
|
let e, t;
|
|
1354
1373
|
try {
|
|
@@ -1356,8 +1375,8 @@ x = new WeakMap(), F = new WeakMap(), A = new WeakMap(), w = new WeakMap(), E =
|
|
|
1356
1375
|
var l;
|
|
1357
1376
|
t = (u) => {
|
|
1358
1377
|
console.error(u), console.error(u.error);
|
|
1359
|
-
const
|
|
1360
|
-
|
|
1378
|
+
const p = new Error("Rethrown");
|
|
1379
|
+
p.cause = u.error, p.betterMessage = u.message, i(p);
|
|
1361
1380
|
}, (l = c(this, E)) == null || l.addEventListener(
|
|
1362
1381
|
"error",
|
|
1363
1382
|
t
|
|
@@ -1382,9 +1401,9 @@ x = new WeakMap(), F = new WeakMap(), A = new WeakMap(), w = new WeakMap(), E =
|
|
|
1382
1401
|
const i = o, a = "betterMessage" in i ? i.betterMessage : i.message, l = new Error(a);
|
|
1383
1402
|
throw l.cause = i, console.error(l), l;
|
|
1384
1403
|
} finally {
|
|
1385
|
-
(n = c(this, E)) == null || n.removeEventListener("error", t),
|
|
1404
|
+
(n = c(this, E)) == null || n.removeEventListener("error", t), h(this, v, {});
|
|
1386
1405
|
}
|
|
1387
|
-
const { headers: r, httpStatusCode: s } = f(this,
|
|
1406
|
+
const { headers: r, httpStatusCode: s } = f(this, B, re).call(this);
|
|
1388
1407
|
return new PHPResponse(
|
|
1389
1408
|
s,
|
|
1390
1409
|
r,
|
|
@@ -1498,27 +1517,27 @@ function expose(e, t = globalThis, r = ["*"]) {
|
|
|
1498
1517
|
const { id: o, type: i, path: a } = Object.assign({ path: [] }, n.data), l = (n.data.argumentList || []).map(fromWireValue);
|
|
1499
1518
|
let u;
|
|
1500
1519
|
try {
|
|
1501
|
-
const
|
|
1520
|
+
const p = a.slice(0, -1).reduce((m, I) => m[I], e), _ = a.reduce((m, I) => m[I], e);
|
|
1502
1521
|
switch (i) {
|
|
1503
1522
|
case "GET":
|
|
1504
|
-
u =
|
|
1523
|
+
u = _;
|
|
1505
1524
|
break;
|
|
1506
1525
|
case "SET":
|
|
1507
|
-
|
|
1526
|
+
p[a.slice(-1)[0]] = fromWireValue(n.data.value), u = !0;
|
|
1508
1527
|
break;
|
|
1509
1528
|
case "APPLY":
|
|
1510
|
-
u =
|
|
1529
|
+
u = _.apply(p, l);
|
|
1511
1530
|
break;
|
|
1512
1531
|
case "CONSTRUCT":
|
|
1513
1532
|
{
|
|
1514
|
-
const
|
|
1515
|
-
u = proxy(
|
|
1533
|
+
const m = new _(...l);
|
|
1534
|
+
u = proxy(m);
|
|
1516
1535
|
}
|
|
1517
1536
|
break;
|
|
1518
1537
|
case "ENDPOINT":
|
|
1519
1538
|
{
|
|
1520
|
-
const { port1:
|
|
1521
|
-
expose(e, I), u = transfer(
|
|
1539
|
+
const { port1: m, port2: I } = new MessageChannel();
|
|
1540
|
+
expose(e, I), u = transfer(m, [m]);
|
|
1522
1541
|
}
|
|
1523
1542
|
break;
|
|
1524
1543
|
case "RELEASE":
|
|
@@ -1527,18 +1546,18 @@ function expose(e, t = globalThis, r = ["*"]) {
|
|
|
1527
1546
|
default:
|
|
1528
1547
|
return;
|
|
1529
1548
|
}
|
|
1530
|
-
} catch (
|
|
1531
|
-
u = { value:
|
|
1549
|
+
} catch (p) {
|
|
1550
|
+
u = { value: p, [throwMarker]: 0 };
|
|
1532
1551
|
}
|
|
1533
|
-
Promise.resolve(u).catch((
|
|
1534
|
-
const [
|
|
1535
|
-
t.postMessage(Object.assign(Object.assign({},
|
|
1536
|
-
}).catch((
|
|
1537
|
-
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({
|
|
1538
1557
|
value: new TypeError("Unserializable return value"),
|
|
1539
1558
|
[throwMarker]: 0
|
|
1540
1559
|
});
|
|
1541
|
-
t.postMessage(Object.assign(Object.assign({},
|
|
1560
|
+
t.postMessage(Object.assign(Object.assign({}, _), { id: o }), m);
|
|
1542
1561
|
});
|
|
1543
1562
|
}), t.start && t.start();
|
|
1544
1563
|
}
|
|
@@ -1598,7 +1617,7 @@ function createProxy(e, t = [], r = function() {
|
|
|
1598
1617
|
const [l, u] = toWireValue(a);
|
|
1599
1618
|
return requestResponseMessage(e, {
|
|
1600
1619
|
type: "SET",
|
|
1601
|
-
path: [...t, i].map((
|
|
1620
|
+
path: [...t, i].map((p) => p.toString()),
|
|
1602
1621
|
value: l
|
|
1603
1622
|
}, u).then(fromWireValue);
|
|
1604
1623
|
},
|
|
@@ -1611,12 +1630,12 @@ function createProxy(e, t = [], r = function() {
|
|
|
1611
1630
|
}).then(fromWireValue);
|
|
1612
1631
|
if (l === "bind")
|
|
1613
1632
|
return createProxy(e, t.slice(0, -1));
|
|
1614
|
-
const [u,
|
|
1633
|
+
const [u, p] = processArguments(a);
|
|
1615
1634
|
return requestResponseMessage(e, {
|
|
1616
1635
|
type: "APPLY",
|
|
1617
|
-
path: t.map((
|
|
1636
|
+
path: t.map((_) => _.toString()),
|
|
1618
1637
|
argumentList: u
|
|
1619
|
-
},
|
|
1638
|
+
}, p).then(fromWireValue);
|
|
1620
1639
|
},
|
|
1621
1640
|
construct(o, i) {
|
|
1622
1641
|
throwIfProxyReleased(s);
|
|
@@ -1986,10 +2005,10 @@ function responseTo(e, t) {
|
|
|
1986
2005
|
async function registerServiceWorker(e, t, r) {
|
|
1987
2006
|
const s = navigator.serviceWorker;
|
|
1988
2007
|
if (!s)
|
|
1989
|
-
throw
|
|
1990
|
-
"Service workers are not supported in
|
|
1991
|
-
) : new
|
|
1992
|
-
"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."
|
|
1993
2012
|
);
|
|
1994
2013
|
console.debug("[window][sw] Registering a Service Worker"), await (await s.register(r, {
|
|
1995
2014
|
type: "module",
|
|
@@ -1998,7 +2017,7 @@ async function registerServiceWorker(e, t, r) {
|
|
|
1998
2017
|
})).update(), navigator.serviceWorker.addEventListener(
|
|
1999
2018
|
"message",
|
|
2000
2019
|
async function(i) {
|
|
2001
|
-
if (
|
|
2020
|
+
if (t && i.data.scope !== t)
|
|
2002
2021
|
return;
|
|
2003
2022
|
const a = i.data.args || [], l = i.data.method, u = await e[l](...a);
|
|
2004
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
|