Skip to content

Commit fcf052c

Browse files
committed
cleanup minimal
1 parent 77996b4 commit fcf052c

File tree

5 files changed

+70
-38
lines changed

5 files changed

+70
-38
lines changed

src/Fetch.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ function fetchXHR(fetch, onsuccess, onerror, onprogress, onreadystatechange) {
434434
function startFetch(fetch, successcb, errorcb, progresscb, readystatechangecb) {
435435
// Avoid shutting down the runtime since we want to wait for the async
436436
// response.
437-
runtimeKeepalivePush();
437+
{{{ runtimeKeepalivePush(); }}}
438438

439439
var fetch_attr = fetch + {{{ C_STRUCTS.emscripten_fetch_t.__attributes }}};
440440
var requestMethod = UTF8ToString(fetch_attr);
@@ -456,7 +456,7 @@ function startFetch(fetch, successcb, errorcb, progresscb, readystatechangecb) {
456456
#if FETCH_DEBUG
457457
console.log('fetch: operation success. e: ' + e);
458458
#endif
459-
runtimeKeepalivePop();
459+
{{{ runtimeKeepalivePop(); }}}
460460
callUserCallback(function() {
461461
if (onsuccess) {{{ makeDynCall('vi', 'onsuccess') }}}(fetch);
462462
else if (successcb) successcb(fetch);
@@ -474,7 +474,7 @@ function startFetch(fetch, successcb, errorcb, progresscb, readystatechangecb) {
474474
#if FETCH_DEBUG
475475
console.error('fetch: operation failed: ' + e);
476476
#endif
477-
runtimeKeepalivePop();
477+
{{{ runtimeKeepalivePop(); }}}
478478
callUserCallback(function() {
479479
if (onerror) {{{ makeDynCall('vi', 'onerror') }}}(fetch);
480480
else if (errorcb) errorcb(fetch);
@@ -507,7 +507,7 @@ function startFetch(fetch, successcb, errorcb, progresscb, readystatechangecb) {
507507
#if FETCH_DEBUG
508508
console.log('fetch: IndexedDB store succeeded.');
509509
#endif
510-
runtimeKeepalivePop();
510+
{{{ runtimeKeepalivePop(); }}}
511511
callUserCallback(function() {
512512
if (onsuccess) {{{ makeDynCall('vi', 'onsuccess') }}}(fetch);
513513
else if (successcb) successcb(fetch);
@@ -517,7 +517,7 @@ function startFetch(fetch, successcb, errorcb, progresscb, readystatechangecb) {
517517
#if FETCH_DEBUG
518518
console.error('fetch: IndexedDB store failed.');
519519
#endif
520-
runtimeKeepalivePop();
520+
{{{ runtimeKeepalivePop(); }}}
521521
callUserCallback(function() {
522522
if (onsuccess) {{{ makeDynCall('vi', 'onsuccess') }}}(fetch);
523523
else if (successcb) successcb(fetch);

src/library.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3772,9 +3772,11 @@ LibraryManager.library = {
37723772

37733773
// Callable in pthread without __proxy needed.
37743774
emscripten_exit_with_live_runtime__sig: 'v',
3775+
#if !MINIMAL_RUNTIME
37753776
emscripten_exit_with_live_runtime__deps: ['$runtimeKeepalivePush'],
3777+
#endif
37763778
emscripten_exit_with_live_runtime: function() {
3777-
runtimeKeepalivePush();
3779+
{{{ runtimeKeepalivePush(); }}}
37783780
throw 'unwind';
37793781
},
37803782

@@ -3883,8 +3885,6 @@ LibraryManager.library = {
38833885
},
38843886
#else
38853887
// MINIMAL_RUNTIME doesn't support the runtimeKeepalive stuff
3886-
$runtimeKeepalivePush: function() {},
3887-
$runtimeKeepalivePop: function() {},
38883888
$callUserCallback: function(func) {
38893889
func();
38903890
},

src/library_browser.js

Lines changed: 44 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ var LibraryBrowser = {
1010
'$setMainLoop',
1111
'$callUserCallback',
1212
'emscripten_set_main_loop_timing',
13+
#if !MINIMAL_RUNTIME
1314
'$runtimeKeepalivePush',
1415
'$runtimeKeepalivePop'
16+
#endif
1517
],
1618
$Browser__postset: 'Module["requestFullscreen"] = function Module_requestFullscreen(lockPointer, resizeCanvas) { Browser.requestFullscreen(lockPointer, resizeCanvas) };\n' + // exports
1719
#if ASSERTIONS
@@ -484,16 +486,16 @@ var LibraryBrowser = {
484486
// abort and pause-aware versions TODO: build main loop on top of this?
485487

486488
safeRequestAnimationFrame: function(func) {
487-
runtimeKeepalivePush();
489+
{{{ runtimeKeepalivePush(); }}}
488490
return Browser.requestAnimationFrame(function() {
489-
runtimeKeepalivePop();
491+
{{{ runtimeKeepalivePop(); }}}
490492
callUserCallback(func);
491493
});
492494
},
493495
safeSetTimeout: function(func, timeout) {
494-
runtimeKeepalivePush();
496+
{{{ runtimeKeepalivePush(); }}}
495497
return setTimeout(function() {
496-
runtimeKeepalivePop();
498+
{{{ runtimeKeepalivePop(); }}}
497499
callUserCallback(func);
498500
}, timeout);
499501
},
@@ -779,18 +781,22 @@ var LibraryBrowser = {
779781
}
780782
},
781783

782-
emscripten_async_wget__deps: ['$PATH_FS', '$runtimeKeepalivePush', '$runtimeKeepalivePop'],
784+
emscripten_async_wget__deps: ['$PATH_FS',
785+
#if !MINIMAL_RUNTIME
786+
'$runtimeKeepalivePush', '$runtimeKeepalivePop',
787+
#endif
788+
],
783789
emscripten_async_wget__proxy: 'sync',
784790
emscripten_async_wget__sig: 'viiii',
785791
emscripten_async_wget: function(url, file, onload, onerror) {
786-
runtimeKeepalivePush();
792+
{{{ runtimeKeepalivePush(); }}}
787793

788794
var _url = UTF8ToString(url);
789795
var _file = UTF8ToString(file);
790796
_file = PATH_FS.resolve(_file);
791797
function doCallback(callback) {
792798
if (callback) {
793-
runtimeKeepalivePop();
799+
{{{ runtimeKeepalivePop(); }}}
794800
var stack = stackSave();
795801
{{{ makeDynCall('vi', 'callback') }}}(allocate(intArrayFromString(_file), ALLOC_STACK));
796802
stackRestore(stack);
@@ -863,11 +869,15 @@ var LibraryBrowser = {
863869
}, true /* no need for run dependency, this is async but will not do any prepare etc. step */ );
864870
},
865871

866-
emscripten_async_wget2__deps: ['$PATH_FS', '$runtimeKeepalivePush', '$runtimeKeepalivePop'],
872+
emscripten_async_wget2__deps: ['$PATH_FS',
873+
#if !MINIMAL_RUNTIME
874+
'$runtimeKeepalivePush', '$runtimeKeepalivePop',
875+
#endif
876+
],
867877
emscripten_async_wget2__proxy: 'sync',
868878
emscripten_async_wget2__sig: 'iiiiiiiii',
869879
emscripten_async_wget2: function(url, file, request, param, arg, onload, onerror, onprogress) {
870-
runtimeKeepalivePush();
880+
{{{ runtimeKeepalivePush(); }}}
871881

872882
var _url = UTF8ToString(url);
873883
var _file = UTF8ToString(file);
@@ -886,7 +896,7 @@ var LibraryBrowser = {
886896

887897
// LOAD
888898
http.onload = function http_onload(e) {
889-
runtimeKeepalivePop();
899+
{{{ runtimeKeepalivePop(); }}}
890900
if (http.status >= 200 && http.status < 300) {
891901
// if a file exists there, we overwrite it
892902
try {
@@ -910,7 +920,7 @@ var LibraryBrowser = {
910920

911921
// ERROR
912922
http.onerror = function http_onerror(e) {
913-
runtimeKeepalivePop();
923+
{{{ runtimeKeepalivePop(); }}}
914924
if (onerror) {{{ makeDynCall('viii', 'onerror') }}}(handle, arg, http.status);
915925
delete Browser.wgetRequests[handle];
916926
};
@@ -925,7 +935,7 @@ var LibraryBrowser = {
925935

926936
// ABORT
927937
http.onabort = function http_onabort(e) {
928-
runtimeKeepalivePop();
938+
{{{ runtimeKeepalivePop(); }}}
929939
delete Browser.wgetRequests[handle];
930940
};
931941

@@ -1009,11 +1019,15 @@ var LibraryBrowser = {
10091019
}
10101020
},
10111021

1012-
emscripten_run_preload_plugins__deps: ['$PATH', '$runtimeKeepalivePush', '$runtimeKeepalivePop'],
1022+
emscripten_run_preload_plugins__deps: ['$PATH',
1023+
#if !MINIMAL_RUNTIME
1024+
'$runtimeKeepalivePush', '$runtimeKeepalivePop',
1025+
#endif
1026+
],
10131027
emscripten_run_preload_plugins__proxy: 'sync',
10141028
emscripten_run_preload_plugins__sig: 'iiii',
10151029
emscripten_run_preload_plugins: function(file, onload, onerror) {
1016-
runtimeKeepalivePush();
1030+
{{{ runtimeKeepalivePush(); }}}
10171031

10181032
var _file = UTF8ToString(file);
10191033
var data = FS.analyzePath(_file);
@@ -1023,23 +1037,25 @@ var LibraryBrowser = {
10231037
PATH.basename(_file),
10241038
new Uint8Array(data.object.contents), true, true,
10251039
function() {
1026-
runtimeKeepalivePop();
1040+
{{{ runtimeKeepalivePop(); }}}
10271041
if (onload) {{{ makeDynCall('vi', 'onload') }}}(file);
10281042
},
10291043
function() {
1030-
runtimeKeepalivePop();
1044+
{{{ runtimeKeepalivePop(); }}}
10311045
if (onerror) {{{ makeDynCall('vi', 'onerror') }}}(file);
10321046
},
10331047
true // don'tCreateFile - it's already there
10341048
);
10351049
return 0;
10361050
},
10371051

1052+
#if !MINIMAL_RUNTIME
10381053
emscripten_run_preload_plugins_data__deps: ['$runtimeKeepalivePush', '$runtimeKeepalivePop'],
1054+
#endif
10391055
emscripten_run_preload_plugins_data__proxy: 'sync',
10401056
emscripten_run_preload_plugins_data__sig: 'viiiiii',
10411057
emscripten_run_preload_plugins_data: function(data, size, suffix, arg, onload, onerror) {
1042-
runtimeKeepalivePush();
1058+
{{{ runtimeKeepalivePush(); }}}
10431059

10441060
var _suffix = UTF8ToString(suffix);
10451061
if (!Browser.asyncPrepareDataCounter) Browser.asyncPrepareDataCounter = 0;
@@ -1053,11 +1069,11 @@ var LibraryBrowser = {
10531069
{{{ makeHEAPView('U8', 'data', 'data + size') }}},
10541070
true, true,
10551071
function() {
1056-
runtimeKeepalivePop();
1072+
{{{ runtimeKeepalivePop(); }}}
10571073
if (onload) {{{ makeDynCall('vii', 'onload') }}}(arg, cname);
10581074
},
10591075
function() {
1060-
runtimeKeepalivePop();
1076+
{{{ runtimeKeepalivePop(); }}}
10611077
if (onerror) {{{ makeDynCall('vi', 'onerror') }}}(arg);
10621078
},
10631079
true // don'tCreateFile - it's already there
@@ -1084,12 +1100,12 @@ var LibraryBrowser = {
10841100
return onerror ? onerror() : undefined;
10851101
}
10861102
#endif
1087-
runtimeKeepalivePush();
1103+
{{{ runtimeKeepalivePush(); }}}
10881104

10891105
assert(runDependencies === 0, 'async_load_script must be run when no other dependencies are active');
10901106
var script = document.createElement('script');
10911107
script.onload = function script_onload() {
1092-
runtimeKeepalivePop();
1108+
{{{ runtimeKeepalivePop(); }}}
10931109
if (onload) {
10941110
if (runDependencies > 0) {
10951111
dependenciesFulfilled = onload;
@@ -1099,7 +1115,7 @@ var LibraryBrowser = {
10991115
}
11001116
};
11011117
script.onerror = function() {
1102-
runtimeKeepalivePop();
1118+
{{{ runtimeKeepalivePop(); }}}
11031119
if (onerror) onerror();
11041120
};
11051121
script.src = UTF8ToString(url);
@@ -1127,7 +1143,7 @@ var LibraryBrowser = {
11271143
}
11281144

11291145
if (!Browser.mainLoop.timingSet) {
1130-
runtimeKeepalivePush();
1146+
{{{ runtimeKeepalivePush(); }}}
11311147
Browser.mainLoop.timingSet = true;
11321148
}
11331149
if (mode == 0 /*EM_TIMING_SETTIMEOUT*/) {
@@ -1236,7 +1252,7 @@ var LibraryBrowser = {
12361252
#if RUNTIME_DEBUG
12371253
err('main loop exiting..');
12381254
#endif
1239-
runtimeKeepalivePop();
1255+
{{{ runtimeKeepalivePop(); }}}
12401256
#if !MINIMAL_RUNTIME
12411257
maybeExit();
12421258
#endif
@@ -1252,7 +1268,7 @@ var LibraryBrowser = {
12521268
#if RUNTIME_DEBUG
12531269
err('main loop exiting..');
12541270
#endif
1255-
runtimeKeepalivePop();
1271+
{{{ runtimeKeepalivePop(); }}}
12561272
#if !MINIMAL_RUNTIME
12571273
maybeExit();
12581274
#endif
@@ -1309,7 +1325,7 @@ var LibraryBrowser = {
13091325
#if RUNTIME_DEBUG
13101326
err('main loop exiting..');
13111327
#endif
1312-
runtimeKeepalivePop();
1328+
{{{ runtimeKeepalivePop(); }}}
13131329
#if !MINIMAL_RUNTIME
13141330
maybeExit();
13151331
#endif
@@ -1485,7 +1501,7 @@ var LibraryBrowser = {
14851501
if (msg.data['finalResponse']) {
14861502
info.awaited--;
14871503
info.callbacks[callbackId] = null; // TODO: reuse callbackIds, compress this
1488-
runtimeKeepalivePop();
1504+
{{{ runtimeKeepalivePop(); }}}
14891505
}
14901506
var data = msg.data['data'];
14911507
if (data) {
@@ -1525,7 +1541,7 @@ var LibraryBrowser = {
15251541
var callbackId = -1;
15261542
if (callback) {
15271543
#if !MINIMAL_RUNTIME
1528-
runtimeKeepalivePush();
1544+
{{{ runtimeKeepalivePush(); }}}
15291545
#endif
15301546
callbackId = info.callbacks.length;
15311547
info.callbacks.push({

src/library_sockfs.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -732,13 +732,15 @@ mergeInto(LibraryManager.library, {
732732
* Passing a NULL callback function to a emscripten_set_socket_*_callback call
733733
* will deregister the callback registered for that Event.
734734
*/
735+
#if !MINIMAL_RUNTIME
735736
$_setNetworkCallback__deps: [
736737
'$runtimeKeepalivePush',
737738
'$runtimeKeepalivePop'
738739
],
740+
#endif
739741
$_setNetworkCallback: function(event, userData, callback) {
740742
function _callback(data) {
741-
runtimeKeepalivePop();
743+
{{{ runtimeKeepalivePop(); }}}
742744
if (!callback) return;
743745
try {
744746
if (event === 'error') {
@@ -759,7 +761,7 @@ mergeInto(LibraryManager.library, {
759761
}
760762
};
761763

762-
runtimeKeepalivePush();
764+
{{{ runtimeKeepalivePush(); }}}
763765
Module['websocket']['on'](event, _callback);
764766
},
765767
emscripten_set_socket_error_callback__deps: ['$_setNetworkCallback'],

src/parseTools.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,3 +1291,17 @@ function makeMalloc(source, param) {
12911291
}
12921292
return `abort('malloc was not included, but is needed in ${source}. Adding "_malloc" to EXPORTED_FUNCTIONS should fix that. This may be a bug in the compiler, please file an issue.');`;
12931293
}
1294+
1295+
// Adds a call to runtimeKeepalivePush, but not under MINIMAL_RUNTIME.
1296+
// Avoids having many `if MINIMAL_RUNTIME` sections in the library code.
1297+
function runtimeKeepalivePush() {
1298+
if (!MINIMAL_RUNTIME) return '';
1299+
return 'runtimeKeepalivePush();';
1300+
}
1301+
1302+
// Adds a call to runtimeKeepalivePop, but not under MINIMAL_RUNTIME.
1303+
// Avoids having many `if MINIMAL_RUNTIME` sections in the library code.
1304+
function runtimeKeepalivePop() {
1305+
if (!MINIMAL_RUNTIME) return '';
1306+
return 'runtimeKeepalivePop();';
1307+
}

0 commit comments

Comments
 (0)