Skip to content

Commit c92f413

Browse files
authored
Use arrow functions in internal JS code. NFC. (#13319)
1 parent 6dcfcb4 commit c92f413

File tree

3 files changed

+22
-26
lines changed

3 files changed

+22
-26
lines changed

src/compiler.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
var nodeFS = require('fs');
1111
var nodePath = require('path');
1212

13-
print = function(x) {
13+
print = (x) => {
1414
process['stdout'].write(x + '\n');
1515
};
1616

17-
printErr = function(x) {
17+
printErr = (x) => {
1818
process['stderr'].write(x + '\n');
1919
};
2020

@@ -29,7 +29,7 @@ function find(filename) {
2929
return filename;
3030
}
3131

32-
read = function(filename) {
32+
read = (filename) => {
3333
var absolute = find(filename);
3434
return nodeFS.readFileSync(absolute).toString();
3535
};
@@ -113,16 +113,12 @@ try {
113113
// Instead of process.exit() directly, wait for stdout flush event.
114114
// See https://github.com/joyent/node/issues/1669 and https://github.com/emscripten-core/emscripten/issues/2582
115115
// Workaround is based on https://github.com/RReverser/acorn/commit/50ab143cecc9ed71a2d66f78b4aec3bb2e9844f6
116-
process['stdout']['once']('drain', function () {
117-
process['exit'](1);
118-
});
116+
process['stdout']['once']('drain', () => process['exit'](1));
119117
// Make sure to print something to force the drain event to occur, in case the
120118
// stdout buffer was empty.
121119
console.log(' ');
122120
// Work around another node bug where sometimes 'drain' is never fired - make
123121
// another effort to emit the exit status, after a significant delay (if node
124122
// hasn't fired drain by then, give up)
125-
setTimeout(function() {
126-
process['exit'](1);
127-
}, 500);
123+
setTimeout(() => process['exit'](1), 500);
128124
}

src/jsifier.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function mangleCSymbolName(f) {
3131
// Splits out items that pass filter. Returns also the original sans the filtered
3232
function splitter(array, filter) {
3333
var splitOut = array.filter(filter);
34-
var leftIn = array.filter(function(x) { return !filter(x) });
34+
var leftIn = array.filter((x) => !filter(x));
3535
return { leftIn: leftIn, splitOut: splitOut };
3636
}
3737

@@ -53,7 +53,7 @@ function stringifyWithFunctions(obj) {
5353
if (Array.isArray(obj)) {
5454
return '[' + obj.map(stringifyWithFunctions).join(',') + ']';
5555
} else {
56-
return '{' + keys(obj).map(function(key) { return escapeJSONKey(key) + ':' + stringifyWithFunctions(obj[key]) }).join(',') + '}';
56+
return '{' + keys(obj).map((key) => escapeJSONKey(key) + ':' + stringifyWithFunctions(obj[key])).join(',') + '}';
5757
}
5858
}
5959

@@ -80,7 +80,7 @@ function JSify(data, functionsOnly) {
8080
} else {
8181
libFuncsToInclude = DEFAULT_LIBRARY_FUNCS_TO_INCLUDE;
8282
}
83-
libFuncsToInclude.forEach(function(ident) {
83+
libFuncsToInclude.forEach((ident) => {
8484
data.functionStubs.push({
8585
identOrig: ident,
8686
identMangled: mangleCSymbolName(ident)
@@ -99,7 +99,7 @@ function JSify(data, functionsOnly) {
9999

100100
// apply LIBRARY_DEBUG if relevant
101101
if (LIBRARY_DEBUG) {
102-
snippet = modifyFunction(snippet, function(name, args, body) {
102+
snippet = modifyFunction(snippet, (name, args, body) => {
103103
return 'function ' + name + '(' + args + ') {\n' +
104104
'var ret = (function() { if (runtimeDebug) err("[library call:' + finalName + ': " + Array.prototype.slice.call(arguments).map(prettyPrint) + "]");\n' +
105105
body +
@@ -200,7 +200,7 @@ function JSify(data, functionsOnly) {
200200
error('JS library directive ' + ident + '__deps=' + deps.toString() + ' is of type ' + typeof deps + ', but it should be an array!');
201201
return;
202202
}
203-
deps.forEach(function(dep) {
203+
deps.forEach((dep) => {
204204
if (typeof snippet === 'string' && !(dep in LibraryManager.library)) warn('missing library dependency ' + dep + ', make sure you are compiling with the right options (see #if in src/library*.js)');
205205
});
206206
var isFunction = false;
@@ -262,8 +262,8 @@ function JSify(data, functionsOnly) {
262262
// In asm, dependencies implemented in C might be needed by JS library functions.
263263
// We don't know yet if they are implemented in C or not. To be safe, export such
264264
// special cases.
265-
[LIBRARY_DEPS_TO_AUTOEXPORT].forEach(function(special) {
266-
deps.forEach(function(dep) {
265+
[LIBRARY_DEPS_TO_AUTOEXPORT].forEach((special) => {
266+
deps.forEach((dep) => {
267267
if (dep == special && !EXPORTED_FUNCTIONS[dep]) {
268268
EXPORTED_FUNCTIONS[dep] = 1;
269269
}
@@ -279,7 +279,7 @@ function JSify(data, functionsOnly) {
279279
}
280280
return addFromLibrary(dep, identDependents + ', referenced by ' + dependent);
281281
}
282-
var depsText = (deps ? deps.map(addDependency).filter(function(x) { return x != '' }).join('\n') + '\n' : '');
282+
var depsText = (deps ? deps.map(addDependency).filter((x) => x != '').join('\n') + '\n' : '');
283283
var contentText;
284284
if (isFunction) {
285285
// Emit the body of a JS library function.
@@ -290,7 +290,7 @@ function JSify(data, functionsOnly) {
290290
}
291291
var sync = proxyingMode === 'sync';
292292
assert(typeof original === 'function');
293-
contentText = modifyFunction(snippet, function(name, args, body) {
293+
contentText = modifyFunction(snippet, (name, args, body) => {
294294
return 'function ' + name + '(' + args + ') {\n' +
295295
'if (ENVIRONMENT_IS_PTHREAD) return _emscripten_proxy_to_main_thread_js(' + proxiedFunctionTable.length + ', ' + (+sync) + (args ? ', ' : '') + args + ');\n' + body + '}\n';
296296
});
@@ -338,7 +338,7 @@ function JSify(data, functionsOnly) {
338338
// Final combiner
339339

340340
function finalCombiner() {
341-
var splitPostSets = splitter(itemsDict.GlobalVariablePostSet, function(x) { return x.ident && x.dependencies });
341+
var splitPostSets = splitter(itemsDict.GlobalVariablePostSet, (x) => x.ident && x.dependencies);
342342
itemsDict.GlobalVariablePostSet = splitPostSets.leftIn;
343343
var orderedPostSets = splitPostSets.splitOut;
344344

@@ -363,7 +363,7 @@ function JSify(data, functionsOnly) {
363363

364364
if (!mainPass) {
365365
var generated = itemsDict.function.concat(itemsDict.type).concat(itemsDict.GlobalVariableStub).concat(itemsDict.GlobalVariable);
366-
print(generated.map(function(item) { return item.JS; }).join('\n'));
366+
print(generated.map((item) => item.JS).join('\n'));
367367
return;
368368
}
369369

@@ -389,7 +389,7 @@ function JSify(data, functionsOnly) {
389389
globalsData = null;
390390

391391
var generated = itemsDict.functionStub.concat(itemsDict.GlobalVariablePostSet);
392-
generated.forEach(function(item) { print(indentify(item.JS || '', 2)); });
392+
generated.forEach((item) => print(indentify(item.JS || '', 2)));
393393

394394
legalizedI64s = legalizedI64sDefault;
395395

src/parseTools.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ let currentlyParsedFilename = '';
1313
// {{{ code }}} will be replaced with |eval(code)|.
1414
// NOTE: Be careful with that ret check. If ret is |0|, |ret ? ret.toString() : ''| would result in ''!
1515
function processMacros(text) {
16-
return text.replace(/{{{([^}]|}(?!}))+}}}/g, function(str) {
16+
return text.replace(/{{{([^}]|}(?!}))+}}}/g, (str) => {
1717
str = str.substr(3, str.length - 6);
1818
try {
1919
const ret = eval(str);
@@ -235,7 +235,7 @@ function isFunctionDef(token, out) {
235235
if (!token.tokens) return false;
236236
let fail = false;
237237
const segments = splitTokenList(token.tokens);
238-
segments.forEach(function(segment) {
238+
segments.forEach((segment) => {
239239
const subtext = segment[0].text;
240240
fail = fail || segment.length > 1 || !(isType(subtext) || subtext == '...');
241241
});
@@ -681,7 +681,7 @@ function makeCopyValues(dest, src, num, type, modifier, align, sep) {
681681
sep = sep || ';';
682682
function unroll(type, num, jump) {
683683
jump = jump || 1;
684-
return range(num).map(function(i) {
684+
return range(num).map((i) => {
685685
return makeSetValue(dest, i * jump, makeGetValue(src, i * jump, type), type);
686686
}).join(sep);
687687
}
@@ -698,7 +698,7 @@ function makeCopyValues(dest, src, num, type, modifier, align, sep) {
698698
src = stripCorrections(src);
699699
// and in the heap assignment expression
700700
const ret = [];
701-
[4, 2, 1].forEach(function(possibleAlign) {
701+
[4, 2, 1].forEach((possibleAlign) => {
702702
if (num == 0) return;
703703
if (align >= possibleAlign) {
704704
ret.push(unroll('i' + (possibleAlign * 8), Math.floor(num / possibleAlign), possibleAlign));
@@ -1266,7 +1266,7 @@ function addReadyPromiseAssertions(promise) {
12661266
// Also warn on onRuntimeInitialized which might be a common pattern with
12671267
// older MODULARIZE-using codebases.
12681268
properties.push('onRuntimeInitialized');
1269-
return properties.map(function(property) {
1269+
return properties.map((property) => {
12701270
const warningEnding = `${property} on the Promise object, instead of the instance. Use .then() to get called back with the instance, see the MODULARIZE docs in src/settings.js`;
12711271
return `
12721272
if (!Object.getOwnPropertyDescriptor(${promise}, '${property}')) {

0 commit comments

Comments
 (0)