| |
| |
| |
| |
| |
|
|
| |
| #if !IMPORTED_MEMORY |
| #error "this file should not be included when IMPORTED_MEMORY is set" |
| #endif |
|
|
| |
|
|
| function initMemory() { |
| #if WASM_ESM_INTEGRATION && PTHREADS |
| if (ENVIRONMENT_IS_PTHREAD) { |
| wasmMemory = globalThis.wasmMemory; |
| assert(wasmMemory); |
| updateMemoryViews(); |
| } |
| #endif |
|
|
| {{{ runIfWorkerThread('return') }}} |
|
|
| #if expectToReceiveOnModule('wasmMemory') |
| if (Module['wasmMemory']) { |
| wasmMemory = Module['wasmMemory']; |
| } else |
| #endif |
| { |
| var INITIAL_MEMORY = {{{ makeModuleReceiveExpr('INITIAL_MEMORY', INITIAL_MEMORY) }}}; |
|
|
| #if ASSERTIONS |
| assert(INITIAL_MEMORY >= {{{ STACK_SIZE }}}, `INITIAL_MEMORY should be larger than STACK_SIZE, was ${INITIAL_MEMORY}! (STACK_SIZE={{{ STACK_SIZE }}})`); |
| #endif |
| |
| #if MINIMAL_RUNTIME && WASM_WORKERS |
| wasmMemory = Module['mem'] || new WebAssembly.Memory({ |
| #else |
| wasmMemory = new WebAssembly.Memory({ |
| #endif |
| 'initial': {{{ toIndexType(`INITIAL_MEMORY / ${WASM_PAGE_SIZE}`) }}}, |
| #if ALLOW_MEMORY_GROWTH |
| |
| |
| |
| |
| |
| 'maximum': {{{ toIndexType(MAXIMUM_MEMORY / WASM_PAGE_SIZE) }}}, |
| #else |
| 'maximum': {{{ toIndexType(`INITIAL_MEMORY / ${WASM_PAGE_SIZE}`) }}}, |
| #endif |
| #if SHARED_MEMORY |
| 'shared': true, |
| #endif |
| #if MEMORY64 == 1 |
| 'address': 'i64', |
| #endif |
| }); |
| } |
|
|
| updateMemoryViews(); |
| } |
|
|
| #if WASM_ESM_INTEGRATION || MINIMAL_RUNTIME |
| initMemory(); |
| #endif |
|
|