@php-wasm/web 0.3.1 → 0.5.2
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/LICENSE +339 -0
- package/index.d.ts +71 -3
- package/index.js +838 -737
- package/kitchen-sink/{php_7_0.wasm → 7_0_33/php_7_0.wasm} +0 -0
- package/kitchen-sink/{php_7_2.wasm → 7_1_30/php_7_1.wasm} +0 -0
- package/kitchen-sink/{php_7_1.wasm → 7_2_34/php_7_2.wasm} +0 -0
- package/kitchen-sink/{php_7_3.wasm → 7_3_33/php_7_3.wasm} +0 -0
- package/kitchen-sink/{php_7_4.wasm → 7_4_33/php_7_4.wasm} +0 -0
- package/kitchen-sink/{php_8_0.wasm → 8_0_30/php_8_0.wasm} +0 -0
- package/kitchen-sink/{php_8_1.wasm → 8_1_23/php_8_1.wasm} +0 -0
- package/kitchen-sink/8_2_10/php_8_2.wasm +0 -0
- package/kitchen-sink/{php_8_2.wasm → 8_3/php_8_3.wasm} +0 -0
- package/kitchen-sink/8_3_0/php_8_3.wasm +0 -0
- package/kitchen-sink/php_7_0.js +10 -11
- package/kitchen-sink/php_7_1.js +10 -11
- package/kitchen-sink/php_7_2.js +10 -11
- package/kitchen-sink/php_7_3.js +10 -11
- package/kitchen-sink/php_7_4.js +10 -11
- package/kitchen-sink/php_8_0.js +10 -11
- package/kitchen-sink/php_8_1.js +10 -11
- package/kitchen-sink/php_8_2.js +10 -11
- package/kitchen-sink/php_8_3.js +84 -0
- 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/php_8_3.wasm +0 -0
- package/light/8_3_0/php_8_3.wasm +0 -0
- package/light/php_7_0.js +10 -11
- package/light/php_7_1.js +10 -11
- package/light/php_7_2.js +10 -11
- package/light/php_7_3.js +10 -11
- package/light/php_7_4.js +10 -11
- package/light/php_8_0.js +10 -11
- package/light/php_8_1.js +10 -11
- package/light/php_8_2.js +10 -11
- package/light/php_8_3.js +84 -0
- package/package.json +41 -35
- package/php_5_6.js +6306 -0
- package/php_7_0.js +6287 -0
- package/php_7_1.js +6272 -0
- package/php_7_2.js +6288 -0
- package/php_7_3.js +6425 -0
- package/php_7_4.js +6442 -0
- package/php_8_0.js +6397 -0
- package/php_8_1.js +6414 -0
- package/php_8_2.js +6420 -0
- package/.htaccess +0 -1
- package/iframe-worker.html +0 -18
- package/kitchen-sink/php_5_6.js +0 -85
- package/kitchen-sink/php_5_6.wasm +0 -0
- package/light/php_5_6.js +0 -85
- package/light/php_5_6.wasm +0 -0
- package/light/php_7_0.wasm +0 -0
- package/light/php_7_1.wasm +0 -0
- package/light/php_7_2.wasm +0 -0
- package/light/php_7_3.wasm +0 -0
- package/light/php_7_4.wasm +0 -0
- package/light/php_8_0.wasm +0 -0
- package/light/php_8_1.wasm +0 -0
- package/light/php_8_2.wasm +0 -0
package/index.js
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
var pe = (t, e, r) => {
|
|
2
|
+
if (!e.has(t))
|
|
3
|
+
throw TypeError("Cannot " + r);
|
|
4
|
+
};
|
|
5
|
+
var c = (t, e, r) => (pe(t, e, "read from private field"), r ? r.call(t) : e.get(t)), d = (t, e, r) => {
|
|
6
|
+
if (e.has(t))
|
|
7
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
8
|
+
e instanceof WeakSet ? e.add(t) : e.set(t, r);
|
|
9
|
+
}, g = (t, e, r, n) => (pe(t, e, "write to private field"), n ? n.call(t, r) : e.set(t, r), r);
|
|
10
|
+
var y = (t, e, r) => (pe(t, e, "access private method"), r);
|
|
11
|
+
const ve = Symbol("error"), xe = Symbol("message");
|
|
12
|
+
class Pe extends Event {
|
|
3
13
|
/**
|
|
4
14
|
* Create a new `ErrorEvent`.
|
|
5
15
|
*
|
|
@@ -8,22 +18,22 @@ class I extends Event {
|
|
|
8
18
|
* attributes via object members of the same name.
|
|
9
19
|
*/
|
|
10
20
|
constructor(e, r = {}) {
|
|
11
|
-
super(e), this[
|
|
21
|
+
super(e), this[ve] = r.error === void 0 ? null : r.error, this[xe] = r.message === void 0 ? "" : r.message;
|
|
12
22
|
}
|
|
13
23
|
get error() {
|
|
14
|
-
return this[
|
|
24
|
+
return this[ve];
|
|
15
25
|
}
|
|
16
26
|
get message() {
|
|
17
|
-
return this[
|
|
27
|
+
return this[xe];
|
|
18
28
|
}
|
|
19
29
|
}
|
|
20
|
-
Object.defineProperty(
|
|
21
|
-
Object.defineProperty(
|
|
22
|
-
const
|
|
23
|
-
function
|
|
24
|
-
return t instanceof Error ? "exitCode" in t && t
|
|
30
|
+
Object.defineProperty(Pe.prototype, "error", { enumerable: !0 });
|
|
31
|
+
Object.defineProperty(Pe.prototype, "message", { enumerable: !0 });
|
|
32
|
+
const it = typeof globalThis.ErrorEvent == "function" ? globalThis.ErrorEvent : Pe;
|
|
33
|
+
function ot(t) {
|
|
34
|
+
return t instanceof Error ? "exitCode" in t && (t == null ? void 0 : t.exitCode) === 0 || (t == null ? void 0 : t.name) === "ExitStatus" && "status" in t && t.status === 0 : !1;
|
|
25
35
|
}
|
|
26
|
-
class
|
|
36
|
+
class at extends EventTarget {
|
|
27
37
|
constructor() {
|
|
28
38
|
super(...arguments), this.listenersCount = 0;
|
|
29
39
|
}
|
|
@@ -37,62 +47,63 @@ class ce extends EventTarget {
|
|
|
37
47
|
return this.listenersCount > 0;
|
|
38
48
|
}
|
|
39
49
|
}
|
|
40
|
-
function
|
|
50
|
+
function ct(t) {
|
|
41
51
|
t.asm = {
|
|
42
52
|
...t.asm
|
|
43
53
|
};
|
|
44
|
-
const e = new
|
|
54
|
+
const e = new at();
|
|
45
55
|
for (const r in t.asm)
|
|
46
56
|
if (typeof t.asm[r] == "function") {
|
|
47
57
|
const n = t.asm[r];
|
|
48
58
|
t.asm[r] = function(...s) {
|
|
59
|
+
var o;
|
|
49
60
|
try {
|
|
50
61
|
return n(...s);
|
|
51
62
|
} catch (i) {
|
|
52
63
|
if (!(i instanceof Error))
|
|
53
64
|
throw i;
|
|
54
|
-
const
|
|
65
|
+
const a = ut(
|
|
55
66
|
i,
|
|
56
|
-
t.lastAsyncifyStackSource
|
|
67
|
+
(o = t.lastAsyncifyStackSource) == null ? void 0 : o.stack
|
|
57
68
|
);
|
|
58
69
|
if (t.lastAsyncifyStackSource && (i.cause = t.lastAsyncifyStackSource), e.hasListeners()) {
|
|
59
70
|
e.dispatchEvent(
|
|
60
|
-
new
|
|
71
|
+
new it("error", {
|
|
61
72
|
error: i,
|
|
62
|
-
message:
|
|
73
|
+
message: a
|
|
63
74
|
})
|
|
64
75
|
);
|
|
65
76
|
return;
|
|
66
77
|
}
|
|
67
|
-
throw
|
|
78
|
+
throw ot(i) || ft(a), i;
|
|
68
79
|
}
|
|
69
80
|
};
|
|
70
81
|
}
|
|
71
82
|
return e;
|
|
72
83
|
}
|
|
73
|
-
let
|
|
74
|
-
function
|
|
75
|
-
return
|
|
84
|
+
let ge = [];
|
|
85
|
+
function lt() {
|
|
86
|
+
return ge;
|
|
76
87
|
}
|
|
77
|
-
function
|
|
88
|
+
function ut(t, e) {
|
|
78
89
|
if (t.message === "unreachable") {
|
|
79
|
-
let r =
|
|
90
|
+
let r = ht;
|
|
80
91
|
e || (r += `
|
|
81
92
|
|
|
82
93
|
This stack trace is lacking. For a better one initialize
|
|
83
94
|
the PHP runtime with { debug: true }, e.g. PHPNode.load('8.1', { debug: true }).
|
|
84
95
|
|
|
85
|
-
`),
|
|
96
|
+
`), ge = pt(
|
|
86
97
|
e || t.stack || ""
|
|
87
98
|
);
|
|
88
|
-
for (const n of
|
|
99
|
+
for (const n of ge)
|
|
89
100
|
r += ` * ${n}
|
|
90
101
|
`;
|
|
91
102
|
return r;
|
|
92
103
|
}
|
|
93
104
|
return t.message;
|
|
94
105
|
}
|
|
95
|
-
const
|
|
106
|
+
const ht = `
|
|
96
107
|
"unreachable" WASM instruction executed.
|
|
97
108
|
|
|
98
109
|
The typical reason is a PHP function missing from the ASYNCIFY_ONLY
|
|
@@ -116,20 +127,20 @@ the Dockerfile, you'll need to trigger this error again with long stack
|
|
|
116
127
|
traces enabled. In node.js, you can do it using the --stack-trace-limit=100
|
|
117
128
|
CLI option:
|
|
118
129
|
|
|
119
|
-
`,
|
|
120
|
-
let
|
|
121
|
-
function
|
|
122
|
-
if (!
|
|
123
|
-
|
|
124
|
-
${
|
|
125
|
-
${
|
|
130
|
+
`, ke = "\x1B[41m", dt = "\x1B[1m", Re = "\x1B[0m", Se = "\x1B[K";
|
|
131
|
+
let _e = !1;
|
|
132
|
+
function ft(t) {
|
|
133
|
+
if (!_e) {
|
|
134
|
+
_e = !0, console.log(`${ke}
|
|
135
|
+
${Se}
|
|
136
|
+
${dt} WASM ERROR${Re}${ke}`);
|
|
126
137
|
for (const e of t.split(`
|
|
127
138
|
`))
|
|
128
|
-
console.log(`${
|
|
129
|
-
console.log(`${
|
|
139
|
+
console.log(`${Se} ${e} `);
|
|
140
|
+
console.log(`${Re}`);
|
|
130
141
|
}
|
|
131
142
|
}
|
|
132
|
-
function
|
|
143
|
+
function pt(t) {
|
|
133
144
|
try {
|
|
134
145
|
const e = t.split(`
|
|
135
146
|
`).slice(1).map((r) => {
|
|
@@ -146,12 +157,12 @@ function me(t) {
|
|
|
146
157
|
return [];
|
|
147
158
|
}
|
|
148
159
|
}
|
|
149
|
-
class
|
|
150
|
-
constructor(e, r, n, s = "",
|
|
151
|
-
this.httpStatusCode = e, this.headers = r, this.bytes = n, this.exitCode =
|
|
160
|
+
class A {
|
|
161
|
+
constructor(e, r, n, s = "", o = 0) {
|
|
162
|
+
this.httpStatusCode = e, this.headers = r, this.bytes = n, this.exitCode = o, this.errors = s;
|
|
152
163
|
}
|
|
153
164
|
static fromRawData(e) {
|
|
154
|
-
return new
|
|
165
|
+
return new A(
|
|
155
166
|
e.httpStatusCode,
|
|
156
167
|
e.headers,
|
|
157
168
|
e.bytes,
|
|
@@ -181,7 +192,8 @@ class b {
|
|
|
181
192
|
return new TextDecoder().decode(this.bytes);
|
|
182
193
|
}
|
|
183
194
|
}
|
|
184
|
-
const
|
|
195
|
+
const mt = [
|
|
196
|
+
"8.3",
|
|
185
197
|
"8.2",
|
|
186
198
|
"8.1",
|
|
187
199
|
"8.0",
|
|
@@ -189,22 +201,22 @@ const ge = [
|
|
|
189
201
|
"7.3",
|
|
190
202
|
"7.2",
|
|
191
203
|
"7.1",
|
|
192
|
-
"7.0"
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
class
|
|
196
|
-
#e;
|
|
197
|
-
#t;
|
|
204
|
+
"7.0"
|
|
205
|
+
], gt = mt[0];
|
|
206
|
+
var C, I;
|
|
207
|
+
class yt {
|
|
198
208
|
/**
|
|
199
209
|
* @param server - The PHP server to browse.
|
|
200
210
|
* @param config - The browser configuration.
|
|
201
211
|
*/
|
|
202
212
|
constructor(e, r = {}) {
|
|
203
|
-
this
|
|
213
|
+
d(this, C, void 0);
|
|
214
|
+
d(this, I, void 0);
|
|
215
|
+
this.requestHandler = e, g(this, C, {}), g(this, I, {
|
|
204
216
|
handleRedirects: !1,
|
|
205
217
|
maxRedirects: 4,
|
|
206
218
|
...r
|
|
207
|
-
};
|
|
219
|
+
});
|
|
208
220
|
}
|
|
209
221
|
/**
|
|
210
222
|
* Sends the request to the server.
|
|
@@ -225,10 +237,10 @@ class we {
|
|
|
225
237
|
...e,
|
|
226
238
|
headers: {
|
|
227
239
|
...e.headers,
|
|
228
|
-
cookie: this
|
|
240
|
+
cookie: this.serializeCookies()
|
|
229
241
|
}
|
|
230
242
|
});
|
|
231
|
-
if (n.headers["set-cookie"] && this
|
|
243
|
+
if (n.headers["set-cookie"] && this.setCookies(n.headers["set-cookie"]), c(this, I).handleRedirects && n.headers.location && r < c(this, I).maxRedirects) {
|
|
232
244
|
const s = new URL(
|
|
233
245
|
n.headers.location[0],
|
|
234
246
|
this.requestHandler.absoluteUrl
|
|
@@ -260,25 +272,26 @@ class we {
|
|
|
260
272
|
get documentRoot() {
|
|
261
273
|
return this.requestHandler.documentRoot;
|
|
262
274
|
}
|
|
263
|
-
|
|
275
|
+
setCookies(e) {
|
|
264
276
|
for (const r of e)
|
|
265
277
|
try {
|
|
266
278
|
if (!r.includes("="))
|
|
267
279
|
continue;
|
|
268
|
-
const n = r.indexOf("="), s = r.substring(0, n),
|
|
269
|
-
this
|
|
280
|
+
const n = r.indexOf("="), s = r.substring(0, n), o = r.substring(n + 1).split(";")[0];
|
|
281
|
+
c(this, C)[s] = o;
|
|
270
282
|
} catch (n) {
|
|
271
283
|
console.error(n);
|
|
272
284
|
}
|
|
273
285
|
}
|
|
274
|
-
|
|
286
|
+
serializeCookies() {
|
|
275
287
|
const e = [];
|
|
276
|
-
for (const r in this
|
|
277
|
-
e.push(`${r}=${this
|
|
288
|
+
for (const r in c(this, C))
|
|
289
|
+
e.push(`${r}=${c(this, C)[r]}`);
|
|
278
290
|
return e.join("; ");
|
|
279
291
|
}
|
|
280
292
|
}
|
|
281
|
-
|
|
293
|
+
C = new WeakMap(), I = new WeakMap();
|
|
294
|
+
class Me {
|
|
282
295
|
constructor({ concurrency: e }) {
|
|
283
296
|
this._running = 0, this.concurrency = e, this.queue = [];
|
|
284
297
|
}
|
|
@@ -306,47 +319,73 @@ class Pe {
|
|
|
306
319
|
}
|
|
307
320
|
}
|
|
308
321
|
}
|
|
309
|
-
const
|
|
310
|
-
function
|
|
322
|
+
const wt = "http://example.com";
|
|
323
|
+
function Te(t) {
|
|
311
324
|
return t.toString().substring(t.origin.length);
|
|
312
325
|
}
|
|
313
|
-
function
|
|
326
|
+
function Ce(t, e) {
|
|
314
327
|
return !e || !t.startsWith(e) ? t : t.substring(e.length);
|
|
315
328
|
}
|
|
316
|
-
function
|
|
329
|
+
function Pt(t, e) {
|
|
317
330
|
return !e || t.startsWith(e) ? t : e + t;
|
|
318
331
|
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
#t;
|
|
322
|
-
#n;
|
|
323
|
-
#r;
|
|
324
|
-
#i;
|
|
325
|
-
#s;
|
|
326
|
-
#o;
|
|
327
|
-
#a;
|
|
332
|
+
var x, N, j, H, U, k, $, W, X, Oe, Z, Ie, ee, Ne;
|
|
333
|
+
class Et {
|
|
328
334
|
/**
|
|
329
335
|
* @param php - The PHP instance.
|
|
330
336
|
* @param config - Request Handler configuration.
|
|
331
337
|
*/
|
|
332
338
|
constructor(e, r = {}) {
|
|
333
|
-
|
|
339
|
+
/**
|
|
340
|
+
* Serves a static file from the PHP filesystem.
|
|
341
|
+
*
|
|
342
|
+
* @param fsPath - Absolute path of the static file to serve.
|
|
343
|
+
* @returns The response.
|
|
344
|
+
*/
|
|
345
|
+
d(this, X);
|
|
346
|
+
/**
|
|
347
|
+
* Runs the requested PHP file with all the request and $_SERVER
|
|
348
|
+
* superglobals populated.
|
|
349
|
+
*
|
|
350
|
+
* @param request - The request.
|
|
351
|
+
* @returns The response.
|
|
352
|
+
*/
|
|
353
|
+
d(this, Z);
|
|
354
|
+
/**
|
|
355
|
+
* Resolve the requested path to the filesystem path of the requested PHP file.
|
|
356
|
+
*
|
|
357
|
+
* Fall back to index.php as if there was a url rewriting rule in place.
|
|
358
|
+
*
|
|
359
|
+
* @param requestedPath - The requested pathname.
|
|
360
|
+
* @throws {Error} If the requested path doesn't exist.
|
|
361
|
+
* @returns The resolved filesystem path.
|
|
362
|
+
*/
|
|
363
|
+
d(this, ee);
|
|
364
|
+
d(this, x, void 0);
|
|
365
|
+
d(this, N, void 0);
|
|
366
|
+
d(this, j, void 0);
|
|
367
|
+
d(this, H, void 0);
|
|
368
|
+
d(this, U, void 0);
|
|
369
|
+
d(this, k, void 0);
|
|
370
|
+
d(this, $, void 0);
|
|
371
|
+
d(this, W, void 0);
|
|
372
|
+
g(this, W, new Me({ concurrency: 1 }));
|
|
334
373
|
const {
|
|
335
374
|
documentRoot: n = "/www/",
|
|
336
|
-
absoluteUrl: s = typeof location == "object" ? location
|
|
375
|
+
absoluteUrl: s = typeof location == "object" ? location == null ? void 0 : location.href : ""
|
|
337
376
|
} = r;
|
|
338
|
-
this.php = e, this
|
|
339
|
-
const
|
|
340
|
-
this
|
|
341
|
-
const
|
|
342
|
-
this
|
|
343
|
-
this
|
|
344
|
-
|
|
345
|
-
].join(""), this
|
|
346
|
-
`${this
|
|
347
|
-
this
|
|
348
|
-
this
|
|
349
|
-
].join("");
|
|
377
|
+
this.php = e, g(this, x, n);
|
|
378
|
+
const o = new URL(s);
|
|
379
|
+
g(this, j, o.hostname), g(this, H, o.port ? Number(o.port) : o.protocol === "https:" ? 443 : 80), g(this, N, (o.protocol || "").replace(":", ""));
|
|
380
|
+
const i = c(this, H) !== 443 && c(this, H) !== 80;
|
|
381
|
+
g(this, U, [
|
|
382
|
+
c(this, j),
|
|
383
|
+
i ? `:${c(this, H)}` : ""
|
|
384
|
+
].join("")), g(this, k, o.pathname.replace(/\/+$/, "")), g(this, $, [
|
|
385
|
+
`${c(this, N)}://`,
|
|
386
|
+
c(this, U),
|
|
387
|
+
c(this, k)
|
|
388
|
+
].join(""));
|
|
350
389
|
}
|
|
351
390
|
/** @inheritDoc */
|
|
352
391
|
pathToInternalUrl(e) {
|
|
@@ -355,162 +394,139 @@ class ke {
|
|
|
355
394
|
/** @inheritDoc */
|
|
356
395
|
internalUrlToPath(e) {
|
|
357
396
|
const r = new URL(e);
|
|
358
|
-
return r.pathname.startsWith(this
|
|
397
|
+
return r.pathname.startsWith(c(this, k)) && (r.pathname = r.pathname.slice(c(this, k).length)), Te(r);
|
|
359
398
|
}
|
|
360
399
|
get isRequestRunning() {
|
|
361
|
-
return this
|
|
400
|
+
return c(this, W).running > 0;
|
|
362
401
|
}
|
|
363
402
|
/** @inheritDoc */
|
|
364
403
|
get absoluteUrl() {
|
|
365
|
-
return this
|
|
404
|
+
return c(this, $);
|
|
366
405
|
}
|
|
367
406
|
/** @inheritDoc */
|
|
368
407
|
get documentRoot() {
|
|
369
|
-
return this
|
|
408
|
+
return c(this, x);
|
|
370
409
|
}
|
|
371
410
|
/** @inheritDoc */
|
|
372
411
|
async request(e) {
|
|
373
412
|
const r = e.url.startsWith("http://") || e.url.startsWith("https://"), n = new URL(
|
|
374
413
|
e.url,
|
|
375
|
-
r ? void 0 :
|
|
376
|
-
), s =
|
|
414
|
+
r ? void 0 : wt
|
|
415
|
+
), s = Ce(
|
|
377
416
|
n.pathname,
|
|
378
|
-
this
|
|
379
|
-
),
|
|
380
|
-
return
|
|
417
|
+
c(this, k)
|
|
418
|
+
), o = `${c(this, x)}${s}`;
|
|
419
|
+
return xt(o) ? await y(this, Z, Ie).call(this, e, n) : y(this, X, Oe).call(this, o);
|
|
381
420
|
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
if (!this.php.fileExists(e))
|
|
390
|
-
return new b(
|
|
391
|
-
404,
|
|
392
|
-
// Let the service worker know that no static file was found
|
|
393
|
-
// and that it's okay to issue a real fetch() to the server.
|
|
394
|
-
{
|
|
395
|
-
"x-file-type": ["static"]
|
|
396
|
-
},
|
|
397
|
-
new TextEncoder().encode("404 File not found")
|
|
398
|
-
);
|
|
399
|
-
const r = this.php.readFileAsBuffer(e);
|
|
400
|
-
return new b(
|
|
401
|
-
200,
|
|
421
|
+
}
|
|
422
|
+
x = new WeakMap(), N = new WeakMap(), j = new WeakMap(), H = new WeakMap(), U = new WeakMap(), k = new WeakMap(), $ = new WeakMap(), W = new WeakMap(), X = new WeakSet(), Oe = function(e) {
|
|
423
|
+
if (!this.php.fileExists(e))
|
|
424
|
+
return new A(
|
|
425
|
+
404,
|
|
426
|
+
// Let the service worker know that no static file was found
|
|
427
|
+
// and that it's okay to issue a real fetch() to the server.
|
|
402
428
|
{
|
|
403
|
-
"
|
|
404
|
-
// @TODO: Infer the content-type from the arrayBuffer instead of the file path.
|
|
405
|
-
// The code below won't return the correct mime-type if the extension
|
|
406
|
-
// was tampered with.
|
|
407
|
-
"content-type": [ve(e)],
|
|
408
|
-
"accept-ranges": ["bytes"],
|
|
409
|
-
"cache-control": ["public, max-age=0"]
|
|
429
|
+
"x-file-type": ["static"]
|
|
410
430
|
},
|
|
411
|
-
|
|
431
|
+
new TextEncoder().encode("404 File not found")
|
|
412
432
|
);
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
433
|
+
const r = this.php.readFileAsBuffer(e);
|
|
434
|
+
return new A(
|
|
435
|
+
200,
|
|
436
|
+
{
|
|
437
|
+
"content-length": [`${r.byteLength}`],
|
|
438
|
+
// @TODO: Infer the content-type from the arrayBuffer instead of the file path.
|
|
439
|
+
// The code below won't return the correct mime-type if the extension
|
|
440
|
+
// was tampered with.
|
|
441
|
+
"content-type": [vt(e)],
|
|
442
|
+
"accept-ranges": ["bytes"],
|
|
443
|
+
"cache-control": ["public, max-age=0"]
|
|
444
|
+
},
|
|
445
|
+
r
|
|
446
|
+
);
|
|
447
|
+
}, Z = new WeakSet(), Ie = async function(e, r) {
|
|
448
|
+
var s;
|
|
449
|
+
const n = await c(this, W).acquire();
|
|
450
|
+
try {
|
|
451
|
+
this.php.addServerGlobalEntry("DOCUMENT_ROOT", c(this, x)), this.php.addServerGlobalEntry(
|
|
452
|
+
"HTTPS",
|
|
453
|
+
c(this, $).startsWith("https://") ? "on" : ""
|
|
454
|
+
);
|
|
455
|
+
let o = "GET";
|
|
456
|
+
const i = {
|
|
457
|
+
host: c(this, U),
|
|
458
|
+
...Ke(e.headers || {})
|
|
459
|
+
}, a = [];
|
|
460
|
+
if (e.files && Object.keys(e.files).length) {
|
|
461
|
+
o = "POST";
|
|
462
|
+
for (const h in e.files) {
|
|
463
|
+
const m = e.files[h];
|
|
464
|
+
a.push({
|
|
465
|
+
key: h,
|
|
466
|
+
name: m.name,
|
|
467
|
+
type: m.type,
|
|
468
|
+
data: new Uint8Array(await m.arrayBuffer())
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
(s = i["content-type"]) != null && s.startsWith("multipart/form-data") && (e.formData = bt(
|
|
472
|
+
e.body || ""
|
|
473
|
+
), i["content-type"] = "application/x-www-form-urlencoded", delete e.body);
|
|
474
|
+
}
|
|
475
|
+
let u;
|
|
476
|
+
e.formData !== void 0 ? (o = "POST", i["content-type"] = i["content-type"] || "application/x-www-form-urlencoded", u = new URLSearchParams(
|
|
477
|
+
e.formData
|
|
478
|
+
).toString()) : u = e.body;
|
|
479
|
+
let l;
|
|
423
480
|
try {
|
|
424
|
-
this.
|
|
425
|
-
|
|
426
|
-
|
|
481
|
+
l = y(this, ee, Ne).call(this, r.pathname);
|
|
482
|
+
} catch {
|
|
483
|
+
return new A(
|
|
484
|
+
404,
|
|
485
|
+
{},
|
|
486
|
+
new TextEncoder().encode("404 File not found")
|
|
427
487
|
);
|
|
428
|
-
let s = "GET";
|
|
429
|
-
const i = {
|
|
430
|
-
host: this.#i,
|
|
431
|
-
...Q(e.headers || {})
|
|
432
|
-
}, o = [];
|
|
433
|
-
if (e.files && Object.keys(e.files).length) {
|
|
434
|
-
s = "POST";
|
|
435
|
-
for (const a in e.files) {
|
|
436
|
-
const h = e.files[a];
|
|
437
|
-
o.push({
|
|
438
|
-
key: a,
|
|
439
|
-
name: h.name,
|
|
440
|
-
type: h.type,
|
|
441
|
-
data: new Uint8Array(await h.arrayBuffer())
|
|
442
|
-
});
|
|
443
|
-
}
|
|
444
|
-
i["content-type"]?.startsWith("multipart/form-data") && (e.formData = Re(
|
|
445
|
-
e.body || ""
|
|
446
|
-
), i["content-type"] = "application/x-www-form-urlencoded", delete e.body);
|
|
447
|
-
}
|
|
448
|
-
let c;
|
|
449
|
-
e.formData !== void 0 ? (s = "POST", i["content-type"] = i["content-type"] || "application/x-www-form-urlencoded", c = new URLSearchParams(
|
|
450
|
-
e.formData
|
|
451
|
-
).toString()) : c = e.body;
|
|
452
|
-
let l;
|
|
453
|
-
try {
|
|
454
|
-
l = this.#u(r.pathname);
|
|
455
|
-
} catch {
|
|
456
|
-
return new b(
|
|
457
|
-
404,
|
|
458
|
-
{},
|
|
459
|
-
new TextEncoder().encode("404 File not found")
|
|
460
|
-
);
|
|
461
|
-
}
|
|
462
|
-
return await this.php.run({
|
|
463
|
-
relativeUri: Ee(
|
|
464
|
-
j(r),
|
|
465
|
-
this.#s
|
|
466
|
-
),
|
|
467
|
-
protocol: this.#t,
|
|
468
|
-
method: e.method || s,
|
|
469
|
-
body: c,
|
|
470
|
-
fileInfos: o,
|
|
471
|
-
scriptPath: l,
|
|
472
|
-
headers: i
|
|
473
|
-
});
|
|
474
|
-
} finally {
|
|
475
|
-
n();
|
|
476
488
|
}
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
489
|
+
return await this.php.run({
|
|
490
|
+
relativeUri: Pt(
|
|
491
|
+
Te(r),
|
|
492
|
+
c(this, k)
|
|
493
|
+
),
|
|
494
|
+
protocol: c(this, N),
|
|
495
|
+
method: e.method || o,
|
|
496
|
+
body: u,
|
|
497
|
+
fileInfos: a,
|
|
498
|
+
scriptPath: l,
|
|
499
|
+
headers: i
|
|
500
|
+
});
|
|
501
|
+
} finally {
|
|
502
|
+
n();
|
|
503
|
+
}
|
|
504
|
+
}, ee = new WeakSet(), Ne = function(e) {
|
|
505
|
+
let r = Ce(e, c(this, k));
|
|
506
|
+
r.includes(".php") ? r = r.split(".php")[0] + ".php" : (r.endsWith("/") || (r += "/"), r.endsWith("index.php") || (r += "index.php"));
|
|
507
|
+
const n = `${c(this, x)}${r}`;
|
|
508
|
+
if (this.php.fileExists(n))
|
|
509
|
+
return n;
|
|
510
|
+
if (!this.php.fileExists(`${c(this, x)}/index.php`))
|
|
511
|
+
throw new Error(`File not found: ${n}`);
|
|
512
|
+
return `${c(this, x)}/index.php`;
|
|
513
|
+
};
|
|
514
|
+
function bt(t) {
|
|
499
515
|
const e = {}, r = t.match(/--(.*)\r\n/);
|
|
500
516
|
if (!r)
|
|
501
517
|
return e;
|
|
502
518
|
const n = r[1], s = t.split(`--${n}`);
|
|
503
|
-
return s.shift(), s.pop(), s.forEach((
|
|
504
|
-
const
|
|
519
|
+
return s.shift(), s.pop(), s.forEach((o) => {
|
|
520
|
+
const i = o.indexOf(`\r
|
|
505
521
|
\r
|
|
506
|
-
`),
|
|
507
|
-
if (
|
|
508
|
-
const h =
|
|
509
|
-
e[h] =
|
|
522
|
+
`), a = o.substring(0, i).trim(), u = o.substring(i + 4).trim(), l = a.match(/name="([^"]+)"/);
|
|
523
|
+
if (l) {
|
|
524
|
+
const h = l[1];
|
|
525
|
+
e[h] = u;
|
|
510
526
|
}
|
|
511
527
|
}), e;
|
|
512
528
|
}
|
|
513
|
-
function
|
|
529
|
+
function vt(t) {
|
|
514
530
|
switch (t.split(".").pop()) {
|
|
515
531
|
case "css":
|
|
516
532
|
return "text/css";
|
|
@@ -550,16 +566,16 @@ function ve(t) {
|
|
|
550
566
|
return "application-octet-stream";
|
|
551
567
|
}
|
|
552
568
|
}
|
|
553
|
-
function
|
|
554
|
-
return
|
|
569
|
+
function xt(t) {
|
|
570
|
+
return kt(t) || Rt(t);
|
|
555
571
|
}
|
|
556
|
-
function
|
|
572
|
+
function kt(t) {
|
|
557
573
|
return t.endsWith(".php") || t.includes(".php/");
|
|
558
574
|
}
|
|
559
|
-
function
|
|
575
|
+
function Rt(t) {
|
|
560
576
|
return !t.split("/").pop().includes(".");
|
|
561
577
|
}
|
|
562
|
-
const
|
|
578
|
+
const He = {
|
|
563
579
|
0: "No error occurred. System call completed successfully.",
|
|
564
580
|
1: "Argument list too long.",
|
|
565
581
|
2: "Permission denied.",
|
|
@@ -638,69 +654,75 @@ const V = {
|
|
|
638
654
|
75: "Cross-device link.",
|
|
639
655
|
76: "Extension: Capabilities insufficient."
|
|
640
656
|
};
|
|
641
|
-
function
|
|
657
|
+
function b(t = "") {
|
|
642
658
|
return function(r, n, s) {
|
|
643
|
-
const
|
|
644
|
-
s.value = function(...
|
|
659
|
+
const o = s.value;
|
|
660
|
+
s.value = function(...i) {
|
|
645
661
|
try {
|
|
646
|
-
return
|
|
647
|
-
} catch (
|
|
648
|
-
const
|
|
649
|
-
if (
|
|
650
|
-
const
|
|
651
|
-
throw new Error(`${
|
|
652
|
-
cause:
|
|
662
|
+
return o.apply(this, i);
|
|
663
|
+
} catch (a) {
|
|
664
|
+
const u = typeof a == "object" ? a == null ? void 0 : a.errno : null;
|
|
665
|
+
if (u in He) {
|
|
666
|
+
const l = He[u], h = typeof i[0] == "string" ? i[0] : null, m = h !== null ? t.replaceAll("{path}", h) : t;
|
|
667
|
+
throw new Error(`${m}: ${l}`, {
|
|
668
|
+
cause: a
|
|
653
669
|
});
|
|
654
670
|
}
|
|
655
|
-
throw
|
|
671
|
+
throw a;
|
|
656
672
|
}
|
|
657
673
|
};
|
|
658
674
|
};
|
|
659
675
|
}
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
676
|
+
const St = Symbol("RuntimeId"), V = /* @__PURE__ */ new Map();
|
|
677
|
+
async function _t(t, e = {}, r = []) {
|
|
678
|
+
const [n, s, o] = Fe(), [i, a] = Fe(), u = t.init(Ct, {
|
|
679
|
+
onAbort(h) {
|
|
680
|
+
o(h), a(), console.error(h);
|
|
664
681
|
},
|
|
665
682
|
ENV: {},
|
|
666
683
|
// Emscripten sometimes prepends a '/' to the path, which
|
|
667
684
|
// breaks vite dev mode. An identity `locateFile` function
|
|
668
685
|
// fixes it.
|
|
669
|
-
locateFile: (
|
|
686
|
+
locateFile: (h) => h,
|
|
670
687
|
...e,
|
|
671
688
|
noInitialRun: !0,
|
|
672
689
|
onRuntimeInitialized() {
|
|
673
690
|
e.onRuntimeInitialized && e.onRuntimeInitialized(), s();
|
|
674
691
|
},
|
|
675
|
-
monitorRunDependencies(
|
|
676
|
-
|
|
692
|
+
monitorRunDependencies(h) {
|
|
693
|
+
h === 0 && (delete u.monitorRunDependencies, a());
|
|
677
694
|
}
|
|
678
695
|
});
|
|
679
|
-
|
|
696
|
+
await Promise.all(
|
|
680
697
|
r.map(
|
|
681
|
-
({ default:
|
|
698
|
+
({ default: h }) => h(u)
|
|
682
699
|
)
|
|
683
|
-
), r.length ||
|
|
700
|
+
), r.length || a(), await i, await n;
|
|
701
|
+
const l = V.size;
|
|
702
|
+
return u.originalExit = u._exit, u._exit = function(h) {
|
|
703
|
+
return V.delete(l), u.originalExit(h);
|
|
704
|
+
}, u[St] = l, V.set(l, u), l;
|
|
684
705
|
}
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
return M[t];
|
|
706
|
+
function Tt(t) {
|
|
707
|
+
return V.get(t);
|
|
688
708
|
}
|
|
689
|
-
const
|
|
690
|
-
|
|
691
|
-
|
|
709
|
+
const Ct = function() {
|
|
710
|
+
var t;
|
|
711
|
+
return typeof process < "u" && ((t = process.release) == null ? void 0 : t.name) === "node" ? "NODE" : typeof window < "u" ? "WEB" : typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope ? "WORKER" : "NODE";
|
|
712
|
+
}(), Fe = () => {
|
|
692
713
|
const t = [], e = new Promise((r, n) => {
|
|
693
714
|
t.push(r, n);
|
|
694
715
|
});
|
|
695
716
|
return t.unshift(e), t;
|
|
696
717
|
};
|
|
697
|
-
var
|
|
698
|
-
for (var s = n > 1 ? void 0 : n ?
|
|
699
|
-
(
|
|
700
|
-
return n && s &&
|
|
718
|
+
var Ht = Object.defineProperty, Ft = Object.getOwnPropertyDescriptor, v = (t, e, r, n) => {
|
|
719
|
+
for (var s = n > 1 ? void 0 : n ? Ft(e, r) : e, o = t.length - 1, i; o >= 0; o--)
|
|
720
|
+
(i = t[o]) && (s = (n ? i(e, r, s) : i(s)) || s);
|
|
721
|
+
return n && s && Ht(e, r, s), s;
|
|
701
722
|
};
|
|
702
|
-
const
|
|
703
|
-
|
|
723
|
+
const w = "string", M = "number", f = Symbol("__private__dont__use");
|
|
724
|
+
var F, S, L, _, R, D, B, te, Ue, re, $e, ne, We, se, De, ie, qe, oe, ze, ae, je, ce, Be, le, Ge, ue, Ve, he, Ye, de, Je;
|
|
725
|
+
class E {
|
|
704
726
|
/**
|
|
705
727
|
* Initializes a PHP runtime.
|
|
706
728
|
*
|
|
@@ -709,18 +731,58 @@ class m {
|
|
|
709
731
|
* @param serverOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
|
|
710
732
|
*/
|
|
711
733
|
constructor(e, r) {
|
|
712
|
-
this
|
|
713
|
-
|
|
734
|
+
d(this, te);
|
|
735
|
+
d(this, re);
|
|
736
|
+
d(this, ne);
|
|
737
|
+
d(this, se);
|
|
738
|
+
d(this, ie);
|
|
739
|
+
d(this, oe);
|
|
740
|
+
d(this, ae);
|
|
741
|
+
d(this, ce);
|
|
742
|
+
d(this, le);
|
|
743
|
+
/**
|
|
744
|
+
* Adds file information to $_FILES superglobal in PHP.
|
|
745
|
+
*
|
|
746
|
+
* In particular:
|
|
747
|
+
* * Creates the file data in the filesystem
|
|
748
|
+
* * Registers the file details in PHP
|
|
749
|
+
*
|
|
750
|
+
* @param fileInfo - File details
|
|
751
|
+
*/
|
|
752
|
+
d(this, ue);
|
|
753
|
+
d(this, he);
|
|
754
|
+
d(this, de);
|
|
755
|
+
d(this, F, void 0);
|
|
756
|
+
d(this, S, void 0);
|
|
757
|
+
d(this, L, void 0);
|
|
758
|
+
d(this, _, void 0);
|
|
759
|
+
d(this, R, void 0);
|
|
760
|
+
d(this, D, void 0);
|
|
761
|
+
d(this, B, void 0);
|
|
762
|
+
g(this, F, []), g(this, S, !1), g(this, L, null), g(this, _, {}), g(this, R, /* @__PURE__ */ new Map()), g(this, D, []), g(this, B, new Me({ concurrency: 1 })), e !== void 0 && this.initializeRuntime(e), r && (this.requestHandler = new yt(
|
|
763
|
+
new Et(this, r)
|
|
714
764
|
));
|
|
715
765
|
}
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
766
|
+
addEventListener(e, r) {
|
|
767
|
+
c(this, R).has(e) || c(this, R).set(e, /* @__PURE__ */ new Set()), c(this, R).get(e).add(r);
|
|
768
|
+
}
|
|
769
|
+
removeEventListener(e, r) {
|
|
770
|
+
var n;
|
|
771
|
+
(n = c(this, R).get(e)) == null || n.delete(r);
|
|
772
|
+
}
|
|
773
|
+
dispatchEvent(e) {
|
|
774
|
+
const r = c(this, R).get(e.type);
|
|
775
|
+
if (r)
|
|
776
|
+
for (const n of r)
|
|
777
|
+
n(e);
|
|
778
|
+
}
|
|
721
779
|
/** @inheritDoc */
|
|
722
780
|
async onMessage(e) {
|
|
723
|
-
this
|
|
781
|
+
c(this, D).push(e);
|
|
782
|
+
}
|
|
783
|
+
/** @inheritDoc */
|
|
784
|
+
async setSpawnHandler(e) {
|
|
785
|
+
this[f].spawnProcess = e;
|
|
724
786
|
}
|
|
725
787
|
/** @inheritDoc */
|
|
726
788
|
get absoluteUrl() {
|
|
@@ -741,21 +803,25 @@ class m {
|
|
|
741
803
|
);
|
|
742
804
|
}
|
|
743
805
|
initializeRuntime(e) {
|
|
744
|
-
if (this[
|
|
806
|
+
if (this[f])
|
|
745
807
|
throw new Error("PHP runtime already initialized.");
|
|
746
|
-
const r =
|
|
808
|
+
const r = Tt(e);
|
|
747
809
|
if (!r)
|
|
748
810
|
throw new Error("Invalid PHP runtime id.");
|
|
749
|
-
this[
|
|
750
|
-
for (const s of this
|
|
751
|
-
s(n);
|
|
752
|
-
|
|
811
|
+
this[f] = r, r.onMessage = async (n) => {
|
|
812
|
+
for (const s of c(this, D)) {
|
|
813
|
+
const o = await s(n);
|
|
814
|
+
if (o)
|
|
815
|
+
return o;
|
|
816
|
+
}
|
|
817
|
+
return "";
|
|
818
|
+
}, g(this, L, ct(r));
|
|
753
819
|
}
|
|
754
820
|
/** @inheritDoc */
|
|
755
821
|
setPhpIniPath(e) {
|
|
756
|
-
if (this
|
|
822
|
+
if (c(this, S))
|
|
757
823
|
throw new Error("Cannot set PHP ini path after calling run().");
|
|
758
|
-
this[
|
|
824
|
+
this[f].ccall(
|
|
759
825
|
"wasm_set_phpini_path",
|
|
760
826
|
null,
|
|
761
827
|
["string"],
|
|
@@ -764,13 +830,13 @@ class m {
|
|
|
764
830
|
}
|
|
765
831
|
/** @inheritDoc */
|
|
766
832
|
setPhpIniEntry(e, r) {
|
|
767
|
-
if (this
|
|
833
|
+
if (c(this, S))
|
|
768
834
|
throw new Error("Cannot set PHP ini entries after calling run().");
|
|
769
|
-
this
|
|
835
|
+
c(this, F).push([e, r]);
|
|
770
836
|
}
|
|
771
837
|
/** @inheritDoc */
|
|
772
838
|
chdir(e) {
|
|
773
|
-
this[
|
|
839
|
+
this[f].FS.chdir(e);
|
|
774
840
|
}
|
|
775
841
|
/** @inheritDoc */
|
|
776
842
|
async request(e, r) {
|
|
@@ -780,221 +846,41 @@ class m {
|
|
|
780
846
|
}
|
|
781
847
|
/** @inheritDoc */
|
|
782
848
|
async run(e) {
|
|
783
|
-
|
|
784
|
-
const { host: r, ...n } = {
|
|
785
|
-
host: "example.com:443",
|
|
786
|
-
...Q(e.headers || {})
|
|
787
|
-
};
|
|
788
|
-
if (this.#c(r, e.protocol || "http"), this.#u(n), e.body && this.#h(e.body), e.fileInfos)
|
|
789
|
-
for (const s of e.fileInfos)
|
|
790
|
-
this.#p(s);
|
|
791
|
-
return e.code && this.#m(" ?>" + e.code), this.#f(), await this.#g();
|
|
792
|
-
}
|
|
793
|
-
#s() {
|
|
794
|
-
if (this.#e.length > 0) {
|
|
795
|
-
const e = this.#e.map(([r, n]) => `${r}=${n}`).join(`
|
|
796
|
-
`) + `
|
|
797
|
-
|
|
798
|
-
`;
|
|
799
|
-
this[u].ccall(
|
|
800
|
-
"wasm_set_phpini_entries",
|
|
801
|
-
null,
|
|
802
|
-
[f],
|
|
803
|
-
[e]
|
|
804
|
-
);
|
|
805
|
-
}
|
|
806
|
-
this[u].ccall("php_wasm_init", null, [], []);
|
|
807
|
-
}
|
|
808
|
-
#o() {
|
|
809
|
-
const e = "/tmp/headers.json";
|
|
810
|
-
if (!this.fileExists(e))
|
|
811
|
-
throw new Error(
|
|
812
|
-
"SAPI Error: Could not find response headers file."
|
|
813
|
-
);
|
|
814
|
-
const r = JSON.parse(this.readFileAsText(e)), n = {};
|
|
815
|
-
for (const s of r.headers) {
|
|
816
|
-
if (!s.includes(": "))
|
|
817
|
-
continue;
|
|
818
|
-
const i = s.indexOf(": "), o = s.substring(0, i).toLowerCase(), c = s.substring(i + 2);
|
|
819
|
-
o in n || (n[o] = []), n[o].push(c);
|
|
820
|
-
}
|
|
821
|
-
return {
|
|
822
|
-
headers: n,
|
|
823
|
-
httpStatusCode: r.status
|
|
824
|
-
};
|
|
825
|
-
}
|
|
826
|
-
#a(e) {
|
|
827
|
-
if (this[u].ccall(
|
|
828
|
-
"wasm_set_request_uri",
|
|
829
|
-
null,
|
|
830
|
-
[f],
|
|
831
|
-
[e]
|
|
832
|
-
), e.includes("?")) {
|
|
833
|
-
const r = e.substring(e.indexOf("?") + 1);
|
|
834
|
-
this[u].ccall(
|
|
835
|
-
"wasm_set_query_string",
|
|
836
|
-
null,
|
|
837
|
-
[f],
|
|
838
|
-
[r]
|
|
839
|
-
);
|
|
840
|
-
}
|
|
841
|
-
}
|
|
842
|
-
#c(e, r) {
|
|
843
|
-
this[u].ccall(
|
|
844
|
-
"wasm_set_request_host",
|
|
845
|
-
null,
|
|
846
|
-
[f],
|
|
847
|
-
[e]
|
|
848
|
-
);
|
|
849
|
-
let n;
|
|
849
|
+
const r = await c(this, B).acquire();
|
|
850
850
|
try {
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
#l(e) {
|
|
862
|
-
this[u].ccall(
|
|
863
|
-
"wasm_set_request_method",
|
|
864
|
-
null,
|
|
865
|
-
[f],
|
|
866
|
-
[e]
|
|
867
|
-
);
|
|
868
|
-
}
|
|
869
|
-
#u(e) {
|
|
870
|
-
e.cookie && this[u].ccall(
|
|
871
|
-
"wasm_set_cookies",
|
|
872
|
-
null,
|
|
873
|
-
[f],
|
|
874
|
-
[e.cookie]
|
|
875
|
-
), e["content-type"] && this[u].ccall(
|
|
876
|
-
"wasm_set_content_type",
|
|
877
|
-
null,
|
|
878
|
-
[f],
|
|
879
|
-
[e["content-type"]]
|
|
880
|
-
), e["content-length"] && this[u].ccall(
|
|
881
|
-
"wasm_set_content_length",
|
|
882
|
-
null,
|
|
883
|
-
[E],
|
|
884
|
-
[parseInt(e["content-length"], 10)]
|
|
885
|
-
);
|
|
886
|
-
for (const r in e) {
|
|
887
|
-
let n = "HTTP_";
|
|
888
|
-
["content-type", "content-length"].includes(r.toLowerCase()) && (n = ""), this.addServerGlobalEntry(
|
|
889
|
-
`${n}${r.toUpperCase().replace(/-/g, "_")}`,
|
|
890
|
-
e[r]
|
|
891
|
-
);
|
|
851
|
+
c(this, S) || (y(this, te, Ue).call(this), g(this, S, !0)), y(this, ce, Be).call(this, e.scriptPath || ""), y(this, ne, We).call(this, e.relativeUri || ""), y(this, ie, qe).call(this, e.method || "GET");
|
|
852
|
+
const n = Ke(e.headers || {}), s = n.host || "example.com:443";
|
|
853
|
+
if (y(this, se, De).call(this, s, e.protocol || "http"), y(this, oe, ze).call(this, n), e.body && y(this, ae, je).call(this, e.body), e.fileInfos)
|
|
854
|
+
for (const o of e.fileInfos)
|
|
855
|
+
y(this, ue, Ve).call(this, o);
|
|
856
|
+
return e.code && y(this, he, Ye).call(this, " ?>" + e.code), y(this, le, Ge).call(this), await y(this, de, Je).call(this);
|
|
857
|
+
} finally {
|
|
858
|
+
r(), this.dispatchEvent({
|
|
859
|
+
type: "request.end"
|
|
860
|
+
});
|
|
892
861
|
}
|
|
893
862
|
}
|
|
894
|
-
#h(e) {
|
|
895
|
-
this[u].ccall(
|
|
896
|
-
"wasm_set_request_body",
|
|
897
|
-
null,
|
|
898
|
-
[f],
|
|
899
|
-
[e]
|
|
900
|
-
), this[u].ccall(
|
|
901
|
-
"wasm_set_content_length",
|
|
902
|
-
null,
|
|
903
|
-
[E],
|
|
904
|
-
[new TextEncoder().encode(e).length]
|
|
905
|
-
);
|
|
906
|
-
}
|
|
907
|
-
#d(e) {
|
|
908
|
-
this[u].ccall(
|
|
909
|
-
"wasm_set_path_translated",
|
|
910
|
-
null,
|
|
911
|
-
[f],
|
|
912
|
-
[e]
|
|
913
|
-
);
|
|
914
|
-
}
|
|
915
863
|
addServerGlobalEntry(e, r) {
|
|
916
|
-
this
|
|
917
|
-
}
|
|
918
|
-
#f() {
|
|
919
|
-
for (const e in this.#r)
|
|
920
|
-
this[u].ccall(
|
|
921
|
-
"wasm_add_SERVER_entry",
|
|
922
|
-
null,
|
|
923
|
-
[f, f],
|
|
924
|
-
[e, this.#r[e]]
|
|
925
|
-
);
|
|
864
|
+
c(this, _)[e] = r;
|
|
926
865
|
}
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
*
|
|
930
|
-
* In particular:
|
|
931
|
-
* * Creates the file data in the filesystem
|
|
932
|
-
* * Registers the file details in PHP
|
|
933
|
-
*
|
|
934
|
-
* @param fileInfo - File details
|
|
935
|
-
*/
|
|
936
|
-
#p(e) {
|
|
937
|
-
const { key: r, name: n, type: s, data: i } = e, o = `/tmp/${Math.random().toFixed(20)}`;
|
|
938
|
-
this.writeFile(o, i);
|
|
939
|
-
const c = 0;
|
|
940
|
-
this[u].ccall(
|
|
941
|
-
"wasm_add_uploaded_file",
|
|
942
|
-
null,
|
|
943
|
-
[f, f, f, f, E, E],
|
|
944
|
-
[r, n, s, o, c, i.byteLength]
|
|
945
|
-
);
|
|
946
|
-
}
|
|
947
|
-
#m(e) {
|
|
948
|
-
this[u].ccall(
|
|
949
|
-
"wasm_set_php_code",
|
|
950
|
-
null,
|
|
951
|
-
[f],
|
|
952
|
-
[e]
|
|
953
|
-
);
|
|
954
|
-
}
|
|
955
|
-
async #g() {
|
|
956
|
-
let e, r;
|
|
866
|
+
defineConstant(e, r) {
|
|
867
|
+
let n = {};
|
|
957
868
|
try {
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
}, this.#n?.addEventListener(
|
|
963
|
-
"error",
|
|
964
|
-
r
|
|
965
|
-
);
|
|
966
|
-
const c = this[u].ccall(
|
|
967
|
-
"wasm_sapi_handle_request",
|
|
968
|
-
E,
|
|
969
|
-
[],
|
|
970
|
-
[]
|
|
971
|
-
);
|
|
972
|
-
return c instanceof Promise ? c.then(i, o) : i(c);
|
|
973
|
-
});
|
|
974
|
-
} catch (i) {
|
|
975
|
-
for (const a in this)
|
|
976
|
-
typeof this[a] == "function" && (this[a] = () => {
|
|
977
|
-
throw new Error(
|
|
978
|
-
"PHP runtime has crashed – see the earlier error for details."
|
|
979
|
-
);
|
|
980
|
-
});
|
|
981
|
-
this.functionsMaybeMissingFromAsyncify = ue();
|
|
982
|
-
const o = i, c = "betterMessage" in o ? o.betterMessage : o.message, l = new Error(c);
|
|
983
|
-
throw l.cause = o, l;
|
|
984
|
-
} finally {
|
|
985
|
-
this.#n?.removeEventListener("error", r), this.#r = {};
|
|
869
|
+
n = JSON.parse(
|
|
870
|
+
this.fileExists("/tmp/consts.json") && this.readFileAsText("/tmp/consts.json") || "{}"
|
|
871
|
+
);
|
|
872
|
+
} catch {
|
|
986
873
|
}
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
e
|
|
874
|
+
this.writeFile(
|
|
875
|
+
"/tmp/consts.json",
|
|
876
|
+
JSON.stringify({
|
|
877
|
+
...n,
|
|
878
|
+
[e]: r
|
|
879
|
+
})
|
|
994
880
|
);
|
|
995
881
|
}
|
|
996
882
|
mkdir(e) {
|
|
997
|
-
this[
|
|
883
|
+
this[f].FS.mkdirTree(e);
|
|
998
884
|
}
|
|
999
885
|
mkdirTree(e) {
|
|
1000
886
|
this.mkdir(e);
|
|
@@ -1003,33 +889,33 @@ class m {
|
|
|
1003
889
|
return new TextDecoder().decode(this.readFileAsBuffer(e));
|
|
1004
890
|
}
|
|
1005
891
|
readFileAsBuffer(e) {
|
|
1006
|
-
return this[
|
|
892
|
+
return this[f].FS.readFile(e);
|
|
1007
893
|
}
|
|
1008
894
|
writeFile(e, r) {
|
|
1009
|
-
this[
|
|
895
|
+
this[f].FS.writeFile(e, r);
|
|
1010
896
|
}
|
|
1011
897
|
unlink(e) {
|
|
1012
|
-
this[
|
|
898
|
+
this[f].FS.unlink(e);
|
|
1013
899
|
}
|
|
1014
900
|
mv(e, r) {
|
|
1015
|
-
this[
|
|
901
|
+
this[f].FS.rename(e, r);
|
|
1016
902
|
}
|
|
1017
903
|
rmdir(e, r = { recursive: !0 }) {
|
|
1018
|
-
r
|
|
904
|
+
r != null && r.recursive && this.listFiles(e).forEach((n) => {
|
|
1019
905
|
const s = `${e}/${n}`;
|
|
1020
906
|
this.isDir(s) ? this.rmdir(s, r) : this.unlink(s);
|
|
1021
|
-
}), this[
|
|
907
|
+
}), this[f].FS.rmdir(e);
|
|
1022
908
|
}
|
|
1023
909
|
listFiles(e, r = { prependPath: !1 }) {
|
|
1024
910
|
if (!this.fileExists(e))
|
|
1025
911
|
return [];
|
|
1026
912
|
try {
|
|
1027
|
-
const n = this[
|
|
913
|
+
const n = this[f].FS.readdir(e).filter(
|
|
1028
914
|
(s) => s !== "." && s !== ".."
|
|
1029
915
|
);
|
|
1030
916
|
if (r.prependPath) {
|
|
1031
917
|
const s = e.replace(/\/$/, "");
|
|
1032
|
-
return n.map((
|
|
918
|
+
return n.map((o) => `${s}/${o}`);
|
|
1033
919
|
}
|
|
1034
920
|
return n;
|
|
1035
921
|
} catch (n) {
|
|
@@ -1037,52 +923,249 @@ class m {
|
|
|
1037
923
|
}
|
|
1038
924
|
}
|
|
1039
925
|
isDir(e) {
|
|
1040
|
-
return this.fileExists(e) ? this[
|
|
1041
|
-
this[
|
|
926
|
+
return this.fileExists(e) ? this[f].FS.isDir(
|
|
927
|
+
this[f].FS.lookupPath(e).node.mode
|
|
1042
928
|
) : !1;
|
|
1043
929
|
}
|
|
1044
930
|
fileExists(e) {
|
|
1045
931
|
try {
|
|
1046
|
-
return this[
|
|
932
|
+
return this[f].FS.lookupPath(e), !0;
|
|
1047
933
|
} catch {
|
|
1048
934
|
return !1;
|
|
1049
935
|
}
|
|
1050
936
|
}
|
|
937
|
+
exit(e = 0) {
|
|
938
|
+
return this[f]._exit(e);
|
|
939
|
+
}
|
|
1051
940
|
}
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
]
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
],
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
941
|
+
F = new WeakMap(), S = new WeakMap(), L = new WeakMap(), _ = new WeakMap(), R = new WeakMap(), D = new WeakMap(), B = new WeakMap(), te = new WeakSet(), Ue = function() {
|
|
942
|
+
if (this.setPhpIniEntry("auto_prepend_file", "/tmp/consts.php"), this.fileExists("/tmp/consts.php") || this.writeFile(
|
|
943
|
+
"/tmp/consts.php",
|
|
944
|
+
`<?php
|
|
945
|
+
if(file_exists('/tmp/consts.json')) {
|
|
946
|
+
$consts = json_decode(file_get_contents('/tmp/consts.json'), true);
|
|
947
|
+
foreach ($consts as $const => $value) {
|
|
948
|
+
if (!defined($const) && is_scalar($value)) {
|
|
949
|
+
define($const, $value);
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
}`
|
|
953
|
+
), c(this, F).length > 0) {
|
|
954
|
+
const e = c(this, F).map(([r, n]) => `${r}=${n}`).join(`
|
|
955
|
+
`) + `
|
|
956
|
+
|
|
957
|
+
`;
|
|
958
|
+
this[f].ccall(
|
|
959
|
+
"wasm_set_phpini_entries",
|
|
960
|
+
null,
|
|
961
|
+
[w],
|
|
962
|
+
[e]
|
|
963
|
+
);
|
|
964
|
+
}
|
|
965
|
+
this[f].ccall("php_wasm_init", null, [], []);
|
|
966
|
+
}, re = new WeakSet(), $e = function() {
|
|
967
|
+
const e = "/tmp/headers.json";
|
|
968
|
+
if (!this.fileExists(e))
|
|
969
|
+
throw new Error(
|
|
970
|
+
"SAPI Error: Could not find response headers file."
|
|
971
|
+
);
|
|
972
|
+
const r = JSON.parse(this.readFileAsText(e)), n = {};
|
|
973
|
+
for (const s of r.headers) {
|
|
974
|
+
if (!s.includes(": "))
|
|
975
|
+
continue;
|
|
976
|
+
const o = s.indexOf(": "), i = s.substring(0, o).toLowerCase(), a = s.substring(o + 2);
|
|
977
|
+
i in n || (n[i] = []), n[i].push(a);
|
|
978
|
+
}
|
|
979
|
+
return {
|
|
980
|
+
headers: n,
|
|
981
|
+
httpStatusCode: r.status
|
|
982
|
+
};
|
|
983
|
+
}, ne = new WeakSet(), We = function(e) {
|
|
984
|
+
if (this[f].ccall(
|
|
985
|
+
"wasm_set_request_uri",
|
|
986
|
+
null,
|
|
987
|
+
[w],
|
|
988
|
+
[e]
|
|
989
|
+
), e.includes("?")) {
|
|
990
|
+
const r = e.substring(e.indexOf("?") + 1);
|
|
991
|
+
this[f].ccall(
|
|
992
|
+
"wasm_set_query_string",
|
|
993
|
+
null,
|
|
994
|
+
[w],
|
|
995
|
+
[r]
|
|
996
|
+
);
|
|
997
|
+
}
|
|
998
|
+
}, se = new WeakSet(), De = function(e, r) {
|
|
999
|
+
this[f].ccall(
|
|
1000
|
+
"wasm_set_request_host",
|
|
1001
|
+
null,
|
|
1002
|
+
[w],
|
|
1003
|
+
[e]
|
|
1004
|
+
);
|
|
1005
|
+
let n;
|
|
1006
|
+
try {
|
|
1007
|
+
n = parseInt(new URL(e).port, 10);
|
|
1008
|
+
} catch {
|
|
1009
|
+
}
|
|
1010
|
+
(!n || isNaN(n) || n === 80) && (n = r === "https" ? 443 : 80), this[f].ccall(
|
|
1011
|
+
"wasm_set_request_port",
|
|
1012
|
+
null,
|
|
1013
|
+
[M],
|
|
1014
|
+
[n]
|
|
1015
|
+
), (r === "https" || !r && n === 443) && this.addServerGlobalEntry("HTTPS", "on");
|
|
1016
|
+
}, ie = new WeakSet(), qe = function(e) {
|
|
1017
|
+
this[f].ccall(
|
|
1018
|
+
"wasm_set_request_method",
|
|
1019
|
+
null,
|
|
1020
|
+
[w],
|
|
1021
|
+
[e]
|
|
1022
|
+
);
|
|
1023
|
+
}, oe = new WeakSet(), ze = function(e) {
|
|
1024
|
+
e.cookie && this[f].ccall(
|
|
1025
|
+
"wasm_set_cookies",
|
|
1026
|
+
null,
|
|
1027
|
+
[w],
|
|
1028
|
+
[e.cookie]
|
|
1029
|
+
), e["content-type"] && this[f].ccall(
|
|
1030
|
+
"wasm_set_content_type",
|
|
1031
|
+
null,
|
|
1032
|
+
[w],
|
|
1033
|
+
[e["content-type"]]
|
|
1034
|
+
), e["content-length"] && this[f].ccall(
|
|
1035
|
+
"wasm_set_content_length",
|
|
1036
|
+
null,
|
|
1037
|
+
[M],
|
|
1038
|
+
[parseInt(e["content-length"], 10)]
|
|
1039
|
+
);
|
|
1040
|
+
for (const r in e) {
|
|
1041
|
+
let n = "HTTP_";
|
|
1042
|
+
["content-type", "content-length"].includes(r.toLowerCase()) && (n = ""), this.addServerGlobalEntry(
|
|
1043
|
+
`${n}${r.toUpperCase().replace(/-/g, "_")}`,
|
|
1044
|
+
e[r]
|
|
1045
|
+
);
|
|
1046
|
+
}
|
|
1047
|
+
}, ae = new WeakSet(), je = function(e) {
|
|
1048
|
+
this[f].ccall(
|
|
1049
|
+
"wasm_set_request_body",
|
|
1050
|
+
null,
|
|
1051
|
+
[w],
|
|
1052
|
+
[e]
|
|
1053
|
+
), this[f].ccall(
|
|
1054
|
+
"wasm_set_content_length",
|
|
1055
|
+
null,
|
|
1056
|
+
[M],
|
|
1057
|
+
[new TextEncoder().encode(e).length]
|
|
1058
|
+
);
|
|
1059
|
+
}, ce = new WeakSet(), Be = function(e) {
|
|
1060
|
+
this[f].ccall(
|
|
1061
|
+
"wasm_set_path_translated",
|
|
1062
|
+
null,
|
|
1063
|
+
[w],
|
|
1064
|
+
[e]
|
|
1065
|
+
);
|
|
1066
|
+
}, le = new WeakSet(), Ge = function() {
|
|
1067
|
+
for (const e in c(this, _))
|
|
1068
|
+
this[f].ccall(
|
|
1069
|
+
"wasm_add_SERVER_entry",
|
|
1070
|
+
null,
|
|
1071
|
+
[w, w],
|
|
1072
|
+
[e, c(this, _)[e]]
|
|
1073
|
+
);
|
|
1074
|
+
}, ue = new WeakSet(), Ve = function(e) {
|
|
1075
|
+
const { key: r, name: n, type: s, data: o } = e, i = `/tmp/${Math.random().toFixed(20)}`;
|
|
1076
|
+
this.writeFile(i, o);
|
|
1077
|
+
const a = 0;
|
|
1078
|
+
this[f].ccall(
|
|
1079
|
+
"wasm_add_uploaded_file",
|
|
1080
|
+
null,
|
|
1081
|
+
[w, w, w, w, M, M],
|
|
1082
|
+
[r, n, s, i, a, o.byteLength]
|
|
1083
|
+
);
|
|
1084
|
+
}, he = new WeakSet(), Ye = function(e) {
|
|
1085
|
+
this[f].ccall(
|
|
1086
|
+
"wasm_set_php_code",
|
|
1087
|
+
null,
|
|
1088
|
+
[w],
|
|
1089
|
+
[e]
|
|
1090
|
+
);
|
|
1091
|
+
}, de = new WeakSet(), Je = async function() {
|
|
1092
|
+
var o;
|
|
1093
|
+
let e, r;
|
|
1094
|
+
try {
|
|
1095
|
+
e = await new Promise((i, a) => {
|
|
1096
|
+
var l;
|
|
1097
|
+
r = (h) => {
|
|
1098
|
+
const m = new Error("Rethrown");
|
|
1099
|
+
m.cause = h.error, m.betterMessage = h.message, a(m);
|
|
1100
|
+
}, (l = c(this, L)) == null || l.addEventListener(
|
|
1101
|
+
"error",
|
|
1102
|
+
r
|
|
1103
|
+
);
|
|
1104
|
+
const u = this[f].ccall(
|
|
1105
|
+
"wasm_sapi_handle_request",
|
|
1106
|
+
M,
|
|
1107
|
+
[],
|
|
1108
|
+
[],
|
|
1109
|
+
{ async: !0 }
|
|
1110
|
+
);
|
|
1111
|
+
return u instanceof Promise ? u.then(i, a) : i(u);
|
|
1112
|
+
});
|
|
1113
|
+
} catch (i) {
|
|
1114
|
+
for (const h in this)
|
|
1115
|
+
typeof this[h] == "function" && (this[h] = () => {
|
|
1116
|
+
throw new Error(
|
|
1117
|
+
"PHP runtime has crashed – see the earlier error for details."
|
|
1118
|
+
);
|
|
1119
|
+
});
|
|
1120
|
+
this.functionsMaybeMissingFromAsyncify = lt();
|
|
1121
|
+
const a = i, u = "betterMessage" in a ? a.betterMessage : a.message, l = new Error(u);
|
|
1122
|
+
throw l.cause = a, l;
|
|
1123
|
+
} finally {
|
|
1124
|
+
(o = c(this, L)) == null || o.removeEventListener("error", r), g(this, _, {});
|
|
1125
|
+
}
|
|
1126
|
+
const { headers: n, httpStatusCode: s } = y(this, re, $e).call(this);
|
|
1127
|
+
return new A(
|
|
1128
|
+
s,
|
|
1129
|
+
n,
|
|
1130
|
+
this.readFileAsBuffer("/tmp/stdout"),
|
|
1131
|
+
this.readFileAsText("/tmp/stderr"),
|
|
1132
|
+
e
|
|
1133
|
+
);
|
|
1134
|
+
};
|
|
1135
|
+
v([
|
|
1136
|
+
b('Could not create directory "{path}"')
|
|
1137
|
+
], E.prototype, "mkdir", 1);
|
|
1138
|
+
v([
|
|
1139
|
+
b('Could not create directory "{path}"')
|
|
1140
|
+
], E.prototype, "mkdirTree", 1);
|
|
1141
|
+
v([
|
|
1142
|
+
b('Could not read "{path}"')
|
|
1143
|
+
], E.prototype, "readFileAsText", 1);
|
|
1144
|
+
v([
|
|
1145
|
+
b('Could not read "{path}"')
|
|
1146
|
+
], E.prototype, "readFileAsBuffer", 1);
|
|
1147
|
+
v([
|
|
1148
|
+
b('Could not write to "{path}"')
|
|
1149
|
+
], E.prototype, "writeFile", 1);
|
|
1150
|
+
v([
|
|
1151
|
+
b('Could not unlink "{path}"')
|
|
1152
|
+
], E.prototype, "unlink", 1);
|
|
1153
|
+
v([
|
|
1154
|
+
b('Could not move "{path}"')
|
|
1155
|
+
], E.prototype, "mv", 1);
|
|
1156
|
+
v([
|
|
1157
|
+
b('Could not remove directory "{path}"')
|
|
1158
|
+
], E.prototype, "rmdir", 1);
|
|
1159
|
+
v([
|
|
1160
|
+
b('Could not list files in "{path}"')
|
|
1161
|
+
], E.prototype, "listFiles", 1);
|
|
1162
|
+
v([
|
|
1163
|
+
b('Could not stat "{path}"')
|
|
1164
|
+
], E.prototype, "isDir", 1);
|
|
1165
|
+
v([
|
|
1166
|
+
b('Could not stat "{path}"')
|
|
1167
|
+
], E.prototype, "fileExists", 1);
|
|
1168
|
+
function Ke(t) {
|
|
1086
1169
|
const e = {};
|
|
1087
1170
|
for (const r in t)
|
|
1088
1171
|
e[r.toLowerCase()] = t[r];
|
|
@@ -1093,17 +1176,17 @@ function Q(t) {
|
|
|
1093
1176
|
* Copyright 2019 Google LLC
|
|
1094
1177
|
* SPDX-License-Identifier: Apache-2.0
|
|
1095
1178
|
*/
|
|
1096
|
-
const
|
|
1097
|
-
canHandle: (t) =>
|
|
1179
|
+
const Qe = Symbol("Comlink.proxy"), Lt = Symbol("Comlink.endpoint"), At = Symbol("Comlink.releaseProxy"), me = Symbol("Comlink.finalizer"), Y = Symbol("Comlink.thrown"), Xe = (t) => typeof t == "object" && t !== null || typeof t == "function", Mt = {
|
|
1180
|
+
canHandle: (t) => Xe(t) && t[Qe],
|
|
1098
1181
|
serialize(t) {
|
|
1099
1182
|
const { port1: e, port2: r } = new MessageChannel();
|
|
1100
|
-
return
|
|
1183
|
+
return fe(t, e), [r, [r]];
|
|
1101
1184
|
},
|
|
1102
1185
|
deserialize(t) {
|
|
1103
|
-
return t.start(),
|
|
1186
|
+
return t.start(), Ee(t);
|
|
1104
1187
|
}
|
|
1105
|
-
},
|
|
1106
|
-
canHandle: (t) =>
|
|
1188
|
+
}, Ot = {
|
|
1189
|
+
canHandle: (t) => Xe(t) && Y in t,
|
|
1107
1190
|
serialize({ value: t }) {
|
|
1108
1191
|
let e;
|
|
1109
1192
|
return t instanceof Error ? e = {
|
|
@@ -1118,182 +1201,182 @@ const X = Symbol("Comlink.proxy"), Me = Symbol("Comlink.endpoint"), Le = Symbol(
|
|
|
1118
1201
|
deserialize(t) {
|
|
1119
1202
|
throw t.isError ? Object.assign(new Error(t.value.message), t.value) : t.value;
|
|
1120
1203
|
}
|
|
1121
|
-
},
|
|
1122
|
-
["proxy",
|
|
1123
|
-
["throw",
|
|
1204
|
+
}, z = /* @__PURE__ */ new Map([
|
|
1205
|
+
["proxy", Mt],
|
|
1206
|
+
["throw", Ot]
|
|
1124
1207
|
]);
|
|
1125
|
-
function
|
|
1208
|
+
function It(t, e) {
|
|
1126
1209
|
for (const r of t)
|
|
1127
1210
|
if (e === r || r === "*" || r instanceof RegExp && r.test(e))
|
|
1128
1211
|
return !0;
|
|
1129
1212
|
return !1;
|
|
1130
1213
|
}
|
|
1131
|
-
function
|
|
1214
|
+
function fe(t, e = globalThis, r = ["*"]) {
|
|
1132
1215
|
e.addEventListener("message", function n(s) {
|
|
1133
1216
|
if (!s || !s.data)
|
|
1134
1217
|
return;
|
|
1135
|
-
if (!
|
|
1218
|
+
if (!It(r, s.origin)) {
|
|
1136
1219
|
console.warn(`Invalid origin '${s.origin}' for comlink proxy`);
|
|
1137
1220
|
return;
|
|
1138
1221
|
}
|
|
1139
|
-
const { id:
|
|
1140
|
-
let
|
|
1222
|
+
const { id: o, type: i, path: a } = Object.assign({ path: [] }, s.data), u = (s.data.argumentList || []).map(T);
|
|
1223
|
+
let l;
|
|
1141
1224
|
try {
|
|
1142
|
-
const h =
|
|
1143
|
-
switch (
|
|
1225
|
+
const h = a.slice(0, -1).reduce((P, q) => P[q], t), m = a.reduce((P, q) => P[q], t);
|
|
1226
|
+
switch (i) {
|
|
1144
1227
|
case "GET":
|
|
1145
|
-
|
|
1228
|
+
l = m;
|
|
1146
1229
|
break;
|
|
1147
1230
|
case "SET":
|
|
1148
|
-
h[
|
|
1231
|
+
h[a.slice(-1)[0]] = T(s.data.value), l = !0;
|
|
1149
1232
|
break;
|
|
1150
1233
|
case "APPLY":
|
|
1151
|
-
|
|
1234
|
+
l = m.apply(h, u);
|
|
1152
1235
|
break;
|
|
1153
1236
|
case "CONSTRUCT":
|
|
1154
1237
|
{
|
|
1155
|
-
const
|
|
1156
|
-
|
|
1238
|
+
const P = new m(...u);
|
|
1239
|
+
l = rt(P);
|
|
1157
1240
|
}
|
|
1158
1241
|
break;
|
|
1159
1242
|
case "ENDPOINT":
|
|
1160
1243
|
{
|
|
1161
|
-
const { port1:
|
|
1162
|
-
|
|
1244
|
+
const { port1: P, port2: q } = new MessageChannel();
|
|
1245
|
+
fe(t, q), l = Dt(P, [P]);
|
|
1163
1246
|
}
|
|
1164
1247
|
break;
|
|
1165
1248
|
case "RELEASE":
|
|
1166
|
-
|
|
1249
|
+
l = void 0;
|
|
1167
1250
|
break;
|
|
1168
1251
|
default:
|
|
1169
1252
|
return;
|
|
1170
1253
|
}
|
|
1171
1254
|
} catch (h) {
|
|
1172
|
-
|
|
1255
|
+
l = { value: h, [Y]: 0 };
|
|
1173
1256
|
}
|
|
1174
|
-
Promise.resolve(
|
|
1175
|
-
const [
|
|
1176
|
-
e.postMessage(Object.assign(Object.assign({},
|
|
1257
|
+
Promise.resolve(l).catch((h) => ({ value: h, [Y]: 0 })).then((h) => {
|
|
1258
|
+
const [m, P] = Q(h);
|
|
1259
|
+
e.postMessage(Object.assign(Object.assign({}, m), { id: o }), P), i === "RELEASE" && (e.removeEventListener("message", n), Ze(e), me in t && typeof t[me] == "function" && t[me]());
|
|
1177
1260
|
}).catch((h) => {
|
|
1178
|
-
const [
|
|
1261
|
+
const [m, P] = Q({
|
|
1179
1262
|
value: new TypeError("Unserializable return value"),
|
|
1180
|
-
[
|
|
1263
|
+
[Y]: 0
|
|
1181
1264
|
});
|
|
1182
|
-
e.postMessage(Object.assign(Object.assign({},
|
|
1265
|
+
e.postMessage(Object.assign(Object.assign({}, m), { id: o }), P);
|
|
1183
1266
|
});
|
|
1184
1267
|
}), e.start && e.start();
|
|
1185
1268
|
}
|
|
1186
|
-
function
|
|
1269
|
+
function Nt(t) {
|
|
1187
1270
|
return t.constructor.name === "MessagePort";
|
|
1188
1271
|
}
|
|
1189
|
-
function
|
|
1190
|
-
|
|
1272
|
+
function Ze(t) {
|
|
1273
|
+
Nt(t) && t.close();
|
|
1191
1274
|
}
|
|
1192
|
-
function
|
|
1193
|
-
return
|
|
1275
|
+
function Ee(t, e) {
|
|
1276
|
+
return ye(t, [], e);
|
|
1194
1277
|
}
|
|
1195
|
-
function
|
|
1278
|
+
function G(t) {
|
|
1196
1279
|
if (t)
|
|
1197
1280
|
throw new Error("Proxy has been released and is not useable");
|
|
1198
1281
|
}
|
|
1199
|
-
function
|
|
1200
|
-
return
|
|
1282
|
+
function et(t) {
|
|
1283
|
+
return O(t, {
|
|
1201
1284
|
type: "RELEASE"
|
|
1202
1285
|
}).then(() => {
|
|
1203
|
-
|
|
1286
|
+
Ze(t);
|
|
1204
1287
|
});
|
|
1205
1288
|
}
|
|
1206
|
-
const
|
|
1207
|
-
const e = (
|
|
1208
|
-
|
|
1289
|
+
const J = /* @__PURE__ */ new WeakMap(), K = "FinalizationRegistry" in globalThis && new FinalizationRegistry((t) => {
|
|
1290
|
+
const e = (J.get(t) || 0) - 1;
|
|
1291
|
+
J.set(t, e), e === 0 && et(t);
|
|
1209
1292
|
});
|
|
1210
|
-
function
|
|
1211
|
-
const r = (
|
|
1212
|
-
|
|
1293
|
+
function Ut(t, e) {
|
|
1294
|
+
const r = (J.get(e) || 0) + 1;
|
|
1295
|
+
J.set(e, r), K && K.register(t, e, t);
|
|
1213
1296
|
}
|
|
1214
|
-
function $
|
|
1215
|
-
|
|
1297
|
+
function $t(t) {
|
|
1298
|
+
K && K.unregister(t);
|
|
1216
1299
|
}
|
|
1217
|
-
function
|
|
1300
|
+
function ye(t, e = [], r = function() {
|
|
1218
1301
|
}) {
|
|
1219
1302
|
let n = !1;
|
|
1220
1303
|
const s = new Proxy(r, {
|
|
1221
|
-
get(
|
|
1222
|
-
if (
|
|
1304
|
+
get(o, i) {
|
|
1305
|
+
if (G(n), i === At)
|
|
1223
1306
|
return () => {
|
|
1224
|
-
$
|
|
1307
|
+
$t(s), et(t), n = !0;
|
|
1225
1308
|
};
|
|
1226
|
-
if (
|
|
1309
|
+
if (i === "then") {
|
|
1227
1310
|
if (e.length === 0)
|
|
1228
1311
|
return { then: () => s };
|
|
1229
|
-
const
|
|
1312
|
+
const a = O(t, {
|
|
1230
1313
|
type: "GET",
|
|
1231
|
-
path: e.map((
|
|
1232
|
-
}).then(
|
|
1233
|
-
return
|
|
1314
|
+
path: e.map((u) => u.toString())
|
|
1315
|
+
}).then(T);
|
|
1316
|
+
return a.then.bind(a);
|
|
1234
1317
|
}
|
|
1235
|
-
return
|
|
1318
|
+
return ye(t, [...e, i]);
|
|
1236
1319
|
},
|
|
1237
|
-
set(
|
|
1238
|
-
|
|
1239
|
-
const [
|
|
1240
|
-
return
|
|
1320
|
+
set(o, i, a) {
|
|
1321
|
+
G(n);
|
|
1322
|
+
const [u, l] = Q(a);
|
|
1323
|
+
return O(t, {
|
|
1241
1324
|
type: "SET",
|
|
1242
|
-
path: [...e,
|
|
1243
|
-
value:
|
|
1244
|
-
},
|
|
1325
|
+
path: [...e, i].map((h) => h.toString()),
|
|
1326
|
+
value: u
|
|
1327
|
+
}, l).then(T);
|
|
1245
1328
|
},
|
|
1246
|
-
apply(
|
|
1247
|
-
|
|
1248
|
-
const
|
|
1249
|
-
if (
|
|
1250
|
-
return
|
|
1329
|
+
apply(o, i, a) {
|
|
1330
|
+
G(n);
|
|
1331
|
+
const u = e[e.length - 1];
|
|
1332
|
+
if (u === Lt)
|
|
1333
|
+
return O(t, {
|
|
1251
1334
|
type: "ENDPOINT"
|
|
1252
|
-
}).then(
|
|
1253
|
-
if (
|
|
1254
|
-
return
|
|
1255
|
-
const [
|
|
1256
|
-
return
|
|
1335
|
+
}).then(T);
|
|
1336
|
+
if (u === "bind")
|
|
1337
|
+
return ye(t, e.slice(0, -1));
|
|
1338
|
+
const [l, h] = Le(a);
|
|
1339
|
+
return O(t, {
|
|
1257
1340
|
type: "APPLY",
|
|
1258
|
-
path: e.map((
|
|
1259
|
-
argumentList:
|
|
1260
|
-
}, h).then(
|
|
1341
|
+
path: e.map((m) => m.toString()),
|
|
1342
|
+
argumentList: l
|
|
1343
|
+
}, h).then(T);
|
|
1261
1344
|
},
|
|
1262
|
-
construct(
|
|
1263
|
-
|
|
1264
|
-
const [
|
|
1265
|
-
return
|
|
1345
|
+
construct(o, i) {
|
|
1346
|
+
G(n);
|
|
1347
|
+
const [a, u] = Le(i);
|
|
1348
|
+
return O(t, {
|
|
1266
1349
|
type: "CONSTRUCT",
|
|
1267
|
-
path: e.map((
|
|
1268
|
-
argumentList:
|
|
1269
|
-
},
|
|
1350
|
+
path: e.map((l) => l.toString()),
|
|
1351
|
+
argumentList: a
|
|
1352
|
+
}, u).then(T);
|
|
1270
1353
|
}
|
|
1271
1354
|
});
|
|
1272
|
-
return
|
|
1355
|
+
return Ut(s, t), s;
|
|
1273
1356
|
}
|
|
1274
|
-
function
|
|
1357
|
+
function Wt(t) {
|
|
1275
1358
|
return Array.prototype.concat.apply([], t);
|
|
1276
1359
|
}
|
|
1277
|
-
function
|
|
1278
|
-
const e = t.map(
|
|
1279
|
-
return [e.map((r) => r[0]),
|
|
1360
|
+
function Le(t) {
|
|
1361
|
+
const e = t.map(Q);
|
|
1362
|
+
return [e.map((r) => r[0]), Wt(e.map((r) => r[1]))];
|
|
1280
1363
|
}
|
|
1281
|
-
const
|
|
1282
|
-
function
|
|
1283
|
-
return
|
|
1364
|
+
const tt = /* @__PURE__ */ new WeakMap();
|
|
1365
|
+
function Dt(t, e) {
|
|
1366
|
+
return tt.set(t, e), t;
|
|
1284
1367
|
}
|
|
1285
|
-
function
|
|
1286
|
-
return Object.assign(t, { [
|
|
1368
|
+
function rt(t) {
|
|
1369
|
+
return Object.assign(t, { [Qe]: !0 });
|
|
1287
1370
|
}
|
|
1288
|
-
function
|
|
1371
|
+
function nt(t, e = globalThis, r = "*") {
|
|
1289
1372
|
return {
|
|
1290
1373
|
postMessage: (n, s) => t.postMessage(n, r, s),
|
|
1291
1374
|
addEventListener: e.addEventListener.bind(e),
|
|
1292
1375
|
removeEventListener: e.removeEventListener.bind(e)
|
|
1293
1376
|
};
|
|
1294
1377
|
}
|
|
1295
|
-
function
|
|
1296
|
-
for (const [e, r] of
|
|
1378
|
+
function Q(t) {
|
|
1379
|
+
for (const [e, r] of z)
|
|
1297
1380
|
if (r.canHandle(t)) {
|
|
1298
1381
|
const [n, s] = r.serialize(t);
|
|
1299
1382
|
return [
|
|
@@ -1310,64 +1393,64 @@ function C(t) {
|
|
|
1310
1393
|
type: "RAW",
|
|
1311
1394
|
value: t
|
|
1312
1395
|
},
|
|
1313
|
-
|
|
1396
|
+
tt.get(t) || []
|
|
1314
1397
|
];
|
|
1315
1398
|
}
|
|
1316
|
-
function
|
|
1399
|
+
function T(t) {
|
|
1317
1400
|
switch (t.type) {
|
|
1318
1401
|
case "HANDLER":
|
|
1319
|
-
return
|
|
1402
|
+
return z.get(t.name).deserialize(t.value);
|
|
1320
1403
|
case "RAW":
|
|
1321
1404
|
return t.value;
|
|
1322
1405
|
}
|
|
1323
1406
|
}
|
|
1324
|
-
function
|
|
1407
|
+
function O(t, e, r) {
|
|
1325
1408
|
return new Promise((n) => {
|
|
1326
|
-
const s =
|
|
1327
|
-
t.addEventListener("message", function i
|
|
1328
|
-
!
|
|
1409
|
+
const s = qt();
|
|
1410
|
+
t.addEventListener("message", function o(i) {
|
|
1411
|
+
!i.data || !i.data.id || i.data.id !== s || (t.removeEventListener("message", o), n(i.data));
|
|
1329
1412
|
}), t.start && t.start(), t.postMessage(Object.assign({ id: s }, e), r);
|
|
1330
1413
|
});
|
|
1331
1414
|
}
|
|
1332
|
-
function
|
|
1415
|
+
function qt() {
|
|
1333
1416
|
return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
|
|
1334
1417
|
}
|
|
1335
|
-
function
|
|
1336
|
-
|
|
1337
|
-
const e = t instanceof Worker ? t :
|
|
1418
|
+
function Jt(t) {
|
|
1419
|
+
st();
|
|
1420
|
+
const e = t instanceof Worker ? t : nt(t), r = Ee(e), n = be(r);
|
|
1338
1421
|
return new Proxy(n, {
|
|
1339
|
-
get: (s,
|
|
1340
|
-
for (let
|
|
1422
|
+
get: (s, o) => o === "isConnected" ? async () => {
|
|
1423
|
+
for (let i = 0; i < 10; i++)
|
|
1341
1424
|
try {
|
|
1342
|
-
await
|
|
1425
|
+
await zt(r.isConnected(), 200);
|
|
1343
1426
|
break;
|
|
1344
1427
|
} catch {
|
|
1345
1428
|
}
|
|
1346
|
-
} : r[
|
|
1429
|
+
} : r[o]
|
|
1347
1430
|
});
|
|
1348
1431
|
}
|
|
1349
|
-
async function
|
|
1432
|
+
async function zt(t, e) {
|
|
1350
1433
|
return new Promise((r, n) => {
|
|
1351
1434
|
setTimeout(n, e), t.then(r);
|
|
1352
1435
|
});
|
|
1353
1436
|
}
|
|
1354
|
-
function
|
|
1355
|
-
|
|
1437
|
+
function Kt(t, e) {
|
|
1438
|
+
st();
|
|
1356
1439
|
const r = Promise.resolve();
|
|
1357
1440
|
let n, s;
|
|
1358
|
-
const
|
|
1359
|
-
n =
|
|
1360
|
-
}),
|
|
1361
|
-
get: (
|
|
1441
|
+
const o = new Promise((u, l) => {
|
|
1442
|
+
n = u, s = l;
|
|
1443
|
+
}), i = be(t), a = new Proxy(i, {
|
|
1444
|
+
get: (u, l) => l === "isConnected" ? () => r : l === "isReady" ? () => o : l in u ? u[l] : e == null ? void 0 : e[l]
|
|
1362
1445
|
});
|
|
1363
|
-
return
|
|
1364
|
-
|
|
1365
|
-
typeof window < "u" ?
|
|
1366
|
-
), [n, s,
|
|
1446
|
+
return fe(
|
|
1447
|
+
a,
|
|
1448
|
+
typeof window < "u" ? nt(self.parent) : void 0
|
|
1449
|
+
), [n, s, a];
|
|
1367
1450
|
}
|
|
1368
|
-
let
|
|
1369
|
-
function
|
|
1370
|
-
|
|
1451
|
+
let Ae = !1;
|
|
1452
|
+
function st() {
|
|
1453
|
+
Ae || (Ae = !0, z.set("EVENT", {
|
|
1371
1454
|
canHandle: (t) => t instanceof CustomEvent,
|
|
1372
1455
|
serialize: (t) => [
|
|
1373
1456
|
{
|
|
@@ -1376,90 +1459,90 @@ function ie() {
|
|
|
1376
1459
|
[]
|
|
1377
1460
|
],
|
|
1378
1461
|
deserialize: (t) => t
|
|
1379
|
-
}),
|
|
1462
|
+
}), z.set("FUNCTION", {
|
|
1380
1463
|
canHandle: (t) => typeof t == "function",
|
|
1381
1464
|
serialize(t) {
|
|
1382
1465
|
console.debug("[Comlink][Performance] Proxying a function");
|
|
1383
1466
|
const { port1: e, port2: r } = new MessageChannel();
|
|
1384
|
-
return
|
|
1467
|
+
return fe(t, e), [r, [r]];
|
|
1385
1468
|
},
|
|
1386
1469
|
deserialize(t) {
|
|
1387
|
-
return t.start(),
|
|
1470
|
+
return t.start(), Ee(t);
|
|
1388
1471
|
}
|
|
1389
|
-
}),
|
|
1472
|
+
}), z.set("PHPResponse", {
|
|
1390
1473
|
canHandle: (t) => typeof t == "object" && t !== null && "headers" in t && "bytes" in t && "errors" in t && "exitCode" in t && "httpStatusCode" in t,
|
|
1391
1474
|
serialize(t) {
|
|
1392
1475
|
return [t.toRawData(), []];
|
|
1393
1476
|
},
|
|
1394
1477
|
deserialize(t) {
|
|
1395
|
-
return
|
|
1478
|
+
return A.fromRawData(t);
|
|
1396
1479
|
}
|
|
1397
1480
|
}));
|
|
1398
1481
|
}
|
|
1399
|
-
function
|
|
1482
|
+
function be(t) {
|
|
1400
1483
|
return new Proxy(t, {
|
|
1401
1484
|
get(e, r) {
|
|
1402
1485
|
switch (typeof e[r]) {
|
|
1403
1486
|
case "function":
|
|
1404
1487
|
return (...n) => e[r](...n);
|
|
1405
1488
|
case "object":
|
|
1406
|
-
return e[r] === null ? e[r] :
|
|
1489
|
+
return e[r] === null ? e[r] : be(e[r]);
|
|
1407
1490
|
case "undefined":
|
|
1408
1491
|
case "number":
|
|
1409
1492
|
case "string":
|
|
1410
1493
|
return e[r];
|
|
1411
1494
|
default:
|
|
1412
|
-
return
|
|
1495
|
+
return rt(e[r]);
|
|
1413
1496
|
}
|
|
1414
1497
|
}
|
|
1415
1498
|
});
|
|
1416
1499
|
}
|
|
1417
|
-
async function
|
|
1500
|
+
async function jt(t = gt, e = "light") {
|
|
1418
1501
|
if (e === "kitchen-sink")
|
|
1419
1502
|
switch (t) {
|
|
1503
|
+
case "8.3":
|
|
1504
|
+
return await import("./kitchen-sink/php_8_3.js");
|
|
1420
1505
|
case "8.2":
|
|
1421
|
-
return await import("./php_8_2.js");
|
|
1506
|
+
return await import("./kitchen-sink/php_8_2.js");
|
|
1422
1507
|
case "8.1":
|
|
1423
|
-
return await import("./php_8_1.js");
|
|
1508
|
+
return await import("./kitchen-sink/php_8_1.js");
|
|
1424
1509
|
case "8.0":
|
|
1425
|
-
return await import("./php_8_0.js");
|
|
1510
|
+
return await import("./kitchen-sink/php_8_0.js");
|
|
1426
1511
|
case "7.4":
|
|
1427
|
-
return await import("./php_7_4.js");
|
|
1512
|
+
return await import("./kitchen-sink/php_7_4.js");
|
|
1428
1513
|
case "7.3":
|
|
1429
|
-
return await import("./php_7_3.js");
|
|
1514
|
+
return await import("./kitchen-sink/php_7_3.js");
|
|
1430
1515
|
case "7.2":
|
|
1431
|
-
return await import("./php_7_2.js");
|
|
1516
|
+
return await import("./kitchen-sink/php_7_2.js");
|
|
1432
1517
|
case "7.1":
|
|
1433
|
-
return await import("./php_7_1.js");
|
|
1518
|
+
return await import("./kitchen-sink/php_7_1.js");
|
|
1434
1519
|
case "7.0":
|
|
1435
|
-
return await import("./php_7_0.js");
|
|
1436
|
-
case "5.6":
|
|
1437
|
-
return await import("./php_5_6.js");
|
|
1520
|
+
return await import("./kitchen-sink/php_7_0.js");
|
|
1438
1521
|
}
|
|
1439
1522
|
else
|
|
1440
1523
|
switch (t) {
|
|
1524
|
+
case "8.3":
|
|
1525
|
+
return await import("./light/php_8_3.js");
|
|
1441
1526
|
case "8.2":
|
|
1442
|
-
return await import("./php_8_2.js");
|
|
1527
|
+
return await import("./light/php_8_2.js");
|
|
1443
1528
|
case "8.1":
|
|
1444
|
-
return await import("./php_8_1.js");
|
|
1529
|
+
return await import("./light/php_8_1.js");
|
|
1445
1530
|
case "8.0":
|
|
1446
|
-
return await import("./php_8_0.js");
|
|
1531
|
+
return await import("./light/php_8_0.js");
|
|
1447
1532
|
case "7.4":
|
|
1448
|
-
return await import("./php_7_4.js");
|
|
1533
|
+
return await import("./light/php_7_4.js");
|
|
1449
1534
|
case "7.3":
|
|
1450
|
-
return await import("./php_7_3.js");
|
|
1535
|
+
return await import("./light/php_7_3.js");
|
|
1451
1536
|
case "7.2":
|
|
1452
|
-
return await import("./php_7_2.js");
|
|
1537
|
+
return await import("./light/php_7_2.js");
|
|
1453
1538
|
case "7.1":
|
|
1454
|
-
return await import("./php_7_1.js");
|
|
1539
|
+
return await import("./light/php_7_1.js");
|
|
1455
1540
|
case "7.0":
|
|
1456
|
-
return await import("./php_7_0.js");
|
|
1457
|
-
case "5.6":
|
|
1458
|
-
return await import("./php_5_6.js");
|
|
1541
|
+
return await import("./light/php_7_0.js");
|
|
1459
1542
|
}
|
|
1460
1543
|
throw new Error(`Unsupported PHP version ${t}`);
|
|
1461
1544
|
}
|
|
1462
|
-
const
|
|
1545
|
+
const Bt = () => ({
|
|
1463
1546
|
websocket: {
|
|
1464
1547
|
decorator: (t) => class extends t {
|
|
1465
1548
|
constructor() {
|
|
@@ -1474,7 +1557,7 @@ const Ge = () => ({
|
|
|
1474
1557
|
}
|
|
1475
1558
|
}
|
|
1476
1559
|
});
|
|
1477
|
-
class
|
|
1560
|
+
class we extends E {
|
|
1478
1561
|
/**
|
|
1479
1562
|
* Creates a new PHP instance.
|
|
1480
1563
|
*
|
|
@@ -1488,7 +1571,7 @@ class O extends m {
|
|
|
1488
1571
|
* @returns A new PHP instance
|
|
1489
1572
|
*/
|
|
1490
1573
|
static async load(e, r = {}) {
|
|
1491
|
-
return await
|
|
1574
|
+
return await we.loadSync(e, r).phpReady;
|
|
1492
1575
|
}
|
|
1493
1576
|
/**
|
|
1494
1577
|
* Does what load() does, but synchronously returns
|
|
@@ -1498,129 +1581,147 @@ class O extends m {
|
|
|
1498
1581
|
* @see load
|
|
1499
1582
|
*/
|
|
1500
1583
|
static loadSync(e, r = {}) {
|
|
1501
|
-
const n = new
|
|
1502
|
-
|
|
1503
|
-
|
|
1584
|
+
const n = new we(void 0, r.requestHandler), s = r.loadAllExtensions ? "kitchen-sink" : "light", i = (async () => {
|
|
1585
|
+
var m, P;
|
|
1586
|
+
const a = await Promise.all([
|
|
1587
|
+
jt(e, s),
|
|
1504
1588
|
...r.dataModules || []
|
|
1505
|
-
]), [
|
|
1506
|
-
r.downloadMonitor
|
|
1507
|
-
const h = await
|
|
1508
|
-
|
|
1589
|
+
]), [u, ...l] = a;
|
|
1590
|
+
(m = r.downloadMonitor) == null || m.setModules(a);
|
|
1591
|
+
const h = await _t(
|
|
1592
|
+
u,
|
|
1509
1593
|
{
|
|
1510
1594
|
...r.emscriptenOptions || {},
|
|
1511
|
-
...r.downloadMonitor
|
|
1512
|
-
...
|
|
1595
|
+
...((P = r.downloadMonitor) == null ? void 0 : P.getEmscriptenOptions()) || {},
|
|
1596
|
+
...Bt()
|
|
1513
1597
|
},
|
|
1514
|
-
|
|
1598
|
+
l
|
|
1515
1599
|
);
|
|
1516
1600
|
n.initializeRuntime(h);
|
|
1517
1601
|
})();
|
|
1518
1602
|
return {
|
|
1519
1603
|
php: n,
|
|
1520
|
-
phpReady:
|
|
1604
|
+
phpReady: i.then(() => n)
|
|
1521
1605
|
};
|
|
1522
1606
|
}
|
|
1523
1607
|
}
|
|
1524
|
-
const
|
|
1525
|
-
class
|
|
1608
|
+
const p = /* @__PURE__ */ new WeakMap();
|
|
1609
|
+
class Xt {
|
|
1526
1610
|
/** @inheritDoc */
|
|
1527
1611
|
constructor(e, r) {
|
|
1528
|
-
|
|
1612
|
+
p.set(this, {
|
|
1529
1613
|
php: e,
|
|
1530
1614
|
monitor: r
|
|
1531
1615
|
}), this.absoluteUrl = e.absoluteUrl, this.documentRoot = e.documentRoot;
|
|
1532
1616
|
}
|
|
1533
1617
|
/** @inheritDoc @php-wasm/universal!RequestHandler.pathToInternalUrl */
|
|
1534
1618
|
pathToInternalUrl(e) {
|
|
1535
|
-
return
|
|
1619
|
+
return p.get(this).php.pathToInternalUrl(e);
|
|
1536
1620
|
}
|
|
1537
1621
|
/** @inheritDoc @php-wasm/universal!RequestHandler.internalUrlToPath */
|
|
1538
1622
|
internalUrlToPath(e) {
|
|
1539
|
-
return
|
|
1623
|
+
return p.get(this).php.internalUrlToPath(e);
|
|
1540
1624
|
}
|
|
1541
1625
|
/**
|
|
1542
1626
|
* The onDownloadProgress event listener.
|
|
1543
1627
|
*/
|
|
1544
1628
|
async onDownloadProgress(e) {
|
|
1545
|
-
|
|
1629
|
+
var r;
|
|
1630
|
+
return (r = p.get(this).monitor) == null ? void 0 : r.addEventListener("progress", e);
|
|
1546
1631
|
}
|
|
1547
1632
|
/** @inheritDoc @php-wasm/universal!IsomorphicLocalPHP.mv */
|
|
1548
1633
|
mv(e, r) {
|
|
1549
|
-
return
|
|
1634
|
+
return p.get(this).php.mv(e, r);
|
|
1550
1635
|
}
|
|
1551
1636
|
/** @inheritDoc @php-wasm/universal!IsomorphicLocalPHP.rmdir */
|
|
1552
1637
|
rmdir(e, r) {
|
|
1553
|
-
return
|
|
1638
|
+
return p.get(this).php.rmdir(e, r);
|
|
1554
1639
|
}
|
|
1555
1640
|
/** @inheritDoc @php-wasm/universal!RequestHandler.request */
|
|
1556
1641
|
request(e, r) {
|
|
1557
|
-
return
|
|
1642
|
+
return p.get(this).php.request(e, r);
|
|
1558
1643
|
}
|
|
1559
1644
|
/** @inheritDoc @php-wasm/web!WebPHP.run */
|
|
1560
1645
|
async run(e) {
|
|
1561
|
-
return
|
|
1646
|
+
return p.get(this).php.run(e);
|
|
1647
|
+
}
|
|
1648
|
+
/** @inheritDoc @php-wasm/web!WebPHP.setSpawnHandler */
|
|
1649
|
+
setSpawnHandler(e) {
|
|
1650
|
+
p.get(this).php.setSpawnHandler(e);
|
|
1562
1651
|
}
|
|
1563
1652
|
/** @inheritDoc @php-wasm/web!WebPHP.chdir */
|
|
1564
1653
|
chdir(e) {
|
|
1565
|
-
return
|
|
1654
|
+
return p.get(this).php.chdir(e);
|
|
1566
1655
|
}
|
|
1567
1656
|
/** @inheritDoc @php-wasm/web!WebPHP.setPhpIniPath */
|
|
1568
1657
|
setPhpIniPath(e) {
|
|
1569
|
-
return
|
|
1658
|
+
return p.get(this).php.setPhpIniPath(e);
|
|
1570
1659
|
}
|
|
1571
1660
|
/** @inheritDoc @php-wasm/web!WebPHP.setPhpIniEntry */
|
|
1572
1661
|
setPhpIniEntry(e, r) {
|
|
1573
|
-
return
|
|
1662
|
+
return p.get(this).php.setPhpIniEntry(e, r);
|
|
1574
1663
|
}
|
|
1575
1664
|
/** @inheritDoc @php-wasm/web!WebPHP.mkdir */
|
|
1576
1665
|
mkdir(e) {
|
|
1577
|
-
return
|
|
1666
|
+
return p.get(this).php.mkdir(e);
|
|
1578
1667
|
}
|
|
1579
1668
|
/** @inheritDoc @php-wasm/web!WebPHP.mkdirTree */
|
|
1580
1669
|
mkdirTree(e) {
|
|
1581
|
-
return
|
|
1670
|
+
return p.get(this).php.mkdirTree(e);
|
|
1582
1671
|
}
|
|
1583
1672
|
/** @inheritDoc @php-wasm/web!WebPHP.readFileAsText */
|
|
1584
1673
|
readFileAsText(e) {
|
|
1585
|
-
return
|
|
1674
|
+
return p.get(this).php.readFileAsText(e);
|
|
1586
1675
|
}
|
|
1587
1676
|
/** @inheritDoc @php-wasm/web!WebPHP.readFileAsBuffer */
|
|
1588
1677
|
readFileAsBuffer(e) {
|
|
1589
|
-
return
|
|
1678
|
+
return p.get(this).php.readFileAsBuffer(e);
|
|
1590
1679
|
}
|
|
1591
1680
|
/** @inheritDoc @php-wasm/web!WebPHP.writeFile */
|
|
1592
1681
|
writeFile(e, r) {
|
|
1593
|
-
return
|
|
1682
|
+
return p.get(this).php.writeFile(e, r);
|
|
1594
1683
|
}
|
|
1595
1684
|
/** @inheritDoc @php-wasm/web!WebPHP.unlink */
|
|
1596
1685
|
unlink(e) {
|
|
1597
|
-
return
|
|
1686
|
+
return p.get(this).php.unlink(e);
|
|
1598
1687
|
}
|
|
1599
1688
|
/** @inheritDoc @php-wasm/web!WebPHP.listFiles */
|
|
1600
1689
|
listFiles(e, r) {
|
|
1601
|
-
return
|
|
1690
|
+
return p.get(this).php.listFiles(e, r);
|
|
1602
1691
|
}
|
|
1603
1692
|
/** @inheritDoc @php-wasm/web!WebPHP.isDir */
|
|
1604
1693
|
isDir(e) {
|
|
1605
|
-
return
|
|
1694
|
+
return p.get(this).php.isDir(e);
|
|
1606
1695
|
}
|
|
1607
1696
|
/** @inheritDoc @php-wasm/web!WebPHP.fileExists */
|
|
1608
1697
|
fileExists(e) {
|
|
1609
|
-
return
|
|
1698
|
+
return p.get(this).php.fileExists(e);
|
|
1610
1699
|
}
|
|
1611
1700
|
/** @inheritDoc @php-wasm/web!WebPHP.onMessage */
|
|
1612
1701
|
onMessage(e) {
|
|
1613
|
-
|
|
1702
|
+
p.get(this).php.onMessage(e);
|
|
1703
|
+
}
|
|
1704
|
+
/** @inheritDoc @php-wasm/web!WebPHP.defineConstant */
|
|
1705
|
+
defineConstant(e, r) {
|
|
1706
|
+
p.get(this).php.defineConstant(e, r);
|
|
1707
|
+
}
|
|
1708
|
+
/** @inheritDoc @php-wasm/web!WebPHP.addEventListener */
|
|
1709
|
+
addEventListener(e, r) {
|
|
1710
|
+
p.get(this).php.addEventListener(e, r);
|
|
1711
|
+
}
|
|
1712
|
+
/** @inheritDoc @php-wasm/web!WebPHP.removeEventListener */
|
|
1713
|
+
removeEventListener(e, r) {
|
|
1714
|
+
p.get(this).php.removeEventListener(e, r);
|
|
1614
1715
|
}
|
|
1615
1716
|
}
|
|
1616
|
-
function
|
|
1717
|
+
function Gt(t, e) {
|
|
1617
1718
|
return {
|
|
1618
1719
|
type: "response",
|
|
1619
1720
|
requestId: t,
|
|
1620
1721
|
response: e
|
|
1621
1722
|
};
|
|
1622
1723
|
}
|
|
1623
|
-
async function
|
|
1724
|
+
async function Zt(t, e, r) {
|
|
1624
1725
|
const n = navigator.serviceWorker;
|
|
1625
1726
|
if (!n)
|
|
1626
1727
|
throw new Error("Service workers are not supported in this browser.");
|
|
@@ -1630,48 +1731,48 @@ async function Ze(t, e, r) {
|
|
|
1630
1731
|
updateViaCache: "none"
|
|
1631
1732
|
})).update(), navigator.serviceWorker.addEventListener(
|
|
1632
1733
|
"message",
|
|
1633
|
-
async function(
|
|
1634
|
-
if (console.debug("[window][sw] Message from ServiceWorker",
|
|
1734
|
+
async function(i) {
|
|
1735
|
+
if (console.debug("[window][sw] Message from ServiceWorker", i), e && i.data.scope !== e)
|
|
1635
1736
|
return;
|
|
1636
|
-
const
|
|
1637
|
-
|
|
1737
|
+
const a = i.data.args || [], u = i.data.method, l = await t[u](...a);
|
|
1738
|
+
i.source.postMessage(Gt(i.data.requestId, l));
|
|
1638
1739
|
}
|
|
1639
1740
|
), n.startMessages();
|
|
1640
1741
|
}
|
|
1641
|
-
async function
|
|
1642
|
-
t =
|
|
1742
|
+
async function er(t, e = {}) {
|
|
1743
|
+
t = Vt(t, e);
|
|
1643
1744
|
const r = new Worker(t, { type: "module" });
|
|
1644
1745
|
return new Promise((n, s) => {
|
|
1645
|
-
r.onerror = (
|
|
1646
|
-
const
|
|
1647
|
-
`WebWorker failed to load at ${t}. ${
|
|
1746
|
+
r.onerror = (i) => {
|
|
1747
|
+
const a = new Error(
|
|
1748
|
+
`WebWorker failed to load at ${t}. ${i.message ? `Original error: ${i.message}` : ""}`
|
|
1648
1749
|
);
|
|
1649
|
-
|
|
1750
|
+
a.filename = i.filename, s(a);
|
|
1650
1751
|
};
|
|
1651
|
-
function i
|
|
1652
|
-
|
|
1752
|
+
function o(i) {
|
|
1753
|
+
i.data === "worker-script-started" && (n(r), r.removeEventListener("message", o));
|
|
1653
1754
|
}
|
|
1654
|
-
r.addEventListener("message",
|
|
1755
|
+
r.addEventListener("message", o);
|
|
1655
1756
|
});
|
|
1656
1757
|
}
|
|
1657
|
-
function
|
|
1758
|
+
function Vt(t, e) {
|
|
1658
1759
|
if (!Object.entries(e).length)
|
|
1659
1760
|
return t + "";
|
|
1660
1761
|
const r = new URL(t);
|
|
1661
1762
|
for (const [n, s] of Object.entries(e))
|
|
1662
1763
|
if (Array.isArray(s))
|
|
1663
|
-
for (const
|
|
1664
|
-
r.searchParams.append(n,
|
|
1764
|
+
for (const o of s)
|
|
1765
|
+
r.searchParams.append(n, o);
|
|
1665
1766
|
else
|
|
1666
1767
|
r.searchParams.set(n, s);
|
|
1667
1768
|
return r.toString();
|
|
1668
1769
|
}
|
|
1669
1770
|
export {
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1771
|
+
we as WebPHP,
|
|
1772
|
+
Xt as WebPHPEndpoint,
|
|
1773
|
+
Jt as consumeAPI,
|
|
1774
|
+
Kt as exposeAPI,
|
|
1775
|
+
jt as getPHPLoaderModule,
|
|
1776
|
+
Zt as registerServiceWorker,
|
|
1777
|
+
er as spawnPHPWorkerThread
|
|
1677
1778
|
};
|