Skip to content

Commit 6a82b9b

Browse files
committed
Merge branch 'main' into always-bulkmem
2 parents 48c1f06 + f0cc3d0 commit 6a82b9b

File tree

6 files changed

+54
-7
lines changed

6 files changed

+54
-7
lines changed

src/library_sdl.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -823,13 +823,16 @@ var LibrarySDL = {
823823

824824
lookupKeyCodeForEvent(event) {
825825
var code = event.keyCode;
826-
if (code >= 65 && code <= 90) {
826+
if (code >= 65 && code <= 90) { // ASCII A-Z
827827
code += 32; // make lowercase for SDL
828828
} else {
829+
// Look up DOM code in the keyCodes table with fallback for ASCII codes
830+
// which can match between DOM codes and SDL keycodes (allows keyCodes
831+
// to be smaller).
832+
code = SDL.keyCodes[code] || (code < 128 ? code : 0);
829833
#if RUNTIME_DEBUG
830-
if (!(event.keyCode in SDL.keyCodes)) dbg('unknown keyCode: ', event.keyCode);
834+
if (!code) dbg('unmapped keyCode: ', event.keyCode);
831835
#endif
832-
code = SDL.keyCodes[event.keyCode] || event.keyCode;
833836
// If this is one of the modifier keys (224 | 1<<10 - 227 | 1<<10), and the event specifies that it is
834837
// a right key, add 4 to get the right key SDL key code.
835838
if (event.location === 2 /*KeyboardEvent.DOM_KEY_LOCATION_RIGHT*/ && code >= (224 | 1<<10) && code <= (227 | 1<<10)) {
@@ -854,6 +857,8 @@ var LibrarySDL = {
854857
case 'keyup': {
855858
var down = event.type === 'keydown';
856859
var code = SDL.lookupKeyCodeForEvent(event);
860+
// Ignore key events that we don't (yet) map to SDL keys
861+
if (!code) return;
857862
#if !SAFE_HEAP
858863
// Assigning a boolean to HEAP8, that's alright but Closure would like to warn about it.
859864
// TODO(https://github.com/emscripten-core/emscripten/issues/16311):
@@ -938,6 +943,8 @@ var LibrarySDL = {
938943
dbg(`received ${event.type} event: keyCode=${event.keyCode}, key=${event.key}, code=${event.code}`);
939944
#endif
940945
var key = SDL.lookupKeyCodeForEvent(event);
946+
// Ignore key events that we don't (yet) map to SDL keys
947+
if (!key) return false;
941948
var scan;
942949
if (key >= 1024) {
943950
scan = key - 1024;

system/include/emscripten/bind.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,13 @@ struct SignatureCode<size_t> {
607607
}
608608
};
609609

610+
template<>
611+
struct SignatureCode<long long> {
612+
static constexpr char get() {
613+
return 'j';
614+
}
615+
};
616+
610617
#ifdef __wasm64__
611618
template<>
612619
struct SignatureCode<long> {
@@ -629,6 +636,8 @@ template<> struct SignatureTranslator<double> { using type = double; };
629636
#ifdef __wasm64__
630637
template<> struct SignatureTranslator<long> { using type = long; };
631638
#endif
639+
template<> struct SignatureTranslator<long long> { using type = long long; };
640+
template<> struct SignatureTranslator<unsigned long long> { using type = long long; };
632641
template<> struct SignatureTranslator<size_t> { using type = size_t; };
633642
template<typename PtrType>
634643
struct SignatureTranslator<PtrType*> { using type = void*; };

test/browser/test_sdl_key.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ int main(int argc, char **argv) {
7272

7373
emscripten_set_main_loop(one, 0, 0);
7474

75-
EM_ASM({keydown(1250);keydown(38);keyup(38);keyup(1250);}); // alt, up
76-
EM_ASM({keydown(1248);keydown(1249);keydown(40);keyup(40);keyup(1249);keyup(1248);}); // ctrl, shift, down
75+
EM_ASM({keydown(18);keydown(38);keyup(38);keyup(18);}); // alt, up
76+
EM_ASM({keydown(17);keydown(16);keydown(40);keyup(40);keyup(16);keyup(17);}); // ctrl, shift, down
7777
EM_ASM({keydown(37);keyup(37);}); // left
7878
EM_ASM({keydown(39);keyup(39);}); // right
7979

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <cstdint>
2+
#include <emscripten.h>
3+
#include <emscripten/bind.h>
4+
5+
int64_t getInt64() {
6+
return 1000000000000;
7+
}
8+
9+
uint64_t getUint64() {
10+
return -1000000000000;
11+
}
12+
13+
int main() {
14+
EM_ASM(
15+
console.log(Module.getInt64());
16+
console.log(Module.getUint64());
17+
);
18+
}
19+
20+
EMSCRIPTEN_BINDINGS(my_module) {
21+
emscripten::function("getInt64", &getInt64);
22+
emscripten::function("getUint64", &getUint64);
23+
}

test/test_browser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -990,8 +990,8 @@ def post():
990990
html = html.replace('</body>', '''
991991
<script src='fake_events.js'></script>
992992
<script>
993-
simulateKeyDown(1250);simulateKeyDown(38);simulateKeyUp(38);simulateKeyUp(1250); // alt, up
994-
simulateKeyDown(1248);simulateKeyDown(1249);simulateKeyDown(40);simulateKeyUp(40);simulateKeyUp(1249);simulateKeyUp(1248); // ctrl, shift, down
993+
simulateKeyDown(18);simulateKeyDown(38);simulateKeyUp(38);simulateKeyUp(18); // alt, up
994+
simulateKeyDown(17);simulateKeyDown(16);simulateKeyDown(40);simulateKeyUp(40);simulateKeyUp(16);simulateKeyUp(17); // ctrl, shift, down
995995
simulateKeyDown(37);simulateKeyUp(37); // left
996996
simulateKeyDown(39);simulateKeyUp(39); // right
997997
simulateKeyDown(65);simulateKeyUp(65); // a

test/test_other.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3320,6 +3320,14 @@ def test_embind_return_value_policy(self):
33203320

33213321
self.do_runf('embind/test_return_value_policy.cpp')
33223322

3323+
@parameterized({
3324+
'': [[]],
3325+
'asyncify': [['-sASYNCIFY=1']]
3326+
})
3327+
def test_embind_long_long(self, args):
3328+
self.do_runf('embind/test_embind_long_long.cpp', '1000000000000n\n-1000000000000n',
3329+
emcc_args=['-lembind', '-sWASM_BIGINT'] + args)
3330+
33233331
@requires_jspi
33243332
@parameterized({
33253333
'': [['-sJSPI_EXPORTS=async*']],

0 commit comments

Comments
 (0)