-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
runtime_shared.js
65 lines (62 loc) · 2.3 KB
/
runtime_shared.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
63
64
65
/**
* @license
* Copyright 2024 The Emscripten Authors
* SPDX-License-Identifier: MIT
*/
{{{
// Helper function to export a heap symbol on the module object,
// if requested.
globalThis.maybeExportHeap = (x) => {
// For now, we export all heap object when not building with MINIMAL_RUNTIME
let shouldExport = !MINIMAL_RUNTIME && !STRICT;
if (!shouldExport) {
if (MODULARIZE && EXPORT_ALL) {
shouldExport = true;
} else if (AUDIO_WORKLET && (x == 'HEAPU32' || x == 'HEAPF32')) {
// Export to the AudioWorkletGlobalScope the needed variables to access
// the heap. AudioWorkletGlobalScope is unable to access global JS vars
// in the compiled main JS file.
shouldExport = true;
} else if (EXPORTED_RUNTIME_METHODS.includes(x)) {
shouldExport = true;
}
}
if (shouldExport) {
if (MODULARIZE === 'instance') {
return `__exp_${x} = `
}
return `Module['${x}'] = `;
}
return '';
};
null;
}}}
function updateMemoryViews() {
var b = wasmMemory.buffer;
#if SUPPORT_BIG_ENDIAN
{{{ maybeExportHeap('HEAP_DATA_VIEW') }}} HEAP_DATA_VIEW = new DataView(b);
#endif
{{{ maybeExportHeap('HEAP8') }}}HEAP8 = new Int8Array(b);
{{{ maybeExportHeap('HEAP16') }}}HEAP16 = new Int16Array(b);
{{{ maybeExportHeap('HEAPU8') }}}HEAPU8 = new Uint8Array(b);
{{{ maybeExportHeap('HEAPU16') }}}HEAPU16 = new Uint16Array(b);
{{{ maybeExportHeap('HEAP32') }}}HEAP32 = new Int32Array(b);
{{{ maybeExportHeap('HEAPU32') }}}HEAPU32 = new Uint32Array(b);
{{{ maybeExportHeap('HEAPF32') }}}HEAPF32 = new Float32Array(b);
{{{ maybeExportHeap('HEAPF64') }}}HEAPF64 = new Float64Array(b);
#if WASM_BIGINT
{{{ maybeExportHeap('HEAP64') }}}HEAP64 = new BigInt64Array(b);
{{{ maybeExportHeap('HEAPU64') }}}HEAPU64 = new BigUint64Array(b);
#endif
}
#if ENVIRONMENT_MAY_BE_NODE && MIN_NODE_VERSION < 160000
// The performance global was added to node in v16.0.0:
// https://nodejs.org/api/globals.html#performance
if (ENVIRONMENT_IS_NODE) {
// This is needed for emscripten_get_now and for pthreads support which
// depends on it for accurate timing.
// Use `global` rather than `globalThis` here since older versions of node
// don't have `globalThis`.
global.performance ??= require('perf_hooks').performance;
}
#endif