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