diff --git a/src/library.js b/src/library.js index da8fa46a669a8..7048ae8e0303d 100644 --- a/src/library.js +++ b/src/library.js @@ -471,17 +471,9 @@ LibraryManager.library = { var oldHeapSize = buffer.byteLength; #endif try { -#if WASM // round size grow request up to wasm page size (fixed 64KB per spec) wasmMemory.grow((size - buffer.byteLength + 65535) >>> 16); // .grow() takes a delta compared to the previous size updateGlobalBufferAndViews(wasmMemory.buffer); -#else // asm.js: - var newBuffer = new ArrayBuffer(size); - if (newBuffer.byteLength != size) return /*undefined, allocation did not succeed*/; - new Int8Array(newBuffer).set(/**@type{!Int8Array}*/(HEAP8)); - _emscripten_replace_memory(newBuffer); - updateGlobalBufferAndViews(newBuffer); -#endif #if MEMORYPROFILER if (typeof emscriptenMemoryProfiler !== 'undefined') { emscriptenMemoryProfiler.onMemoryResize(oldHeapSize, buffer.byteLength); @@ -949,7 +941,6 @@ LibraryManager.library = { } var result = lib.module[modSymbol]; -#if WASM // Attempt to get the real "unwrapped" symbol so we have more chance of // getting wasm function which can be added to a table. if (isMainModule) { @@ -958,11 +949,10 @@ LibraryManager.library = { result = lib.module["asm"][asmSymbol]; } } -#endif if (typeof result !== 'function') return result; -#if WASM && EMULATE_FUNCTION_POINTER_CASTS +#if EMULATE_FUNCTION_POINTER_CASTS // for wasm with emulated function pointers, the i64 ABI is used for all // function calls, so we can't just call addFunction on something JS // can call (which does not use that ABI), as the function pointer would @@ -980,16 +970,10 @@ LibraryManager.library = { return result; #else // WASM && EMULATE_FUNCTION_POINTER_CASTS -#if WASM // Insert the function into the wasm table. Since we know the function // comes directly from the loaded wasm module we can insert it directly // into the table, avoiding any JS interaction. return addFunctionWasm(result); -#else - // convert the exported function into a function pointer using our generic - // JS mechanism. - return addFunction(result); -#endif // WASM #endif // WASM && EMULATE_FUNCTION_POINTER_CASTS }, diff --git a/src/library_browser.js b/src/library_browser.js index 4dce3af830ffd..0acb22c16506a 100644 --- a/src/library_browser.js +++ b/src/library_browser.js @@ -234,7 +234,6 @@ var LibraryBrowser = { }; Module['preloadPlugins'].push(audioPlugin); -#if WASM #if MAIN_MODULE var wasmPlugin = {}; wasmPlugin['asyncWasmLoadPromise'] = new Promise( @@ -261,7 +260,6 @@ var LibraryBrowser = { }; Module['preloadPlugins'].push(wasmPlugin); #endif // MAIN_MODULE -#endif // WASM // Canvas event setup diff --git a/src/library_emmalloc.js b/src/library_emmalloc.js index 58b10cba370e6..6dbf137a30784 100644 --- a/src/library_emmalloc.js +++ b/src/library_emmalloc.js @@ -6,24 +6,19 @@ mergeInto(LibraryManager.library, { emmalloc_unclaimed_heap_memory: function() { - var dynamicTop = _sbrk(); + var dynamicTop = _sbrk(); #if ALLOW_MEMORY_GROWTH -#if WASM #if MAXIMUM_MEMORY != -1 - // Using MAXIMUM_MEMORY to constrain max heap size. - return {{{ MAXIMUM_MEMORY }}} - dynamicTop; + // Using MAXIMUM_MEMORY to constrain max heap size. + return {{{ MAXIMUM_MEMORY }}} - dynamicTop; #else - // Not using a Wasm memory bound. - return 2*1024*1024*1024 - 65536 - dynamicTop; + // Not using a Wasm memory bound. + return 2*1024*1024*1024 - 65536 - dynamicTop; #endif #else - // asm.js: - return 2*1024*1024*1024 - 16777216 - dynamicTop; -#endif -#else - // ALLOW_MEMORY_GROWTH is disabled, the current heap size - // is all we got. - return HEAPU8.length - dynamicTop; + // ALLOW_MEMORY_GROWTH is disabled, the current heap size + // is all we got. + return HEAPU8.length - dynamicTop; #endif } }); diff --git a/src/library_html5.js b/src/library_html5.js index 77594bd292f6a..5654478de35f2 100644 --- a/src/library_html5.js +++ b/src/library_html5.js @@ -2728,15 +2728,10 @@ var LibraryJSEvents = { var t = performance.now(); var n = t + msecs; if ({{{ makeDynCall('idi', 'cb') }}}(t, userData)) { - setTimeout(tick, -#if WASM - // Save a little bit of code space: modern browsers should treat negative setTimeout as timeout of 0 (https://stackoverflow.com/questions/8430966/is-calling-settimeout-with-a-negative-delay-ok) - t - performance.now() -#else - // For old browsers, cap the timeout to zero. - Math.max(0, t - performance.now()) -#endif - ); + // Save a little bit of code space: modern browsers should treat + // negative setTimeout as timeout of 0 + // (https://stackoverflow.com/questions/8430966/is-calling-settimeout-with-a-negative-delay-ok) + setTimeout(tick, t - performance.now()); } } return setTimeout(tick, 0); diff --git a/src/library_pthread.js b/src/library_pthread.js index 0d6e82b7d2de8..d89e9f3faef64 100644 --- a/src/library_pthread.js +++ b/src/library_pthread.js @@ -380,7 +380,7 @@ var LibraryPThread = { } #endif -#if ASSERTIONS && WASM +#if ASSERTIONS assert(wasmMemory instanceof WebAssembly.Memory, 'WebAssembly memory should have been loaded by now!'); assert(wasmModule instanceof WebAssembly.Module, 'WebAssembly Module should have been loaded by now!'); #endif @@ -394,7 +394,6 @@ var LibraryPThread = { // object in Module['mainScriptUrlOrBlob'], or a URL to it, so that pthread Workers can // independently load up the same main application file. 'urlOrBlob': Module['mainScriptUrlOrBlob'] || _scriptDir, -#if WASM #if WASM2JS // the polyfill WebAssembly.Memory instance has function properties, // which will fail in postMessage, so just send a custom object with the @@ -410,10 +409,6 @@ var LibraryPThread = { #if USE_OFFSET_CONVERTER 'wasmOffsetConverter': wasmOffsetConverter, #endif -#else - 'buffer': HEAPU8.buffer, - 'asmJsUrlOrBlob': Module["asmJsUrlOrBlob"], -#endif #if !MINIMAL_RUNTIME 'DYNAMIC_BASE': DYNAMIC_BASE #endif diff --git a/src/postamble_minimal.js b/src/postamble_minimal.js index 200a9372584e2..77e5ffbc4b85d 100644 --- a/src/postamble_minimal.js +++ b/src/postamble_minimal.js @@ -79,8 +79,6 @@ function initRuntime(asm) { {{{ getQuoted('ATINITS') }}} } -#if WASM - // Initialize wasm (asynchronous) var imports = { @@ -94,11 +92,11 @@ var imports = { // In non-fastcomp non-asm.js builds, grab wasm exports to outer scope // for emscripten_get_exported_function() to be able to access them. -#if LibraryManager.has('library_exports.js') && WASM +#if LibraryManager.has('library_exports.js') var asm; #endif -#if USE_PTHREADS && WASM +#if USE_PTHREADS var wasmModule; #if PTHREAD_POOL_SIZE function loadWasmModuleToWorkers() { @@ -151,7 +149,7 @@ WebAssembly.instantiate(Module['wasm'], imports).then(function(output) { wasmModule = output.module || Module['wasm']; #endif -#if !(LibraryManager.has('library_exports.js') && WASM) && !EMBIND +#if !LibraryManager.has('library_exports.js') && !EMBIND // If not using the emscripten_get_exported_function() API or embind, keep the 'asm' // exports variable in local scope to this instantiate function to save code size. // (otherwise access it without to export it to outer scope) @@ -234,22 +232,5 @@ WebAssembly.instantiate(Module['wasm'], imports).then(function(output) { #endif // ASSERTIONS || WASM == 2 ; -#else - -// Initialize asm.js (synchronous) -initRuntime(asm); - -#if USE_PTHREADS && PTHREAD_POOL_SIZE -if (!ENVIRONMENT_IS_PTHREAD) loadWasmModuleToWorkers(); -#if !PTHREAD_POOL_DELAY_LOAD -else -#endif - ready(); -#else -ready(); -#endif - -#endif - {{GLOBAL_VARS}} diff --git a/src/preamble.js b/src/preamble.js index 298779eb7a288..cdfa2eed66a3c 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -393,10 +393,6 @@ var TOTAL_STACK = {{{ TOTAL_STACK }}}; #if ASSERTIONS if (Module['TOTAL_STACK']) assert(TOTAL_STACK === Module['TOTAL_STACK'], 'the stack size can no longer be determined at runtime') #endif -#if MAIN_MODULE && !WASM -// JS side modules use this value to decide their stack size. -Module['TOTAL_STACK'] = TOTAL_STACK; -#endif {{{ makeModuleReceiveWithVar('INITIAL_INITIAL_MEMORY', 'INITIAL_MEMORY', INITIAL_MEMORY) }}} @@ -429,8 +425,6 @@ if (typeof SharedArrayBuffer === 'undefined' || typeof Atomics === 'undefined') #endif #endif -#include "runtime_sab_polyfill.js" - #if STANDALONE_WASM #if ASSERTIONS // In standalone mode, the wasm creates the memory, and the user can't provide it. @@ -664,7 +658,7 @@ function removeRunDependency(id) { Module["preloadedImages"] = {}; // maps url to image data Module["preloadedAudios"] = {}; // maps url to audio data -#if WASM && MAIN_MODULE +#if MAIN_MODULE Module["preloadedWasm"] = {}; // maps url to wasm instance exports #endif @@ -692,14 +686,10 @@ function abort(what) { what = output; #endif // ASSERTIONS -#if WASM // Use a wasm runtime error, because a JS error might be seen as a foreign // exception, which means we'd run destructors on it. We need the error to // simply make the program stop. var e = new WebAssembly.RuntimeError(what); -#else - var e = what; -#endif #if MODULARIZE readyPromiseReject(e); @@ -732,7 +722,6 @@ addOnPreRun(function() { } } // if we can load dynamic libraries synchronously, do so, otherwise, preload -#if WASM if (Module['dynamicLibraries'] && Module['dynamicLibraries'].length > 0 && !readBinary) { // we can't read binary data synchronously, so preload addRunDependency('preload_dynamicLibraries'); @@ -744,7 +733,6 @@ addOnPreRun(function() { }); return; } -#endif loadDynamicLibraries(Module['dynamicLibraries']); }); @@ -805,7 +793,6 @@ function createExportWrapper(name, fixedasm) { } #endif -#if WASM var wasmBinaryFile = '{{{ WASM_BINARY_FILE }}}'; if (!isDataURI(wasmBinaryFile)) { wasmBinaryFile = locateFile(wasmBinaryFile); @@ -1132,7 +1119,6 @@ function createWasm() { return Module['asm']; // exports were assigned here #endif } -#endif // Globals used by JS i64 conversions var tempDouble; diff --git a/src/preamble_minimal.js b/src/preamble_minimal.js index 21daca0864fb4..cecd22aae39f3 100644 --- a/src/preamble_minimal.js +++ b/src/preamble_minimal.js @@ -54,7 +54,6 @@ Module['wasm'] = base64Decode('{{{ getQuoted("WASM_BINARY_DATA") }}}'); #include "runtime_functions.js" #include "runtime_strings.js" -#include "runtime_sab_polyfill.js" #if USE_PTHREADS var STATIC_BASE = {{{ GLOBAL_BASE }}}; @@ -72,8 +71,6 @@ var GLOBAL_BASE = {{{ GLOBAL_BASE }}}, STACK_MAX = {{{ getQuoted('STACK_MAX') }}} ; -#if WASM - #if ALLOW_MEMORY_GROWTH && MAXIMUM_MEMORY != -1 var wasmMaximumMemory = {{{ MAXIMUM_MEMORY >>> 16 }}}; #else @@ -101,20 +98,6 @@ assert(buffer instanceof SharedArrayBuffer, 'requested a shared WebAssembly.Memo #include "runtime_init_table.js" -#else - -#if USE_PTHREADS -var buffer = new SharedArrayBuffer({{{ INITIAL_MEMORY }}}); -#else -var buffer = new ArrayBuffer({{{ INITIAL_MEMORY }}}); -#endif - -#if USE_PTHREADS -} -#endif - -#endif - #if ASSERTIONS var WASM_PAGE_SIZE = {{{ WASM_PAGE_SIZE }}}; #if USE_PTHREADS diff --git a/src/runtime_functions.js b/src/runtime_functions.js index 5b331f3f4f3cf..8ab0e501aab75 100644 --- a/src/runtime_functions.js +++ b/src/runtime_functions.js @@ -4,7 +4,6 @@ * SPDX-License-Identifier: MIT */ -#if WASM // Wraps a JS function as a wasm function with a given signature. function convertJsFunctionToWasm(func, sig) { #if WASM2JS @@ -170,7 +169,6 @@ function removeFunctionWasm(index) { functionsInTableMap.delete(wasmTable.get(index)); freeTableIndexes.push(index); } -#endif // 'sig' parameter is required for the llvm backend but only when func is not // already a WebAssembly function. diff --git a/src/runtime_init_memory.js b/src/runtime_init_memory.js index 7c5a9e925ea39..8b63e6b99020d 100644 --- a/src/runtime_init_memory.js +++ b/src/runtime_init_memory.js @@ -12,7 +12,6 @@ if (ENVIRONMENT_IS_PTHREAD) { buffer = Module['buffer']; } else { #endif // USE_PTHREADS -#if WASM #if expectToReceiveOnModule('wasmMemory') if (Module['wasmMemory']) { @@ -47,34 +46,18 @@ if (ENVIRONMENT_IS_PTHREAD) { #endif } -#else // WASM - - if (Module['buffer']) { - buffer = Module['buffer']; - } -#ifdef USE_PTHREADS - else if (typeof SharedArrayBuffer !== 'undefined') { - buffer = new SharedArrayBuffer(INITIAL_INITIAL_MEMORY); - } -#endif - else { - buffer = new ArrayBuffer(INITIAL_INITIAL_MEMORY); - } -#endif // WASM #if USE_PTHREADS } #endif -#if WASM if (wasmMemory) { buffer = wasmMemory.buffer; } -#endif // If the user provides an incorrect length, just use that length instead rather than providing the user to // specifically provide the memory length with Module['INITIAL_MEMORY']. INITIAL_INITIAL_MEMORY = buffer.byteLength; -#ifdef ASSERTIONS && WASM +#ifdef ASSERTIONS assert(INITIAL_INITIAL_MEMORY % WASM_PAGE_SIZE === 0); #ifdef ALLOW_MEMORY_GROWTH && MAXIMUM_MEMORY != -1 assert({{{ WASM_PAGE_SIZE }}} % WASM_PAGE_SIZE === 0); diff --git a/src/runtime_sab_polyfill.js b/src/runtime_sab_polyfill.js deleted file mode 100644 index 3d1912da3b17e..0000000000000 --- a/src/runtime_sab_polyfill.js +++ /dev/null @@ -1,55 +0,0 @@ -/** - * @license - * Copyright 2019 The Emscripten Authors - * SPDX-License-Identifier: MIT - */ - -#if USE_PTHREADS && !WASM -if (typeof SharedArrayBuffer !== 'undefined') { - // Currently SharedArrayBuffer does not have a slice() operation, so polyfill it in. - // Adapted from https://github.com/ttaubert/node-arraybuffer-slice, (c) 2014 Tim Taubert - // arraybuffer-slice may be freely distributed under the MIT license. - (function (undefined) { - "use strict"; - function clamp(val, length) { - val = (val|0) || 0; - if (val < 0) return Math.max(val + length, 0); - return Math.min(val, length); - } - if (typeof SharedArrayBuffer !== 'undefined' && !SharedArrayBuffer.prototype.slice) { - SharedArrayBuffer.prototype.slice = function (from, to) { - var length = this.byteLength; - var begin = clamp(from, length); - var end = length; - if (to !== undefined) end = clamp(to, length); - if (begin > end) return new ArrayBuffer(0); - var num = end - begin; - var target = new ArrayBuffer(num); - var targetArray = new Uint8Array(target); - var sourceArray = new Uint8Array(this, begin, num); - targetArray.set(sourceArray); - return target; - }; - } - })(); -} - -if (typeof Atomics === 'undefined') { - // Polyfill singlethreaded atomics ops from http://lars-t-hansen.github.io/ecmascript_sharedmem/shmem.html#Atomics.add - // No thread-safety needed since we don't have multithreading support. - Atomics = {}; - Atomics['add'] = function(t, i, v) { var w = t[i]; t[i] += v; return w; } - Atomics['and'] = function(t, i, v) { var w = t[i]; t[i] &= v; return w; } - Atomics['compareExchange'] = function(t, i, e, r) { var w = t[i]; if (w == e) t[i] = r; return w; } - Atomics['exchange'] = function(t, i, v) { var w = t[i]; t[i] = v; return w; } - Atomics['wait'] = function(t, i, v, o) { if (t[i] != v) return 'not-equal'; else return 'timed-out'; } - Atomics['notify'] = function(t, i, c) { return 0; } - Atomics['wakeOrRequeue'] = function(t, i1, c, i2, v) { return 0; } - Atomics['isLockFree'] = function(s) { return true; } - Atomics['load'] = function(t, i) { return t[i]; } - Atomics['or'] = function(t, i, v) { var w = t[i]; t[i] |= v; return w; } - Atomics['store'] = function(t, i, v) { t[i] = v; return v; } - Atomics['sub'] = function(t, i, v) { var w = t[i]; t[i] -= v; return w; } - Atomics['xor'] = function(t, i, v) { var w = t[i]; t[i] ^= v; return w; } -} -#endif diff --git a/src/shell_minimal.js b/src/shell_minimal.js index 3786dd107a3f4..8e23c274506de 100644 --- a/src/shell_minimal.js +++ b/src/shell_minimal.js @@ -57,7 +57,6 @@ if (ENVIRONMENT_IS_NODE && ENVIRONMENT_IS_SHELL) { if (ENVIRONMENT_IS_NODE) { var fs = require('fs'); -#if WASM #if WASM == 2 if (typeof WebAssembly !== 'undefined') Module['wasm'] = fs.readFileSync(__dirname + '/{{{ TARGET_BASENAME }}}.wasm'); else eval(fs.readFileSync(__dirname + '/{{{ TARGET_BASENAME }}}.wasm.js')+''); @@ -66,8 +65,6 @@ if (ENVIRONMENT_IS_NODE) { Module['wasm'] = fs.readFileSync(__dirname + '/{{{ TARGET_BASENAME }}}.wasm'); #endif #endif -#else -#endif #if MEM_INIT_METHOD == 1 && !MEM_INIT_IN_WASM Module['mem'] = fs.readFileSync(__dirname + '/{{{ TARGET_BASENAME }}}.mem'); #endif @@ -76,7 +73,6 @@ if (ENVIRONMENT_IS_NODE) { #if ENVIRONMENT_MAY_BE_SHELL && ((WASM == 1 && (!WASM2JS || !MEM_INIT_IN_WASM)) || WASM == 2) if (ENVIRONMENT_IS_SHELL) { -#if WASM #if WASM == 2 if (typeof WebAssembly !== 'undefined') Module['wasm'] = read('{{{ TARGET_BASENAME }}}.wasm', 'binary'); else eval(read('{{{ TARGET_BASENAME }}}.wasm.js')+''); @@ -85,9 +81,6 @@ if (ENVIRONMENT_IS_SHELL) { Module['wasm'] = read('{{{ TARGET_BASENAME }}}.wasm', 'binary'); #endif #endif -#else - eval(read('{{{ TARGET_BASENAME }}}.asm.js')+''); -#endif #if MEM_INIT_METHOD == 1 && !MEM_INIT_IN_WASM Module['mem'] = read('{{{ TARGET_BASENAME }}}.mem', 'binary'); #endif diff --git a/src/support.js b/src/support.js index 3a167d7709ed0..69fd8da46c433 100644 --- a/src/support.js +++ b/src/support.js @@ -121,7 +121,6 @@ function loadDynamicLibrary(lib, flags) { // libData <- libFile function loadLibData(libFile) { -#if WASM // for wasm, we can use fetch for async, but for fs mode we can only imitate it if (flags.fs) { var libData = flags.fs.readFile(libFile, {encoding: 'binary'}); @@ -136,44 +135,11 @@ function loadDynamicLibrary(lib, flags) { } // load the binary synchronously return readBinary(libFile); -#else - // for js we only imitate async for both native & fs modes. - var libData; - if (flags.fs) { - libData = flags.fs.readFile(libFile, {encoding: 'utf8'}); - } else { - libData = read_(libFile); - } - return flags.loadAsync ? Promise.resolve(libData) : libData; -#endif } // libModule <- libData function createLibModule(libData) { -#if WASM return loadWebAssemblyModule(libData, flags) -#else - var libModule = /**@type{function(...)}*/(eval(libData))( - alignFunctionTables(), - Module - ); - // load dynamic libraries that this js lib depends on - // (wasm loads needed libraries _before_ lib in its own codepath) - if (libModule.dynamicLibraries) { - if (flags.loadAsync) { - return Promise.all(libModule.dynamicLibraries.map(function(dynNeeded) { - return loadDynamicLibrary(dynNeeded, flags); - })).then(function() { - return libModule; - }); - } - - libModule.dynamicLibraries.forEach(function(dynNeeded) { - loadDynamicLibrary(dynNeeded, flags); - }); - } - return libModule; -#endif } // libModule <- lib @@ -244,7 +210,6 @@ function loadDynamicLibrary(lib, flags) { return handle; } -#if WASM // Applies relocations to exported things. function relocateExports(exports, memoryBase, tableBase, moduleLocal) { var relocated = {}; @@ -544,7 +509,6 @@ function loadWebAssemblyModule(binary, flags) { } Module['loadWebAssemblyModule'] = loadWebAssemblyModule; -#endif // WASM #endif // RELOCATABLE #include "runtime_functions.js" diff --git a/src/worker.js b/src/worker.js index 61b53a1e48871..c589f28612dec 100644 --- a/src/worker.js +++ b/src/worker.js @@ -40,7 +40,7 @@ var out = function() { var err = threadPrintErr; this.alert = threadAlert; -#if WASM && !MINIMAL_RUNTIME +#if !MINIMAL_RUNTIME Module['instantiateWasm'] = function(info, receiveInstance) { // Instantiate from the module posted from the main thread. // We can just use sync instantiation in the worker. @@ -77,7 +77,6 @@ this.onmessage = function(e) { Module['DYNAMIC_BASE'] = e.data.DYNAMIC_BASE; #endif -#if WASM // Module and memory were sent from main thread #if MINIMAL_RUNTIME #if MODULARIZE @@ -99,10 +98,6 @@ this.onmessage = function(e) { #endif {{{ makeAsmImportsAccessInPthread('buffer') }}} = {{{ makeAsmImportsAccessInPthread('wasmMemory') }}}.buffer; -#else // asm.js: - {{{ makeAsmImportsAccessInPthread('buffer') }}} = e.data.buffer; - -#endif // WASM #if !MINIMAL_RUNTIME || MODULARIZE {{{ makeAsmImportsAccessInPthread('ENVIRONMENT_IS_PTHREAD') }}} = true; @@ -137,7 +132,7 @@ this.onmessage = function(e) { #endif #endif -#if !MODULARIZE && (!MINIMAL_RUNTIME || !WASM) +#if !MODULARIZE && !MINIMAL_RUNTIME // MINIMAL_RUNTIME always compiled Wasm (&Wasm2JS) asynchronously, even in pthreads. But // regular runtime and asm.js are loaded synchronously, so in those cases // we are now loaded, and can post back to main thread.