aboutsummaryrefslogtreecommitdiff
path: root/web/callback.js
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2025-06-05 08:37:34 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2025-06-05 08:37:34 +0200
commit52c74a1c33ce12b93ec5830f5a6348d9578c7c6e (patch)
treee763fa21a5bc057b36a42af8caa9766bb1cfd8b3 /web/callback.js
parent57f194ef57e393d84e2d3c73115ec528e02ea3c9 (diff)
downloadnissy-core-52c74a1c33ce12b93ec5830f5a6348d9578c7c6e.tar.gz
nissy-core-52c74a1c33ce12b93ec5830f5a6348d9578c7c6e.zip
Simplify callback business (web version)
Diffstat (limited to '')
-rw-r--r--web/callback.js52
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 @@
1addToLibrary({
2
3cbfl: [],
4
5validateCallbackId__deps: [ 'cbfl' ],
6validateCallbackId: 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
26addCallbackFunction__deps: [ 'cbfl' ],
27addCallbackFunction: function(f) {
28 _cbfl.push(f)
29 return _cbfl.length - 1
30},
31
32callFunction__deps: [ 'cbfl', 'validateCallbackId' ],
33callFunction: 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
45callFunctionInt__deps: [ 'cbfl', 'validateCallbackId' ],
46callFunctionInt: function(id) {
47 if (_validateCallbackId(id))
48 return _cbfl[id]();
49 return 0;
50},
51
52});

Generated with cgit - Back to sebastiano.tronto.net