-
Notifications
You must be signed in to change notification settings - Fork 237
/
esm-suffix.js
62 lines (57 loc) · 2.05 KB
/
esm-suffix.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* Emscripten resolves `localhost` to a random IP address. Let's
* make it always resolve to 127.0.0.1.
*/
DNS.address_map.addrs.localhost = '127.0.0.1';
/**
* Debugging Asyncify errors is tricky because the stack trace is lost when the
* error is thrown. This code saves the stack trace in a global variable
* so that it can be inspected later.
*/
PHPLoader.debug = 'debug' in PHPLoader ? PHPLoader.debug : true;
if (PHPLoader.debug && typeof Asyncify !== "undefined") {
const originalHandleSleep = Asyncify.handleSleep;
Asyncify.handleSleep = function (startAsync) {
if (!ABORT) {
Module["lastAsyncifyStackSource"] = new Error();
}
return originalHandleSleep(startAsync);
}
}
/**
* Data dependencies call removeRunDependency() when they are loaded.
* The synchronous call stack then continues to run. If an error occurs
* in PHP initialization, e.g. Out Of Memory error, it will not be
* caught by any try/catch. This override propagates the failure to
* PHPLoader.onAbort() so that it can be handled.
*/
const originalRemoveRunDependency = PHPLoader['removeRunDependency'];
PHPLoader['removeRunDependency'] = function (...args) {
try {
originalRemoveRunDependency(...args);
} catch (e) {
PHPLoader['onAbort'](e);
}
}
/**
* Other exports live in the Dockerfile in:
*
* * EXTRA_EXPORTED_RUNTIME_METHODS
* * EXPORTED_FUNCTIONS
*
* These exports, however, live in here because:
*
* * Listing them in EXTRA_EXPORTED_RUNTIME_METHODS doesn't actually
* export them. This could be a bug in Emscripten or a consequence of
* that option being deprecated.
* * Listing them in EXPORTED_FUNCTIONS works, but they are overridden
* on every `BasePHP.run()` call. This is a problem because we want to
* spy on these calls in some unit tests.
*
* Therefore, we export them here.
*/
PHPLoader['malloc'] = _malloc;
PHPLoader['free'] = () => { console.warn("free isn't exported by the latest Emscripten anymore"); }//_free;
return PHPLoader;
// Close the opening bracket from esm-prefix.js:
}