Rename callUserCallback to callFromEventLoop This is to better reflect the usage of this function, which is designed to be a wrapper around calling into application code from the event loop. The old `callUserCallback` callback name is still available as an alias.
diff --git a/src/Fetch.js b/src/Fetch.js index 17bba7f..c259cd6 100644 --- a/src/Fetch.js +++ b/src/Fetch.js
@@ -458,7 +458,7 @@ if (fetchAttrSynchronous) { f(); } else { - callUserCallback(f); + callFromEventLoop(f); } }
diff --git a/src/library.js b/src/library.js index 9f7f33d..b17211f 100644 --- a/src/library.js +++ b/src/library.js
@@ -2275,10 +2275,10 @@ }, // http://pubs.opengroup.org/onlinepubs/000095399/functions/alarm.html - alarm__deps: ['raise', '$callUserCallback'], + alarm__deps: ['raise', '$callFromEventLoop'], alarm: function(seconds) { setTimeout(function() { - callUserCallback(function() { + callFromEventLoop(function() { _raise({{{ cDefine('SIGALRM') }}}); }); }, seconds*1000); @@ -3488,12 +3488,12 @@ // The job of this wrapper is the handle emscripten-specfic exceptions such // as ExitStatus and 'unwind' and prevent these from escaping to the top // level. - $callUserCallback__deps: ['$handleException', + $callFromEventLoop__deps: ['$handleException', #if EXIT_RUNTIME || USE_PTHREADS '$maybeExit', #endif ], - $callUserCallback: function(func) { + $callFromEventLoop: function(func) { #if EXIT_RUNTIME if (runtimeExited || ABORT) { #else @@ -3545,18 +3545,18 @@ }, #else // MINIMAL_RUNTIME doesn't support the runtimeKeepalive stuff - $callUserCallback: function(func) { + $callFromEventLoop: function(func) { func(); }, #endif - $safeSetTimeout__deps: ['$callUserCallback'], + $safeSetTimeout__deps: ['$callFromEventLoop'], $safeSetTimeout__docs: '/** @param {number=} timeout */', $safeSetTimeout: function(func, timeout) { {{{ runtimeKeepalivePush() }}} return setTimeout(function() { {{{ runtimeKeepalivePop() }}} - callUserCallback(func); + callFromEventLoop(func); }, timeout); }, @@ -3664,6 +3664,11 @@ err('done preloading data files'); #endif }, + +#if LEGACY_RUNTIME + // Legacy name for callFromEventLoop + $callUserCallback: '$callFromEventLoop', +#endif }); function autoAddDeps(object, name) {
diff --git a/src/library_async.js b/src/library_async.js index 8ccffcc..ca0dba3 100644 --- a/src/library_async.js +++ b/src/library_async.js
@@ -20,7 +20,7 @@ }, #if ASYNCIFY - $Asyncify__deps: ['$runAndAbortIfError', '$callUserCallback', '$sigToWasmTypes', + $Asyncify__deps: ['$runAndAbortIfError', '$callFromEventLoop', '$sigToWasmTypes', #if !MINIMAL_RUNTIME '$runtimeKeepalivePush', '$runtimeKeepalivePop' #endif @@ -420,7 +420,7 @@ _free(Asyncify.currData); Asyncify.currData = null; // Call all sleep callbacks now that the sleep-resume is all done. - Asyncify.sleepCallbacks.forEach((func) => callUserCallback(func)); + Asyncify.sleepCallbacks.forEach((func) => callFromEventLoop(func)); } else { abort('invalid state: ' + Asyncify.state); }
diff --git a/src/library_browser.js b/src/library_browser.js index b819e53..78f3b1f 100644 --- a/src/library_browser.js +++ b/src/library_browser.js
@@ -8,7 +8,7 @@ var LibraryBrowser = { $Browser__deps: [ '$setMainLoop', - '$callUserCallback', + '$callFromEventLoop', '$safeSetTimeout', '$warnOnce', 'emscripten_set_main_loop_timing', @@ -91,7 +91,7 @@ return; // |return false| skips a frame } } - callUserCallback(func); + callFromEventLoop(func); if (Module['postMainLoop']) Module['postMainLoop'](); } }, @@ -516,7 +516,7 @@ {{{ runtimeKeepalivePush() }}} return Browser.requestAnimationFrame(function() { {{{ runtimeKeepalivePop() }}} - callUserCallback(func); + callFromEventLoop(func); }); },
diff --git a/src/library_dylink.js b/src/library_dylink.js index 9731c02..8f1822c 100644 --- a/src/library_dylink.js +++ b/src/library_dylink.js
@@ -964,7 +964,7 @@ }, // Async version of dlopen. - _emscripten_dlopen_js__deps: ['$dlopenInternal', '$callUserCallback', '$dlSetError'], + _emscripten_dlopen_js__deps: ['$dlopenInternal', '$callFromEventLoop', '$dlSetError'], _emscripten_dlopen_js__sig: 'viiiii', _emscripten_dlopen_js: function(handle, onsuccess, onerror) { /** @param {Object=} e */ @@ -972,11 +972,11 @@ var filename = UTF8ToString({{{ makeGetValue('handle', C_STRUCTS.dso.name, '*') }}}); dlSetError('Could not load dynamic lib: ' + filename + '\n' + e); {{{ runtimeKeepalivePop() }}} - callUserCallback(function () { {{{ makeDynCall('vi', 'onerror') }}}(handle); }); + callFromEventLoop(function () { {{{ makeDynCall('vi', 'onerror') }}}(handle); }); } function successCallback() { {{{ runtimeKeepalivePop() }}} - callUserCallback(function () { {{{ makeDynCall('vii', 'onsuccess') }}}(handle); }); + callFromEventLoop(function () { {{{ makeDynCall('vii', 'onsuccess') }}}(handle); }); } {{{ runtimeKeepalivePush() }}}
diff --git a/src/library_eventloop.js b/src/library_eventloop.js index a8f9c3c..b10e0fd 100644 --- a/src/library_eventloop.js +++ b/src/library_eventloop.js
@@ -70,13 +70,13 @@ // emscripten_set_immediate_loop() if application links to both of them. }, - emscripten_set_immediate__deps: ['$polyfillSetImmediate', '$callUserCallback'], + emscripten_set_immediate__deps: ['$polyfillSetImmediate', '$callFromEventLoop'], emscripten_set_immediate: function(cb, userData) { polyfillSetImmediate(); {{{ runtimeKeepalivePush(); }}} return emSetImmediate(function() { {{{ runtimeKeepalivePop(); }}} - callUserCallback(function() { + callFromEventLoop(function() { {{{ makeDynCall('vi', 'cb') }}}(userData); }); }); @@ -88,12 +88,12 @@ emClearImmediate(id); }, - emscripten_set_immediate_loop__deps: ['$polyfillSetImmediate', '$callUserCallback'], + emscripten_set_immediate_loop__deps: ['$polyfillSetImmediate', '$callFromEventLoop'], emscripten_set_immediate_loop: function(cb, userData) { polyfillSetImmediate(); function tick() { {{{ runtimeKeepalivePop(); }}} - callUserCallback(function() { + callFromEventLoop(function() { if ({{{ makeDynCall('ii', 'cb') }}}(userData)) { {{{ runtimeKeepalivePush(); }}} emSetImmediate(tick); @@ -104,12 +104,12 @@ return emSetImmediate(tick); }, - emscripten_set_timeout__deps: ['$callUserCallback'], + emscripten_set_timeout__deps: ['$callFromEventLoop'], emscripten_set_timeout: function(cb, msecs, userData) { {{{ runtimeKeepalivePush() }}} return setTimeout(function() { {{{ runtimeKeepalivePop() }}} - callUserCallback(function() { + callFromEventLoop(function() { {{{ makeDynCall('vi', 'cb') }}}(userData); }); }, msecs); @@ -119,13 +119,13 @@ clearTimeout(id); }, - emscripten_set_timeout_loop__deps: ['$callUserCallback'], + emscripten_set_timeout_loop__deps: ['$callFromEventLoop'], emscripten_set_timeout_loop: function(cb, msecs, userData) { function tick() { var t = performance.now(); var n = t + msecs; {{{ runtimeKeepalivePop() }}} - callUserCallback(function() { + callFromEventLoop(function() { if ({{{ makeDynCall('idi', 'cb') }}}(t, userData)) { // Save a little bit of code space: modern browsers should treat // negative setTimeout as timeout of 0 @@ -139,11 +139,11 @@ return setTimeout(tick, 0); }, - emscripten_set_interval__deps: ['$callUserCallback'], + emscripten_set_interval__deps: ['$callFromEventLoop'], emscripten_set_interval: function(cb, msecs, userData) { {{{ runtimeKeepalivePush() }}} return setInterval(function() { - callUserCallback(function() { + callFromEventLoop(function() { {{{ makeDynCall('vi', 'cb') }}}(userData) }); }, msecs);
diff --git a/src/library_fetch.js b/src/library_fetch.js index 07b909f..c9c6ab0 100644 --- a/src/library_fetch.js +++ b/src/library_fetch.js
@@ -31,7 +31,7 @@ emscripten_start_fetch__deps: [ '$Fetch', '$fetchXHR', - '$callUserCallback', + '$callFromEventLoop', #if FETCH_SUPPORT_INDEXEDDB '$fetchCacheData', '$fetchLoadCachedData',
diff --git a/src/library_glfw.js b/src/library_glfw.js index d585608..efd8137 100644 --- a/src/library_glfw.js +++ b/src/library_glfw.js
@@ -80,7 +80,7 @@ }, $GLFW__deps: ['emscripten_get_now', '$GL', '$Browser', '$GLFW_Window', - '$callUserCallback', + '$callFromEventLoop', '$allocateUTF8', #if FILESYSTEM '$FS', @@ -591,7 +591,7 @@ if (!GLFW.active.windowSizeFunc) return; - callUserCallback(function() { + callFromEventLoop(function() { #if USE_GLFW == 2 {{{ makeDynCall('vii', 'GLFW.active.windowSizeFunc') }}}(GLFW.active.width, GLFW.active.height); #endif @@ -607,7 +607,7 @@ if (!GLFW.active.framebufferSizeFunc) return; - callUserCallback(function() { + callFromEventLoop(function() { #if USE_GLFW == 3 {{{ makeDynCall('viii', 'GLFW.active.framebufferSizeFunc') }}}(GLFW.active.id, GLFW.active.width, GLFW.active.height); #endif
diff --git a/src/library_pthread.js b/src/library_pthread.js index a205913..a0857a2 100644 --- a/src/library_pthread.js +++ b/src/library_pthread.js
@@ -998,7 +998,7 @@ Atomics.store(HEAP32, queue >> 2, {{{ cDefine('NOTIFICATION_RECEIVED') }}}); // Only execute the queue if we have a live pthread runtime. We // implement pthread_self to return 0 if there is no live runtime. - // TODO: Use `callUserCallback` to correctly handle unwinds, etc. once + // TODO: Use `callFromEventLoop` to correctly handle unwinds, etc. once // `runtimeExited` is correctly unset on workers. if (_pthread_self()) { __emscripten_proxy_execute_task_queue(queue);
diff --git a/src/library_webgpu.js b/src/library_webgpu.js index 69ba39b..1a0c433 100644 --- a/src/library_webgpu.js +++ b/src/library_webgpu.js
@@ -753,13 +753,13 @@ device["pushErrorScope"](WebGPU.ErrorFilter[filter]); }, - wgpuDevicePopErrorScope__deps: ['$callUserCallback', '$allocateUTF8'], + wgpuDevicePopErrorScope__deps: ['$callFromEventLoop', '$allocateUTF8'], wgpuDevicePopErrorScope: function(deviceId, callback, userdata) { var device = WebGPU.mgrDevice.get(deviceId); {{{ runtimeKeepalivePush() }}} device["popErrorScope"]().then(function(gpuError) { {{{ runtimeKeepalivePop() }}} - callUserCallback(function() { + callFromEventLoop(function() { if (!gpuError) { {{{ makeDynCall('viii', 'callback') }}}( {{{ gpu.ErrorType.NoError }}}, 0, userdata); @@ -777,7 +777,7 @@ }); }, function(ex) { {{{ runtimeKeepalivePop() }}} - callUserCallback(function() { + callFromEventLoop(function() { var messagePtr = allocateUTF8(ex.message); // TODO: This can mean either the device was lost or the error scope stack was empty. Figure // out how to synthesize the DeviceLost error type. (Could be by simply tracking the error @@ -793,7 +793,7 @@ device.label = UTF8ToString(labelPtr); }, - wgpuDeviceSetDeviceLostCallback__deps: ['$callUserCallback', '$allocateUTF8'], + wgpuDeviceSetDeviceLostCallback__deps: ['$callFromEventLoop', '$allocateUTF8'], wgpuDeviceSetDeviceLostCallback: function(deviceId, callback, userdata) { var deviceWrapper = WebGPU.mgrDevice.objects[deviceId]; {{{ gpu.makeCheckDefined('deviceWrapper') }}} @@ -805,7 +805,7 @@ } deviceWrapper.lostCallback = function(info) { // This will skip the callback if the runtime is no longer alive. - callUserCallback(function() { + callFromEventLoop(function() { var messagePtr = allocateUTF8(info.message); {{{ makeDynCall('viii', 'callback') }}}(WebGPU.DeviceLostReason[info.reason], messagePtr, userdata); _free(messagePtr); @@ -813,12 +813,12 @@ }; }, - wgpuDeviceSetUncapturedErrorCallback__deps: ['$callUserCallback', '$allocateUTF8'], + wgpuDeviceSetUncapturedErrorCallback__deps: ['$callFromEventLoop', '$allocateUTF8'], wgpuDeviceSetUncapturedErrorCallback: function(deviceId, callback, userdata) { var device = WebGPU.mgrDevice.get(deviceId); device["onuncapturederror"] = function(ev) { // This will skip the callback if the runtime is no longer alive. - callUserCallback(function() { + callFromEventLoop(function() { // WGPUErrorType type, const char* message, void* userdata var Validation = 0x00000001; var OutOfMemory = 0x00000002; @@ -1472,7 +1472,7 @@ queue["submit"](cmds); }, - wgpuQueueOnSubmittedWorkDone__deps: ['$callUserCallback'], + wgpuQueueOnSubmittedWorkDone__deps: ['$callFromEventLoop'], wgpuQueueOnSubmittedWorkDone: function(queueId, {{{ defineI64Param('signalValue') }}}, callback, userdata) { var queue = WebGPU.mgrQueue.get(queueId); #if ASSERTIONS @@ -1482,12 +1482,12 @@ {{{ runtimeKeepalivePush() }}} queue["onSubmittedWorkDone"]().then(function() { {{{ runtimeKeepalivePop() }}} - callUserCallback(function() { + callFromEventLoop(function() { {{{ makeDynCall('vii', 'callback') }}}({{{ gpu.QueueWorkDoneStatus.Success }}}, userdata); }); }, function() { {{{ runtimeKeepalivePop() }}} - callUserCallback(function() { + callFromEventLoop(function() { {{{ makeDynCall('vii', 'callback') }}}({{{ gpu.QueueWorkDoneStatus.Error }}}, userdata); }); }); @@ -1889,7 +1889,7 @@ // In webgpu.h offset and size are passed in as size_t. // And library_webgpu assumes that size_t is always 32bit in emscripten. - wgpuBufferMapAsync__deps: ['$callUserCallback'], + wgpuBufferMapAsync__deps: ['$callFromEventLoop'], wgpuBufferMapAsync: function(bufferId, mode, offset, size, callback, userdata) { var bufferWrapper = WebGPU.mgrBuffer.objects[bufferId]; {{{ gpu.makeCheckDefined('bufferWrapper') }}} @@ -1905,12 +1905,12 @@ {{{ runtimeKeepalivePush() }}} buffer["mapAsync"](mode, offset, size).then(function() { {{{ runtimeKeepalivePop() }}} - callUserCallback(function() { + callFromEventLoop(function() { {{{ makeDynCall('vii', 'callback') }}}({{{ gpu.BufferMapAsyncStatus.Success }}}, userdata); }); }, function() { {{{ runtimeKeepalivePop() }}} - callUserCallback(function() { + callFromEventLoop(function() { // TODO(kainino0x): Figure out how to pick other error status values. {{{ makeDynCall('vii', 'callback') }}}({{{ gpu.BufferMapAsyncStatus.Error }}}, userdata); }); @@ -2349,7 +2349,7 @@ #endif }, - wgpuInstanceRequestAdapter__deps: ['$callUserCallback', '$allocateUTF8'], + wgpuInstanceRequestAdapter__deps: ['$callFromEventLoop', '$allocateUTF8'], wgpuInstanceRequestAdapter: function(instanceId, options, callback, userdata) { {{{ gpu.makeCheck('instanceId === 0, "WGPUInstance is ignored"') }}} @@ -2374,7 +2374,7 @@ {{{ runtimeKeepalivePush() }}} navigator["gpu"]["requestAdapter"](opts).then(function(adapter) { {{{ runtimeKeepalivePop() }}} - callUserCallback(function() { + callFromEventLoop(function() { if (adapter) { var adapterId = WebGPU.mgrAdapter.create(adapter); {{{ makeDynCall('viiii', 'callback') }}}({{{ gpu.RequestAdapterStatus.Success }}}, adapterId, 0, userdata); @@ -2386,7 +2386,7 @@ }); }, function(ex) { {{{ runtimeKeepalivePop() }}} - callUserCallback(function() { + callFromEventLoop(function() { var messagePtr = allocateUTF8(ex.message); {{{ makeDynCall('viiii', 'callback') }}}({{{ gpu.RequestAdapterStatus.Error }}}, 0, messagePtr, userdata); _free(messagePtr); @@ -2428,7 +2428,7 @@ return adapter.features.has(WebGPU.FeatureName[featureEnumValue]); }, - wgpuAdapterRequestDevice__deps: ['$callUserCallback', '$allocateUTF8'], + wgpuAdapterRequestDevice__deps: ['$callFromEventLoop', '$allocateUTF8'], wgpuAdapterRequestDevice: function(adapterId, descriptor, callback, userdata) { var adapter = WebGPU.mgrAdapter.get(adapterId); @@ -2507,14 +2507,14 @@ {{{ runtimeKeepalivePush() }}} adapter["requestDevice"](desc).then(function(device) { {{{ runtimeKeepalivePop() }}} - callUserCallback(function() { + callFromEventLoop(function() { var deviceWrapper = { queueId: WebGPU.mgrQueue.create(device["queue"]) }; var deviceId = WebGPU.mgrDevice.create(device, deviceWrapper); {{{ makeDynCall('viiii', 'callback') }}}({{{ gpu.RequestDeviceStatus.Success }}}, deviceId, 0, userdata); }); }, function(ex) { {{{ runtimeKeepalivePop() }}} - callUserCallback(function() { + callFromEventLoop(function() { var messagePtr = allocateUTF8(ex.message); {{{ makeDynCall('viiii', 'callback') }}}({{{ gpu.RequestDeviceStatus.Error }}}, 0, messagePtr, userdata); _free(messagePtr);
diff --git a/src/library_wget.js b/src/library_wget.js index 35b0a65..edb3307 100644 --- a/src/library_wget.js +++ b/src/library_wget.js
@@ -16,7 +16,7 @@ }, }, - emscripten_async_wget__deps: ['$PATH_FS', '$wget', '$callUserCallback', '$Browser', '$withStackSave'], + emscripten_async_wget__deps: ['$PATH_FS', '$wget', '$callFromEventLoop', '$Browser', '$withStackSave'], emscripten_async_wget__proxy: 'sync', emscripten_async_wget__sig: 'viiii', emscripten_async_wget: function(url, file, onload, onerror) { @@ -28,7 +28,7 @@ function doCallback(callback) { if (callback) { {{{ runtimeKeepalivePop() }}} - callUserCallback(function() { + callFromEventLoop(function() { withStackSave(function() { {{{ makeDynCall('vi', 'callback') }}}(allocateUTF8OnStack(_file)); }); @@ -59,14 +59,14 @@ ); }, - emscripten_async_wget_data__deps: ['$asyncLoad', 'malloc', 'free', '$callUserCallback'], + emscripten_async_wget_data__deps: ['$asyncLoad', 'malloc', 'free', '$callFromEventLoop'], emscripten_async_wget_data__proxy: 'sync', emscripten_async_wget_data__sig: 'viiii', emscripten_async_wget_data: function(url, arg, onload, onerror) { {{{ runtimeKeepalivePush() }}} asyncLoad(UTF8ToString(url), function(byteArray) { {{{ runtimeKeepalivePop() }}} - callUserCallback(function() { + callFromEventLoop(function() { var buffer = _malloc(byteArray.length); HEAPU8.set(byteArray, buffer); {{{ makeDynCall('viii', 'onload') }}}(arg, buffer, byteArray.length); @@ -75,7 +75,7 @@ }, function() { if (onerror) { {{{ runtimeKeepalivePop() }}} - callUserCallback(function() { + callFromEventLoop(function() { {{{ makeDynCall('vi', 'onerror') }}}(arg); }); }
diff --git a/tests/other/metadce/test_metadce_hello_O0.jssize b/tests/other/metadce/test_metadce_hello_O0.jssize index b385b4b..8c63172 100644 --- a/tests/other/metadce/test_metadce_hello_O0.jssize +++ b/tests/other/metadce/test_metadce_hello_O0.jssize
@@ -1 +1 @@ -27528 +27547
diff --git a/tests/other/metadce/test_metadce_minimal_O0.jssize b/tests/other/metadce/test_metadce_minimal_O0.jssize index 2328b45..8c5691e 100644 --- a/tests/other/metadce/test_metadce_minimal_O0.jssize +++ b/tests/other/metadce/test_metadce_minimal_O0.jssize
@@ -1 +1 @@ -22384 +22403
diff --git a/tests/other/test_runtime_keepalive.cpp b/tests/other/test_runtime_keepalive.cpp index a6ef832..7c911d2 100644 --- a/tests/other/test_runtime_keepalive.cpp +++ b/tests/other/test_runtime_keepalive.cpp
@@ -16,7 +16,7 @@ out("runtimeKeepalivePop done"); } counter += 1; - callUserCallback(() => { + callFromEventLoop(() => { out("in user callback: " + counter); }, 0); setTimeout(timerCallback, 0);
diff --git a/tests/other/test_unoptimized_code_size.js.size b/tests/other/test_unoptimized_code_size.js.size index 22f2b3f..26bac5d 100644 --- a/tests/other/test_unoptimized_code_size.js.size +++ b/tests/other/test_unoptimized_code_size.js.size
@@ -1 +1 @@ -84076 +84100
diff --git a/tests/other/test_unoptimized_code_size_strict.js.size b/tests/other/test_unoptimized_code_size_strict.js.size index a6b0329..de617b5 100644 --- a/tests/other/test_unoptimized_code_size_strict.js.size +++ b/tests/other/test_unoptimized_code_size_strict.js.size
@@ -1 +1 @@ -66141 +66143
diff --git a/tests/test_other.py b/tests/test_other.py index dbf447f..3d73ba2 100644 --- a/tests/test_other.py +++ b/tests/test_other.py
@@ -11300,7 +11300,7 @@ def test_runtime_keepalive(self): self.uses_es6 = True - self.set_setting('DEFAULT_LIBRARY_FUNCS_TO_INCLUDE', ['$runtimeKeepalivePush', '$runtimeKeepalivePop', '$callUserCallback']) + self.set_setting('DEFAULT_LIBRARY_FUNCS_TO_INCLUDE', ['$runtimeKeepalivePush', '$runtimeKeepalivePop', '$callFromEventLoop']) self.set_setting('EXIT_RUNTIME') self.do_other_test('test_runtime_keepalive.cpp')