@php-wasm/web 0.6.2 → 0.6.4
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 +9 -22
- package/index.js +362 -346
- 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 +20 -3
- package/kitchen-sink/php_7_1.js +20 -3
- package/kitchen-sink/php_7_2.js +20 -3
- package/kitchen-sink/php_7_3.js +20 -3
- package/kitchen-sink/php_7_4.js +20 -3
- package/kitchen-sink/php_8_0.js +20 -3
- package/kitchen-sink/php_8_1.js +20 -3
- package/kitchen-sink/php_8_2.js +20 -3
- package/kitchen-sink/php_8_3.js +20 -3
- 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 +20 -3
- package/light/php_7_1.js +20 -3
- package/light/php_7_2.js +20 -3
- package/light/php_7_3.js +20 -3
- package/light/php_7_4.js +20 -3
- package/light/php_8_0.js +20 -3
- package/light/php_8_1.js +20 -3
- package/light/php_8_2.js +20 -3
- package/light/php_8_3.js +20 -3
- 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
|
|
5
|
+
var c = (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 o;
|
|
16
|
+
n != null && n.lastModified && (o = /* @__PURE__ */ new Date()), (!o || isNaN(o.getFullYear())) && (o = /* @__PURE__ */ new Date()), this.lastModifiedDate = o, this.lastModified = o.getMilliseconds(), this.name = s || "";
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
global.File = e;
|
|
@@ -50,9 +50,9 @@ function isByobSupported() {
|
|
|
50
50
|
// this if needed.
|
|
51
51
|
autoAllocateChunkSize: 512 * 1024,
|
|
52
52
|
async pull(r) {
|
|
53
|
-
const s = r.byobRequest.view,
|
|
54
|
-
new Uint8Array(s.buffer).set(
|
|
55
|
-
const a =
|
|
53
|
+
const s = r.byobRequest.view, o = await t.slice(e, e + s.byteLength).arrayBuffer(), i = new Uint8Array(o);
|
|
54
|
+
new Uint8Array(s.buffer).set(i);
|
|
55
|
+
const a = i.byteLength;
|
|
56
56
|
r.byobRequest.respond(a), e += a, e >= t.size && r.close();
|
|
57
57
|
}
|
|
58
58
|
});
|
|
@@ -114,27 +114,27 @@ 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 o;
|
|
119
119
|
try {
|
|
120
|
-
return s(...
|
|
121
|
-
} catch (
|
|
122
|
-
if (!(
|
|
123
|
-
throw
|
|
120
|
+
return s(...n);
|
|
121
|
+
} catch (i) {
|
|
122
|
+
if (!(i instanceof Error))
|
|
123
|
+
throw i;
|
|
124
124
|
const a = clarifyErrorMessage(
|
|
125
|
-
|
|
126
|
-
(
|
|
125
|
+
i,
|
|
126
|
+
(o = e.lastAsyncifyStackSource) == null ? void 0 : o.stack
|
|
127
127
|
);
|
|
128
|
-
if (e.lastAsyncifyStackSource && (
|
|
128
|
+
if (e.lastAsyncifyStackSource && (i.cause = e.lastAsyncifyStackSource), t.hasListeners()) {
|
|
129
129
|
t.dispatchEvent(
|
|
130
130
|
new ErrorEvent("error", {
|
|
131
|
-
error:
|
|
131
|
+
error: i,
|
|
132
132
|
message: a
|
|
133
133
|
})
|
|
134
134
|
);
|
|
135
135
|
return;
|
|
136
136
|
}
|
|
137
|
-
throw isExitCodeZero(
|
|
137
|
+
throw isExitCodeZero(i) || showCriticalErrorBox(a), i;
|
|
138
138
|
}
|
|
139
139
|
};
|
|
140
140
|
}
|
|
@@ -259,20 +259,39 @@ 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--)
|
|
267
267
|
e.unshift("..");
|
|
268
268
|
return e;
|
|
269
269
|
}
|
|
270
|
+
function splitShellCommand(e) {
|
|
271
|
+
let s = 0, n = "";
|
|
272
|
+
const o = [];
|
|
273
|
+
let i = "";
|
|
274
|
+
for (let a = 0; a < e.length; a++) {
|
|
275
|
+
const l = e[a];
|
|
276
|
+
l === "\\" ? ((e[a + 1] === '"' || e[a + 1] === "'") && a++, i += e[a]) : s === 0 ? l === '"' || l === "'" ? (s = 1, n = l) : l.match(/\s/) ? (i.trim().length && o.push(i.trim()), i = l) : o.length && !i ? i = o.pop() + l : i += l : s === 1 && (l === n ? (s = 0, n = "") : i += l);
|
|
277
|
+
}
|
|
278
|
+
return i && o.push(i.trim()), o;
|
|
279
|
+
}
|
|
270
280
|
function createSpawnHandler(e) {
|
|
271
|
-
return function(t) {
|
|
272
|
-
const
|
|
281
|
+
return function(t, r = [], s = {}) {
|
|
282
|
+
const n = new ChildProcess(), o = new ProcessApi(n);
|
|
273
283
|
return setTimeout(async () => {
|
|
274
|
-
|
|
275
|
-
|
|
284
|
+
let i = [];
|
|
285
|
+
if (r.length)
|
|
286
|
+
i = [t, ...r];
|
|
287
|
+
else if (typeof t == "string")
|
|
288
|
+
i = splitShellCommand(t);
|
|
289
|
+
else if (Array.isArray(t))
|
|
290
|
+
i = t;
|
|
291
|
+
else
|
|
292
|
+
throw new Error("Invalid command ", t);
|
|
293
|
+
await e(i, o, s), n.emit("spawn", !0);
|
|
294
|
+
}), n;
|
|
276
295
|
};
|
|
277
296
|
}
|
|
278
297
|
class EventEmitter {
|
|
@@ -297,9 +316,15 @@ class ProcessApi extends EventEmitter {
|
|
|
297
316
|
stdout(t) {
|
|
298
317
|
typeof t == "string" && (t = new TextEncoder().encode(t)), this.childProcess.stdout.emit("data", t);
|
|
299
318
|
}
|
|
319
|
+
stdoutEnd() {
|
|
320
|
+
this.childProcess.stdout.emit("end", {});
|
|
321
|
+
}
|
|
300
322
|
stderr(t) {
|
|
301
323
|
typeof t == "string" && (t = new TextEncoder().encode(t)), this.childProcess.stderr.emit("data", t);
|
|
302
324
|
}
|
|
325
|
+
stderrEnd() {
|
|
326
|
+
this.childProcess.stderr.emit("end", {});
|
|
327
|
+
}
|
|
303
328
|
exit(t) {
|
|
304
329
|
this.exited || (this.exited = !0, this.childProcess.emit("exit", t));
|
|
305
330
|
}
|
|
@@ -337,8 +362,8 @@ ReadableStream.prototype[Symbol.asyncIterator] || (ReadableStream.prototype[Symb
|
|
|
337
362
|
}, ReadableStream.prototype.iterate = // @ts-ignore
|
|
338
363
|
ReadableStream.prototype[Symbol.asyncIterator]);
|
|
339
364
|
class PHPResponse {
|
|
340
|
-
constructor(t, r, s,
|
|
341
|
-
this.httpStatusCode = t, this.headers = r, this.bytes = s, this.exitCode =
|
|
365
|
+
constructor(t, r, s, n = "", o = 0) {
|
|
366
|
+
this.httpStatusCode = t, this.headers = r, this.bytes = s, this.exitCode = o, this.errors = n;
|
|
342
367
|
}
|
|
343
368
|
static fromRawData(t) {
|
|
344
369
|
return new PHPResponse(
|
|
@@ -382,16 +407,16 @@ const SupportedPHPVersions = [
|
|
|
382
407
|
"7.1",
|
|
383
408
|
"7.0"
|
|
384
409
|
], LatestSupportedPHPVersion = SupportedPHPVersions[0];
|
|
385
|
-
var
|
|
410
|
+
var b, T;
|
|
386
411
|
class PHPBrowser {
|
|
387
412
|
/**
|
|
388
413
|
* @param server - The PHP server to browse.
|
|
389
414
|
* @param config - The browser configuration.
|
|
390
415
|
*/
|
|
391
416
|
constructor(t, r = {}) {
|
|
392
|
-
d(this,
|
|
393
|
-
d(this,
|
|
394
|
-
this.requestHandler = t, p(this,
|
|
417
|
+
d(this, b, void 0);
|
|
418
|
+
d(this, T, void 0);
|
|
419
|
+
this.requestHandler = t, p(this, b, {}), p(this, T, {
|
|
395
420
|
handleRedirects: !1,
|
|
396
421
|
maxRedirects: 4,
|
|
397
422
|
...r
|
|
@@ -419,14 +444,14 @@ class PHPBrowser {
|
|
|
419
444
|
cookie: this.serializeCookies()
|
|
420
445
|
}
|
|
421
446
|
});
|
|
422
|
-
if (s.headers["set-cookie"] && this.setCookies(s.headers["set-cookie"]),
|
|
423
|
-
const
|
|
447
|
+
if (s.headers["set-cookie"] && this.setCookies(s.headers["set-cookie"]), c(this, T).handleRedirects && s.headers.location && r < c(this, T).maxRedirects) {
|
|
448
|
+
const n = new URL(
|
|
424
449
|
s.headers.location[0],
|
|
425
450
|
this.requestHandler.absoluteUrl
|
|
426
451
|
);
|
|
427
452
|
return this.request(
|
|
428
453
|
{
|
|
429
|
-
url:
|
|
454
|
+
url: n.toString(),
|
|
430
455
|
method: "GET",
|
|
431
456
|
headers: {}
|
|
432
457
|
},
|
|
@@ -456,20 +481,20 @@ class PHPBrowser {
|
|
|
456
481
|
try {
|
|
457
482
|
if (!r.includes("="))
|
|
458
483
|
continue;
|
|
459
|
-
const s = r.indexOf("="),
|
|
460
|
-
|
|
484
|
+
const s = r.indexOf("="), n = r.substring(0, s), o = r.substring(s + 1).split(";")[0];
|
|
485
|
+
c(this, b)[n] = o;
|
|
461
486
|
} catch (s) {
|
|
462
487
|
console.error(s);
|
|
463
488
|
}
|
|
464
489
|
}
|
|
465
490
|
serializeCookies() {
|
|
466
491
|
const t = [];
|
|
467
|
-
for (const r in
|
|
468
|
-
t.push(`${r}=${
|
|
492
|
+
for (const r in c(this, b))
|
|
493
|
+
t.push(`${r}=${c(this, b)[r]}`);
|
|
469
494
|
return t.join("; ");
|
|
470
495
|
}
|
|
471
496
|
}
|
|
472
|
-
|
|
497
|
+
b = new WeakMap(), T = new WeakMap();
|
|
473
498
|
const DEFAULT_BASE_URL = "http://example.com";
|
|
474
499
|
function toRelativeUrl(e) {
|
|
475
500
|
return e.toString().substring(e.origin.length);
|
|
@@ -480,7 +505,35 @@ function removePathPrefix(e, t) {
|
|
|
480
505
|
function ensurePathPrefix(e, t) {
|
|
481
506
|
return !t || e.startsWith(t) ? e : t + e;
|
|
482
507
|
}
|
|
483
|
-
|
|
508
|
+
async function encodeAsMultipart(e) {
|
|
509
|
+
const t = `----${Math.random().toString(36).slice(2)}`, r = `multipart/form-data; boundary=${t}`, s = new TextEncoder(), n = [];
|
|
510
|
+
for (const [l, u] of Object.entries(e))
|
|
511
|
+
n.push(`--${t}\r
|
|
512
|
+
`), n.push(`Content-Disposition: form-data; name="${l}"`), u instanceof File && n.push(`; filename="${u.name}"`), n.push(`\r
|
|
513
|
+
`), u instanceof File && (n.push("Content-Type: application/octet-stream"), n.push(`\r
|
|
514
|
+
`)), n.push(`\r
|
|
515
|
+
`), u instanceof File ? n.push(await fileToUint8Array(u)) : n.push(u), n.push(`\r
|
|
516
|
+
`);
|
|
517
|
+
n.push(`--${t}--\r
|
|
518
|
+
`);
|
|
519
|
+
const o = n.reduce((l, u) => l + u.length, 0), i = new Uint8Array(o);
|
|
520
|
+
let a = 0;
|
|
521
|
+
for (const l of n)
|
|
522
|
+
i.set(
|
|
523
|
+
typeof l == "string" ? s.encode(l) : l,
|
|
524
|
+
a
|
|
525
|
+
), a += l.length;
|
|
526
|
+
return { bytes: i, contentType: r };
|
|
527
|
+
}
|
|
528
|
+
function fileToUint8Array(e) {
|
|
529
|
+
return new Promise((t) => {
|
|
530
|
+
const r = new FileReader();
|
|
531
|
+
r.onload = () => {
|
|
532
|
+
t(new Uint8Array(r.result));
|
|
533
|
+
}, r.readAsArrayBuffer(e);
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
var g, H, L, R, k, y, C, S, N, Z, U, X, O, ee;
|
|
484
537
|
class PHPRequestHandler {
|
|
485
538
|
/**
|
|
486
539
|
* @param php - The PHP instance.
|
|
@@ -511,31 +564,31 @@ class PHPRequestHandler {
|
|
|
511
564
|
* @throws {Error} If the requested path doesn't exist.
|
|
512
565
|
* @returns The resolved filesystem path.
|
|
513
566
|
*/
|
|
514
|
-
d(this,
|
|
515
|
-
d(this,
|
|
516
|
-
d(this,
|
|
567
|
+
d(this, O);
|
|
568
|
+
d(this, g, void 0);
|
|
569
|
+
d(this, H, void 0);
|
|
517
570
|
d(this, L, void 0);
|
|
518
|
-
d(this,
|
|
571
|
+
d(this, R, void 0);
|
|
572
|
+
d(this, k, void 0);
|
|
573
|
+
d(this, y, void 0);
|
|
519
574
|
d(this, C, void 0);
|
|
520
|
-
d(this,
|
|
521
|
-
|
|
522
|
-
d(this, x, void 0);
|
|
523
|
-
p(this, x, new Semaphore({ concurrency: 1 }));
|
|
575
|
+
d(this, S, void 0);
|
|
576
|
+
p(this, S, new Semaphore({ concurrency: 1 }));
|
|
524
577
|
const {
|
|
525
578
|
documentRoot: s = "/www/",
|
|
526
|
-
absoluteUrl:
|
|
579
|
+
absoluteUrl: n = typeof location == "object" ? location == null ? void 0 : location.href : ""
|
|
527
580
|
} = r;
|
|
528
|
-
this.php = t, p(this,
|
|
529
|
-
const
|
|
530
|
-
p(this, L,
|
|
531
|
-
const
|
|
532
|
-
p(this,
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
].join("")), p(this,
|
|
536
|
-
`${
|
|
537
|
-
|
|
538
|
-
|
|
581
|
+
this.php = t, p(this, g, s);
|
|
582
|
+
const o = new URL(n);
|
|
583
|
+
p(this, L, o.hostname), p(this, R, o.port ? Number(o.port) : o.protocol === "https:" ? 443 : 80), p(this, H, (o.protocol || "").replace(":", ""));
|
|
584
|
+
const i = c(this, R) !== 443 && c(this, R) !== 80;
|
|
585
|
+
p(this, k, [
|
|
586
|
+
c(this, L),
|
|
587
|
+
i ? `:${c(this, R)}` : ""
|
|
588
|
+
].join("")), p(this, y, o.pathname.replace(/\/+$/, "")), p(this, C, [
|
|
589
|
+
`${c(this, H)}://`,
|
|
590
|
+
c(this, k),
|
|
591
|
+
c(this, y)
|
|
539
592
|
].join(""));
|
|
540
593
|
}
|
|
541
594
|
/** @inheritDoc */
|
|
@@ -545,32 +598,32 @@ class PHPRequestHandler {
|
|
|
545
598
|
/** @inheritDoc */
|
|
546
599
|
internalUrlToPath(t) {
|
|
547
600
|
const r = new URL(t);
|
|
548
|
-
return r.pathname.startsWith(
|
|
601
|
+
return r.pathname.startsWith(c(this, y)) && (r.pathname = r.pathname.slice(c(this, y).length)), toRelativeUrl(r);
|
|
549
602
|
}
|
|
550
603
|
get isRequestRunning() {
|
|
551
|
-
return
|
|
604
|
+
return c(this, S).running > 0;
|
|
552
605
|
}
|
|
553
606
|
/** @inheritDoc */
|
|
554
607
|
get absoluteUrl() {
|
|
555
|
-
return
|
|
608
|
+
return c(this, C);
|
|
556
609
|
}
|
|
557
610
|
/** @inheritDoc */
|
|
558
611
|
get documentRoot() {
|
|
559
|
-
return
|
|
612
|
+
return c(this, g);
|
|
560
613
|
}
|
|
561
614
|
/** @inheritDoc */
|
|
562
615
|
async request(t) {
|
|
563
616
|
const r = t.url.startsWith("http://") || t.url.startsWith("https://"), s = new URL(
|
|
564
617
|
t.url,
|
|
565
618
|
r ? void 0 : DEFAULT_BASE_URL
|
|
566
|
-
),
|
|
619
|
+
), n = removePathPrefix(
|
|
567
620
|
s.pathname,
|
|
568
|
-
|
|
569
|
-
),
|
|
570
|
-
return seemsLikeAPHPRequestHandlerPath(
|
|
621
|
+
c(this, y)
|
|
622
|
+
), o = `${c(this, g)}${n}`;
|
|
623
|
+
return seemsLikeAPHPRequestHandlerPath(o) ? await f(this, U, X).call(this, t, s) : f(this, N, Z).call(this, o);
|
|
571
624
|
}
|
|
572
625
|
}
|
|
573
|
-
|
|
626
|
+
g = new WeakMap(), H = new WeakMap(), L = new WeakMap(), R = new WeakMap(), k = new WeakMap(), y = new WeakMap(), C = new WeakMap(), S = new WeakMap(), N = new WeakSet(), Z = function(t) {
|
|
574
627
|
if (!this.php.fileExists(t))
|
|
575
628
|
return new PHPResponse(
|
|
576
629
|
404,
|
|
@@ -596,8 +649,8 @@ E = new WeakMap(), k = new WeakMap(), L = new WeakMap(), S = new WeakMap(), C =
|
|
|
596
649
|
r
|
|
597
650
|
);
|
|
598
651
|
}, U = new WeakSet(), X = async function(t, r) {
|
|
599
|
-
var
|
|
600
|
-
if (
|
|
652
|
+
var n, o;
|
|
653
|
+
if (c(this, S).running > 0 && ((n = t.headers) == null ? void 0 : n["x-request-issuer"]) === "php")
|
|
601
654
|
return console.warn(
|
|
602
655
|
"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
656
|
), new PHPResponse(
|
|
@@ -605,47 +658,34 @@ E = new WeakMap(), k = new WeakMap(), L = new WeakMap(), S = new WeakMap(), C =
|
|
|
605
658
|
{},
|
|
606
659
|
new TextEncoder().encode("502 Bad Gateway")
|
|
607
660
|
);
|
|
608
|
-
const s = await
|
|
661
|
+
const s = await c(this, S).acquire();
|
|
609
662
|
try {
|
|
610
|
-
this.php.addServerGlobalEntry("REMOTE_ADDR", "127.0.0.1"), this.php.addServerGlobalEntry("DOCUMENT_ROOT",
|
|
663
|
+
this.php.addServerGlobalEntry("REMOTE_ADDR", "127.0.0.1"), this.php.addServerGlobalEntry("DOCUMENT_ROOT", c(this, g)), this.php.addServerGlobalEntry(
|
|
611
664
|
"HTTPS",
|
|
612
|
-
|
|
665
|
+
c(this, C).startsWith("https://") ? "on" : ""
|
|
613
666
|
);
|
|
614
|
-
let
|
|
615
|
-
const
|
|
616
|
-
host:
|
|
667
|
+
let i = "GET";
|
|
668
|
+
const a = {
|
|
669
|
+
host: c(this, k),
|
|
617
670
|
...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);
|
|
671
|
+
};
|
|
672
|
+
let l = t.body;
|
|
673
|
+
if (typeof l == "object" && !(l instanceof Uint8Array)) {
|
|
674
|
+
i = "POST";
|
|
675
|
+
const { bytes: h, contentType: m } = await encodeAsMultipart(l);
|
|
676
|
+
l = h, a["content-type"] = m;
|
|
633
677
|
}
|
|
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 _;
|
|
678
|
+
let u;
|
|
639
679
|
try {
|
|
640
|
-
let
|
|
680
|
+
let h = r.pathname;
|
|
641
681
|
if ((o = t.headers) != null && o["x-rewrite-url"])
|
|
642
682
|
try {
|
|
643
|
-
|
|
683
|
+
h = new URL(
|
|
644
684
|
t.headers["x-rewrite-url"]
|
|
645
685
|
).pathname;
|
|
646
686
|
} catch {
|
|
647
687
|
}
|
|
648
|
-
|
|
688
|
+
u = f(this, O, ee).call(this, h);
|
|
649
689
|
} catch {
|
|
650
690
|
return new PHPResponse(
|
|
651
691
|
404,
|
|
@@ -656,41 +696,25 @@ E = new WeakMap(), k = new WeakMap(), L = new WeakMap(), S = new WeakMap(), C =
|
|
|
656
696
|
return await this.php.run({
|
|
657
697
|
relativeUri: ensurePathPrefix(
|
|
658
698
|
toRelativeUrl(r),
|
|
659
|
-
|
|
699
|
+
c(this, y)
|
|
660
700
|
),
|
|
661
|
-
protocol:
|
|
662
|
-
method: t.method ||
|
|
663
|
-
body:
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
headers: u
|
|
701
|
+
protocol: c(this, H),
|
|
702
|
+
method: t.method || i,
|
|
703
|
+
body: l,
|
|
704
|
+
scriptPath: u,
|
|
705
|
+
headers: a
|
|
667
706
|
});
|
|
668
707
|
} finally {
|
|
669
708
|
s();
|
|
670
709
|
}
|
|
671
|
-
},
|
|
672
|
-
let r = removePathPrefix(t,
|
|
673
|
-
r.includes(".php") ? r = r.split(".php")[0] + ".php" : (r.endsWith("/") || (r
|
|
674
|
-
const s = `${
|
|
710
|
+
}, O = new WeakSet(), ee = function(t) {
|
|
711
|
+
let r = removePathPrefix(t, c(this, y));
|
|
712
|
+
r.includes(".php") ? r = r.split(".php")[0] + ".php" : this.php.isDir(`${c(this, g)}${r}`) ? (r.endsWith("/") || (r = `${r}/`), r = `${r}index.php`) : r = "/index.php";
|
|
713
|
+
const s = `${c(this, g)}${r}`;
|
|
675
714
|
if (this.php.fileExists(s))
|
|
676
715
|
return s;
|
|
677
716
|
throw new Error(`File not found: ${s}`);
|
|
678
717
|
};
|
|
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
718
|
function inferMimeType(e) {
|
|
695
719
|
switch (e.split(".").pop()) {
|
|
696
720
|
case "css":
|
|
@@ -825,16 +849,16 @@ function getEmscriptenFsError(e) {
|
|
|
825
849
|
return FileErrorCodes[t];
|
|
826
850
|
}
|
|
827
851
|
function rethrowFileSystemError(e = "") {
|
|
828
|
-
return function(r, s,
|
|
829
|
-
const
|
|
830
|
-
|
|
852
|
+
return function(r, s, n) {
|
|
853
|
+
const o = n.value;
|
|
854
|
+
n.value = function(...i) {
|
|
831
855
|
try {
|
|
832
|
-
return
|
|
856
|
+
return o.apply(this, i);
|
|
833
857
|
} catch (a) {
|
|
834
|
-
const
|
|
835
|
-
if (
|
|
836
|
-
const
|
|
837
|
-
throw new Error(`${
|
|
858
|
+
const l = typeof a == "object" ? a == null ? void 0 : a.errno : null;
|
|
859
|
+
if (l in FileErrorCodes) {
|
|
860
|
+
const u = FileErrorCodes[l], h = typeof i[0] == "string" ? i[0] : null, m = h !== null ? e.replaceAll("{path}", h) : e;
|
|
861
|
+
throw new Error(`${m}: ${u}`, {
|
|
838
862
|
cause: a
|
|
839
863
|
});
|
|
840
864
|
}
|
|
@@ -846,9 +870,9 @@ function rethrowFileSystemError(e = "") {
|
|
|
846
870
|
const RuntimeId = Symbol("RuntimeId"), loadedRuntimes = /* @__PURE__ */ new Map();
|
|
847
871
|
let lastRuntimeId = 0;
|
|
848
872
|
async function loadPHPRuntime(e, t = {}) {
|
|
849
|
-
const [r, s,
|
|
873
|
+
const [r, s, n] = makePromise(), o = e.init(currentJsRuntime, {
|
|
850
874
|
onAbort(a) {
|
|
851
|
-
|
|
875
|
+
n(a), console.error(a);
|
|
852
876
|
},
|
|
853
877
|
ENV: {},
|
|
854
878
|
// Emscripten sometimes prepends a '/' to the path, which
|
|
@@ -862,10 +886,10 @@ async function loadPHPRuntime(e, t = {}) {
|
|
|
862
886
|
}
|
|
863
887
|
});
|
|
864
888
|
await r;
|
|
865
|
-
const
|
|
866
|
-
return
|
|
867
|
-
return loadedRuntimes.delete(
|
|
868
|
-
},
|
|
889
|
+
const i = ++lastRuntimeId;
|
|
890
|
+
return o.id = i, o.originalExit = o._exit, o._exit = function(a) {
|
|
891
|
+
return loadedRuntimes.delete(i), o.originalExit(a);
|
|
892
|
+
}, o[RuntimeId] = i, loadedRuntimes.set(i, o), i;
|
|
869
893
|
}
|
|
870
894
|
function getLoadedRuntime(e) {
|
|
871
895
|
return loadedRuntimes.get(e);
|
|
@@ -880,12 +904,12 @@ const currentJsRuntime = function() {
|
|
|
880
904
|
return e.unshift(t), e;
|
|
881
905
|
};
|
|
882
906
|
var __defProp = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __decorateClass = (e, t, r, s) => {
|
|
883
|
-
for (var
|
|
884
|
-
(
|
|
885
|
-
return s &&
|
|
907
|
+
for (var n = s > 1 ? void 0 : s ? __getOwnPropDesc(t, r) : t, o = e.length - 1, i; o >= 0; o--)
|
|
908
|
+
(i = e[o]) && (n = (s ? i(t, r, n) : i(n)) || n);
|
|
909
|
+
return s && n && __defProp(t, r, n), n;
|
|
886
910
|
};
|
|
887
911
|
const STRING = "string", NUMBER = "number", __private__dont__use = Symbol("__private__dont__use");
|
|
888
|
-
var
|
|
912
|
+
var x, F, A, w, E, v, P, M, B, te, W, re, q, se, D, ne, $, ie, z, oe, j, ae, G, le, V, ce, Q, ue, Y, de, J, he;
|
|
889
913
|
class BasePHP {
|
|
890
914
|
/**
|
|
891
915
|
* Initializes a PHP runtime.
|
|
@@ -895,55 +919,46 @@ class BasePHP {
|
|
|
895
919
|
* @param serverOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
|
|
896
920
|
*/
|
|
897
921
|
constructor(e, t) {
|
|
898
|
-
d(this,
|
|
922
|
+
d(this, B);
|
|
899
923
|
d(this, W);
|
|
900
924
|
d(this, q);
|
|
901
|
-
d(this, z);
|
|
902
925
|
d(this, D);
|
|
903
926
|
d(this, $);
|
|
927
|
+
d(this, z);
|
|
904
928
|
d(this, j);
|
|
905
929
|
d(this, G);
|
|
906
930
|
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
|
-
*/
|
|
931
|
+
d(this, Q);
|
|
916
932
|
d(this, Y);
|
|
917
933
|
d(this, J);
|
|
918
|
-
d(this,
|
|
919
|
-
d(this,
|
|
920
|
-
d(this,
|
|
921
|
-
d(this, I, void 0);
|
|
934
|
+
d(this, x, void 0);
|
|
935
|
+
d(this, F, void 0);
|
|
936
|
+
d(this, A, void 0);
|
|
922
937
|
d(this, w, void 0);
|
|
938
|
+
d(this, E, void 0);
|
|
923
939
|
d(this, v, void 0);
|
|
924
|
-
d(this, b, void 0);
|
|
925
940
|
d(this, P, void 0);
|
|
926
|
-
d(this,
|
|
927
|
-
p(this,
|
|
941
|
+
d(this, M, void 0);
|
|
942
|
+
p(this, x, []), p(this, w, !1), p(this, E, null), p(this, v, {}), p(this, P, /* @__PURE__ */ new Map()), p(this, M, []), this.semaphore = new Semaphore({ concurrency: 1 }), e !== void 0 && this.initializeRuntime(e), t && (this.requestHandler = new PHPBrowser(
|
|
928
943
|
new PHPRequestHandler(this, t)
|
|
929
944
|
));
|
|
930
945
|
}
|
|
931
946
|
addEventListener(e, t) {
|
|
932
|
-
|
|
947
|
+
c(this, P).has(e) || c(this, P).set(e, /* @__PURE__ */ new Set()), c(this, P).get(e).add(t);
|
|
933
948
|
}
|
|
934
949
|
removeEventListener(e, t) {
|
|
935
950
|
var r;
|
|
936
|
-
(r =
|
|
951
|
+
(r = c(this, P).get(e)) == null || r.delete(t);
|
|
937
952
|
}
|
|
938
953
|
dispatchEvent(e) {
|
|
939
|
-
const t =
|
|
954
|
+
const t = c(this, P).get(e.type);
|
|
940
955
|
if (t)
|
|
941
956
|
for (const r of t)
|
|
942
957
|
r(e);
|
|
943
958
|
}
|
|
944
959
|
/** @inheritDoc */
|
|
945
960
|
async onMessage(e) {
|
|
946
|
-
|
|
961
|
+
c(this, M).push(e);
|
|
947
962
|
}
|
|
948
963
|
/** @inheritDoc */
|
|
949
964
|
async setSpawnHandler(handler) {
|
|
@@ -974,13 +989,13 @@ class BasePHP {
|
|
|
974
989
|
if (!t)
|
|
975
990
|
throw new Error("Invalid PHP runtime id.");
|
|
976
991
|
this[__private__dont__use] = t, t.onMessage = async (r) => {
|
|
977
|
-
for (const s of
|
|
978
|
-
const
|
|
979
|
-
if (
|
|
980
|
-
return
|
|
992
|
+
for (const s of c(this, M)) {
|
|
993
|
+
const n = await s(r);
|
|
994
|
+
if (n)
|
|
995
|
+
return n;
|
|
981
996
|
}
|
|
982
997
|
return "";
|
|
983
|
-
}, p(this,
|
|
998
|
+
}, p(this, E, improveWASMErrorReporting(t)), this.dispatchEvent({
|
|
984
999
|
type: "runtime.initialized"
|
|
985
1000
|
});
|
|
986
1001
|
}
|
|
@@ -995,13 +1010,13 @@ class BasePHP {
|
|
|
995
1010
|
throw new Error(
|
|
996
1011
|
"Could not set SAPI name. This can only be done before the PHP WASM module is initialized.Did you already dispatch any requests?"
|
|
997
1012
|
);
|
|
998
|
-
p(this,
|
|
1013
|
+
p(this, A, e);
|
|
999
1014
|
}
|
|
1000
1015
|
/** @inheritDoc */
|
|
1001
1016
|
setPhpIniPath(e) {
|
|
1002
|
-
if (
|
|
1017
|
+
if (c(this, w))
|
|
1003
1018
|
throw new Error("Cannot set PHP ini path after calling run().");
|
|
1004
|
-
p(this,
|
|
1019
|
+
p(this, F, e), this[__private__dont__use].ccall(
|
|
1005
1020
|
"wasm_set_phpini_path",
|
|
1006
1021
|
null,
|
|
1007
1022
|
["string"],
|
|
@@ -1010,9 +1025,9 @@ class BasePHP {
|
|
|
1010
1025
|
}
|
|
1011
1026
|
/** @inheritDoc */
|
|
1012
1027
|
setPhpIniEntry(e, t) {
|
|
1013
|
-
if (
|
|
1028
|
+
if (c(this, w))
|
|
1014
1029
|
throw new Error("Cannot set PHP ini entries after calling run().");
|
|
1015
|
-
|
|
1030
|
+
c(this, x).push([e, t]);
|
|
1016
1031
|
}
|
|
1017
1032
|
/** @inheritDoc */
|
|
1018
1033
|
chdir(e) {
|
|
@@ -1029,25 +1044,29 @@ class BasePHP {
|
|
|
1029
1044
|
const t = await this.semaphore.acquire();
|
|
1030
1045
|
let r;
|
|
1031
1046
|
try {
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1047
|
+
if (c(this, w) || (f(this, B, te).call(this), p(this, w, !0)), e.scriptPath && !this.fileExists(e.scriptPath))
|
|
1048
|
+
throw new Error(
|
|
1049
|
+
`The script path "${e.scriptPath}" does not exist.`
|
|
1050
|
+
);
|
|
1051
|
+
f(this, G, le).call(this, e.scriptPath || ""), f(this, q, se).call(this, e.relativeUri || ""), f(this, $, ie).call(this, e.method || "GET");
|
|
1052
|
+
const s = normalizeHeaders(e.headers || {}), n = s.host || "example.com:443";
|
|
1053
|
+
f(this, D, ne).call(this, n, e.protocol || "http"), f(this, z, oe).call(this, s), e.body && (r = f(this, j, ae).call(this, e.body)), typeof e.code == "string" && f(this, Y, de).call(this, " ?>" + e.code), f(this, V, ce).call(this);
|
|
1054
|
+
const o = e.env || {};
|
|
1055
|
+
for (const a in o)
|
|
1056
|
+
f(this, Q, ue).call(this, a, o[a]);
|
|
1057
|
+
const i = await f(this, J, he).call(this);
|
|
1058
|
+
if (e.throwOnError && i.exitCode !== 0) {
|
|
1059
|
+
const a = {
|
|
1060
|
+
stdout: i.text,
|
|
1061
|
+
stderr: i.errors
|
|
1043
1062
|
};
|
|
1044
|
-
console.warn("PHP.run() output was:",
|
|
1045
|
-
const
|
|
1046
|
-
`PHP.run() failed with exit code ${
|
|
1063
|
+
console.warn("PHP.run() output was:", a);
|
|
1064
|
+
const l = new Error(
|
|
1065
|
+
`PHP.run() failed with exit code ${i.exitCode} and the following output: ` + i.errors
|
|
1047
1066
|
);
|
|
1048
|
-
throw
|
|
1067
|
+
throw l.output = a, console.error(l), l;
|
|
1049
1068
|
}
|
|
1050
|
-
return
|
|
1069
|
+
return i;
|
|
1051
1070
|
} finally {
|
|
1052
1071
|
try {
|
|
1053
1072
|
r && this[__private__dont__use].free(r);
|
|
@@ -1059,18 +1078,18 @@ class BasePHP {
|
|
|
1059
1078
|
}
|
|
1060
1079
|
}
|
|
1061
1080
|
addServerGlobalEntry(e, t) {
|
|
1062
|
-
|
|
1081
|
+
c(this, v)[e] = t;
|
|
1063
1082
|
}
|
|
1064
1083
|
defineConstant(e, t) {
|
|
1065
1084
|
let r = {};
|
|
1066
1085
|
try {
|
|
1067
1086
|
r = JSON.parse(
|
|
1068
|
-
this.fileExists("/
|
|
1087
|
+
this.fileExists("/internal/consts.json") && this.readFileAsText("/internal/consts.json") || "{}"
|
|
1069
1088
|
);
|
|
1070
1089
|
} catch {
|
|
1071
1090
|
}
|
|
1072
1091
|
this.writeFile(
|
|
1073
|
-
"/
|
|
1092
|
+
"/internal/consts.json",
|
|
1074
1093
|
JSON.stringify({
|
|
1075
1094
|
...r,
|
|
1076
1095
|
[e]: t
|
|
@@ -1124,7 +1143,7 @@ class BasePHP {
|
|
|
1124
1143
|
);
|
|
1125
1144
|
if (t.prependPath) {
|
|
1126
1145
|
const s = e.replace(/\/$/, "");
|
|
1127
|
-
return r.map((
|
|
1146
|
+
return r.map((n) => `${s}/${n}`);
|
|
1128
1147
|
}
|
|
1129
1148
|
return r;
|
|
1130
1149
|
} catch (r) {
|
|
@@ -1155,9 +1174,9 @@ class BasePHP {
|
|
|
1155
1174
|
this.exit();
|
|
1156
1175
|
} catch {
|
|
1157
1176
|
}
|
|
1158
|
-
if (this.initializeRuntime(e),
|
|
1177
|
+
if (this.initializeRuntime(e), c(this, F) && this.setPhpIniPath(c(this, F)), c(this, A) && this.setSapiName(c(this, A)), this.requestHandler) {
|
|
1159
1178
|
const r = this.documentRoot;
|
|
1160
|
-
|
|
1179
|
+
copyFS(t, this[__private__dont__use].FS, r);
|
|
1161
1180
|
}
|
|
1162
1181
|
}
|
|
1163
1182
|
exit(e = 0) {
|
|
@@ -1168,23 +1187,23 @@ class BasePHP {
|
|
|
1168
1187
|
this[__private__dont__use]._exit(e);
|
|
1169
1188
|
} catch {
|
|
1170
1189
|
}
|
|
1171
|
-
p(this, w, !1), p(this,
|
|
1190
|
+
p(this, w, !1), p(this, E, null), delete this[__private__dont__use].onMessage, delete this[__private__dont__use];
|
|
1172
1191
|
}
|
|
1173
1192
|
}
|
|
1174
|
-
|
|
1175
|
-
if (this.setPhpIniEntry("auto_prepend_file", "/
|
|
1176
|
-
"/
|
|
1193
|
+
x = new WeakMap(), F = new WeakMap(), A = new WeakMap(), w = new WeakMap(), E = new WeakMap(), v = new WeakMap(), P = new WeakMap(), M = new WeakMap(), B = new WeakSet(), te = function() {
|
|
1194
|
+
if (this.setPhpIniEntry("auto_prepend_file", "/internal/consts.php"), this.fileExists("/internal/consts.php") || this.writeFile(
|
|
1195
|
+
"/internal/consts.php",
|
|
1177
1196
|
`<?php
|
|
1178
|
-
if(file_exists('/
|
|
1179
|
-
$consts = json_decode(file_get_contents('/
|
|
1197
|
+
if(file_exists('/internal/consts.json')) {
|
|
1198
|
+
$consts = json_decode(file_get_contents('/internal/consts.json'), true);
|
|
1180
1199
|
foreach ($consts as $const => $value) {
|
|
1181
1200
|
if (!defined($const) && is_scalar($value)) {
|
|
1182
1201
|
define($const, $value);
|
|
1183
1202
|
}
|
|
1184
1203
|
}
|
|
1185
1204
|
}`
|
|
1186
|
-
),
|
|
1187
|
-
const e =
|
|
1205
|
+
), c(this, x).length > 0) {
|
|
1206
|
+
const e = c(this, x).map(([t, r]) => `${t}=${r}`).join(`
|
|
1188
1207
|
`) + `
|
|
1189
1208
|
|
|
1190
1209
|
`;
|
|
@@ -1197,7 +1216,7 @@ T = new WeakMap(), M = new WeakMap(), I = new WeakMap(), w = new WeakMap(), v =
|
|
|
1197
1216
|
}
|
|
1198
1217
|
this[__private__dont__use].ccall("php_wasm_init", null, [], []);
|
|
1199
1218
|
}, W = new WeakSet(), re = function() {
|
|
1200
|
-
const e = "/
|
|
1219
|
+
const e = "/internal/headers.json";
|
|
1201
1220
|
if (!this.fileExists(e))
|
|
1202
1221
|
throw new Error(
|
|
1203
1222
|
"SAPI Error: Could not find response headers file."
|
|
@@ -1206,8 +1225,8 @@ T = new WeakMap(), M = new WeakMap(), I = new WeakMap(), w = new WeakMap(), v =
|
|
|
1206
1225
|
for (const s of t.headers) {
|
|
1207
1226
|
if (!s.includes(": "))
|
|
1208
1227
|
continue;
|
|
1209
|
-
const
|
|
1210
|
-
|
|
1228
|
+
const n = s.indexOf(": "), o = s.substring(0, n).toLowerCase(), i = s.substring(n + 2);
|
|
1229
|
+
o in r || (r[o] = []), r[o].push(i);
|
|
1211
1230
|
}
|
|
1212
1231
|
return {
|
|
1213
1232
|
headers: r,
|
|
@@ -1228,7 +1247,7 @@ T = new WeakMap(), M = new WeakMap(), I = new WeakMap(), w = new WeakMap(), v =
|
|
|
1228
1247
|
[t]
|
|
1229
1248
|
);
|
|
1230
1249
|
}
|
|
1231
|
-
},
|
|
1250
|
+
}, D = new WeakSet(), ne = function(e, t) {
|
|
1232
1251
|
this[__private__dont__use].ccall(
|
|
1233
1252
|
"wasm_set_request_host",
|
|
1234
1253
|
null,
|
|
@@ -1246,14 +1265,14 @@ T = new WeakMap(), M = new WeakMap(), I = new WeakMap(), w = new WeakMap(), v =
|
|
|
1246
1265
|
[NUMBER],
|
|
1247
1266
|
[r]
|
|
1248
1267
|
), (t === "https" || !t && r === 443) && this.addServerGlobalEntry("HTTPS", "on");
|
|
1249
|
-
},
|
|
1268
|
+
}, $ = new WeakSet(), ie = function(e) {
|
|
1250
1269
|
this[__private__dont__use].ccall(
|
|
1251
1270
|
"wasm_set_request_method",
|
|
1252
1271
|
null,
|
|
1253
1272
|
[STRING],
|
|
1254
1273
|
[e]
|
|
1255
1274
|
);
|
|
1256
|
-
},
|
|
1275
|
+
}, z = new WeakSet(), oe = function(e) {
|
|
1257
1276
|
e.cookie && this[__private__dont__use].ccall(
|
|
1258
1277
|
"wasm_set_cookies",
|
|
1259
1278
|
null,
|
|
@@ -1278,24 +1297,28 @@ T = new WeakMap(), M = new WeakMap(), I = new WeakMap(), w = new WeakMap(), v =
|
|
|
1278
1297
|
);
|
|
1279
1298
|
}
|
|
1280
1299
|
}, j = new WeakSet(), ae = function(e) {
|
|
1281
|
-
|
|
1282
|
-
|
|
1300
|
+
let t, r;
|
|
1301
|
+
typeof e == "string" ? (console.warn(
|
|
1302
|
+
"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"
|
|
1303
|
+
), r = this[__private__dont__use].lengthBytesUTF8(e), t = r + 1) : (r = e.byteLength, t = e.byteLength);
|
|
1304
|
+
const s = this[__private__dont__use].malloc(t);
|
|
1305
|
+
if (!s)
|
|
1283
1306
|
throw new Error("Could not allocate memory for the request body.");
|
|
1284
|
-
return this[__private__dont__use].stringToUTF8(
|
|
1307
|
+
return typeof e == "string" ? this[__private__dont__use].stringToUTF8(
|
|
1285
1308
|
e,
|
|
1286
|
-
|
|
1309
|
+
s,
|
|
1287
1310
|
t + 1
|
|
1288
|
-
), this[__private__dont__use].ccall(
|
|
1311
|
+
) : this[__private__dont__use].HEAPU8.set(e, s), this[__private__dont__use].ccall(
|
|
1289
1312
|
"wasm_set_request_body",
|
|
1290
1313
|
null,
|
|
1291
1314
|
[NUMBER],
|
|
1292
|
-
[
|
|
1315
|
+
[s]
|
|
1293
1316
|
), this[__private__dont__use].ccall(
|
|
1294
1317
|
"wasm_set_content_length",
|
|
1295
1318
|
null,
|
|
1296
1319
|
[NUMBER],
|
|
1297
|
-
[
|
|
1298
|
-
),
|
|
1320
|
+
[r]
|
|
1321
|
+
), s;
|
|
1299
1322
|
}, G = new WeakSet(), le = function(e) {
|
|
1300
1323
|
this[__private__dont__use].ccall(
|
|
1301
1324
|
"wasm_set_path_translated",
|
|
@@ -1304,40 +1327,38 @@ T = new WeakMap(), M = new WeakMap(), I = new WeakMap(), w = new WeakMap(), v =
|
|
|
1304
1327
|
[e]
|
|
1305
1328
|
);
|
|
1306
1329
|
}, V = new WeakSet(), ce = function() {
|
|
1307
|
-
for (const e in
|
|
1330
|
+
for (const e in c(this, v))
|
|
1308
1331
|
this[__private__dont__use].ccall(
|
|
1309
1332
|
"wasm_add_SERVER_entry",
|
|
1310
1333
|
null,
|
|
1311
1334
|
[STRING, STRING],
|
|
1312
|
-
[e,
|
|
1335
|
+
[e, c(this, v)[e]]
|
|
1313
1336
|
);
|
|
1314
|
-
},
|
|
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;
|
|
1337
|
+
}, Q = new WeakSet(), ue = function(e, t) {
|
|
1318
1338
|
this[__private__dont__use].ccall(
|
|
1319
|
-
"
|
|
1339
|
+
"wasm_add_ENV_entry",
|
|
1320
1340
|
null,
|
|
1321
|
-
[STRING, STRING
|
|
1322
|
-
[
|
|
1341
|
+
[STRING, STRING],
|
|
1342
|
+
[e, t]
|
|
1323
1343
|
);
|
|
1324
|
-
},
|
|
1344
|
+
}, Y = new WeakSet(), de = function(e) {
|
|
1325
1345
|
this[__private__dont__use].ccall(
|
|
1326
1346
|
"wasm_set_php_code",
|
|
1327
1347
|
null,
|
|
1328
1348
|
[STRING],
|
|
1329
1349
|
[e]
|
|
1330
1350
|
);
|
|
1331
|
-
},
|
|
1332
|
-
var
|
|
1351
|
+
}, J = new WeakSet(), he = async function() {
|
|
1352
|
+
var n;
|
|
1333
1353
|
let e, t;
|
|
1334
1354
|
try {
|
|
1335
|
-
e = await new Promise((
|
|
1336
|
-
var
|
|
1337
|
-
t = (
|
|
1355
|
+
e = await new Promise((o, i) => {
|
|
1356
|
+
var l;
|
|
1357
|
+
t = (u) => {
|
|
1358
|
+
console.error(u), console.error(u.error);
|
|
1338
1359
|
const h = new Error("Rethrown");
|
|
1339
|
-
h.cause =
|
|
1340
|
-
}, (
|
|
1360
|
+
h.cause = u.error, h.betterMessage = u.message, i(h);
|
|
1361
|
+
}, (l = c(this, E)) == null || l.addEventListener(
|
|
1341
1362
|
"error",
|
|
1342
1363
|
t
|
|
1343
1364
|
);
|
|
@@ -1348,27 +1369,27 @@ T = new WeakMap(), M = new WeakMap(), I = new WeakMap(), w = new WeakMap(), v =
|
|
|
1348
1369
|
[],
|
|
1349
1370
|
{ async: !0 }
|
|
1350
1371
|
);
|
|
1351
|
-
return a instanceof Promise ? a.then(
|
|
1372
|
+
return a instanceof Promise ? a.then(o, i) : o(a);
|
|
1352
1373
|
});
|
|
1353
|
-
} catch (
|
|
1354
|
-
for (const
|
|
1355
|
-
typeof this[
|
|
1374
|
+
} catch (o) {
|
|
1375
|
+
for (const u in this)
|
|
1376
|
+
typeof this[u] == "function" && (this[u] = () => {
|
|
1356
1377
|
throw new Error(
|
|
1357
1378
|
"PHP runtime has crashed – see the earlier error for details."
|
|
1358
1379
|
);
|
|
1359
1380
|
});
|
|
1360
1381
|
this.functionsMaybeMissingFromAsyncify = getFunctionsMaybeMissingFromAsyncify();
|
|
1361
|
-
const
|
|
1362
|
-
throw
|
|
1382
|
+
const i = o, a = "betterMessage" in i ? i.betterMessage : i.message, l = new Error(a);
|
|
1383
|
+
throw l.cause = i, console.error(l), l;
|
|
1363
1384
|
} finally {
|
|
1364
|
-
(
|
|
1385
|
+
(n = c(this, E)) == null || n.removeEventListener("error", t), p(this, v, {});
|
|
1365
1386
|
}
|
|
1366
|
-
const { headers: r, httpStatusCode: s } =
|
|
1387
|
+
const { headers: r, httpStatusCode: s } = f(this, W, re).call(this);
|
|
1367
1388
|
return new PHPResponse(
|
|
1368
1389
|
s,
|
|
1369
1390
|
r,
|
|
1370
|
-
this.readFileAsBuffer("/
|
|
1371
|
-
this.readFileAsText("/
|
|
1391
|
+
this.readFileAsBuffer("/internal/stdout"),
|
|
1392
|
+
this.readFileAsText("/internal/stderr"),
|
|
1372
1393
|
e
|
|
1373
1394
|
);
|
|
1374
1395
|
};
|
|
@@ -1408,28 +1429,23 @@ function normalizeHeaders(e) {
|
|
|
1408
1429
|
t[r.toLowerCase()] = e[r];
|
|
1409
1430
|
return t;
|
|
1410
1431
|
}
|
|
1411
|
-
function
|
|
1432
|
+
function copyFS(e, t, r) {
|
|
1412
1433
|
let s;
|
|
1413
1434
|
try {
|
|
1414
|
-
s =
|
|
1435
|
+
s = e.lookupPath(r);
|
|
1415
1436
|
} catch {
|
|
1416
1437
|
return;
|
|
1417
1438
|
}
|
|
1418
1439
|
if (!("contents" in s.node))
|
|
1419
1440
|
return;
|
|
1420
|
-
|
|
1421
|
-
|
|
1441
|
+
if (!e.isDir(s.node.mode)) {
|
|
1442
|
+
t.writeFile(r, e.readFile(r));
|
|
1422
1443
|
return;
|
|
1423
|
-
} catch {
|
|
1424
1444
|
}
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
e.mkdirTree(r);
|
|
1430
|
-
const i = t.readdir(r).filter((n) => n !== "." && n !== "..");
|
|
1431
|
-
for (const n of i)
|
|
1432
|
-
recreateMemFS(e, t, joinPaths(r, n));
|
|
1445
|
+
t.mkdirTree(r);
|
|
1446
|
+
const n = e.readdir(r).filter((o) => o !== "." && o !== "..");
|
|
1447
|
+
for (const o of n)
|
|
1448
|
+
copyFS(e, t, joinPaths(r, o));
|
|
1433
1449
|
}
|
|
1434
1450
|
/**
|
|
1435
1451
|
* @license
|
|
@@ -1472,57 +1488,57 @@ function isAllowedOrigin(e, t) {
|
|
|
1472
1488
|
return !1;
|
|
1473
1489
|
}
|
|
1474
1490
|
function expose(e, t = globalThis, r = ["*"]) {
|
|
1475
|
-
t.addEventListener("message", function s(
|
|
1476
|
-
if (!
|
|
1491
|
+
t.addEventListener("message", function s(n) {
|
|
1492
|
+
if (!n || !n.data)
|
|
1477
1493
|
return;
|
|
1478
|
-
if (!isAllowedOrigin(r,
|
|
1479
|
-
console.warn(`Invalid origin '${
|
|
1494
|
+
if (!isAllowedOrigin(r, n.origin)) {
|
|
1495
|
+
console.warn(`Invalid origin '${n.origin}' for comlink proxy`);
|
|
1480
1496
|
return;
|
|
1481
1497
|
}
|
|
1482
|
-
const { id:
|
|
1483
|
-
let
|
|
1498
|
+
const { id: o, type: i, path: a } = Object.assign({ path: [] }, n.data), l = (n.data.argumentList || []).map(fromWireValue);
|
|
1499
|
+
let u;
|
|
1484
1500
|
try {
|
|
1485
|
-
const h = a.slice(0, -1).reduce((
|
|
1486
|
-
switch (
|
|
1501
|
+
const h = a.slice(0, -1).reduce((_, I) => _[I], e), m = a.reduce((_, I) => _[I], e);
|
|
1502
|
+
switch (i) {
|
|
1487
1503
|
case "GET":
|
|
1488
|
-
|
|
1504
|
+
u = m;
|
|
1489
1505
|
break;
|
|
1490
1506
|
case "SET":
|
|
1491
|
-
h[a.slice(-1)[0]] = fromWireValue(
|
|
1507
|
+
h[a.slice(-1)[0]] = fromWireValue(n.data.value), u = !0;
|
|
1492
1508
|
break;
|
|
1493
1509
|
case "APPLY":
|
|
1494
|
-
|
|
1510
|
+
u = m.apply(h, l);
|
|
1495
1511
|
break;
|
|
1496
1512
|
case "CONSTRUCT":
|
|
1497
1513
|
{
|
|
1498
|
-
const
|
|
1499
|
-
|
|
1514
|
+
const _ = new m(...l);
|
|
1515
|
+
u = proxy(_);
|
|
1500
1516
|
}
|
|
1501
1517
|
break;
|
|
1502
1518
|
case "ENDPOINT":
|
|
1503
1519
|
{
|
|
1504
|
-
const { port1:
|
|
1505
|
-
expose(e,
|
|
1520
|
+
const { port1: _, port2: I } = new MessageChannel();
|
|
1521
|
+
expose(e, I), u = transfer(_, [_]);
|
|
1506
1522
|
}
|
|
1507
1523
|
break;
|
|
1508
1524
|
case "RELEASE":
|
|
1509
|
-
|
|
1525
|
+
u = void 0;
|
|
1510
1526
|
break;
|
|
1511
1527
|
default:
|
|
1512
1528
|
return;
|
|
1513
1529
|
}
|
|
1514
1530
|
} catch (h) {
|
|
1515
|
-
|
|
1531
|
+
u = { value: h, [throwMarker]: 0 };
|
|
1516
1532
|
}
|
|
1517
|
-
Promise.resolve(
|
|
1518
|
-
const [
|
|
1519
|
-
t.postMessage(Object.assign(Object.assign({},
|
|
1533
|
+
Promise.resolve(u).catch((h) => ({ value: h, [throwMarker]: 0 })).then((h) => {
|
|
1534
|
+
const [m, _] = toWireValue(h);
|
|
1535
|
+
t.postMessage(Object.assign(Object.assign({}, m), { id: o }), _), i === "RELEASE" && (t.removeEventListener("message", s), closeEndPoint(t), finalizer in e && typeof e[finalizer] == "function" && e[finalizer]());
|
|
1520
1536
|
}).catch((h) => {
|
|
1521
|
-
const [
|
|
1537
|
+
const [m, _] = toWireValue({
|
|
1522
1538
|
value: new TypeError("Unserializable return value"),
|
|
1523
1539
|
[throwMarker]: 0
|
|
1524
1540
|
});
|
|
1525
|
-
t.postMessage(Object.assign(Object.assign({},
|
|
1541
|
+
t.postMessage(Object.assign(Object.assign({}, m), { id: o }), _);
|
|
1526
1542
|
});
|
|
1527
1543
|
}), t.start && t.start();
|
|
1528
1544
|
}
|
|
@@ -1560,59 +1576,59 @@ function unregisterProxy(e) {
|
|
|
1560
1576
|
function createProxy(e, t = [], r = function() {
|
|
1561
1577
|
}) {
|
|
1562
1578
|
let s = !1;
|
|
1563
|
-
const
|
|
1564
|
-
get(
|
|
1565
|
-
if (throwIfProxyReleased(s),
|
|
1579
|
+
const n = new Proxy(r, {
|
|
1580
|
+
get(o, i) {
|
|
1581
|
+
if (throwIfProxyReleased(s), i === releaseProxy)
|
|
1566
1582
|
return () => {
|
|
1567
|
-
unregisterProxy(
|
|
1583
|
+
unregisterProxy(n), releaseEndpoint(e), s = !0;
|
|
1568
1584
|
};
|
|
1569
|
-
if (
|
|
1585
|
+
if (i === "then") {
|
|
1570
1586
|
if (t.length === 0)
|
|
1571
|
-
return { then: () =>
|
|
1587
|
+
return { then: () => n };
|
|
1572
1588
|
const a = requestResponseMessage(e, {
|
|
1573
1589
|
type: "GET",
|
|
1574
|
-
path: t.map((
|
|
1590
|
+
path: t.map((l) => l.toString())
|
|
1575
1591
|
}).then(fromWireValue);
|
|
1576
1592
|
return a.then.bind(a);
|
|
1577
1593
|
}
|
|
1578
|
-
return createProxy(e, [...t,
|
|
1594
|
+
return createProxy(e, [...t, i]);
|
|
1579
1595
|
},
|
|
1580
|
-
set(
|
|
1596
|
+
set(o, i, a) {
|
|
1581
1597
|
throwIfProxyReleased(s);
|
|
1582
|
-
const [
|
|
1598
|
+
const [l, u] = toWireValue(a);
|
|
1583
1599
|
return requestResponseMessage(e, {
|
|
1584
1600
|
type: "SET",
|
|
1585
|
-
path: [...t,
|
|
1586
|
-
value:
|
|
1587
|
-
},
|
|
1601
|
+
path: [...t, i].map((h) => h.toString()),
|
|
1602
|
+
value: l
|
|
1603
|
+
}, u).then(fromWireValue);
|
|
1588
1604
|
},
|
|
1589
|
-
apply(
|
|
1605
|
+
apply(o, i, a) {
|
|
1590
1606
|
throwIfProxyReleased(s);
|
|
1591
|
-
const
|
|
1592
|
-
if (
|
|
1607
|
+
const l = t[t.length - 1];
|
|
1608
|
+
if (l === createEndpoint)
|
|
1593
1609
|
return requestResponseMessage(e, {
|
|
1594
1610
|
type: "ENDPOINT"
|
|
1595
1611
|
}).then(fromWireValue);
|
|
1596
|
-
if (
|
|
1612
|
+
if (l === "bind")
|
|
1597
1613
|
return createProxy(e, t.slice(0, -1));
|
|
1598
|
-
const [
|
|
1614
|
+
const [u, h] = processArguments(a);
|
|
1599
1615
|
return requestResponseMessage(e, {
|
|
1600
1616
|
type: "APPLY",
|
|
1601
|
-
path: t.map((
|
|
1602
|
-
argumentList:
|
|
1617
|
+
path: t.map((m) => m.toString()),
|
|
1618
|
+
argumentList: u
|
|
1603
1619
|
}, h).then(fromWireValue);
|
|
1604
1620
|
},
|
|
1605
|
-
construct(
|
|
1621
|
+
construct(o, i) {
|
|
1606
1622
|
throwIfProxyReleased(s);
|
|
1607
|
-
const [a,
|
|
1623
|
+
const [a, l] = processArguments(i);
|
|
1608
1624
|
return requestResponseMessage(e, {
|
|
1609
1625
|
type: "CONSTRUCT",
|
|
1610
|
-
path: t.map((
|
|
1626
|
+
path: t.map((u) => u.toString()),
|
|
1611
1627
|
argumentList: a
|
|
1612
|
-
},
|
|
1628
|
+
}, l).then(fromWireValue);
|
|
1613
1629
|
}
|
|
1614
1630
|
});
|
|
1615
|
-
return registerProxy(
|
|
1631
|
+
return registerProxy(n, e), n;
|
|
1616
1632
|
}
|
|
1617
1633
|
function myFlat(e) {
|
|
1618
1634
|
return Array.prototype.concat.apply([], e);
|
|
@@ -1630,7 +1646,7 @@ function proxy(e) {
|
|
|
1630
1646
|
}
|
|
1631
1647
|
function windowEndpoint(e, t = globalThis, r = "*") {
|
|
1632
1648
|
return {
|
|
1633
|
-
postMessage: (s,
|
|
1649
|
+
postMessage: (s, n) => e.postMessage(s, r, n),
|
|
1634
1650
|
addEventListener: t.addEventListener.bind(t),
|
|
1635
1651
|
removeEventListener: t.removeEventListener.bind(t)
|
|
1636
1652
|
};
|
|
@@ -1638,14 +1654,14 @@ function windowEndpoint(e, t = globalThis, r = "*") {
|
|
|
1638
1654
|
function toWireValue(e) {
|
|
1639
1655
|
for (const [t, r] of transferHandlers)
|
|
1640
1656
|
if (r.canHandle(e)) {
|
|
1641
|
-
const [s,
|
|
1657
|
+
const [s, n] = r.serialize(e);
|
|
1642
1658
|
return [
|
|
1643
1659
|
{
|
|
1644
1660
|
type: "HANDLER",
|
|
1645
1661
|
name: t,
|
|
1646
1662
|
value: s
|
|
1647
1663
|
},
|
|
1648
|
-
|
|
1664
|
+
n
|
|
1649
1665
|
];
|
|
1650
1666
|
}
|
|
1651
1667
|
return [
|
|
@@ -1666,10 +1682,10 @@ function fromWireValue(e) {
|
|
|
1666
1682
|
}
|
|
1667
1683
|
function requestResponseMessage(e, t, r) {
|
|
1668
1684
|
return new Promise((s) => {
|
|
1669
|
-
const
|
|
1670
|
-
e.addEventListener("message", function
|
|
1671
|
-
!
|
|
1672
|
-
}), e.start && e.start(), e.postMessage(Object.assign({ id:
|
|
1685
|
+
const n = generateUUID();
|
|
1686
|
+
e.addEventListener("message", function o(i) {
|
|
1687
|
+
!i.data || !i.data.id || i.data.id !== n || (e.removeEventListener("message", o), s(i.data));
|
|
1688
|
+
}), e.start && e.start(), e.postMessage(Object.assign({ id: n }, t), r);
|
|
1673
1689
|
});
|
|
1674
1690
|
}
|
|
1675
1691
|
function generateUUID() {
|
|
@@ -1679,14 +1695,14 @@ function consumeAPI(e) {
|
|
|
1679
1695
|
setupTransferHandlers();
|
|
1680
1696
|
const t = e instanceof Worker ? e : windowEndpoint(e), r = wrap(t), s = proxyClone(r);
|
|
1681
1697
|
return new Proxy(s, {
|
|
1682
|
-
get: (
|
|
1683
|
-
for (let
|
|
1698
|
+
get: (n, o) => o === "isConnected" ? async () => {
|
|
1699
|
+
for (let i = 0; i < 10; i++)
|
|
1684
1700
|
try {
|
|
1685
1701
|
await runWithTimeout(r.isConnected(), 200);
|
|
1686
1702
|
break;
|
|
1687
1703
|
} catch {
|
|
1688
1704
|
}
|
|
1689
|
-
} : r[
|
|
1705
|
+
} : r[o]
|
|
1690
1706
|
});
|
|
1691
1707
|
}
|
|
1692
1708
|
async function runWithTimeout(e, t) {
|
|
@@ -1697,16 +1713,16 @@ async function runWithTimeout(e, t) {
|
|
|
1697
1713
|
function exposeAPI(e, t) {
|
|
1698
1714
|
setupTransferHandlers();
|
|
1699
1715
|
const r = Promise.resolve();
|
|
1700
|
-
let s,
|
|
1701
|
-
const
|
|
1702
|
-
s =
|
|
1703
|
-
}),
|
|
1704
|
-
get: (
|
|
1716
|
+
let s, n;
|
|
1717
|
+
const o = new Promise((l, u) => {
|
|
1718
|
+
s = l, n = u;
|
|
1719
|
+
}), i = proxyClone(e), a = new Proxy(i, {
|
|
1720
|
+
get: (l, u) => u === "isConnected" ? () => r : u === "isReady" ? () => o : u in l ? l[u] : t == null ? void 0 : t[u]
|
|
1705
1721
|
});
|
|
1706
1722
|
return expose(
|
|
1707
1723
|
a,
|
|
1708
1724
|
typeof window < "u" ? windowEndpoint(self.parent) : void 0
|
|
1709
|
-
), [s,
|
|
1725
|
+
), [s, n, a];
|
|
1710
1726
|
}
|
|
1711
1727
|
let isTransferHandlersSetup = !1;
|
|
1712
1728
|
function setupTransferHandlers() {
|
|
@@ -1837,11 +1853,11 @@ class WebPHP extends BasePHP {
|
|
|
1837
1853
|
);
|
|
1838
1854
|
}
|
|
1839
1855
|
static async loadRuntime(t, r = {}) {
|
|
1840
|
-
var
|
|
1841
|
-
const s = r.loadAllExtensions ? "kitchen-sink" : "light",
|
|
1842
|
-
return (
|
|
1843
|
-
[
|
|
1844
|
-
}), await loadPHPRuntime(
|
|
1856
|
+
var o;
|
|
1857
|
+
const s = r.loadAllExtensions ? "kitchen-sink" : "light", n = await getPHPLoaderModule(t, s);
|
|
1858
|
+
return (o = r.downloadMonitor) == null || o.expectAssets({
|
|
1859
|
+
[n.dependencyFilename]: n.dependenciesTotalSize
|
|
1860
|
+
}), await loadPHPRuntime(n, {
|
|
1845
1861
|
...r.emscriptenOptions || {},
|
|
1846
1862
|
...fakeWebsocket()
|
|
1847
1863
|
});
|
|
@@ -1981,40 +1997,40 @@ async function registerServiceWorker(e, t, r) {
|
|
|
1981
1997
|
updateViaCache: "none"
|
|
1982
1998
|
})).update(), navigator.serviceWorker.addEventListener(
|
|
1983
1999
|
"message",
|
|
1984
|
-
async function(
|
|
1985
|
-
if (console.debug("[window][sw] Message from ServiceWorker",
|
|
2000
|
+
async function(i) {
|
|
2001
|
+
if (console.debug("[window][sw] Message from ServiceWorker", i), t && i.data.scope !== t)
|
|
1986
2002
|
return;
|
|
1987
|
-
const a =
|
|
1988
|
-
|
|
2003
|
+
const a = i.data.args || [], l = i.data.method, u = await e[l](...a);
|
|
2004
|
+
i.source.postMessage(responseTo(i.data.requestId, u));
|
|
1989
2005
|
}
|
|
1990
2006
|
), s.startMessages();
|
|
1991
2007
|
}
|
|
1992
2008
|
async function spawnPHPWorkerThread(e, t = {}) {
|
|
1993
2009
|
e = addQueryParams(e, t);
|
|
1994
2010
|
const r = new Worker(e, { type: "module" });
|
|
1995
|
-
return new Promise((s,
|
|
1996
|
-
r.onerror = (
|
|
2011
|
+
return new Promise((s, n) => {
|
|
2012
|
+
r.onerror = (i) => {
|
|
1997
2013
|
const a = new Error(
|
|
1998
|
-
`WebWorker failed to load at ${e}. ${
|
|
2014
|
+
`WebWorker failed to load at ${e}. ${i.message ? `Original error: ${i.message}` : ""}`
|
|
1999
2015
|
);
|
|
2000
|
-
a.filename =
|
|
2016
|
+
a.filename = i.filename, n(a);
|
|
2001
2017
|
};
|
|
2002
|
-
function
|
|
2003
|
-
|
|
2018
|
+
function o(i) {
|
|
2019
|
+
i.data === "worker-script-started" && (s(r), r.removeEventListener("message", o));
|
|
2004
2020
|
}
|
|
2005
|
-
r.addEventListener("message",
|
|
2021
|
+
r.addEventListener("message", o);
|
|
2006
2022
|
});
|
|
2007
2023
|
}
|
|
2008
2024
|
function addQueryParams(e, t) {
|
|
2009
2025
|
if (!Object.entries(t).length)
|
|
2010
2026
|
return e + "";
|
|
2011
2027
|
const r = new URL(e);
|
|
2012
|
-
for (const [s,
|
|
2013
|
-
if (Array.isArray(
|
|
2014
|
-
for (const
|
|
2015
|
-
r.searchParams.append(s,
|
|
2028
|
+
for (const [s, n] of Object.entries(t))
|
|
2029
|
+
if (Array.isArray(n))
|
|
2030
|
+
for (const o of n)
|
|
2031
|
+
r.searchParams.append(s, o);
|
|
2016
2032
|
else
|
|
2017
|
-
r.searchParams.set(s,
|
|
2033
|
+
r.searchParams.set(s, n);
|
|
2018
2034
|
return r.toString();
|
|
2019
2035
|
}
|
|
2020
2036
|
export {
|