-
Notifications
You must be signed in to change notification settings - Fork 3.4k
/
Copy pathruntime_shared.js
115 lines (102 loc) · 3.25 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/**
* @license
* Copyright 2024 The Emscripten Authors
* SPDX-License-Identifier: MIT
*/
#include "runtime_stack_check.js"
#include "runtime_exceptions.js"
#include "runtime_debug.js"
#include "memoryprofiler.js"
#if SAFE_HEAP
#include "runtime_safe_heap.js"
#endif
#if SHARED_MEMORY && ALLOW_MEMORY_GROWTH
#include "growableHeap.js"
#endif
#if USE_ASAN
#include "runtime_asan.js"
#endif
#if PTHREADS || WASM_WORKERS
#if !MINIMAL_RUNTIME
var wasmModuleReceived;
#endif
#if ENVIRONMENT_MAY_BE_NODE
if (ENVIRONMENT_IS_NODE && {{{ ENVIRONMENT_IS_WORKER_THREAD() }}}) {
// Create as web-worker-like an environment as we can.
var parentPort = worker_threads['parentPort'];
parentPort.on('message', (msg) => global.onmessage?.({ data: msg }));
Object.assign(globalThis, {
self: global,
postMessage: (msg) => parentPort['postMessage'](msg),
});
}
#endif // ENVIRONMENT_MAY_BE_NODE
#endif
#if PTHREADS
#include "runtime_pthread.js"
#endif
#if WASM_WORKERS
#include "wasm_worker.js"
#endif
#if LOAD_SOURCE_MAP
var wasmSourceMap;
#include "source_map_support.js"
#endif
#if USE_OFFSET_CONVERTER
var wasmOffsetConverter;
#include "wasm_offset_converter.js"
#endif
{{{
// Helper function to export a heap symbol on the module object,
// if requested.
const shouldExportHeap = (x) => {
let shouldExport = false;
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;
}
return shouldExport;
}
const maybeExportHeap = (x) => {
if (shouldExportHeap(x) && MODULARIZE != 'instance') {
return `Module['${x}'] = `;
}
return '';
};
}}}
function updateMemoryViews() {
var b = wasmMemory.buffer;
{{{ 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 SUPPORT_BIG_ENDIAN
{{{ maybeExportHeap('HEAP_DATA_VIEW') }}} HEAP_DATA_VIEW = new DataView(b);
LE_HEAP_UPDATE();
#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