Skip to content

Commit d5ec187

Browse files
authored
Remove use of WASM setting in library JS (#12122)
This setting is always true since we removed fastcomp. See #11860
1 parent ff1e14c commit d5ec187

14 files changed

+21
-226
lines changed

src/library.js

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -471,17 +471,9 @@ LibraryManager.library = {
471471
var oldHeapSize = buffer.byteLength;
472472
#endif
473473
try {
474-
#if WASM
475474
// round size grow request up to wasm page size (fixed 64KB per spec)
476475
wasmMemory.grow((size - buffer.byteLength + 65535) >>> 16); // .grow() takes a delta compared to the previous size
477476
updateGlobalBufferAndViews(wasmMemory.buffer);
478-
#else // asm.js:
479-
var newBuffer = new ArrayBuffer(size);
480-
if (newBuffer.byteLength != size) return /*undefined, allocation did not succeed*/;
481-
new Int8Array(newBuffer).set(/**@type{!Int8Array}*/(HEAP8));
482-
_emscripten_replace_memory(newBuffer);
483-
updateGlobalBufferAndViews(newBuffer);
484-
#endif
485477
#if MEMORYPROFILER
486478
if (typeof emscriptenMemoryProfiler !== 'undefined') {
487479
emscriptenMemoryProfiler.onMemoryResize(oldHeapSize, buffer.byteLength);
@@ -949,7 +941,6 @@ LibraryManager.library = {
949941
}
950942

951943
var result = lib.module[modSymbol];
952-
#if WASM
953944
// Attempt to get the real "unwrapped" symbol so we have more chance of
954945
// getting wasm function which can be added to a table.
955946
if (isMainModule) {
@@ -958,11 +949,10 @@ LibraryManager.library = {
958949
result = lib.module["asm"][asmSymbol];
959950
}
960951
}
961-
#endif
962952
if (typeof result !== 'function')
963953
return result;
964954

965-
#if WASM && EMULATE_FUNCTION_POINTER_CASTS
955+
#if EMULATE_FUNCTION_POINTER_CASTS
966956
// for wasm with emulated function pointers, the i64 ABI is used for all
967957
// function calls, so we can't just call addFunction on something JS
968958
// can call (which does not use that ABI), as the function pointer would
@@ -980,16 +970,10 @@ LibraryManager.library = {
980970
return result;
981971
#else // WASM && EMULATE_FUNCTION_POINTER_CASTS
982972

983-
#if WASM
984973
// Insert the function into the wasm table. Since we know the function
985974
// comes directly from the loaded wasm module we can insert it directly
986975
// into the table, avoiding any JS interaction.
987976
return addFunctionWasm(result);
988-
#else
989-
// convert the exported function into a function pointer using our generic
990-
// JS mechanism.
991-
return addFunction(result);
992-
#endif // WASM
993977
#endif // WASM && EMULATE_FUNCTION_POINTER_CASTS
994978
},
995979

src/library_browser.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ var LibraryBrowser = {
234234
};
235235
Module['preloadPlugins'].push(audioPlugin);
236236

237-
#if WASM
238237
#if MAIN_MODULE
239238
var wasmPlugin = {};
240239
wasmPlugin['asyncWasmLoadPromise'] = new Promise(
@@ -261,7 +260,6 @@ var LibraryBrowser = {
261260
};
262261
Module['preloadPlugins'].push(wasmPlugin);
263262
#endif // MAIN_MODULE
264-
#endif // WASM
265263

266264
// Canvas event setup
267265

src/library_emmalloc.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,19 @@
66

77
mergeInto(LibraryManager.library, {
88
emmalloc_unclaimed_heap_memory: function() {
9-
var dynamicTop = _sbrk();
9+
var dynamicTop = _sbrk();
1010
#if ALLOW_MEMORY_GROWTH
11-
#if WASM
1211
#if MAXIMUM_MEMORY != -1
13-
// Using MAXIMUM_MEMORY to constrain max heap size.
14-
return {{{ MAXIMUM_MEMORY }}} - dynamicTop;
12+
// Using MAXIMUM_MEMORY to constrain max heap size.
13+
return {{{ MAXIMUM_MEMORY }}} - dynamicTop;
1514
#else
16-
// Not using a Wasm memory bound.
17-
return 2*1024*1024*1024 - 65536 - dynamicTop;
15+
// Not using a Wasm memory bound.
16+
return 2*1024*1024*1024 - 65536 - dynamicTop;
1817
#endif
1918
#else
20-
// asm.js:
21-
return 2*1024*1024*1024 - 16777216 - dynamicTop;
22-
#endif
23-
#else
24-
// ALLOW_MEMORY_GROWTH is disabled, the current heap size
25-
// is all we got.
26-
return HEAPU8.length - dynamicTop;
19+
// ALLOW_MEMORY_GROWTH is disabled, the current heap size
20+
// is all we got.
21+
return HEAPU8.length - dynamicTop;
2722
#endif
2823
}
2924
});

src/library_html5.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2728,15 +2728,10 @@ var LibraryJSEvents = {
27282728
var t = performance.now();
27292729
var n = t + msecs;
27302730
if ({{{ makeDynCall('idi', 'cb') }}}(t, userData)) {
2731-
setTimeout(tick,
2732-
#if WASM
2733-
// 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)
2734-
t - performance.now()
2735-
#else
2736-
// For old browsers, cap the timeout to zero.
2737-
Math.max(0, t - performance.now())
2738-
#endif
2739-
);
2731+
// Save a little bit of code space: modern browsers should treat
2732+
// negative setTimeout as timeout of 0
2733+
// (https://stackoverflow.com/questions/8430966/is-calling-settimeout-with-a-negative-delay-ok)
2734+
setTimeout(tick, t - performance.now());
27402735
}
27412736
}
27422737
return setTimeout(tick, 0);

src/library_pthread.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ var LibraryPThread = {
380380
}
381381
#endif
382382

383-
#if ASSERTIONS && WASM
383+
#if ASSERTIONS
384384
assert(wasmMemory instanceof WebAssembly.Memory, 'WebAssembly memory should have been loaded by now!');
385385
assert(wasmModule instanceof WebAssembly.Module, 'WebAssembly Module should have been loaded by now!');
386386
#endif
@@ -394,7 +394,6 @@ var LibraryPThread = {
394394
// object in Module['mainScriptUrlOrBlob'], or a URL to it, so that pthread Workers can
395395
// independently load up the same main application file.
396396
'urlOrBlob': Module['mainScriptUrlOrBlob'] || _scriptDir,
397-
#if WASM
398397
#if WASM2JS
399398
// the polyfill WebAssembly.Memory instance has function properties,
400399
// which will fail in postMessage, so just send a custom object with the
@@ -410,10 +409,6 @@ var LibraryPThread = {
410409
#if USE_OFFSET_CONVERTER
411410
'wasmOffsetConverter': wasmOffsetConverter,
412411
#endif
413-
#else
414-
'buffer': HEAPU8.buffer,
415-
'asmJsUrlOrBlob': Module["asmJsUrlOrBlob"],
416-
#endif
417412
#if !MINIMAL_RUNTIME
418413
'DYNAMIC_BASE': DYNAMIC_BASE
419414
#endif

src/postamble_minimal.js

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ function initRuntime(asm) {
7979
{{{ getQuoted('ATINITS') }}}
8080
}
8181

82-
#if WASM
83-
8482
// Initialize wasm (asynchronous)
8583

8684
var imports = {
@@ -94,11 +92,11 @@ var imports = {
9492

9593
// In non-fastcomp non-asm.js builds, grab wasm exports to outer scope
9694
// for emscripten_get_exported_function() to be able to access them.
97-
#if LibraryManager.has('library_exports.js') && WASM
95+
#if LibraryManager.has('library_exports.js')
9896
var asm;
9997
#endif
10098

101-
#if USE_PTHREADS && WASM
99+
#if USE_PTHREADS
102100
var wasmModule;
103101
#if PTHREAD_POOL_SIZE
104102
function loadWasmModuleToWorkers() {
@@ -151,7 +149,7 @@ WebAssembly.instantiate(Module['wasm'], imports).then(function(output) {
151149
wasmModule = output.module || Module['wasm'];
152150
#endif
153151

154-
#if !(LibraryManager.has('library_exports.js') && WASM) && !EMBIND
152+
#if !LibraryManager.has('library_exports.js') && !EMBIND
155153
// If not using the emscripten_get_exported_function() API or embind, keep the 'asm'
156154
// exports variable in local scope to this instantiate function to save code size.
157155
// (otherwise access it without to export it to outer scope)
@@ -234,22 +232,5 @@ WebAssembly.instantiate(Module['wasm'], imports).then(function(output) {
234232
#endif // ASSERTIONS || WASM == 2
235233
;
236234

237-
#else
238-
239-
// Initialize asm.js (synchronous)
240-
initRuntime(asm);
241-
242-
#if USE_PTHREADS && PTHREAD_POOL_SIZE
243-
if (!ENVIRONMENT_IS_PTHREAD) loadWasmModuleToWorkers();
244-
#if !PTHREAD_POOL_DELAY_LOAD
245-
else
246-
#endif
247-
ready();
248-
#else
249-
ready();
250-
#endif
251-
252-
#endif
253-
254235
{{GLOBAL_VARS}}
255236

src/preamble.js

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -393,10 +393,6 @@ var TOTAL_STACK = {{{ TOTAL_STACK }}};
393393
#if ASSERTIONS
394394
if (Module['TOTAL_STACK']) assert(TOTAL_STACK === Module['TOTAL_STACK'], 'the stack size can no longer be determined at runtime')
395395
#endif
396-
#if MAIN_MODULE && !WASM
397-
// JS side modules use this value to decide their stack size.
398-
Module['TOTAL_STACK'] = TOTAL_STACK;
399-
#endif
400396

401397
{{{ makeModuleReceiveWithVar('INITIAL_INITIAL_MEMORY', 'INITIAL_MEMORY', INITIAL_MEMORY) }}}
402398

@@ -429,8 +425,6 @@ if (typeof SharedArrayBuffer === 'undefined' || typeof Atomics === 'undefined')
429425
#endif
430426
#endif
431427

432-
#include "runtime_sab_polyfill.js"
433-
434428
#if STANDALONE_WASM
435429
#if ASSERTIONS
436430
// In standalone mode, the wasm creates the memory, and the user can't provide it.
@@ -664,7 +658,7 @@ function removeRunDependency(id) {
664658

665659
Module["preloadedImages"] = {}; // maps url to image data
666660
Module["preloadedAudios"] = {}; // maps url to audio data
667-
#if WASM && MAIN_MODULE
661+
#if MAIN_MODULE
668662
Module["preloadedWasm"] = {}; // maps url to wasm instance exports
669663
#endif
670664

@@ -692,14 +686,10 @@ function abort(what) {
692686
what = output;
693687
#endif // ASSERTIONS
694688

695-
#if WASM
696689
// Use a wasm runtime error, because a JS error might be seen as a foreign
697690
// exception, which means we'd run destructors on it. We need the error to
698691
// simply make the program stop.
699692
var e = new WebAssembly.RuntimeError(what);
700-
#else
701-
var e = what;
702-
#endif
703693

704694
#if MODULARIZE
705695
readyPromiseReject(e);
@@ -732,7 +722,6 @@ addOnPreRun(function() {
732722
}
733723
}
734724
// if we can load dynamic libraries synchronously, do so, otherwise, preload
735-
#if WASM
736725
if (Module['dynamicLibraries'] && Module['dynamicLibraries'].length > 0 && !readBinary) {
737726
// we can't read binary data synchronously, so preload
738727
addRunDependency('preload_dynamicLibraries');
@@ -744,7 +733,6 @@ addOnPreRun(function() {
744733
});
745734
return;
746735
}
747-
#endif
748736
loadDynamicLibraries(Module['dynamicLibraries']);
749737
});
750738

@@ -805,7 +793,6 @@ function createExportWrapper(name, fixedasm) {
805793
}
806794
#endif
807795

808-
#if WASM
809796
var wasmBinaryFile = '{{{ WASM_BINARY_FILE }}}';
810797
if (!isDataURI(wasmBinaryFile)) {
811798
wasmBinaryFile = locateFile(wasmBinaryFile);
@@ -1132,7 +1119,6 @@ function createWasm() {
11321119
return Module['asm']; // exports were assigned here
11331120
#endif
11341121
}
1135-
#endif
11361122

11371123
// Globals used by JS i64 conversions
11381124
var tempDouble;

src/preamble_minimal.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ Module['wasm'] = base64Decode('{{{ getQuoted("WASM_BINARY_DATA") }}}');
5454

5555
#include "runtime_functions.js"
5656
#include "runtime_strings.js"
57-
#include "runtime_sab_polyfill.js"
5857

5958
#if USE_PTHREADS
6059
var STATIC_BASE = {{{ GLOBAL_BASE }}};
@@ -72,8 +71,6 @@ var GLOBAL_BASE = {{{ GLOBAL_BASE }}},
7271
STACK_MAX = {{{ getQuoted('STACK_MAX') }}}
7372
;
7473

75-
#if WASM
76-
7774
#if ALLOW_MEMORY_GROWTH && MAXIMUM_MEMORY != -1
7875
var wasmMaximumMemory = {{{ MAXIMUM_MEMORY >>> 16 }}};
7976
#else
@@ -101,20 +98,6 @@ assert(buffer instanceof SharedArrayBuffer, 'requested a shared WebAssembly.Memo
10198

10299
#include "runtime_init_table.js"
103100

104-
#else
105-
106-
#if USE_PTHREADS
107-
var buffer = new SharedArrayBuffer({{{ INITIAL_MEMORY }}});
108-
#else
109-
var buffer = new ArrayBuffer({{{ INITIAL_MEMORY }}});
110-
#endif
111-
112-
#if USE_PTHREADS
113-
}
114-
#endif
115-
116-
#endif
117-
118101
#if ASSERTIONS
119102
var WASM_PAGE_SIZE = {{{ WASM_PAGE_SIZE }}};
120103
#if USE_PTHREADS

src/runtime_functions.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* SPDX-License-Identifier: MIT
55
*/
66

7-
#if WASM
87
// Wraps a JS function as a wasm function with a given signature.
98
function convertJsFunctionToWasm(func, sig) {
109
#if WASM2JS
@@ -170,7 +169,6 @@ function removeFunctionWasm(index) {
170169
functionsInTableMap.delete(wasmTable.get(index));
171170
freeTableIndexes.push(index);
172171
}
173-
#endif
174172

175173
// 'sig' parameter is required for the llvm backend but only when func is not
176174
// already a WebAssembly function.

src/runtime_init_memory.js

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ if (ENVIRONMENT_IS_PTHREAD) {
1212
buffer = Module['buffer'];
1313
} else {
1414
#endif // USE_PTHREADS
15-
#if WASM
1615

1716
#if expectToReceiveOnModule('wasmMemory')
1817
if (Module['wasmMemory']) {
@@ -47,34 +46,18 @@ if (ENVIRONMENT_IS_PTHREAD) {
4746
#endif
4847
}
4948

50-
#else // WASM
51-
52-
if (Module['buffer']) {
53-
buffer = Module['buffer'];
54-
}
55-
#ifdef USE_PTHREADS
56-
else if (typeof SharedArrayBuffer !== 'undefined') {
57-
buffer = new SharedArrayBuffer(INITIAL_INITIAL_MEMORY);
58-
}
59-
#endif
60-
else {
61-
buffer = new ArrayBuffer(INITIAL_INITIAL_MEMORY);
62-
}
63-
#endif // WASM
6449
#if USE_PTHREADS
6550
}
6651
#endif
6752

68-
#if WASM
6953
if (wasmMemory) {
7054
buffer = wasmMemory.buffer;
7155
}
72-
#endif
7356

7457
// If the user provides an incorrect length, just use that length instead rather than providing the user to
7558
// specifically provide the memory length with Module['INITIAL_MEMORY'].
7659
INITIAL_INITIAL_MEMORY = buffer.byteLength;
77-
#ifdef ASSERTIONS && WASM
60+
#ifdef ASSERTIONS
7861
assert(INITIAL_INITIAL_MEMORY % WASM_PAGE_SIZE === 0);
7962
#ifdef ALLOW_MEMORY_GROWTH && MAXIMUM_MEMORY != -1
8063
assert({{{ WASM_PAGE_SIZE }}} % WASM_PAGE_SIZE === 0);

0 commit comments

Comments
 (0)