Skip to content

Commit dab8702

Browse files
authored
Extract JSEvents.memcpy helper. NFC (#22846)
I notices that were was a bug here in `emscripten_get_devicemotion_status` and `emscripten_get_deviceorientation_status` where `HEAP32` was used instead of `HEAP8`.
1 parent 989cd48 commit dab8702

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/library_html5.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ var LibraryHTML5 = {
5858
currentEventHandler: null,
5959
#endif
6060
*/
61+
memcpy(target, src, size) {
62+
HEAP8.set(HEAP8.subarray(src, src + size), target);
63+
},
6164

6265
removeAllEventListeners() {
6366
while (JSEvents.eventHandlers.length) {
@@ -594,7 +597,7 @@ var LibraryHTML5 = {
594597
// HTML5 does not really have a polling API for mouse events, so implement one manually by
595598
// returning the data from the most recently received event. This requires that user has registered
596599
// at least some no-op function as an event handler to any of the mouse function.
597-
HEAP8.set(HEAP8.subarray(JSEvents.mouseEvent, JSEvents.mouseEvent + {{{ C_STRUCTS.EmscriptenMouseEvent.__size__ }}}), mouseState);
600+
JSEvents.memcpy(mouseState, JSEvents.mouseEvent, {{{ C_STRUCTS.EmscriptenMouseEvent.__size__ }}});
598601
return {{{ cDefs.EMSCRIPTEN_RESULT_SUCCESS }}};
599602
},
600603

@@ -852,7 +855,7 @@ var LibraryHTML5 = {
852855
// HTML5 does not really have a polling API for device orientation events, so implement one manually by
853856
// returning the data from the most recently received event. This requires that user has registered
854857
// at least some no-op function as an event handler.
855-
HEAP32.set(HEAP32.subarray(JSEvents.deviceOrientationEvent, {{{ C_STRUCTS.EmscriptenDeviceOrientationEvent.__size__ }}}), orientationState);
858+
JSEvents.memcpy(orientationState, JSEvents.deviceOrientationEvent, {{{ C_STRUCTS.EmscriptenDeviceOrientationEvent.__size__ }}});
856859
return {{{ cDefs.EMSCRIPTEN_RESULT_SUCCESS }}};
857860
},
858861

@@ -922,7 +925,7 @@ var LibraryHTML5 = {
922925
// HTML5 does not really have a polling API for device motion events, so implement one manually by
923926
// returning the data from the most recently received event. This requires that user has registered
924927
// at least some no-op function as an event handler.
925-
HEAP32.set(HEAP32.subarray(JSEvents.deviceMotionEvent, {{{ C_STRUCTS.EmscriptenDeviceMotionEvent.__size__ }}}), motionState);
928+
JSEvents.memcpy(motionState, JSEvents.deviceMotionEvent, {{{ C_STRUCTS.EmscriptenDeviceMotionEvent.__size__ }}});
926929
return {{{ cDefs.EMSCRIPTEN_RESULT_SUCCESS }}};
927930
},
928931

0 commit comments

Comments
 (0)