Skip to content

Commit ebcb003

Browse files
authored
Use runtime_init_memory.js in MINIMAL_RUNTIME. NFC (#22726)
This code was essentially duplicated.
1 parent 04313cb commit ebcb003

File tree

2 files changed

+5
-46
lines changed

2 files changed

+5
-46
lines changed

src/preamble_minimal.js

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -61,52 +61,7 @@ var HEAP8, HEAP16, HEAP32, HEAPU8, HEAPU16, HEAPU32, HEAPF32, HEAPF64,
6161
#endif
6262

6363
#if IMPORTED_MEMORY
64-
// This code is largely a duplcate of src/runtime_init_memory.js
65-
// TODO(sbc): merge these two.
66-
#if PTHREADS
67-
if (!ENVIRONMENT_IS_PTHREAD) {
68-
#endif
69-
wasmMemory =
70-
#if WASM_WORKERS
71-
Module['mem'] ||
72-
#endif
73-
new WebAssembly.Memory({
74-
'initial': {{{ toIndexType(`${INITIAL_MEMORY} / ${WASM_PAGE_SIZE}`) }}},
75-
#if ALLOW_MEMORY_GROWTH
76-
// In theory we should not need to emit the maximum if we want "unlimited"
77-
// or 4GB of memory, but VMs error on that atm, see
78-
// https://github.com/emscripten-core/emscripten/issues/14130
79-
// And in the pthreads case we definitely need to emit a maximum. So
80-
// always emit one.
81-
'maximum': {{{ toIndexType(MAXIMUM_MEMORY / WASM_PAGE_SIZE) }}},
82-
#else
83-
'maximum': {{{ toIndexType(`${INITIAL_MEMORY} / ${WASM_PAGE_SIZE}`) }}},
84-
#endif // ALLOW_MEMORY_GROWTH
85-
#if SHARED_MEMORY
86-
'shared': true,
87-
#endif
88-
#if MEMORY64 == 1
89-
'index': 'i64',
90-
#endif
91-
});
92-
#if PTHREADS
93-
}
94-
#if MODULARIZE
95-
else {
96-
wasmMemory = Module['wasmMemory'];
97-
}
98-
#endif // MODULARIZE
99-
#endif // PTHREADS
100-
101-
#if PTHREADS
102-
if (!ENVIRONMENT_IS_PTHREAD) {
103-
#endif
104-
105-
updateMemoryViews();
106-
107-
#if PTHREADS
108-
}
109-
#endif
64+
#include "runtime_init_memory.js"
11065
#endif // IMPORTED_MEMORY
11166

11267
#include "runtime_stack_check.js"

src/runtime_init_memory.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ if (!ENVIRONMENT_IS_PTHREAD) {
2626
#if ASSERTIONS
2727
assert(INITIAL_MEMORY >= {{{STACK_SIZE}}}, 'INITIAL_MEMORY should be larger than STACK_SIZE, was ' + INITIAL_MEMORY + '! (STACK_SIZE=' + {{{STACK_SIZE}}} + ')');
2828
#endif
29+
#if MINIMAL_RUNTIME && WASM_WORKERS
30+
wasmMemory = Module['mem'] || new WebAssembly.Memory({
31+
#else
2932
wasmMemory = new WebAssembly.Memory({
33+
#endif
3034
'initial': {{{ toIndexType(`INITIAL_MEMORY / ${WASM_PAGE_SIZE}`) }}},
3135
#if ALLOW_MEMORY_GROWTH
3236
// In theory we should not need to emit the maximum if we want "unlimited"

0 commit comments

Comments
 (0)