Skip to content

Commit a8f0eb4

Browse files
castholmslouken
authored andcommitted
emscripten: Don't use legacy JS library functions for assertions
(cherry picked from commit 54f5b73)
1 parent 069eb01 commit a8f0eb4

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

src/SDL_assert.c

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,7 @@
4242
#endif
4343

4444
#if defined(__EMSCRIPTEN__)
45-
#include <emscripten.h>
46-
/* older Emscriptens don't have this, but we need to for wasm64 compatibility. */
47-
#ifndef MAIN_THREAD_EM_ASM_PTR
48-
#ifdef __wasm64__
49-
#error You need to upgrade your Emscripten compiler to support wasm64
50-
#else
51-
#define MAIN_THREAD_EM_ASM_PTR MAIN_THREAD_EM_ASM_INT
52-
#endif
53-
#endif
45+
#include <emscripten.h>
5446
#endif
5547

5648
/* The size of the stack buffer to use for rendering assert messages. */
@@ -259,34 +251,39 @@ static SDL_assert_state SDLCALL SDL_PromptAssertion(const SDL_assert_data *data,
259251
for (;;) {
260252
SDL_bool okay = SDL_TRUE;
261253
/* *INDENT-OFF* */ /* clang-format off */
262-
char *buf = (char *) MAIN_THREAD_EM_ASM_PTR({
254+
int reply = MAIN_THREAD_EM_ASM_INT({
263255
var str =
264256
UTF8ToString($0) + '\n\n' +
265257
'Abort/Retry/Ignore/AlwaysIgnore? [ariA] :';
266258
var reply = window.prompt(str, "i");
267259
if (reply === null) {
268260
reply = "i";
269261
}
270-
return allocate(intArrayFromString(reply), 'i8', ALLOC_NORMAL);
262+
return reply.length === 1 ? reply.charCodeAt(0) : -1;
271263
}, message);
272264
/* *INDENT-ON* */ /* clang-format on */
273265

274-
if (SDL_strcmp(buf, "a") == 0) {
266+
switch (reply) {
267+
case 'a':
275268
state = SDL_ASSERTION_ABORT;
276269
#if 0 /* (currently) no break functionality on Emscripten */
277-
} else if (SDL_strcmp(buf, "b") == 0) {
270+
case 'b':
278271
state = SDL_ASSERTION_BREAK;
272+
break;
279273
#endif
280-
} else if (SDL_strcmp(buf, "r") == 0) {
274+
case 'r':
281275
state = SDL_ASSERTION_RETRY;
282-
} else if (SDL_strcmp(buf, "i") == 0) {
276+
break;
277+
case 'i':
283278
state = SDL_ASSERTION_IGNORE;
284-
} else if (SDL_strcmp(buf, "A") == 0) {
279+
break;
280+
case 'A':
285281
state = SDL_ASSERTION_ALWAYS_IGNORE;
286-
} else {
282+
break;
283+
default:
287284
okay = SDL_FALSE;
285+
break;
288286
}
289-
free(buf);
290287

291288
if (okay) {
292289
break;

0 commit comments

Comments
 (0)