@@ -25,18 +25,32 @@ if (!ENVIRONMENT_IS_PTHREAD) {
2525
2626#if ASSERTIONS
2727 assert ( INITIAL_MEMORY >= { { { STACK_SIZE } } } , 'INITIAL_MEMORY should be larger than STACK_SIZE, was ' + INITIAL_MEMORY + '! (STACK_SIZE=' + { { { STACK_SIZE } } } + ')' ) ;
28+ #endif
29+ #if MEMORY64 == 1
30+ // Probe for support of bigint bounds with memory64.
31+ // TODO(sbc): Remove this once all browsers start requiring bigint here.
32+ // See https://github.com/WebAssembly/memory64/issues/68
33+ var bigintMemoryBounds = 1 ;
34+ try {
35+ /** @suppress {checkTypes} */
36+ new WebAssembly . Memory ( { 'initial' : 1n , 'index' : 'i64' } )
37+ } catch ( e ) {
38+ console . log ( e ) ;
39+ bigintMemoryBounds = 0 ;
40+ }
41+ var toMemoryBounds = ( i ) => bigintMemoryBounds ? BigInt ( i ) : i ;
2842#endif
2943 wasmMemory = new WebAssembly . Memory ( {
30- 'initial' : INITIAL_MEMORY / { { { WASM_PAGE_SIZE } } } ,
44+ 'initial' : { { { memoryBounds ( ` INITIAL_MEMORY / ${ WASM_PAGE_SIZE } ` ) } } } ,
3145#if ALLOW_MEMORY_GROWTH
3246 // In theory we should not need to emit the maximum if we want "unlimited"
3347 // or 4GB of memory, but VMs error on that atm, see
3448 // https://github.com/emscripten-core/emscripten/issues/14130
3549 // And in the pthreads case we definitely need to emit a maximum. So
3650 // always emit one.
37- 'maximum' : { { { MAXIMUM_MEMORY } } } / { { { W A S M _ P A G E _ S I Z E } } } ,
51+ 'maximum' : { { { memoryBounds ( MAXIMUM_MEMORY / WASM_PAGE_SIZE ) } } } ,
3852#else
39- 'maximum' : INITIAL_MEMORY / { { { WASM_PAGE_SIZE } } } ,
53+ 'maximum' : { { { memoryBounds ( ` INITIAL_MEMORY / ${ WASM_PAGE_SIZE } ` ) } } } ,
4054#endif // ALLOW_MEMORY_GROWTH
4155#if SHARED_MEMORY
4256 'shared' : true ,
0 commit comments