-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Expand file tree
/
Copy pathlibSystem.Native.Browser.Utils.footer.js
More file actions
66 lines (59 loc) · 2.6 KB
/
Copy pathlibSystem.Native.Browser.Utils.footer.js
File metadata and controls
66 lines (59 loc) · 2.6 KB
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
63
64
65
66
//! Licensed to the .NET Foundation under one or more agreements.
//! The .NET Foundation licenses this file to you under the MIT license.
/**
* This is root of **Emscripten library** that would become part of `dotnet.native.js`
* It implements utilities and a public JS API related to memory and runtime hosting.
*/
/* eslint-disable no-undef */
function libBrowserUtilsFactory() {
// this executes the function at link time in order to capture exports
// this is what Emscripten does for linking JS libraries
// https://emscripten.org/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.html#javascript-limits-in-library-files
// it would execute the code at link time and call .toString() on functions to move it to the final output
// this process would loose any closure references, unless they are passed to `__deps` and also explicitly given to the linker
// JS name mangling and minification also applies, see src\native\rollup.config.defines.js and `reserved` there
const exports = {};
libBrowserUtils(exports);
let commonDeps = [
"$libBrowserUtilsFn",
"$DOTNET",
"GetDotNetRuntimeContractDescriptor",
"_exit",
"abort",
"__trap",
"__stack_pointer",
"__coreclr_wasm_rtlrestorecontext_tag",
"__async_continuation",
"$readI53FromU64",
"$readI53FromI64",
"$writeI53ToI64"
];
const mergeBrowserUtils = {
$BROWSER_UTILS: {
selfInitialize: () => {
if (typeof dotnetInternals !== "undefined") {
BROWSER_UTILS.dotnetInternals = dotnetInternals;
const exports = {};
libBrowserUtilsFn(exports);
exports.dotnetInitializeModule(dotnetInternals);
}
},
},
$libBrowserUtilsFn: libBrowserUtils,
$BROWSER_UTILS__postset: "BROWSER_UTILS.selfInitialize()",
$BROWSER_UTILS__deps: commonDeps,
};
// install cross-module symbols as "_ems_" ambient symbols in Emscripten closure
// keep in sync with `reserved`+`keep_fnames` in src\native\rollup.config.defines.js
for (const exportName of Reflect.ownKeys(exports._ems_ambient_)) {
const name = String(exportName);
if (name === "dotnetInternals") continue;
if (name === "Module") continue;
const emName = "$" + name;
mergeBrowserUtils[emName] = exports._ems_ambient_[exportName];
commonDeps.push(emName);
}
autoAddDeps(mergeBrowserUtils, "$BROWSER_UTILS");
addToLibrary(mergeBrowserUtils);
}
libBrowserUtilsFactory();