Skip to content

Commit e1ce10d

Browse files
authored
Use single-line JS arrow functions where possible. NFC (#22965)
1 parent 119a427 commit e1ce10d

31 files changed

+81
-127
lines changed

src/library.js

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -393,13 +393,12 @@ addToLibrary({
393393
// Used to implement the native `abort` symbol. Note that we use the
394394
// JavaScript `abort` helper in order to implement this function, but we use a
395395
// distinct name here to avoid confusing the two.
396-
_abort_js: () => {
396+
_abort_js: () =>
397397
#if ASSERTIONS
398-
abort('native code called abort()');
398+
abort('native code called abort()'),
399399
#else
400-
abort('');
400+
abort(''),
401401
#endif
402-
},
403402
#endif
404403

405404
// This object can be modified by the user during startup, which affects
@@ -443,9 +442,8 @@ addToLibrary({
443442
// assert.h
444443
// ==========================================================================
445444

446-
__assert_fail: (condition, filename, line, func) => {
447-
abort(`Assertion failed: ${UTF8ToString(condition)}, at: ` + [filename ? UTF8ToString(filename) : 'unknown filename', line, func ? UTF8ToString(func) : 'unknown function']);
448-
},
445+
__assert_fail: (condition, filename, line, func) =>
446+
abort(`Assertion failed: ${UTF8ToString(condition)}, at: ` + [filename ? UTF8ToString(filename) : 'unknown filename', line, func ? UTF8ToString(func) : 'unknown function']),
449447
#endif
450448

451449
#if STACK_OVERFLOW_CHECK >= 2
@@ -662,9 +660,7 @@ addToLibrary({
662660
$strError: (errno) => errno + '',
663661
#else
664662
$strError__deps: ['strerror', '$UTF8ToString'],
665-
$strError: (errno) => {
666-
return UTF8ToString(_strerror(errno));
667-
},
663+
$strError: (errno) => UTF8ToString(_strerror(errno)),
668664
#endif
669665

670666
#if PROXY_POSIX_SOCKETS == 0
@@ -681,9 +677,8 @@ addToLibrary({
681677
}
682678
return (b[0] | (b[1] << 8) | (b[2] << 16) | (b[3] << 24)) >>> 0;
683679
},
684-
$inetNtop4: (addr) => {
685-
return (addr & 0xff) + '.' + ((addr >> 8) & 0xff) + '.' + ((addr >> 16) & 0xff) + '.' + ((addr >> 24) & 0xff)
686-
},
680+
$inetNtop4: (addr) =>
681+
(addr & 0xff) + '.' + ((addr >> 8) & 0xff) + '.' + ((addr >> 16) & 0xff) + '.' + ((addr >> 24) & 0xff),
687682
$inetPton6__deps: ['htons', '$jstoi_q'],
688683
$inetPton6: (str) => {
689684
var words;
@@ -1724,9 +1719,7 @@ addToLibrary({
17241719
return ___cxa_throw(ex, 0, 0);
17251720
},
17261721

1727-
_Unwind_DeleteException: (ex) => {
1728-
err('TODO: Unwind_DeleteException');
1729-
},
1722+
_Unwind_DeleteException: (ex) => err('TODO: Unwind_DeleteException'),
17301723
#endif
17311724

17321725
// special runtime support
@@ -1743,29 +1736,28 @@ addToLibrary({
17431736
},
17441737
#endif
17451738

1746-
$getExecutableName: () => {
17471739
#if MINIMAL_RUNTIME // MINIMAL_RUNTIME does not have a global runtime variable thisProgram
1740+
$getExecutableName: () => {
17481741
#if ENVIRONMENT_MAY_BE_NODE
17491742
if (ENVIRONMENT_IS_NODE && process.argv.length > 1) {
17501743
return process.argv[1].replace(/\\/g, '/');
17511744
}
17521745
#endif
17531746
return "./this.program";
1747+
},
17541748
#else
1755-
return thisProgram || './this.program';
1749+
$getExecutableName: () => thisProgram || './this.program',
17561750
#endif
1757-
},
17581751

1759-
$listenOnce: (object, event, func) => {
1752+
$listenOnce: (object, event, func) =>
17601753
#if MIN_CHROME_VERSION < 55 || MIN_FIREFOX_VERSION < 50 // https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
17611754
object.addEventListener(event, function handler() {
17621755
func();
17631756
object.removeEventListener(event, handler);
1764-
});
1757+
}),
17651758
#else
1766-
object.addEventListener(event, func, { 'once': true });
1759+
object.addEventListener(event, func, { 'once': true }),
17671760
#endif
1768-
},
17691761

17701762
// Receives a Web Audio context plus a set of elements to listen for user
17711763
// input events on, and registers a context resume() for them. This lets
@@ -1999,9 +1991,7 @@ addToLibrary({
19991991
// Use program_invocation_short_name and program_invocation_name in compiled
20001992
// programs. This function is for implementing them.
20011993
_emscripten_get_progname__deps: ['$getExecutableName', '$stringToUTF8'],
2002-
_emscripten_get_progname: (str, len) => {
2003-
stringToUTF8(getExecutableName(), str, len);
2004-
},
1994+
_emscripten_get_progname: (str, len) => stringToUTF8(getExecutableName(), str, len),
20051995

20061996
emscripten_console_log: (str) => {
20071997
#if ASSERTIONS

src/library_browser.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -738,9 +738,7 @@ var LibraryBrowser = {
738738
},
739739

740740
emscripten_set_canvas_size__proxy: 'sync',
741-
emscripten_set_canvas_size: (width, height) => {
742-
Browser.setCanvasSize(width, height);
743-
},
741+
emscripten_set_canvas_size: (width, height) => Browser.setCanvasSize(width, height),
744742

745743
emscripten_get_canvas_size__proxy: 'sync',
746744
emscripten_get_canvas_size: (width, height, isFullscreen) => {

src/library_egl.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,13 @@ var LibraryEGL = {
146146

147147
// EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigs(EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config);
148148
eglGetConfigs__proxy: 'sync',
149-
eglGetConfigs: (display, configs, config_size, numConfigs) => {
150-
return EGL.chooseConfig(display, 0, configs, config_size, numConfigs);
151-
},
149+
eglGetConfigs: (display, configs, config_size, numConfigs) =>
150+
EGL.chooseConfig(display, 0, configs, config_size, numConfigs),
152151

153152
// EGLAPI EGLBoolean EGLAPIENTRY eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config);
154153
eglChooseConfig__proxy: 'sync',
155-
eglChooseConfig: (display, attrib_list, configs, config_size, numConfigs) => {
156-
return EGL.chooseConfig(display, attrib_list, configs, config_size, numConfigs);
157-
},
154+
eglChooseConfig: (display, attrib_list, configs, config_size, numConfigs) =>
155+
EGL.chooseConfig(display, attrib_list, configs, config_size, numConfigs),
158156

159157
// EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value);
160158
eglGetConfigAttrib__proxy: 'sync',

src/library_eventloop.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -515,14 +515,10 @@ LibraryJSEventLoop = {
515515
},
516516

517517
emscripten_pause_main_loop__deps: ['$MainLoop'],
518-
emscripten_pause_main_loop: () => {
519-
MainLoop.pause();
520-
},
518+
emscripten_pause_main_loop: () => MainLoop.pause(),
521519

522520
emscripten_resume_main_loop__deps: ['$MainLoop'],
523-
emscripten_resume_main_loop: () => {
524-
MainLoop.resume();
525-
},
521+
emscripten_resume_main_loop: () => MainLoop.resume(),
526522

527523
_emscripten_push_main_loop_blocker__deps: ['$MainLoop'],
528524
_emscripten_push_main_loop_blocker: (func, arg, name) => {

src/library_html5.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -914,9 +914,8 @@ var LibraryHTML5 = {
914914

915915
emscripten_set_devicemotion_callback_on_thread__proxy: 'sync',
916916
emscripten_set_devicemotion_callback_on_thread__deps: ['$registerDeviceMotionEventCallback'],
917-
emscripten_set_devicemotion_callback_on_thread: (userData, useCapture, callbackfunc, targetThread) => {
918-
return registerDeviceMotionEventCallback({{{ cDefs.EMSCRIPTEN_EVENT_TARGET_WINDOW }}}, userData, useCapture, callbackfunc, {{{ cDefs.EMSCRIPTEN_EVENT_DEVICEMOTION }}}, "devicemotion", targetThread);
919-
},
917+
emscripten_set_devicemotion_callback_on_thread: (userData, useCapture, callbackfunc, targetThread) =>
918+
registerDeviceMotionEventCallback({{{ cDefs.EMSCRIPTEN_EVENT_TARGET_WINDOW }}}, userData, useCapture, callbackfunc, {{{ cDefs.EMSCRIPTEN_EVENT_DEVICEMOTION }}}, "devicemotion", targetThread),
920919

921920
emscripten_get_devicemotion_status__proxy: 'sync',
922921
emscripten_get_devicemotion_status__deps: ['$JSEvents'],

src/library_html5_webgl.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -444,9 +444,8 @@ var LibraryHtml5WebGL = {
444444
},
445445

446446
emscripten_is_webgl_context_lost__proxy: 'sync_on_webgl_context_handle_thread',
447-
emscripten_is_webgl_context_lost: (contextHandle) => {
448-
return !GL.contexts[contextHandle] || GL.contexts[contextHandle].GLctx.isContextLost(); // No context ~> lost context.
449-
},
447+
emscripten_is_webgl_context_lost: (contextHandle) =>
448+
!GL.contexts[contextHandle] || GL.contexts[contextHandle].GLctx.isContextLost(), // No context ~> lost context.
450449

451450
emscripten_webgl_get_supported_extensions__proxy: 'sync_on_current_webgl_context_thread',
452451
emscripten_webgl_get_supported_extensions__deps: ['$stringToNewUTF8'],

src/library_sdl.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2936,9 +2936,7 @@ var LibrarySDL = {
29362936
},
29372937
29382938
Mix_VolumeMusic__proxy: 'sync',
2939-
Mix_VolumeMusic: (volume) => {
2940-
return SDL.setGetVolume(SDL.music, volume);
2941-
},
2939+
Mix_VolumeMusic: (volume) => SDL.setGetVolume(SDL.music, volume),
29422940
29432941
Mix_LoadMUS_RW__deps: ['Mix_LoadWAV_RW'],
29442942
Mix_LoadMUS_RW: (filename) => _Mix_LoadWAV_RW(filename, 0),
@@ -3019,9 +3017,7 @@ var LibrarySDL = {
30193017
Mix_FadeOutMusic: 'Mix_HaltMusic', // XXX ignore fading out effect
30203018
30213019
Mix_PlayingMusic__proxy: 'sync',
3022-
Mix_PlayingMusic: () => {
3023-
return (SDL.music.audio && !SDL.music.audio.paused) ? 1 : 0;
3024-
},
3020+
Mix_PlayingMusic: () => (SDL.music.audio && !SDL.music.audio.paused),
30253021
30263022
// http://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer_38.html#SEC38
30273023
// "Note: Does not check if the channel has been paused."
@@ -3346,9 +3342,8 @@ var LibrarySDL = {
33463342
},
33473343

33483344
SDL_GL_SwapBuffers__proxy: 'sync',
3349-
SDL_GL_SwapBuffers: () => {
3350-
Browser.doSwapBuffers?.(); // in workers, this is used to send out a buffered frame
3351-
},
3345+
// in workers, this is used to send out a buffered frame
3346+
SDL_GL_SwapBuffers: () => Browser.doSwapBuffers?.(),
33523347

33533348
// SDL 2
33543349

@@ -3382,9 +3377,7 @@ var LibrarySDL = {
33823377
},
33833378

33843379
SDL_GL_SetSwapInterval__deps: ['emscripten_set_main_loop_timing'],
3385-
SDL_GL_SetSwapInterval: (state) => {
3386-
_emscripten_set_main_loop_timing({{{ cDefs.EM_TIMING_RAF }}}, state);
3387-
},
3380+
SDL_GL_SetSwapInterval: (state) => _emscripten_set_main_loop_timing({{{ cDefs.EM_TIMING_RAF }}}, state),
33883381

33893382
SDL_SetWindowTitle__proxy: 'sync',
33903383
SDL_SetWindowTitle: (window, title) => {

src/library_sockfs.js

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -754,27 +754,21 @@ addToLibrary({
754754
SOCKFS.on(event, callback ? _callback : null);
755755
},
756756
emscripten_set_socket_error_callback__deps: ['$_setNetworkCallback'],
757-
emscripten_set_socket_error_callback: (userData, callback) => {
758-
_setNetworkCallback('error', userData, callback);
759-
},
757+
emscripten_set_socket_error_callback: (userData, callback) =>
758+
_setNetworkCallback('error', userData, callback),
760759
emscripten_set_socket_open_callback__deps: ['$_setNetworkCallback'],
761-
emscripten_set_socket_open_callback: (userData, callback) => {
762-
_setNetworkCallback('open', userData, callback);
763-
},
760+
emscripten_set_socket_open_callback: (userData, callback) =>
761+
_setNetworkCallback('open', userData, callback),
764762
emscripten_set_socket_listen_callback__deps: ['$_setNetworkCallback'],
765-
emscripten_set_socket_listen_callback: (userData, callback) => {
766-
_setNetworkCallback('listen', userData, callback);
767-
},
763+
emscripten_set_socket_listen_callback: (userData, callback) =>
764+
_setNetworkCallback('listen', userData, callback),
768765
emscripten_set_socket_connection_callback__deps: ['$_setNetworkCallback'],
769-
emscripten_set_socket_connection_callback: (userData, callback) => {
770-
_setNetworkCallback('connection', userData, callback);
771-
},
766+
emscripten_set_socket_connection_callback: (userData, callback) =>
767+
_setNetworkCallback('connection', userData, callback),
772768
emscripten_set_socket_message_callback__deps: ['$_setNetworkCallback'],
773-
emscripten_set_socket_message_callback: (userData, callback) => {
774-
_setNetworkCallback('message', userData, callback);
775-
},
769+
emscripten_set_socket_message_callback: (userData, callback) =>
770+
_setNetworkCallback('message', userData, callback),
776771
emscripten_set_socket_close_callback__deps: ['$_setNetworkCallback'],
777-
emscripten_set_socket_close_callback: (userData, callback) => {
778-
_setNetworkCallback('close', userData, callback);
779-
}
772+
emscripten_set_socket_close_callback: (userData, callback) =>
773+
_setNetworkCallback('close', userData, callback),
780774
});

src/library_strings.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,7 @@ addToLibrary({
383383

384384
// Returns the number of bytes the given Javascript string takes if encoded as
385385
// a UTF16 byte array, EXCLUDING the null terminator byte.
386-
$lengthBytesUTF16: (str) => {
387-
return str.length*2;
388-
},
386+
$lengthBytesUTF16: (str) => str.length*2,
389387

390388
$UTF32ToString: (ptr, maxBytesToRead) => {
391389
#if ASSERTIONS

src/library_syscall.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -821,9 +821,7 @@ var SyscallsLibrary = {
821821
},
822822
__syscall_fadvise64__nothrow: true,
823823
__syscall_fadvise64__proxy: 'none',
824-
__syscall_fadvise64: (fd, offset, len, advice) => {
825-
return 0; // your advice is important to us (but we can't use it)
826-
},
824+
__syscall_fadvise64: (fd, offset, len, advice) => 0,
827825
__syscall_openat__deps: ['$syscallGetVarargI'],
828826
__syscall_openat: (dirfd, path, flags, varargs) => {
829827
path = SYSCALLS.getStr(path);

0 commit comments

Comments
 (0)