@php-wasm/web 0.6.2 → 0.6.3
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 +7 -24
- package/index.js +258 -278
- 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 +19 -2
- package/kitchen-sink/php_7_1.js +19 -2
- package/kitchen-sink/php_7_2.js +19 -2
- package/kitchen-sink/php_7_3.js +19 -2
- package/kitchen-sink/php_7_4.js +19 -2
- package/kitchen-sink/php_8_0.js +19 -2
- package/kitchen-sink/php_8_1.js +19 -2
- package/kitchen-sink/php_8_2.js +19 -2
- package/kitchen-sink/php_8_3.js +18 -1
- 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 +19 -2
- package/light/php_7_1.js +19 -2
- package/light/php_7_2.js +19 -2
- package/light/php_7_3.js +19 -2
- package/light/php_7_4.js +19 -2
- package/light/php_8_0.js +19 -2
- package/light/php_8_1.js +19 -2
- package/light/php_8_2.js +19 -2
- package/light/php_8_3.js +19 -2
- package/package.json +5 -5
package/index.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
var
|
|
1
|
+
var K = (e, t, r) => {
|
|
2
2
|
if (!t.has(e))
|
|
3
3
|
throw TypeError("Cannot " + r);
|
|
4
4
|
};
|
|
5
|
-
var l = (e, t, r) => (
|
|
5
|
+
var l = (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
|
-
}, p = (e, t, r, s) => (
|
|
10
|
-
var
|
|
9
|
+
}, p = (e, t, r, s) => (K(e, t, "write to private field"), s ? s.call(e, r) : t.set(e, r), r);
|
|
10
|
+
var f = (e, t, r) => (K(e, t, "access private method"), r);
|
|
11
11
|
if (typeof File > "u") {
|
|
12
12
|
class e extends Blob {
|
|
13
|
-
constructor(r, s,
|
|
13
|
+
constructor(r, s, n) {
|
|
14
14
|
super(r);
|
|
15
|
-
let
|
|
16
|
-
|
|
15
|
+
let i;
|
|
16
|
+
n != null && n.lastModified && (i = /* @__PURE__ */ new Date()), (!i || isNaN(i.getFullYear())) && (i = /* @__PURE__ */ new Date()), this.lastModifiedDate = i, this.lastModified = i.getMilliseconds(), this.name = s || "";
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
global.File = e;
|
|
@@ -50,7 +50,7 @@ function isByobSupported() {
|
|
|
50
50
|
// this if needed.
|
|
51
51
|
autoAllocateChunkSize: 512 * 1024,
|
|
52
52
|
async pull(r) {
|
|
53
|
-
const s = r.byobRequest.view,
|
|
53
|
+
const s = r.byobRequest.view, i = await t.slice(e, e + s.byteLength).arrayBuffer(), o = new Uint8Array(i);
|
|
54
54
|
new Uint8Array(s.buffer).set(o);
|
|
55
55
|
const a = o.byteLength;
|
|
56
56
|
r.byobRequest.respond(a), e += a, e >= t.size && r.close();
|
|
@@ -114,16 +114,16 @@ function improveWASMErrorReporting(e) {
|
|
|
114
114
|
for (const r in e.asm)
|
|
115
115
|
if (typeof e.asm[r] == "function") {
|
|
116
116
|
const s = e.asm[r];
|
|
117
|
-
e.asm[r] = function(...
|
|
118
|
-
var
|
|
117
|
+
e.asm[r] = function(...n) {
|
|
118
|
+
var i;
|
|
119
119
|
try {
|
|
120
|
-
return s(...
|
|
120
|
+
return s(...n);
|
|
121
121
|
} catch (o) {
|
|
122
122
|
if (!(o instanceof Error))
|
|
123
123
|
throw o;
|
|
124
124
|
const a = clarifyErrorMessage(
|
|
125
125
|
o,
|
|
126
|
-
(
|
|
126
|
+
(i = e.lastAsyncifyStackSource) == null ? void 0 : i.stack
|
|
127
127
|
);
|
|
128
128
|
if (e.lastAsyncifyStackSource && (o.cause = e.lastAsyncifyStackSource), t.hasListeners()) {
|
|
129
129
|
t.dispatchEvent(
|
|
@@ -259,8 +259,8 @@ function normalizePath(e) {
|
|
|
259
259
|
function normalizePathsArray(e, t) {
|
|
260
260
|
let r = 0;
|
|
261
261
|
for (let s = e.length - 1; s >= 0; s--) {
|
|
262
|
-
const
|
|
263
|
-
|
|
262
|
+
const n = e[s];
|
|
263
|
+
n === "." ? e.splice(s, 1) : n === ".." ? (e.splice(s, 1), r++) : r && (e.splice(s, 1), r--);
|
|
264
264
|
}
|
|
265
265
|
if (t)
|
|
266
266
|
for (; r; r--)
|
|
@@ -337,8 +337,8 @@ ReadableStream.prototype[Symbol.asyncIterator] || (ReadableStream.prototype[Symb
|
|
|
337
337
|
}, ReadableStream.prototype.iterate = // @ts-ignore
|
|
338
338
|
ReadableStream.prototype[Symbol.asyncIterator]);
|
|
339
339
|
class PHPResponse {
|
|
340
|
-
constructor(t, r, s,
|
|
341
|
-
this.httpStatusCode = t, this.headers = r, this.bytes = s, this.exitCode =
|
|
340
|
+
constructor(t, r, s, n = "", i = 0) {
|
|
341
|
+
this.httpStatusCode = t, this.headers = r, this.bytes = s, this.exitCode = i, this.errors = n;
|
|
342
342
|
}
|
|
343
343
|
static fromRawData(t) {
|
|
344
344
|
return new PHPResponse(
|
|
@@ -382,16 +382,16 @@ const SupportedPHPVersions = [
|
|
|
382
382
|
"7.1",
|
|
383
383
|
"7.0"
|
|
384
384
|
], LatestSupportedPHPVersion = SupportedPHPVersions[0];
|
|
385
|
-
var
|
|
385
|
+
var b, T;
|
|
386
386
|
class PHPBrowser {
|
|
387
387
|
/**
|
|
388
388
|
* @param server - The PHP server to browse.
|
|
389
389
|
* @param config - The browser configuration.
|
|
390
390
|
*/
|
|
391
391
|
constructor(t, r = {}) {
|
|
392
|
-
d(this,
|
|
393
|
-
d(this,
|
|
394
|
-
this.requestHandler = t, p(this,
|
|
392
|
+
d(this, b, void 0);
|
|
393
|
+
d(this, T, void 0);
|
|
394
|
+
this.requestHandler = t, p(this, b, {}), p(this, T, {
|
|
395
395
|
handleRedirects: !1,
|
|
396
396
|
maxRedirects: 4,
|
|
397
397
|
...r
|
|
@@ -419,14 +419,14 @@ class PHPBrowser {
|
|
|
419
419
|
cookie: this.serializeCookies()
|
|
420
420
|
}
|
|
421
421
|
});
|
|
422
|
-
if (s.headers["set-cookie"] && this.setCookies(s.headers["set-cookie"]), l(this,
|
|
423
|
-
const
|
|
422
|
+
if (s.headers["set-cookie"] && this.setCookies(s.headers["set-cookie"]), l(this, T).handleRedirects && s.headers.location && r < l(this, T).maxRedirects) {
|
|
423
|
+
const n = new URL(
|
|
424
424
|
s.headers.location[0],
|
|
425
425
|
this.requestHandler.absoluteUrl
|
|
426
426
|
);
|
|
427
427
|
return this.request(
|
|
428
428
|
{
|
|
429
|
-
url:
|
|
429
|
+
url: n.toString(),
|
|
430
430
|
method: "GET",
|
|
431
431
|
headers: {}
|
|
432
432
|
},
|
|
@@ -456,20 +456,20 @@ class PHPBrowser {
|
|
|
456
456
|
try {
|
|
457
457
|
if (!r.includes("="))
|
|
458
458
|
continue;
|
|
459
|
-
const s = r.indexOf("="),
|
|
460
|
-
l(this,
|
|
459
|
+
const s = r.indexOf("="), n = r.substring(0, s), i = r.substring(s + 1).split(";")[0];
|
|
460
|
+
l(this, b)[n] = i;
|
|
461
461
|
} catch (s) {
|
|
462
462
|
console.error(s);
|
|
463
463
|
}
|
|
464
464
|
}
|
|
465
465
|
serializeCookies() {
|
|
466
466
|
const t = [];
|
|
467
|
-
for (const r in l(this,
|
|
468
|
-
t.push(`${r}=${l(this,
|
|
467
|
+
for (const r in l(this, b))
|
|
468
|
+
t.push(`${r}=${l(this, b)[r]}`);
|
|
469
469
|
return t.join("; ");
|
|
470
470
|
}
|
|
471
471
|
}
|
|
472
|
-
|
|
472
|
+
b = new WeakMap(), T = new WeakMap();
|
|
473
473
|
const DEFAULT_BASE_URL = "http://example.com";
|
|
474
474
|
function toRelativeUrl(e) {
|
|
475
475
|
return e.toString().substring(e.origin.length);
|
|
@@ -480,7 +480,35 @@ function removePathPrefix(e, t) {
|
|
|
480
480
|
function ensurePathPrefix(e, t) {
|
|
481
481
|
return !t || e.startsWith(t) ? e : t + e;
|
|
482
482
|
}
|
|
483
|
-
|
|
483
|
+
async function encodeAsMultipart(e) {
|
|
484
|
+
const t = `----${Math.random().toString(36).slice(2)}`, r = `multipart/form-data; boundary=${t}`, s = new TextEncoder(), n = [];
|
|
485
|
+
for (const [u, c] of Object.entries(e))
|
|
486
|
+
n.push(`--${t}\r
|
|
487
|
+
`), n.push(`Content-Disposition: form-data; name="${u}"`), c instanceof File && n.push(`; filename="${c.name}"`), n.push(`\r
|
|
488
|
+
`), c instanceof File && n.push("Content-Type: application/octet-stream"), n.push(`\r
|
|
489
|
+
\r
|
|
490
|
+
`), c instanceof File ? n.push(await fileToUint8Array(c)) : n.push(c), n.push(`\r
|
|
491
|
+
`);
|
|
492
|
+
n.push(`--${t}--\r
|
|
493
|
+
`);
|
|
494
|
+
const i = n.reduce((u, c) => u + c.length, 0), o = new Uint8Array(i);
|
|
495
|
+
let a = 0;
|
|
496
|
+
for (const u of n)
|
|
497
|
+
o.set(
|
|
498
|
+
typeof u == "string" ? s.encode(u) : u,
|
|
499
|
+
a
|
|
500
|
+
), a += u.length;
|
|
501
|
+
return { bytes: o, contentType: r };
|
|
502
|
+
}
|
|
503
|
+
function fileToUint8Array(e) {
|
|
504
|
+
return new Promise((t) => {
|
|
505
|
+
const r = new FileReader();
|
|
506
|
+
r.onload = () => {
|
|
507
|
+
t(new Uint8Array(r.result));
|
|
508
|
+
}, r.readAsArrayBuffer(e);
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
var P, H, L, R, k, y, C, x, N, Q, U, Z, O, X;
|
|
484
512
|
class PHPRequestHandler {
|
|
485
513
|
/**
|
|
486
514
|
* @param php - The PHP instance.
|
|
@@ -511,31 +539,31 @@ class PHPRequestHandler {
|
|
|
511
539
|
* @throws {Error} If the requested path doesn't exist.
|
|
512
540
|
* @returns The resolved filesystem path.
|
|
513
541
|
*/
|
|
514
|
-
d(this,
|
|
515
|
-
d(this,
|
|
516
|
-
d(this,
|
|
542
|
+
d(this, O);
|
|
543
|
+
d(this, P, void 0);
|
|
544
|
+
d(this, H, void 0);
|
|
517
545
|
d(this, L, void 0);
|
|
518
|
-
d(this,
|
|
546
|
+
d(this, R, void 0);
|
|
547
|
+
d(this, k, void 0);
|
|
548
|
+
d(this, y, void 0);
|
|
519
549
|
d(this, C, void 0);
|
|
520
|
-
d(this, g, void 0);
|
|
521
|
-
d(this, F, void 0);
|
|
522
550
|
d(this, x, void 0);
|
|
523
551
|
p(this, x, new Semaphore({ concurrency: 1 }));
|
|
524
552
|
const {
|
|
525
553
|
documentRoot: s = "/www/",
|
|
526
|
-
absoluteUrl:
|
|
554
|
+
absoluteUrl: n = typeof location == "object" ? location == null ? void 0 : location.href : ""
|
|
527
555
|
} = r;
|
|
528
|
-
this.php = t, p(this,
|
|
529
|
-
const
|
|
530
|
-
p(this, L,
|
|
531
|
-
const o = l(this,
|
|
532
|
-
p(this,
|
|
556
|
+
this.php = t, p(this, P, s);
|
|
557
|
+
const i = new URL(n);
|
|
558
|
+
p(this, L, i.hostname), p(this, R, i.port ? Number(i.port) : i.protocol === "https:" ? 443 : 80), p(this, H, (i.protocol || "").replace(":", ""));
|
|
559
|
+
const o = l(this, R) !== 443 && l(this, R) !== 80;
|
|
560
|
+
p(this, k, [
|
|
533
561
|
l(this, L),
|
|
534
|
-
o ? `:${l(this,
|
|
535
|
-
].join("")), p(this,
|
|
536
|
-
`${l(this,
|
|
537
|
-
l(this,
|
|
538
|
-
l(this,
|
|
562
|
+
o ? `:${l(this, R)}` : ""
|
|
563
|
+
].join("")), p(this, y, i.pathname.replace(/\/+$/, "")), p(this, C, [
|
|
564
|
+
`${l(this, H)}://`,
|
|
565
|
+
l(this, k),
|
|
566
|
+
l(this, y)
|
|
539
567
|
].join(""));
|
|
540
568
|
}
|
|
541
569
|
/** @inheritDoc */
|
|
@@ -545,32 +573,32 @@ class PHPRequestHandler {
|
|
|
545
573
|
/** @inheritDoc */
|
|
546
574
|
internalUrlToPath(t) {
|
|
547
575
|
const r = new URL(t);
|
|
548
|
-
return r.pathname.startsWith(l(this,
|
|
576
|
+
return r.pathname.startsWith(l(this, y)) && (r.pathname = r.pathname.slice(l(this, y).length)), toRelativeUrl(r);
|
|
549
577
|
}
|
|
550
578
|
get isRequestRunning() {
|
|
551
579
|
return l(this, x).running > 0;
|
|
552
580
|
}
|
|
553
581
|
/** @inheritDoc */
|
|
554
582
|
get absoluteUrl() {
|
|
555
|
-
return l(this,
|
|
583
|
+
return l(this, C);
|
|
556
584
|
}
|
|
557
585
|
/** @inheritDoc */
|
|
558
586
|
get documentRoot() {
|
|
559
|
-
return l(this,
|
|
587
|
+
return l(this, P);
|
|
560
588
|
}
|
|
561
589
|
/** @inheritDoc */
|
|
562
590
|
async request(t) {
|
|
563
591
|
const r = t.url.startsWith("http://") || t.url.startsWith("https://"), s = new URL(
|
|
564
592
|
t.url,
|
|
565
593
|
r ? void 0 : DEFAULT_BASE_URL
|
|
566
|
-
),
|
|
594
|
+
), n = removePathPrefix(
|
|
567
595
|
s.pathname,
|
|
568
|
-
l(this,
|
|
569
|
-
),
|
|
570
|
-
return seemsLikeAPHPRequestHandlerPath(
|
|
596
|
+
l(this, y)
|
|
597
|
+
), i = `${l(this, P)}${n}`;
|
|
598
|
+
return seemsLikeAPHPRequestHandlerPath(i) ? await f(this, U, Z).call(this, t, s) : f(this, N, Q).call(this, i);
|
|
571
599
|
}
|
|
572
600
|
}
|
|
573
|
-
|
|
601
|
+
P = new WeakMap(), H = new WeakMap(), L = new WeakMap(), R = new WeakMap(), k = new WeakMap(), y = new WeakMap(), C = new WeakMap(), x = new WeakMap(), N = new WeakSet(), Q = function(t) {
|
|
574
602
|
if (!this.php.fileExists(t))
|
|
575
603
|
return new PHPResponse(
|
|
576
604
|
404,
|
|
@@ -595,9 +623,9 @@ E = new WeakMap(), k = new WeakMap(), L = new WeakMap(), S = new WeakMap(), C =
|
|
|
595
623
|
},
|
|
596
624
|
r
|
|
597
625
|
);
|
|
598
|
-
}, U = new WeakSet(),
|
|
599
|
-
var
|
|
600
|
-
if (l(this, x).running > 0 && ((
|
|
626
|
+
}, U = new WeakSet(), Z = async function(t, r) {
|
|
627
|
+
var n, i;
|
|
628
|
+
if (l(this, x).running > 0 && ((n = t.headers) == null ? void 0 : n["x-request-issuer"]) === "php")
|
|
601
629
|
return console.warn(
|
|
602
630
|
"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."
|
|
603
631
|
), new PHPResponse(
|
|
@@ -607,45 +635,32 @@ E = new WeakMap(), k = new WeakMap(), L = new WeakMap(), S = new WeakMap(), C =
|
|
|
607
635
|
);
|
|
608
636
|
const s = await l(this, x).acquire();
|
|
609
637
|
try {
|
|
610
|
-
this.php.addServerGlobalEntry("REMOTE_ADDR", "127.0.0.1"), this.php.addServerGlobalEntry("DOCUMENT_ROOT", l(this,
|
|
638
|
+
this.php.addServerGlobalEntry("REMOTE_ADDR", "127.0.0.1"), this.php.addServerGlobalEntry("DOCUMENT_ROOT", l(this, P)), this.php.addServerGlobalEntry(
|
|
611
639
|
"HTTPS",
|
|
612
|
-
l(this,
|
|
640
|
+
l(this, C).startsWith("https://") ? "on" : ""
|
|
613
641
|
);
|
|
614
|
-
let
|
|
615
|
-
const
|
|
616
|
-
host: l(this,
|
|
642
|
+
let o = "GET";
|
|
643
|
+
const a = {
|
|
644
|
+
host: l(this, k),
|
|
617
645
|
...normalizeHeaders(t.headers || {})
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
key: f,
|
|
625
|
-
name: y.name,
|
|
626
|
-
type: y.type,
|
|
627
|
-
data: new Uint8Array(await y.arrayBuffer())
|
|
628
|
-
});
|
|
629
|
-
}
|
|
630
|
-
(n = u["content-type"]) != null && n.startsWith("multipart/form-data") && (t.formData = parseMultipartFormDataString(
|
|
631
|
-
t.body || ""
|
|
632
|
-
), u["content-type"] = "application/x-www-form-urlencoded", delete t.body);
|
|
646
|
+
};
|
|
647
|
+
let u = t.body;
|
|
648
|
+
if (typeof u == "object" && !(u instanceof Uint8Array)) {
|
|
649
|
+
o = "POST";
|
|
650
|
+
const { bytes: h, contentType: m } = await encodeAsMultipart(u);
|
|
651
|
+
u = h, a["content-type"] = m;
|
|
633
652
|
}
|
|
634
|
-
let
|
|
635
|
-
t.formData !== void 0 ? (a = "POST", u["content-type"] = u["content-type"] || "application/x-www-form-urlencoded", h = new URLSearchParams(
|
|
636
|
-
t.formData
|
|
637
|
-
).toString()) : h = t.body;
|
|
638
|
-
let _;
|
|
653
|
+
let c;
|
|
639
654
|
try {
|
|
640
|
-
let
|
|
641
|
-
if ((
|
|
655
|
+
let h = r.pathname;
|
|
656
|
+
if ((i = t.headers) != null && i["x-rewrite-url"])
|
|
642
657
|
try {
|
|
643
|
-
|
|
658
|
+
h = new URL(
|
|
644
659
|
t.headers["x-rewrite-url"]
|
|
645
660
|
).pathname;
|
|
646
661
|
} catch {
|
|
647
662
|
}
|
|
648
|
-
|
|
663
|
+
c = f(this, O, X).call(this, h);
|
|
649
664
|
} catch {
|
|
650
665
|
return new PHPResponse(
|
|
651
666
|
404,
|
|
@@ -656,41 +671,25 @@ E = new WeakMap(), k = new WeakMap(), L = new WeakMap(), S = new WeakMap(), C =
|
|
|
656
671
|
return await this.php.run({
|
|
657
672
|
relativeUri: ensurePathPrefix(
|
|
658
673
|
toRelativeUrl(r),
|
|
659
|
-
l(this,
|
|
674
|
+
l(this, y)
|
|
660
675
|
),
|
|
661
|
-
protocol: l(this,
|
|
662
|
-
method: t.method ||
|
|
663
|
-
body:
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
headers: u
|
|
676
|
+
protocol: l(this, H),
|
|
677
|
+
method: t.method || o,
|
|
678
|
+
body: u,
|
|
679
|
+
scriptPath: c,
|
|
680
|
+
headers: a
|
|
667
681
|
});
|
|
668
682
|
} finally {
|
|
669
683
|
s();
|
|
670
684
|
}
|
|
671
|
-
},
|
|
672
|
-
let r = removePathPrefix(t, l(this,
|
|
685
|
+
}, O = new WeakSet(), X = function(t) {
|
|
686
|
+
let r = removePathPrefix(t, l(this, y));
|
|
673
687
|
r.includes(".php") ? r = r.split(".php")[0] + ".php" : (r.endsWith("/") || (r += "/"), r.endsWith("index.php") || (r += "index.php"));
|
|
674
|
-
const s = `${l(this,
|
|
688
|
+
const s = `${l(this, P)}${r}`;
|
|
675
689
|
if (this.php.fileExists(s))
|
|
676
690
|
return s;
|
|
677
691
|
throw new Error(`File not found: ${s}`);
|
|
678
692
|
};
|
|
679
|
-
function parseMultipartFormDataString(e) {
|
|
680
|
-
const t = {}, r = e.match(/--(.*)\r\n/);
|
|
681
|
-
if (!r)
|
|
682
|
-
return t;
|
|
683
|
-
const s = r[1], i = e.split(`--${s}`);
|
|
684
|
-
return i.shift(), i.pop(), i.forEach((n) => {
|
|
685
|
-
const o = n.indexOf(`\r
|
|
686
|
-
\r
|
|
687
|
-
`), a = n.substring(0, o).trim(), u = n.substring(o + 4).trim(), c = a.match(/name="([^"]+)"/);
|
|
688
|
-
if (c) {
|
|
689
|
-
const h = c[1];
|
|
690
|
-
t[h] = u;
|
|
691
|
-
}
|
|
692
|
-
}), t;
|
|
693
|
-
}
|
|
694
693
|
function inferMimeType(e) {
|
|
695
694
|
switch (e.split(".").pop()) {
|
|
696
695
|
case "css":
|
|
@@ -825,16 +824,16 @@ function getEmscriptenFsError(e) {
|
|
|
825
824
|
return FileErrorCodes[t];
|
|
826
825
|
}
|
|
827
826
|
function rethrowFileSystemError(e = "") {
|
|
828
|
-
return function(r, s,
|
|
829
|
-
const
|
|
830
|
-
|
|
827
|
+
return function(r, s, n) {
|
|
828
|
+
const i = n.value;
|
|
829
|
+
n.value = function(...o) {
|
|
831
830
|
try {
|
|
832
|
-
return
|
|
831
|
+
return i.apply(this, o);
|
|
833
832
|
} catch (a) {
|
|
834
833
|
const u = typeof a == "object" ? a == null ? void 0 : a.errno : null;
|
|
835
834
|
if (u in FileErrorCodes) {
|
|
836
|
-
const c = FileErrorCodes[u], h = typeof o[0] == "string" ? o[0] : null,
|
|
837
|
-
throw new Error(`${
|
|
835
|
+
const c = FileErrorCodes[u], h = typeof o[0] == "string" ? o[0] : null, m = h !== null ? e.replaceAll("{path}", h) : e;
|
|
836
|
+
throw new Error(`${m}: ${c}`, {
|
|
838
837
|
cause: a
|
|
839
838
|
});
|
|
840
839
|
}
|
|
@@ -846,9 +845,9 @@ function rethrowFileSystemError(e = "") {
|
|
|
846
845
|
const RuntimeId = Symbol("RuntimeId"), loadedRuntimes = /* @__PURE__ */ new Map();
|
|
847
846
|
let lastRuntimeId = 0;
|
|
848
847
|
async function loadPHPRuntime(e, t = {}) {
|
|
849
|
-
const [r, s,
|
|
848
|
+
const [r, s, n] = makePromise(), i = e.init(currentJsRuntime, {
|
|
850
849
|
onAbort(a) {
|
|
851
|
-
|
|
850
|
+
n(a), console.error(a);
|
|
852
851
|
},
|
|
853
852
|
ENV: {},
|
|
854
853
|
// Emscripten sometimes prepends a '/' to the path, which
|
|
@@ -863,9 +862,9 @@ async function loadPHPRuntime(e, t = {}) {
|
|
|
863
862
|
});
|
|
864
863
|
await r;
|
|
865
864
|
const o = ++lastRuntimeId;
|
|
866
|
-
return
|
|
867
|
-
return loadedRuntimes.delete(o),
|
|
868
|
-
},
|
|
865
|
+
return i.id = o, i.originalExit = i._exit, i._exit = function(a) {
|
|
866
|
+
return loadedRuntimes.delete(o), i.originalExit(a);
|
|
867
|
+
}, i[RuntimeId] = o, loadedRuntimes.set(o, i), o;
|
|
869
868
|
}
|
|
870
869
|
function getLoadedRuntime(e) {
|
|
871
870
|
return loadedRuntimes.get(e);
|
|
@@ -880,12 +879,12 @@ const currentJsRuntime = function() {
|
|
|
880
879
|
return e.unshift(t), e;
|
|
881
880
|
};
|
|
882
881
|
var __defProp = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __decorateClass = (e, t, r, s) => {
|
|
883
|
-
for (var
|
|
884
|
-
(o = e[
|
|
885
|
-
return s &&
|
|
882
|
+
for (var n = s > 1 ? void 0 : s ? __getOwnPropDesc(t, r) : t, i = e.length - 1, o; i >= 0; i--)
|
|
883
|
+
(o = e[i]) && (n = (s ? o(t, r, n) : o(n)) || n);
|
|
884
|
+
return s && n && __defProp(t, r, n), n;
|
|
886
885
|
};
|
|
887
886
|
const STRING = "string", NUMBER = "number", __private__dont__use = Symbol("__private__dont__use");
|
|
888
|
-
var
|
|
887
|
+
var S, F, A, g, E, v, w, M, q, ee, B, te, W, re, $, se, z, ne, D, ie, j, oe, G, ae, V, le, Y, ce, J, ue;
|
|
889
888
|
class BasePHP {
|
|
890
889
|
/**
|
|
891
890
|
* Initializes a PHP runtime.
|
|
@@ -895,55 +894,45 @@ class BasePHP {
|
|
|
895
894
|
* @param serverOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
|
|
896
895
|
*/
|
|
897
896
|
constructor(e, t) {
|
|
898
|
-
d(this, O);
|
|
899
|
-
d(this, W);
|
|
900
897
|
d(this, q);
|
|
898
|
+
d(this, B);
|
|
899
|
+
d(this, W);
|
|
900
|
+
d(this, $);
|
|
901
901
|
d(this, z);
|
|
902
902
|
d(this, D);
|
|
903
|
-
d(this, $);
|
|
904
903
|
d(this, j);
|
|
905
904
|
d(this, G);
|
|
906
905
|
d(this, V);
|
|
907
|
-
/**
|
|
908
|
-
* Adds file information to $_FILES superglobal in PHP.
|
|
909
|
-
*
|
|
910
|
-
* In particular:
|
|
911
|
-
* * Creates the file data in the filesystem
|
|
912
|
-
* * Registers the file details in PHP
|
|
913
|
-
*
|
|
914
|
-
* @param fileInfo - File details
|
|
915
|
-
*/
|
|
916
906
|
d(this, Y);
|
|
917
907
|
d(this, J);
|
|
918
|
-
d(this,
|
|
919
|
-
d(this,
|
|
920
|
-
d(this, M, void 0);
|
|
921
|
-
d(this, I, void 0);
|
|
922
|
-
d(this, w, void 0);
|
|
923
|
-
d(this, v, void 0);
|
|
924
|
-
d(this, b, void 0);
|
|
925
|
-
d(this, P, void 0);
|
|
908
|
+
d(this, S, void 0);
|
|
909
|
+
d(this, F, void 0);
|
|
926
910
|
d(this, A, void 0);
|
|
927
|
-
|
|
911
|
+
d(this, g, void 0);
|
|
912
|
+
d(this, E, void 0);
|
|
913
|
+
d(this, v, void 0);
|
|
914
|
+
d(this, w, void 0);
|
|
915
|
+
d(this, M, void 0);
|
|
916
|
+
p(this, S, []), p(this, g, !1), p(this, E, null), p(this, v, {}), p(this, w, /* @__PURE__ */ new Map()), p(this, M, []), this.semaphore = new Semaphore({ concurrency: 1 }), e !== void 0 && this.initializeRuntime(e), t && (this.requestHandler = new PHPBrowser(
|
|
928
917
|
new PHPRequestHandler(this, t)
|
|
929
918
|
));
|
|
930
919
|
}
|
|
931
920
|
addEventListener(e, t) {
|
|
932
|
-
l(this,
|
|
921
|
+
l(this, w).has(e) || l(this, w).set(e, /* @__PURE__ */ new Set()), l(this, w).get(e).add(t);
|
|
933
922
|
}
|
|
934
923
|
removeEventListener(e, t) {
|
|
935
924
|
var r;
|
|
936
|
-
(r = l(this,
|
|
925
|
+
(r = l(this, w).get(e)) == null || r.delete(t);
|
|
937
926
|
}
|
|
938
927
|
dispatchEvent(e) {
|
|
939
|
-
const t = l(this,
|
|
928
|
+
const t = l(this, w).get(e.type);
|
|
940
929
|
if (t)
|
|
941
930
|
for (const r of t)
|
|
942
931
|
r(e);
|
|
943
932
|
}
|
|
944
933
|
/** @inheritDoc */
|
|
945
934
|
async onMessage(e) {
|
|
946
|
-
l(this,
|
|
935
|
+
l(this, M).push(e);
|
|
947
936
|
}
|
|
948
937
|
/** @inheritDoc */
|
|
949
938
|
async setSpawnHandler(handler) {
|
|
@@ -974,13 +963,13 @@ class BasePHP {
|
|
|
974
963
|
if (!t)
|
|
975
964
|
throw new Error("Invalid PHP runtime id.");
|
|
976
965
|
this[__private__dont__use] = t, t.onMessage = async (r) => {
|
|
977
|
-
for (const s of l(this,
|
|
978
|
-
const
|
|
979
|
-
if (
|
|
980
|
-
return
|
|
966
|
+
for (const s of l(this, M)) {
|
|
967
|
+
const n = await s(r);
|
|
968
|
+
if (n)
|
|
969
|
+
return n;
|
|
981
970
|
}
|
|
982
971
|
return "";
|
|
983
|
-
}, p(this,
|
|
972
|
+
}, p(this, E, improveWASMErrorReporting(t)), this.dispatchEvent({
|
|
984
973
|
type: "runtime.initialized"
|
|
985
974
|
});
|
|
986
975
|
}
|
|
@@ -995,13 +984,13 @@ class BasePHP {
|
|
|
995
984
|
throw new Error(
|
|
996
985
|
"Could not set SAPI name. This can only be done before the PHP WASM module is initialized.Did you already dispatch any requests?"
|
|
997
986
|
);
|
|
998
|
-
p(this,
|
|
987
|
+
p(this, A, e);
|
|
999
988
|
}
|
|
1000
989
|
/** @inheritDoc */
|
|
1001
990
|
setPhpIniPath(e) {
|
|
1002
|
-
if (l(this,
|
|
991
|
+
if (l(this, g))
|
|
1003
992
|
throw new Error("Cannot set PHP ini path after calling run().");
|
|
1004
|
-
p(this,
|
|
993
|
+
p(this, F, e), this[__private__dont__use].ccall(
|
|
1005
994
|
"wasm_set_phpini_path",
|
|
1006
995
|
null,
|
|
1007
996
|
["string"],
|
|
@@ -1010,9 +999,9 @@ class BasePHP {
|
|
|
1010
999
|
}
|
|
1011
1000
|
/** @inheritDoc */
|
|
1012
1001
|
setPhpIniEntry(e, t) {
|
|
1013
|
-
if (l(this,
|
|
1002
|
+
if (l(this, g))
|
|
1014
1003
|
throw new Error("Cannot set PHP ini entries after calling run().");
|
|
1015
|
-
l(this,
|
|
1004
|
+
l(this, S).push([e, t]);
|
|
1016
1005
|
}
|
|
1017
1006
|
/** @inheritDoc */
|
|
1018
1007
|
chdir(e) {
|
|
@@ -1029,25 +1018,22 @@ class BasePHP {
|
|
|
1029
1018
|
const t = await this.semaphore.acquire();
|
|
1030
1019
|
let r;
|
|
1031
1020
|
try {
|
|
1032
|
-
l(this,
|
|
1033
|
-
const s = normalizeHeaders(e.headers || {}),
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
typeof e.code == "string" && m(this, J, de).call(this, " ?>" + e.code), m(this, V, ce).call(this);
|
|
1038
|
-
const n = await m(this, K, he).call(this);
|
|
1039
|
-
if (e.throwOnError && n.exitCode !== 0) {
|
|
1021
|
+
l(this, g) || (f(this, q, ee).call(this), p(this, g, !0)), f(this, G, ae).call(this, e.scriptPath || ""), f(this, W, re).call(this, e.relativeUri || ""), f(this, z, ne).call(this, e.method || "GET");
|
|
1022
|
+
const s = normalizeHeaders(e.headers || {}), n = s.host || "example.com:443";
|
|
1023
|
+
f(this, $, se).call(this, n, e.protocol || "http"), f(this, D, ie).call(this, s), e.body && (r = f(this, j, oe).call(this, e.body)), typeof e.code == "string" && f(this, Y, ce).call(this, " ?>" + e.code), f(this, V, le).call(this);
|
|
1024
|
+
const i = await f(this, J, ue).call(this);
|
|
1025
|
+
if (e.throwOnError && i.exitCode !== 0) {
|
|
1040
1026
|
const o = {
|
|
1041
|
-
stdout:
|
|
1042
|
-
stderr:
|
|
1027
|
+
stdout: i.text,
|
|
1028
|
+
stderr: i.errors
|
|
1043
1029
|
};
|
|
1044
1030
|
console.warn("PHP.run() output was:", o);
|
|
1045
1031
|
const a = new Error(
|
|
1046
|
-
`PHP.run() failed with exit code ${
|
|
1032
|
+
`PHP.run() failed with exit code ${i.exitCode} and the following output`
|
|
1047
1033
|
);
|
|
1048
1034
|
throw a.output = o, a;
|
|
1049
1035
|
}
|
|
1050
|
-
return
|
|
1036
|
+
return i;
|
|
1051
1037
|
} finally {
|
|
1052
1038
|
try {
|
|
1053
1039
|
r && this[__private__dont__use].free(r);
|
|
@@ -1059,7 +1045,7 @@ class BasePHP {
|
|
|
1059
1045
|
}
|
|
1060
1046
|
}
|
|
1061
1047
|
addServerGlobalEntry(e, t) {
|
|
1062
|
-
l(this,
|
|
1048
|
+
l(this, v)[e] = t;
|
|
1063
1049
|
}
|
|
1064
1050
|
defineConstant(e, t) {
|
|
1065
1051
|
let r = {};
|
|
@@ -1124,7 +1110,7 @@ class BasePHP {
|
|
|
1124
1110
|
);
|
|
1125
1111
|
if (t.prependPath) {
|
|
1126
1112
|
const s = e.replace(/\/$/, "");
|
|
1127
|
-
return r.map((
|
|
1113
|
+
return r.map((n) => `${s}/${n}`);
|
|
1128
1114
|
}
|
|
1129
1115
|
return r;
|
|
1130
1116
|
} catch (r) {
|
|
@@ -1155,7 +1141,7 @@ class BasePHP {
|
|
|
1155
1141
|
this.exit();
|
|
1156
1142
|
} catch {
|
|
1157
1143
|
}
|
|
1158
|
-
if (this.initializeRuntime(e), l(this,
|
|
1144
|
+
if (this.initializeRuntime(e), l(this, F) && this.setPhpIniPath(l(this, F)), l(this, A) && this.setSapiName(l(this, A)), this.requestHandler) {
|
|
1159
1145
|
const r = this.documentRoot;
|
|
1160
1146
|
recreateMemFS(this[__private__dont__use].FS, t, r);
|
|
1161
1147
|
}
|
|
@@ -1168,10 +1154,10 @@ class BasePHP {
|
|
|
1168
1154
|
this[__private__dont__use]._exit(e);
|
|
1169
1155
|
} catch {
|
|
1170
1156
|
}
|
|
1171
|
-
p(this,
|
|
1157
|
+
p(this, g, !1), p(this, E, null), delete this[__private__dont__use].onMessage, delete this[__private__dont__use];
|
|
1172
1158
|
}
|
|
1173
1159
|
}
|
|
1174
|
-
|
|
1160
|
+
S = new WeakMap(), F = new WeakMap(), A = new WeakMap(), g = new WeakMap(), E = new WeakMap(), v = new WeakMap(), w = new WeakMap(), M = new WeakMap(), q = new WeakSet(), ee = function() {
|
|
1175
1161
|
if (this.setPhpIniEntry("auto_prepend_file", "/tmp/consts.php"), this.fileExists("/tmp/consts.php") || this.writeFile(
|
|
1176
1162
|
"/tmp/consts.php",
|
|
1177
1163
|
`<?php
|
|
@@ -1183,8 +1169,8 @@ T = new WeakMap(), M = new WeakMap(), I = new WeakMap(), w = new WeakMap(), v =
|
|
|
1183
1169
|
}
|
|
1184
1170
|
}
|
|
1185
1171
|
}`
|
|
1186
|
-
), l(this,
|
|
1187
|
-
const e = l(this,
|
|
1172
|
+
), l(this, S).length > 0) {
|
|
1173
|
+
const e = l(this, S).map(([t, r]) => `${t}=${r}`).join(`
|
|
1188
1174
|
`) + `
|
|
1189
1175
|
|
|
1190
1176
|
`;
|
|
@@ -1196,7 +1182,7 @@ T = new WeakMap(), M = new WeakMap(), I = new WeakMap(), w = new WeakMap(), v =
|
|
|
1196
1182
|
);
|
|
1197
1183
|
}
|
|
1198
1184
|
this[__private__dont__use].ccall("php_wasm_init", null, [], []);
|
|
1199
|
-
},
|
|
1185
|
+
}, B = new WeakSet(), te = function() {
|
|
1200
1186
|
const e = "/tmp/headers.json";
|
|
1201
1187
|
if (!this.fileExists(e))
|
|
1202
1188
|
throw new Error(
|
|
@@ -1206,14 +1192,14 @@ T = new WeakMap(), M = new WeakMap(), I = new WeakMap(), w = new WeakMap(), v =
|
|
|
1206
1192
|
for (const s of t.headers) {
|
|
1207
1193
|
if (!s.includes(": "))
|
|
1208
1194
|
continue;
|
|
1209
|
-
const
|
|
1210
|
-
|
|
1195
|
+
const n = s.indexOf(": "), i = s.substring(0, n).toLowerCase(), o = s.substring(n + 2);
|
|
1196
|
+
i in r || (r[i] = []), r[i].push(o);
|
|
1211
1197
|
}
|
|
1212
1198
|
return {
|
|
1213
1199
|
headers: r,
|
|
1214
1200
|
httpStatusCode: t.status
|
|
1215
1201
|
};
|
|
1216
|
-
},
|
|
1202
|
+
}, W = new WeakSet(), re = function(e) {
|
|
1217
1203
|
if (this[__private__dont__use].ccall(
|
|
1218
1204
|
"wasm_set_request_uri",
|
|
1219
1205
|
null,
|
|
@@ -1228,7 +1214,7 @@ T = new WeakMap(), M = new WeakMap(), I = new WeakMap(), w = new WeakMap(), v =
|
|
|
1228
1214
|
[t]
|
|
1229
1215
|
);
|
|
1230
1216
|
}
|
|
1231
|
-
},
|
|
1217
|
+
}, $ = new WeakSet(), se = function(e, t) {
|
|
1232
1218
|
this[__private__dont__use].ccall(
|
|
1233
1219
|
"wasm_set_request_host",
|
|
1234
1220
|
null,
|
|
@@ -1246,14 +1232,14 @@ T = new WeakMap(), M = new WeakMap(), I = new WeakMap(), w = new WeakMap(), v =
|
|
|
1246
1232
|
[NUMBER],
|
|
1247
1233
|
[r]
|
|
1248
1234
|
), (t === "https" || !t && r === 443) && this.addServerGlobalEntry("HTTPS", "on");
|
|
1249
|
-
},
|
|
1235
|
+
}, z = new WeakSet(), ne = function(e) {
|
|
1250
1236
|
this[__private__dont__use].ccall(
|
|
1251
1237
|
"wasm_set_request_method",
|
|
1252
1238
|
null,
|
|
1253
1239
|
[STRING],
|
|
1254
1240
|
[e]
|
|
1255
1241
|
);
|
|
1256
|
-
},
|
|
1242
|
+
}, D = new WeakSet(), ie = function(e) {
|
|
1257
1243
|
e.cookie && this[__private__dont__use].ccall(
|
|
1258
1244
|
"wasm_set_cookies",
|
|
1259
1245
|
null,
|
|
@@ -1277,67 +1263,61 @@ T = new WeakMap(), M = new WeakMap(), I = new WeakMap(), w = new WeakMap(), v =
|
|
|
1277
1263
|
e[t]
|
|
1278
1264
|
);
|
|
1279
1265
|
}
|
|
1280
|
-
}, j = new WeakSet(),
|
|
1281
|
-
|
|
1282
|
-
|
|
1266
|
+
}, j = new WeakSet(), oe = function(e) {
|
|
1267
|
+
let t, r;
|
|
1268
|
+
typeof e == "string" ? (console.warn(
|
|
1269
|
+
"Passing a string as the request body is deprecated. Please use a Uint8Array instead. See https://github.com/WordPress/wordpress-playground/issues/997 for more details"
|
|
1270
|
+
), r = this[__private__dont__use].lengthBytesUTF8(e), t = r + 1) : (r = e.byteLength, t = e.byteLength);
|
|
1271
|
+
const s = this[__private__dont__use].malloc(t);
|
|
1272
|
+
if (!s)
|
|
1283
1273
|
throw new Error("Could not allocate memory for the request body.");
|
|
1284
|
-
return this[__private__dont__use].stringToUTF8(
|
|
1274
|
+
return typeof e == "string" ? this[__private__dont__use].stringToUTF8(
|
|
1285
1275
|
e,
|
|
1286
|
-
|
|
1276
|
+
s,
|
|
1287
1277
|
t + 1
|
|
1288
|
-
), this[__private__dont__use].ccall(
|
|
1278
|
+
) : this[__private__dont__use].HEAPU8.set(e, s), this[__private__dont__use].ccall(
|
|
1289
1279
|
"wasm_set_request_body",
|
|
1290
1280
|
null,
|
|
1291
1281
|
[NUMBER],
|
|
1292
|
-
[
|
|
1282
|
+
[s]
|
|
1293
1283
|
), this[__private__dont__use].ccall(
|
|
1294
1284
|
"wasm_set_content_length",
|
|
1295
1285
|
null,
|
|
1296
1286
|
[NUMBER],
|
|
1297
|
-
[
|
|
1298
|
-
),
|
|
1299
|
-
}, G = new WeakSet(),
|
|
1287
|
+
[r]
|
|
1288
|
+
), s;
|
|
1289
|
+
}, G = new WeakSet(), ae = function(e) {
|
|
1300
1290
|
this[__private__dont__use].ccall(
|
|
1301
1291
|
"wasm_set_path_translated",
|
|
1302
1292
|
null,
|
|
1303
1293
|
[STRING],
|
|
1304
1294
|
[e]
|
|
1305
1295
|
);
|
|
1306
|
-
}, V = new WeakSet(),
|
|
1307
|
-
for (const e in l(this,
|
|
1296
|
+
}, V = new WeakSet(), le = function() {
|
|
1297
|
+
for (const e in l(this, v))
|
|
1308
1298
|
this[__private__dont__use].ccall(
|
|
1309
1299
|
"wasm_add_SERVER_entry",
|
|
1310
1300
|
null,
|
|
1311
1301
|
[STRING, STRING],
|
|
1312
|
-
[e, l(this,
|
|
1302
|
+
[e, l(this, v)[e]]
|
|
1313
1303
|
);
|
|
1314
|
-
}, Y = new WeakSet(),
|
|
1315
|
-
const { key: t, name: r, type: s, data: i } = e, n = `/tmp/${Math.random().toFixed(20)}`;
|
|
1316
|
-
this.writeFile(n, i);
|
|
1317
|
-
const o = 0;
|
|
1318
|
-
this[__private__dont__use].ccall(
|
|
1319
|
-
"wasm_add_uploaded_file",
|
|
1320
|
-
null,
|
|
1321
|
-
[STRING, STRING, STRING, STRING, NUMBER, NUMBER],
|
|
1322
|
-
[t, r, s, n, o, i.byteLength]
|
|
1323
|
-
);
|
|
1324
|
-
}, J = new WeakSet(), de = function(e) {
|
|
1304
|
+
}, Y = new WeakSet(), ce = function(e) {
|
|
1325
1305
|
this[__private__dont__use].ccall(
|
|
1326
1306
|
"wasm_set_php_code",
|
|
1327
1307
|
null,
|
|
1328
1308
|
[STRING],
|
|
1329
1309
|
[e]
|
|
1330
1310
|
);
|
|
1331
|
-
},
|
|
1332
|
-
var
|
|
1311
|
+
}, J = new WeakSet(), ue = async function() {
|
|
1312
|
+
var n;
|
|
1333
1313
|
let e, t;
|
|
1334
1314
|
try {
|
|
1335
|
-
e = await new Promise((
|
|
1315
|
+
e = await new Promise((i, o) => {
|
|
1336
1316
|
var u;
|
|
1337
1317
|
t = (c) => {
|
|
1338
1318
|
const h = new Error("Rethrown");
|
|
1339
1319
|
h.cause = c.error, h.betterMessage = c.message, o(h);
|
|
1340
|
-
}, (u = l(this,
|
|
1320
|
+
}, (u = l(this, E)) == null || u.addEventListener(
|
|
1341
1321
|
"error",
|
|
1342
1322
|
t
|
|
1343
1323
|
);
|
|
@@ -1348,9 +1328,9 @@ T = new WeakMap(), M = new WeakMap(), I = new WeakMap(), w = new WeakMap(), v =
|
|
|
1348
1328
|
[],
|
|
1349
1329
|
{ async: !0 }
|
|
1350
1330
|
);
|
|
1351
|
-
return a instanceof Promise ? a.then(
|
|
1331
|
+
return a instanceof Promise ? a.then(i, o) : i(a);
|
|
1352
1332
|
});
|
|
1353
|
-
} catch (
|
|
1333
|
+
} catch (i) {
|
|
1354
1334
|
for (const c in this)
|
|
1355
1335
|
typeof this[c] == "function" && (this[c] = () => {
|
|
1356
1336
|
throw new Error(
|
|
@@ -1358,12 +1338,12 @@ T = new WeakMap(), M = new WeakMap(), I = new WeakMap(), w = new WeakMap(), v =
|
|
|
1358
1338
|
);
|
|
1359
1339
|
});
|
|
1360
1340
|
this.functionsMaybeMissingFromAsyncify = getFunctionsMaybeMissingFromAsyncify();
|
|
1361
|
-
const o =
|
|
1341
|
+
const o = i, a = "betterMessage" in o ? o.betterMessage : o.message, u = new Error(a);
|
|
1362
1342
|
throw u.cause = o, u;
|
|
1363
1343
|
} finally {
|
|
1364
|
-
(
|
|
1344
|
+
(n = l(this, E)) == null || n.removeEventListener("error", t), p(this, v, {});
|
|
1365
1345
|
}
|
|
1366
|
-
const { headers: r, httpStatusCode: s } =
|
|
1346
|
+
const { headers: r, httpStatusCode: s } = f(this, B, te).call(this);
|
|
1367
1347
|
return new PHPResponse(
|
|
1368
1348
|
s,
|
|
1369
1349
|
r,
|
|
@@ -1427,9 +1407,9 @@ function recreateMemFS(e, t, r) {
|
|
|
1427
1407
|
return;
|
|
1428
1408
|
}
|
|
1429
1409
|
e.mkdirTree(r);
|
|
1430
|
-
const
|
|
1431
|
-
for (const
|
|
1432
|
-
recreateMemFS(e, t, joinPaths(r,
|
|
1410
|
+
const n = t.readdir(r).filter((i) => i !== "." && i !== "..");
|
|
1411
|
+
for (const i of n)
|
|
1412
|
+
recreateMemFS(e, t, joinPaths(r, i));
|
|
1433
1413
|
}
|
|
1434
1414
|
/**
|
|
1435
1415
|
* @license
|
|
@@ -1472,37 +1452,37 @@ function isAllowedOrigin(e, t) {
|
|
|
1472
1452
|
return !1;
|
|
1473
1453
|
}
|
|
1474
1454
|
function expose(e, t = globalThis, r = ["*"]) {
|
|
1475
|
-
t.addEventListener("message", function s(
|
|
1476
|
-
if (!
|
|
1455
|
+
t.addEventListener("message", function s(n) {
|
|
1456
|
+
if (!n || !n.data)
|
|
1477
1457
|
return;
|
|
1478
|
-
if (!isAllowedOrigin(r,
|
|
1479
|
-
console.warn(`Invalid origin '${
|
|
1458
|
+
if (!isAllowedOrigin(r, n.origin)) {
|
|
1459
|
+
console.warn(`Invalid origin '${n.origin}' for comlink proxy`);
|
|
1480
1460
|
return;
|
|
1481
1461
|
}
|
|
1482
|
-
const { id:
|
|
1462
|
+
const { id: i, type: o, path: a } = Object.assign({ path: [] }, n.data), u = (n.data.argumentList || []).map(fromWireValue);
|
|
1483
1463
|
let c;
|
|
1484
1464
|
try {
|
|
1485
|
-
const h = a.slice(0, -1).reduce((
|
|
1465
|
+
const h = a.slice(0, -1).reduce((_, I) => _[I], e), m = a.reduce((_, I) => _[I], e);
|
|
1486
1466
|
switch (o) {
|
|
1487
1467
|
case "GET":
|
|
1488
|
-
c =
|
|
1468
|
+
c = m;
|
|
1489
1469
|
break;
|
|
1490
1470
|
case "SET":
|
|
1491
|
-
h[a.slice(-1)[0]] = fromWireValue(
|
|
1471
|
+
h[a.slice(-1)[0]] = fromWireValue(n.data.value), c = !0;
|
|
1492
1472
|
break;
|
|
1493
1473
|
case "APPLY":
|
|
1494
|
-
c =
|
|
1474
|
+
c = m.apply(h, u);
|
|
1495
1475
|
break;
|
|
1496
1476
|
case "CONSTRUCT":
|
|
1497
1477
|
{
|
|
1498
|
-
const
|
|
1499
|
-
c = proxy(
|
|
1478
|
+
const _ = new m(...u);
|
|
1479
|
+
c = proxy(_);
|
|
1500
1480
|
}
|
|
1501
1481
|
break;
|
|
1502
1482
|
case "ENDPOINT":
|
|
1503
1483
|
{
|
|
1504
|
-
const { port1:
|
|
1505
|
-
expose(e,
|
|
1484
|
+
const { port1: _, port2: I } = new MessageChannel();
|
|
1485
|
+
expose(e, I), c = transfer(_, [_]);
|
|
1506
1486
|
}
|
|
1507
1487
|
break;
|
|
1508
1488
|
case "RELEASE":
|
|
@@ -1515,14 +1495,14 @@ function expose(e, t = globalThis, r = ["*"]) {
|
|
|
1515
1495
|
c = { value: h, [throwMarker]: 0 };
|
|
1516
1496
|
}
|
|
1517
1497
|
Promise.resolve(c).catch((h) => ({ value: h, [throwMarker]: 0 })).then((h) => {
|
|
1518
|
-
const [
|
|
1519
|
-
t.postMessage(Object.assign(Object.assign({},
|
|
1498
|
+
const [m, _] = toWireValue(h);
|
|
1499
|
+
t.postMessage(Object.assign(Object.assign({}, m), { id: i }), _), o === "RELEASE" && (t.removeEventListener("message", s), closeEndPoint(t), finalizer in e && typeof e[finalizer] == "function" && e[finalizer]());
|
|
1520
1500
|
}).catch((h) => {
|
|
1521
|
-
const [
|
|
1501
|
+
const [m, _] = toWireValue({
|
|
1522
1502
|
value: new TypeError("Unserializable return value"),
|
|
1523
1503
|
[throwMarker]: 0
|
|
1524
1504
|
});
|
|
1525
|
-
t.postMessage(Object.assign(Object.assign({},
|
|
1505
|
+
t.postMessage(Object.assign(Object.assign({}, m), { id: i }), _);
|
|
1526
1506
|
});
|
|
1527
1507
|
}), t.start && t.start();
|
|
1528
1508
|
}
|
|
@@ -1560,15 +1540,15 @@ function unregisterProxy(e) {
|
|
|
1560
1540
|
function createProxy(e, t = [], r = function() {
|
|
1561
1541
|
}) {
|
|
1562
1542
|
let s = !1;
|
|
1563
|
-
const
|
|
1564
|
-
get(
|
|
1543
|
+
const n = new Proxy(r, {
|
|
1544
|
+
get(i, o) {
|
|
1565
1545
|
if (throwIfProxyReleased(s), o === releaseProxy)
|
|
1566
1546
|
return () => {
|
|
1567
|
-
unregisterProxy(
|
|
1547
|
+
unregisterProxy(n), releaseEndpoint(e), s = !0;
|
|
1568
1548
|
};
|
|
1569
1549
|
if (o === "then") {
|
|
1570
1550
|
if (t.length === 0)
|
|
1571
|
-
return { then: () =>
|
|
1551
|
+
return { then: () => n };
|
|
1572
1552
|
const a = requestResponseMessage(e, {
|
|
1573
1553
|
type: "GET",
|
|
1574
1554
|
path: t.map((u) => u.toString())
|
|
@@ -1577,7 +1557,7 @@ function createProxy(e, t = [], r = function() {
|
|
|
1577
1557
|
}
|
|
1578
1558
|
return createProxy(e, [...t, o]);
|
|
1579
1559
|
},
|
|
1580
|
-
set(
|
|
1560
|
+
set(i, o, a) {
|
|
1581
1561
|
throwIfProxyReleased(s);
|
|
1582
1562
|
const [u, c] = toWireValue(a);
|
|
1583
1563
|
return requestResponseMessage(e, {
|
|
@@ -1586,7 +1566,7 @@ function createProxy(e, t = [], r = function() {
|
|
|
1586
1566
|
value: u
|
|
1587
1567
|
}, c).then(fromWireValue);
|
|
1588
1568
|
},
|
|
1589
|
-
apply(
|
|
1569
|
+
apply(i, o, a) {
|
|
1590
1570
|
throwIfProxyReleased(s);
|
|
1591
1571
|
const u = t[t.length - 1];
|
|
1592
1572
|
if (u === createEndpoint)
|
|
@@ -1598,11 +1578,11 @@ function createProxy(e, t = [], r = function() {
|
|
|
1598
1578
|
const [c, h] = processArguments(a);
|
|
1599
1579
|
return requestResponseMessage(e, {
|
|
1600
1580
|
type: "APPLY",
|
|
1601
|
-
path: t.map((
|
|
1581
|
+
path: t.map((m) => m.toString()),
|
|
1602
1582
|
argumentList: c
|
|
1603
1583
|
}, h).then(fromWireValue);
|
|
1604
1584
|
},
|
|
1605
|
-
construct(
|
|
1585
|
+
construct(i, o) {
|
|
1606
1586
|
throwIfProxyReleased(s);
|
|
1607
1587
|
const [a, u] = processArguments(o);
|
|
1608
1588
|
return requestResponseMessage(e, {
|
|
@@ -1612,7 +1592,7 @@ function createProxy(e, t = [], r = function() {
|
|
|
1612
1592
|
}, u).then(fromWireValue);
|
|
1613
1593
|
}
|
|
1614
1594
|
});
|
|
1615
|
-
return registerProxy(
|
|
1595
|
+
return registerProxy(n, e), n;
|
|
1616
1596
|
}
|
|
1617
1597
|
function myFlat(e) {
|
|
1618
1598
|
return Array.prototype.concat.apply([], e);
|
|
@@ -1630,7 +1610,7 @@ function proxy(e) {
|
|
|
1630
1610
|
}
|
|
1631
1611
|
function windowEndpoint(e, t = globalThis, r = "*") {
|
|
1632
1612
|
return {
|
|
1633
|
-
postMessage: (s,
|
|
1613
|
+
postMessage: (s, n) => e.postMessage(s, r, n),
|
|
1634
1614
|
addEventListener: t.addEventListener.bind(t),
|
|
1635
1615
|
removeEventListener: t.removeEventListener.bind(t)
|
|
1636
1616
|
};
|
|
@@ -1638,14 +1618,14 @@ function windowEndpoint(e, t = globalThis, r = "*") {
|
|
|
1638
1618
|
function toWireValue(e) {
|
|
1639
1619
|
for (const [t, r] of transferHandlers)
|
|
1640
1620
|
if (r.canHandle(e)) {
|
|
1641
|
-
const [s,
|
|
1621
|
+
const [s, n] = r.serialize(e);
|
|
1642
1622
|
return [
|
|
1643
1623
|
{
|
|
1644
1624
|
type: "HANDLER",
|
|
1645
1625
|
name: t,
|
|
1646
1626
|
value: s
|
|
1647
1627
|
},
|
|
1648
|
-
|
|
1628
|
+
n
|
|
1649
1629
|
];
|
|
1650
1630
|
}
|
|
1651
1631
|
return [
|
|
@@ -1666,10 +1646,10 @@ function fromWireValue(e) {
|
|
|
1666
1646
|
}
|
|
1667
1647
|
function requestResponseMessage(e, t, r) {
|
|
1668
1648
|
return new Promise((s) => {
|
|
1669
|
-
const
|
|
1670
|
-
e.addEventListener("message", function
|
|
1671
|
-
!o.data || !o.data.id || o.data.id !==
|
|
1672
|
-
}), e.start && e.start(), e.postMessage(Object.assign({ id:
|
|
1649
|
+
const n = generateUUID();
|
|
1650
|
+
e.addEventListener("message", function i(o) {
|
|
1651
|
+
!o.data || !o.data.id || o.data.id !== n || (e.removeEventListener("message", i), s(o.data));
|
|
1652
|
+
}), e.start && e.start(), e.postMessage(Object.assign({ id: n }, t), r);
|
|
1673
1653
|
});
|
|
1674
1654
|
}
|
|
1675
1655
|
function generateUUID() {
|
|
@@ -1679,14 +1659,14 @@ function consumeAPI(e) {
|
|
|
1679
1659
|
setupTransferHandlers();
|
|
1680
1660
|
const t = e instanceof Worker ? e : windowEndpoint(e), r = wrap(t), s = proxyClone(r);
|
|
1681
1661
|
return new Proxy(s, {
|
|
1682
|
-
get: (
|
|
1662
|
+
get: (n, i) => i === "isConnected" ? async () => {
|
|
1683
1663
|
for (let o = 0; o < 10; o++)
|
|
1684
1664
|
try {
|
|
1685
1665
|
await runWithTimeout(r.isConnected(), 200);
|
|
1686
1666
|
break;
|
|
1687
1667
|
} catch {
|
|
1688
1668
|
}
|
|
1689
|
-
} : r[
|
|
1669
|
+
} : r[i]
|
|
1690
1670
|
});
|
|
1691
1671
|
}
|
|
1692
1672
|
async function runWithTimeout(e, t) {
|
|
@@ -1697,16 +1677,16 @@ async function runWithTimeout(e, t) {
|
|
|
1697
1677
|
function exposeAPI(e, t) {
|
|
1698
1678
|
setupTransferHandlers();
|
|
1699
1679
|
const r = Promise.resolve();
|
|
1700
|
-
let s,
|
|
1701
|
-
const
|
|
1702
|
-
s = u,
|
|
1680
|
+
let s, n;
|
|
1681
|
+
const i = new Promise((u, c) => {
|
|
1682
|
+
s = u, n = c;
|
|
1703
1683
|
}), o = proxyClone(e), a = new Proxy(o, {
|
|
1704
|
-
get: (u, c) => c === "isConnected" ? () => r : c === "isReady" ? () =>
|
|
1684
|
+
get: (u, c) => c === "isConnected" ? () => r : c === "isReady" ? () => i : c in u ? u[c] : t == null ? void 0 : t[c]
|
|
1705
1685
|
});
|
|
1706
1686
|
return expose(
|
|
1707
1687
|
a,
|
|
1708
1688
|
typeof window < "u" ? windowEndpoint(self.parent) : void 0
|
|
1709
|
-
), [s,
|
|
1689
|
+
), [s, n, a];
|
|
1710
1690
|
}
|
|
1711
1691
|
let isTransferHandlersSetup = !1;
|
|
1712
1692
|
function setupTransferHandlers() {
|
|
@@ -1837,11 +1817,11 @@ class WebPHP extends BasePHP {
|
|
|
1837
1817
|
);
|
|
1838
1818
|
}
|
|
1839
1819
|
static async loadRuntime(t, r = {}) {
|
|
1840
|
-
var
|
|
1841
|
-
const s = r.loadAllExtensions ? "kitchen-sink" : "light",
|
|
1842
|
-
return (
|
|
1843
|
-
[
|
|
1844
|
-
}), await loadPHPRuntime(
|
|
1820
|
+
var i;
|
|
1821
|
+
const s = r.loadAllExtensions ? "kitchen-sink" : "light", n = await getPHPLoaderModule(t, s);
|
|
1822
|
+
return (i = r.downloadMonitor) == null || i.expectAssets({
|
|
1823
|
+
[n.dependencyFilename]: n.dependenciesTotalSize
|
|
1824
|
+
}), await loadPHPRuntime(n, {
|
|
1845
1825
|
...r.emscriptenOptions || {},
|
|
1846
1826
|
...fakeWebsocket()
|
|
1847
1827
|
});
|
|
@@ -1992,29 +1972,29 @@ async function registerServiceWorker(e, t, r) {
|
|
|
1992
1972
|
async function spawnPHPWorkerThread(e, t = {}) {
|
|
1993
1973
|
e = addQueryParams(e, t);
|
|
1994
1974
|
const r = new Worker(e, { type: "module" });
|
|
1995
|
-
return new Promise((s,
|
|
1975
|
+
return new Promise((s, n) => {
|
|
1996
1976
|
r.onerror = (o) => {
|
|
1997
1977
|
const a = new Error(
|
|
1998
1978
|
`WebWorker failed to load at ${e}. ${o.message ? `Original error: ${o.message}` : ""}`
|
|
1999
1979
|
);
|
|
2000
|
-
a.filename = o.filename,
|
|
1980
|
+
a.filename = o.filename, n(a);
|
|
2001
1981
|
};
|
|
2002
|
-
function
|
|
2003
|
-
o.data === "worker-script-started" && (s(r), r.removeEventListener("message",
|
|
1982
|
+
function i(o) {
|
|
1983
|
+
o.data === "worker-script-started" && (s(r), r.removeEventListener("message", i));
|
|
2004
1984
|
}
|
|
2005
|
-
r.addEventListener("message",
|
|
1985
|
+
r.addEventListener("message", i);
|
|
2006
1986
|
});
|
|
2007
1987
|
}
|
|
2008
1988
|
function addQueryParams(e, t) {
|
|
2009
1989
|
if (!Object.entries(t).length)
|
|
2010
1990
|
return e + "";
|
|
2011
1991
|
const r = new URL(e);
|
|
2012
|
-
for (const [s,
|
|
2013
|
-
if (Array.isArray(
|
|
2014
|
-
for (const
|
|
2015
|
-
r.searchParams.append(s,
|
|
1992
|
+
for (const [s, n] of Object.entries(t))
|
|
1993
|
+
if (Array.isArray(n))
|
|
1994
|
+
for (const i of n)
|
|
1995
|
+
r.searchParams.append(s, i);
|
|
2016
1996
|
else
|
|
2017
|
-
r.searchParams.set(s,
|
|
1997
|
+
r.searchParams.set(s, n);
|
|
2018
1998
|
return r.toString();
|
|
2019
1999
|
}
|
|
2020
2000
|
export {
|