@@ -25,18 +25,31 @@ 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+ new WebAssembly . Memory ( { 'initial' : 1n , 'index' : 'i64' } )
36+ } catch ( e ) {
37+ console . log ( e ) ;
38+ bigintMemoryBounds = 0 ;
39+ }
40+ var toMemoryBounds = ( i ) => bigintMemoryBounds ? BigInt ( i ) : i ;
2841#endif
2942 wasmMemory = new WebAssembly . Memory ( {
30- 'initial' : INITIAL_MEMORY / { { { WASM_PAGE_SIZE } } } ,
43+ 'initial' : { { { memoryBounds ( ` INITIAL_MEMORY / ${ WASM_PAGE_SIZE } ` ) } } } ,
3144#if ALLOW_MEMORY_GROWTH
3245 // In theory we should not need to emit the maximum if we want "unlimited"
3346 // or 4GB of memory, but VMs error on that atm, see
3447 // https://github.com/emscripten-core/emscripten/issues/14130
3548 // And in the pthreads case we definitely need to emit a maximum. So
3649 // always emit one.
37- 'maximum' : { { { MAXIMUM_MEMORY } } } / { { { W A S M _ P A G E _ S I Z E } } } ,
50+ 'maximum' : { { { memoryBounds ( MAXIMUM_MEMORY / WASM_PAGE_SIZE } } } ,
3851#else
39- 'maximum' : INITIAL_MEMORY / { { { WASM_PAGE_SIZE } } } ,
52+ 'maximum' : { { { memoryBounds ( ` INITIAL_MEMORY / ${ WASM_PAGE_SIZE } ` ) } } } ,
4053#endif // ALLOW_MEMORY_GROWTH
4154#if SHARED_MEMORY
4255 'shared' : true ,
0 commit comments