42 Commits

Author SHA1 Message Date
Laytan Laats
8ce30dbb72 sys/wasm/js: fix vet error 2025-12-22 16:56:56 +01:00
Laytan Laats
06076e02c0 js: improve warning about conflicting memory strategies 2025-12-21 17:02:41 +01:00
Courtney Strachan
e724b23aac Fix #5843 2025-10-23 03:18:03 -04:00
xenobas
3edf964b55 Fix #5225 wasm odin.js undefined this.mem 2025-10-05 20:18:41 +01:00
Bailey Gibbons
26d066d369 Add add/remove_document_event_listener() to core:sys/wasm/js 2025-08-22 15:34:50 +10:00
Alex Riedl
277c6cac71 Fix some webgl bindings 2025-08-09 10:47:07 -05:00
Alexander Lunsford
edba218a7c Simplified function call to loadCstringDirect 2025-05-30 20:02:08 -05:00
Alexander Lunsford
9d223e178b Fix odin.js loadCstring to use pointer address correctly. 2025-05-30 19:50:34 -05:00
Jonathan Tron
1b5e83bfb6 Prevent odin.js from printing empty line in the console for the ending "\n" 2025-03-26 21:58:58 +01:00
Laytan Laats
73fd564634 fix tabs 2025-03-21 23:02:00 +01:00
Jonathan Tron
2bccd07426 Prevent registering the same event listener twice on the same element with the exact same data in wasm. 2025-03-21 09:38:23 +01:00
Jonathan Tron
dbe53d053a Fix add/remove event listeners in core:sys/wasm
There were multiple issues here:

1. listeners stored in the same key overwriting the previous one
2. missing `use_capture` parameter in `remove_event_listener`/`remove_window_event_listener`

The key used to store the listener function in `listenerMap` was a
javascript `Object`, when used as a key it was thus serialized to
the string `"[object Object]"`, meaning all listeners where effectively
set to the same key when calling `add_event_listener`/`add_window_event_listener`.
Later on when calling `remove_event_listener`/`remove_window_event_listener`,
it then tried to remove the incorrect one or none at all if there was a
mix of the same event name registered on an element or the window.

To fix I implemented a function `listener_key` in the javascript code
which will generate a different key based on the event's:
- `id`: dom element's id or 'window' (when event listener added to the
  window)
- `name`: the event name (eg: `click`), each event handler should be
  removed for the event name it was register on.
- `data`: we can register events with different data, each one generate
  a new listener which has to be removed.
- `callback`: same as `data`, if you register two similar handler but
  with two different callback, each one should be removed.
- `useCapture`: this one is a bit tricky, but when you register an event
  handler in javascript, if you don't pass `useCapture`, it defaults to `false`.
  When you remove an handler, you have to pass the exact same
  `useCapture` option you registered it with. In this case, we allowed
  to register an event with different `useCapture`, but didn't allow to
  pass the `useCapture` when removing it. We always called `removeEventListener`
  without the `useCapture` parameter which removed the handler properly
  only when it was registered with `useCapture=false`.

I also switched the `WasmMemoryInterface.listenerMap` from `{}`
(javascript object) to a `new Map()`, which is available everywhere
nowadays.
2025-03-20 16:43:49 +01:00
gingerBill
408b3af550 Merge pull request #4933 from laytan/js-open-binding
core/sys/wasm/js: add `open` binding to `window.open`
2025-03-13 09:22:20 +00:00
gingerBill
35340de928 Merge pull request #4932 from laytan/js-pointer-event-and-charcode
core/sys/wasm/js: add pointer event info and add charCode to keyboard
2025-03-13 09:22:03 +00:00
gingerBill
5a12190f51 Merge pull request #4931 from laytan/webgl-improvements
webgl: add `BlendEquationSeparate` and `GetParameter4i`
2025-03-13 09:21:44 +00:00
Laytan Laats
6691acfa03 core/sys/wasm/js: add open binding to window.open 2025-03-12 18:43:03 +01:00
Laytan Laats
b76fd84084 webgl: add BlendEquationSeparate and GetParameter4i
`GetParameter4i` can be used to retrieve the current scissor rect, or
the curent viewport, which was previously impossible.

