From 52c74a1c33ce12b93ec5830f5a6348d9578c7c6e Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Thu, 5 Jun 2025 08:37:34 +0200 Subject: Simplify callback business (web version) --- web/callback.js | 52 ---------------------------------------------------- 1 file changed, 52 deletions(-) delete mode 100644 web/callback.js (limited to 'web/callback.js') diff --git a/web/callback.js b/web/callback.js deleted file mode 100644 index e277cf5..0000000 --- a/web/callback.js +++ /dev/null @@ -1,52 +0,0 @@ -addToLibrary({ - -cbfl: [], - -validateCallbackId__deps: [ 'cbfl' ], -validateCallbackId: function(i) { - if (i < 0) { - console.log("--- WARNING ---"); - console.log("Trying to access callback function of invalid id " + i); - console.log("--- WARNING ---"); - return false; - } - - if (i >= _cbfl.length) { - console.log("--- WARNING ---"); - console.log("Trying to access callback function " + i + ", but only " - + _cbfl.length + " have been registered. This may be caused by a " - + "call outside of the main thread."); - console.log("--- WARNING ---"); - return false; - } - - return true; -}, - -addCallbackFunction__deps: [ 'cbfl' ], -addCallbackFunction: function(f) { - _cbfl.push(f) - return _cbfl.length - 1 -}, - -callFunction__deps: [ 'cbfl', 'validateCallbackId' ], -callFunction: function(id, arg) { - // This is a workaround related to usign WASM64 - // JavaScript's UTF8ToString expects a pointer argument, which for JS is - // of type "number", but WASM64 is passing a BigInt. See also: - // https://github.com/emscripten-core/emscripten/issues/21541 - // (but I could not make the suggested solution work in this case). - // TODO: check if there is a better workaround. - const non64_arg = Number(arg); - if (_validateCallbackId(id)) - _cbfl[id](UTF8ToString(non64_arg)); -}, - -callFunctionInt__deps: [ 'cbfl', 'validateCallbackId' ], -callFunctionInt: function(id) { - if (_validateCallbackId(id)) - return _cbfl[id](); - return 0; -}, - -}); -- cgit v1.3