Skip to content

Commit 980af85

Browse files
authored
Consistent use of arrow functions in JS library code. NFC (#22807)
1 parent c0575ef commit 980af85

File tree

8 files changed

+21
-24
lines changed

8 files changed

+21
-24
lines changed

src/library.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1561,7 +1561,7 @@ addToLibrary({
15611561

15621562
emscripten_has_asyncify: () => {{{ ASYNCIFY }}},
15631563

1564-
emscripten_debugger: function() { debugger },
1564+
emscripten_debugger: () => { debugger },
15651565

15661566
emscripten_print_double__deps: ['$stringToUTF8', '$lengthBytesUTF8'],
15671567
emscripten_print_double: (x, to, max) => {

src/library_async.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ addToLibrary({
632632
emscripten_scan_registers: (func) => {
633633
throw 'Please compile your program with async support in order to use asynchronous operations like emscripten_scan_registers';
634634
},
635-
emscripten_fiber_swap: function(oldFiber, newFiber) {
635+
emscripten_fiber_swap: (oldFiber, newFiber) => {
636636
throw 'Please compile your program with async support in order to use asynchronous operations like emscripten_fiber_swap';
637637
},
638638
#endif // ASYNCIFY

src/library_bootstrap.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ assert(Object.keys(LibraryManager.library).length === 0);
1515
addToLibrary({
1616
$callRuntimeCallbacks: () => {},
1717

18-
$ExitStatus__docs: '/** @constructor */',
19-
$ExitStatus: function(status) {
20-
this.name = 'ExitStatus';
21-
this.message = 'Program terminated with exit(' + status + ')';
22-
this.status = status;
18+
$ExitStatus: class {
19+
name = 'ExitStatus';
20+
constructor(status) {
21+
this.message = `Program terminated with exit(${status})`;
22+
this.status = status;
23+
}
2324
},
2425

2526
$exitJS__deps: ['$ExitStatus'],

src/library_fs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ addToLibrary({
3131
'$strError', '$ERRNO_CODES',
3232
#endif
3333
],
34-
$FS__postset: function() {
34+
$FS__postset: () => {
3535
// TODO: do we need noFSInit?
3636
addAtInit(`
3737
if (!Module['noFSInit'] && !FS.initialized)

src/library_legacy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ legacyFuncs = {
122122
#endif
123123

124124
$stackTrace__deps: ['$jsStackTrace'],
125-
$stackTrace: function() {
125+
$stackTrace: () => {
126126
var js = jsStackTrace();
127127
if (Module['extraStackTrace']) js += '\n' + Module['extraStackTrace']();
128128
return js;

src/library_stack_trace.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@
55
*/
66

77
var LibraryStackTrace = {
8-
$jsStackTrace: function() {
9-
return new Error().stack.toString();
10-
},
8+
$jsStackTrace: () => new Error().stack.toString(),
119

1210
$getCallstack__deps: ['$jsStackTrace', '$warnOnce'],
1311
$getCallstack__docs: '/** @param {number=} flags */',
14-
$getCallstack: function(flags) {
12+
$getCallstack: (flags) => {
1513
var callstack = jsStackTrace();
1614

1715
// Find the symbols in the callstack that corresponds to the functions that
@@ -99,7 +97,7 @@ var LibraryStackTrace = {
9997
},
10098

10199
emscripten_get_callstack__deps: ['$getCallstack', '$lengthBytesUTF8', '$stringToUTF8'],
102-
emscripten_get_callstack: function(flags, str, maxbytes) {
100+
emscripten_get_callstack: (flags, str, maxbytes) => {
103101
var callstack = getCallstack(flags);
104102
// User can query the required amount of bytes to hold the callstack.
105103
if (!str || maxbytes <= 0) {
@@ -205,7 +203,7 @@ var LibraryStackTrace = {
205203
// must be able to unwind from a PC value that may no longer be on the
206204
// execution stack, and so we are forced to cache the entire call stack.
207205
emscripten_stack_snapshot__deps: ['$convertFrameToPC', '$UNWIND_CACHE', '$saveInUnwindCache', '$jsStackTrace'],
208-
emscripten_stack_snapshot: function() {
206+
emscripten_stack_snapshot: () => {
209207
var callstack = jsStackTrace().split('\n');
210208
if (callstack[0] == 'Error') {
211209
callstack.shift();

src/library_syscall.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ var SyscallsLibrary = {
9797
},
9898

9999
$syscallGetVarargI__internal: true,
100-
$syscallGetVarargI: function() {
100+
$syscallGetVarargI: () => {
101101
#if ASSERTIONS
102102
assert(SYSCALLS.varargs != undefined);
103103
#endif
@@ -112,7 +112,7 @@ var SyscallsLibrary = {
112112

113113
$syscallGetVarargP__internal: true,
114114
#if MEMORY64
115-
$syscallGetVarargP: function() {
115+
$syscallGetVarargP: () => {
116116
#if ASSERTIONS
117117
assert(SYSCALLS.varargs != undefined);
118118
#endif
@@ -568,9 +568,7 @@ var SyscallsLibrary = {
568568
(writefds ? {{{ makeGetValue('writefds', 4, 'i32') }}} : 0) |
569569
(exceptfds ? {{{ makeGetValue('exceptfds', 4, 'i32') }}} : 0);
570570
571-
var check = function(fd, low, high, val) {
572-
return (fd < 32 ? (low & val) : (high & val));
573-
};
571+
var check = (fd, low, high, val) => fd < 32 ? (low & val) : (high & val);
574572
575573
for (var fd = 0; fd < nfds; fd++) {
576574
var mask = 1 << (fd % 32);

src/library_trace.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ var LibraryTracing = {
210210
},
211211

212212
emscripten_trace_record_allocation: (address, size) => {
213-
if (typeof Module['onMalloc'] == 'function') Module['onMalloc'](address, size);
213+
Module['onMalloc']?.(address, size);
214214
if (EmscriptenTrace.postEnabled) {
215215
var now = EmscriptenTrace.now();
216216
EmscriptenTrace.post([EmscriptenTrace.EVENT_ALLOCATE,
@@ -219,7 +219,7 @@ var LibraryTracing = {
219219
},
220220

221221
emscripten_trace_record_reallocation: (old_address, new_address, size) => {
222-
if (typeof Module['onRealloc'] == 'function') Module['onRealloc'](old_address, new_address, size);
222+
Module['onRealloc']?.(old_address, new_address, size);
223223
if (EmscriptenTrace.postEnabled) {
224224
var now = EmscriptenTrace.now();
225225
EmscriptenTrace.post([EmscriptenTrace.EVENT_REALLOCATE,
@@ -228,7 +228,7 @@ var LibraryTracing = {
228228
},
229229

230230
emscripten_trace_record_free: (address) => {
231-
if (typeof Module['onFree'] == 'function') Module['onFree'](address);
231+
Module['onFree']?.(address);
232232
if (EmscriptenTrace.postEnabled) {
233233
var now = EmscriptenTrace.now();
234234
EmscriptenTrace.post([EmscriptenTrace.EVENT_FREE,
@@ -266,7 +266,7 @@ var LibraryTracing = {
266266
}
267267
},
268268

269-
emscripten_trace_report_off_heap_data: function () {
269+
emscripten_trace_report_off_heap_data: () => {
270270
function openal_audiodata_size() {
271271
if (typeof AL == 'undefined' || !AL.currentContext) {
272272
return 0;

0 commit comments

Comments
 (0)