Also adds `BlendEquationSeparate` which seemed to be missing.

Also removes an instance of `do`.
2025-03-12 18:39:57 +01:00
Laytan Laats
00ac48c06c core/sys/wasm/js: add pointer event info and add charCode to keyboard events 2025-03-12 18:37:42 +01:00
Laytan Laats
d349c96071 core/sys/wasm/js: improve gamepad API
1. Properly set `id` and `mapping` on the `get_gamepad_state` result
2. Increase `id` limit to 96 bytes, connecting my DualShock 4 made it crash
3. If an `id` or `mapping` is longer than the limits, slice it and add `...`
2025-03-12 18:32:51 +01:00
Laytan Laats
1511162b0a webgpu: fix cstring as parameter not loading correctly 2025-01-09 17:29:31 +01:00
p2jason
2beb495140 Increase size of JS keyboard event key/code buffer size 2024-11-12 13:37:08 +13:00
Laytan
7cfaf0b181 Merge pull request #4415 from p2jason/master
Remove the event queue from odin.js and directly invoke callbacks so they are executed in context where prevent default is possible
2024-11-01 19:48:36 +01:00
p2jason
94acfaf21e Removed event hook callback from add_*_event_listener functions 2024-10-31 13:15:39 +00:00
p2jason
e825326d73 Removed event queue from add_*_event_listener JS functions and added event hook callback 2024-10-31 13:02:46 +00:00
Laytan Laats
bd38b4839c sys/wasm/js: add set_element_style 2024-10-26 22:41:14 +02:00
p2jason
cf89526a9f Changed boolean parameters to bit set in the add_*_event_listener functions 2024-10-25 12:45:24 +01:00
p2jason
8371995bfc Added parameters to the add_*_event_listener JS functions for stopping event behavior 2024-10-24 23:27:40 +01:00
gingerBill
4a616d97df Pass delta time instead of current time to odin.js step 2024-09-29 10:14:56 +01:00
gingerBill
95721fe296 Add gamepad support 2024-09-22 19:29:05 +01:00
gingerBill
66e83ef30d Add gamepad events 2024-09-22 16:24:46 +01:00
gingerBill
94288161e9 Add new js events 2024-09-22 15:52:04 +01:00
gingerBill
634fa7aa30 Move vendor:wasm/js to core:sys/wasm/js 2024-09-22 13:13:34 +01:00
Karl Zylinski
19f0127e55 Moved all packages in core, base, vendor, tests and examples to use new #+ file tag syntax. 2024-09-14 18:27:49 +02:00
Laytan Laats
a2cd763dbb time: wasi implementation 2024-08-10 23:01:31 +02:00
gingerBill
9f9abb8fb3 Use union #shared_nil for os.Error 2024-08-04 11:05:30 +01:00
Laytan Laats
4e18e1b191 wasi: make os.open work with absolute paths 2024-07-02 15:29:24 +02:00
gingerBill
c1eb536726 Change to "contextless" from "c"` 2023-05-29 23:30:48 +01:00
gingerBill
220dfd7440 Minor clean up of wasi_api.odin 2022-07-25 17:00:32 +01:00
gingerBill
c13c30b466 Update wasi to use string and slice types 2021-10-31 15:21:39 +00:00
gingerBill
0c1675c8b0 Correct string usage 2021-10-31 15:01:13 +00:00
gingerBill
906c7ef0fc Correct wasi linking 2021-10-31 13:04:28 +00:00
gingerBill
c6e08b059b Move sys/wasi to sys/wasm/wasi 2021-10-31 12:30:10 +00:00