diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-06-05 08:37:34 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-06-05 08:37:34 +0200 |
| commit | 52c74a1c33ce12b93ec5830f5a6348d9578c7c6e (patch) | |
| tree | e763fa21a5bc057b36a42af8caa9766bb1cfd8b3 /web/callback.js | |
| parent | 57f194ef57e393d84e2d3c73115ec528e02ea3c9 (diff) | |
| download | nissy-core-52c74a1c33ce12b93ec5830f5a6348d9578c7c6e.tar.gz nissy-core-52c74a1c33ce12b93ec5830f5a6348d9578c7c6e.zip | |
Simplify callback business (web version)
Diffstat (limited to 'web/callback.js')
| -rw-r--r-- | web/callback.js | 52 |
1 files changed, 0 insertions, 52 deletions
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 @@ | |||
| 1 | addToLibrary({ | ||
| 2 | |||
| 3 | cbfl: [], | ||
| 4 | |||
| 5 | validateCallbackId__deps: [ 'cbfl' ], | ||
| 6 | validateCallbackId: function(i) { | ||
| 7 | if (i < 0) { | ||
| 8 | console.log("--- WARNING ---"); | ||
| 9 | console.log("Trying to access callback function of invalid id " + i); | ||
| 10 | console.log("--- WARNING ---"); | ||
| 11 | return false; | ||
| 12 | } | ||
| 13 | |||
| 14 | if (i >= _cbfl.length) { | ||
| 15 | console.log("--- WARNING ---"); | ||
| 16 | console.log("Trying to access callback function " + i + ", but only " | ||
| 17 | + _cbfl.length + " have been registered. This may be caused by a " | ||
| 18 | + "call outside of the main thread."); | ||
| 19 | console.log("--- WARNING ---"); | ||
| 20 | return false; | ||
| 21 | } | ||
| 22 | |||
| 23 | return true; | ||
| 24 | }, | ||
| 25 | |||
| 26 | addCallbackFunction__deps: [ 'cbfl' ], | ||
| 27 | addCallbackFunction: function(f) { | ||
| 28 | _cbfl.push(f) | ||
| 29 | return _cbfl.length - 1 | ||
| 30 | }, | ||
| 31 | |||
| 32 | callFunction__deps: [ 'cbfl', 'validateCallbackId' ], | ||
| 33 | callFunction: function(id, arg) { | ||
| 34 | // This is a workaround related to usign WASM64 | ||
| 35 | // JavaScript's UTF8ToString expects a pointer argument, which for JS is | ||
| 36 | // of type "number", but WASM64 is passing a BigInt. See also: | ||
| 37 | // https://github.com/emscripten-core/emscripten/issues/21541 | ||
| 38 | // (but I could not make the suggested solution work in this case). | ||
| 39 | // TODO: check if there is a better workaround. | ||
| 40 | const non64_arg = Number(arg); | ||
| 41 | if (_validateCallbackId(id)) | ||
| 42 | _cbfl[id](UTF8ToString(non64_arg)); | ||
| 43 | }, | ||
| 44 | |||
| 45 | callFunctionInt__deps: [ 'cbfl', 'validateCallbackId' ], | ||
| 46 | callFunctionInt: function(id) { | ||
| 47 | if (_validateCallbackId(id)) | ||
| 48 | return _cbfl[id](); | ||
| 49 | return 0; | ||
| 50 | }, | ||
| 51 | |||
| 52 | }); | ||
