Skip to content

Commit

Permalink
Convert more JS lambda functions to arrow syntax. NFC (emscripten-cor…
Browse files Browse the repository at this point in the history
  • Loading branch information
sbc100 authored Sep 5, 2024
1 parent b537af8 commit 189d7a1
Show file tree
Hide file tree
Showing 77 changed files with 97 additions and 115 deletions.
4 changes: 1 addition & 3 deletions src/embind/embind_shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ var LibraryEmbindShared = {
'$awaitingDependencies', '$registeredTypes',
'$typeDependencies', '$throwInternalError'],
$whenDependentTypesAreResolved: (myTypes, dependentTypes, getTypeConverters) => {
myTypes.forEach(function(type) {
typeDependencies[type] = dependentTypes;
});
myTypes.forEach((type) => typeDependencies[type] = dependentTypes);

function onComplete(typeConverters) {
var myTypeConverters = getTypeConverters(typeConverters);
Expand Down
2 changes: 1 addition & 1 deletion src/gl-matrix.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(function() {
(() => {

/**
* @fileoverview gl-matrix - High performance matrix and vector operations for WebGL
Expand Down
2 changes: 1 addition & 1 deletion src/headless.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ var Audio = () => ({
},
});
var Image = () => {
window.setTimeout(function() {
window.setTimeout(() => {
this.complete = true;
this.width = 64;
this.height = 64;
Expand Down
8 changes: 2 additions & 6 deletions src/headlessCanvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -600,9 +600,7 @@ function headlessCanvas() {
},
requestPointerLock: function() {
document.pointerLockElement = document.getElementById('canvas');
window.setTimeout(function() {
document.callEventListeners('pointerlockchange');
});
window.setTimeout(() => document.callEventListeners('pointerlockchange'));
},
exitPointerLock: function(){},
style: {
Expand All @@ -614,9 +612,7 @@ function headlessCanvas() {
removeEventListener: function(){},
requestFullscreen: function() {
document.fullscreenElement = document.getElementById('canvas');
window.setTimeout(function() {
document.callEventListeners('fullscreenchange');
});
window.setTimeout(() => document.callEventListeners('fullscreenchange'));
},
offsetTop: 0,
offsetLeft: 0,
Expand Down
2 changes: 1 addition & 1 deletion src/library_browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ var LibraryBrowser = {
}
};
addEventListener("message", Browser_setImmediate_messageHandler, true);
Browser.setImmediate = /** @type{function(function(): ?, ...?): number} */(function Browser_emulated_setImmediate(func) {
Browser.setImmediate = /** @type{function(function(): ?, ...?): number} */((func) => {
setImmediates.push(func);
if (ENVIRONMENT_IS_WORKER) {
Module['setImmediates'] ??= [];
Expand Down
2 changes: 1 addition & 1 deletion src/library_c_preprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ addToLibrary({
// Consume tokens array into a function tree until the tokens array is exhausted
// to a single root node that evaluates it.
while (tokens.length > 1 || typeof tokens[0] != 'function') {
tokens = (function(tokens) {
tokens = ((tokens) => {
// Find the index 'i' of the operator we should evaluate next:
var i, j, p, operatorAndPriority = -2;
for (j = 0; j < tokens.length; ++j) {
Expand Down
4 changes: 1 addition & 3 deletions src/library_dylink.js
Original file line number Diff line number Diff line change
Expand Up @@ -1009,9 +1009,7 @@ var LibraryDylink = {

var libFile = locateFile(libName);
if (flags.loadAsync) {
return new Promise(function(resolve, reject) {
asyncLoad(libFile, resolve, reject);
});
return new Promise((resolve, reject) => asyncLoad(libFile, resolve, reject));
}

// load the binary synchronously
Expand Down
2 changes: 1 addition & 1 deletion src/library_egl.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ var LibraryEGL = {
// Run callbacks so that GL emulation works
GL.makeContextCurrent(EGL.context);
Browser.useWebGL = true;
Browser.moduleContextCreatedCallbacks.forEach(function(callback) { callback() });
Browser.moduleContextCreatedCallbacks.forEach((callback) => callback());

// Note: This function only creates a context, but it shall not make it active.
GL.makeContextCurrent(null);
Expand Down
2 changes: 1 addition & 1 deletion src/library_exceptions_stub.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var LibraryExceptions = {};
'__cxa_rethrow_primary_exception',
'__cxa_find_matching_catch',
'__resumeException',
].forEach(function(name) {
].forEach((name) => {
LibraryExceptions[name] = function() { abort(); };
#if !INCLUDE_FULL_LIBRARY
// This method of link-time error generation is not compatible with INCLUDE_FULL_LIBRARY
Expand Down
8 changes: 2 additions & 6 deletions src/library_formatString.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,7 @@ addToLibrary({

// Insert the result into the buffer.
argText = prefix + argText;
argText.split('').forEach(function(chr) {
ret.push(chr.charCodeAt(0));
});
argText.split('').forEach((chr) => ret.push(chr.charCodeAt(0)));
break;
}
case 'f': case 'F': case 'e': case 'E': case 'g': case 'G': {
Expand Down Expand Up @@ -401,9 +399,7 @@ addToLibrary({
if (next < {{{ charCode('a') }}}) argText = argText.toUpperCase();

// Insert the result into the buffer.
argText.split('').forEach(function(chr) {
ret.push(chr.charCodeAt(0));
});
argText.split('').forEach((chr) => ret.push(chr.charCodeAt(0)));
break;
}
case 's': {
Expand Down
10 changes: 4 additions & 6 deletions src/library_glut.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,13 +336,13 @@ var LibraryGLUT = {
// Firefox
window.addEventListener("DOMMouseScroll", GLUT.onMouseWheel, true);

Browser.resizeListeners.push(function(width, height) {
Browser.resizeListeners.push((width, height) => {
if (GLUT.reshapeFunc) {
{{{ makeDynCall('vii', 'GLUT.reshapeFunc') }}}(width, height);
}
});

__ATEXIT__.push(function() {
__ATEXIT__.push(() => {
if (isTouchDevice) {
window.removeEventListener("touchmove", GLUT.touchHandler, true);
window.removeEventListener("touchstart", GLUT.touchHandler, true);
Expand Down Expand Up @@ -620,11 +620,9 @@ var LibraryGLUT = {
glutPostRedisplay: () => {
if (GLUT.displayFunc && !GLUT.requestedAnimationFrame) {
GLUT.requestedAnimationFrame = true;
Browser.requestAnimationFrame(function() {
Browser.requestAnimationFrame(() => {
GLUT.requestedAnimationFrame = false;
Browser.mainLoop.runIter(function() {
{{{ makeDynCall('v', 'GLUT.displayFunc') }}}();
});
Browser.mainLoop.runIter(() => {{{ makeDynCall('v', 'GLUT.displayFunc') }}}());
});
}
},
Expand Down
4 changes: 2 additions & 2 deletions src/library_idbfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ addToLibrary({
var total = 0;

var create = [];
Object.keys(src.entries).forEach(function (key) {
Object.keys(src.entries).forEach((key) => {
var e = src.entries[key];
var e2 = dst.entries[key];
if (!e2 || e['timestamp'].getTime() != e2['timestamp'].getTime()) {
Expand All @@ -323,7 +323,7 @@ addToLibrary({
});

var remove = [];
Object.keys(dst.entries).forEach(function (key) {
Object.keys(dst.entries).forEach((key) => {
if (!src.entries[key]) {
remove.push(key);
total++;
Expand Down
2 changes: 1 addition & 1 deletion src/library_lz4.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ addToLibrary({
codec: null,
init() {
if (LZ4.codec) return;
LZ4.codec = (function() {
LZ4.codec = (() => {
{{{ read('../third_party/mini-lz4.js') }}};
return MiniLZ4;
})();
Expand Down
2 changes: 1 addition & 1 deletion src/library_noderawfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ addToLibrary({
if (typeof flags == "string") {
flags = FS_modeStringToFlags(flags)
}
var pathTruncated = path.split('/').map(function(s) { return s.substr(0, 255); }).join('/');
var pathTruncated = path.split('/').map((s) => s.substr(0, 255)).join('/');
var nfd = fs.openSync(pathTruncated, NODEFS.flagsForNode(flags), mode);
var st = fs.fstatSync(nfd);
if (flags & {{{ cDefs.O_DIRECTORY }}} && !st.isDirectory()) {
Expand Down
6 changes: 3 additions & 3 deletions src/library_workerfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ addToLibrary({
Array.prototype.forEach.call(mount.opts["files"] || [], function(file) {
WORKERFS.createNode(ensureParent(file.name), base(file.name), WORKERFS.FILE_MODE, 0, file, file.lastModifiedDate);
});
(mount.opts["blobs"] || []).forEach(function(obj) {
(mount.opts["blobs"] || []).forEach((obj) => {
WORKERFS.createNode(ensureParent(obj["name"]), base(obj["name"]), WORKERFS.FILE_MODE, 0, obj["data"]);
});
(mount.opts["packages"] || []).forEach(function(pack) {
pack['metadata'].files.forEach(function(file) {
(mount.opts["packages"] || []).forEach((pack) => {
pack['metadata'].files.forEach((file) => {
var name = file.filename.substr(1); // remove initial slash
WORKERFS.createNode(ensureParent(name), base(name), WORKERFS.FILE_MODE, 0, pack['blob'].slice(file.start, file.end));
});
Expand Down
14 changes: 5 additions & 9 deletions src/postamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,8 @@ function run() {
#if expectToReceiveOnModule('setStatus')
if (Module['setStatus']) {
Module['setStatus']('Running...');
setTimeout(function() {
setTimeout(function() {
Module['setStatus']('');
}, 1);
setTimeout(() => {
setTimeout(() => Module['setStatus'](''), 1);
doRun();
}, 1);
} else
Expand Down Expand Up @@ -289,7 +287,7 @@ function checkUnflushedContent() {
#endif
#if '$FS' in addedLibraryItems && '$TTY' in addedLibraryItems
// also flush in the JS FS layer
['stdout', 'stderr'].forEach(function(name) {
['stdout', 'stderr'].forEach((name) => {
var info = FS.analyzePath('/dev/' + name);
if (!info) return;
var stream = info.object;
Expand Down Expand Up @@ -342,17 +340,15 @@ run();

var workerResponded = false, workerCallbackId = -1;

(function() {
(() => {
var messageBuffer = null, buffer = 0, bufferSize = 0;

function flushMessages() {
if (!messageBuffer) return;
if (runtimeInitialized) {
var temp = messageBuffer;
messageBuffer = null;
temp.forEach(function(message) {
onmessage(message);
});
temp.forEach((message) => onmessage(message));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/proxyClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ if (typeof window != 'undefined') {
}

/*
(function() {
(() => {
var trueRAF = window.requestAnimationFrame;
var tracker = new FPSTracker('client');
window.requestAnimationFrame = (func) => {
Expand Down
4 changes: 2 additions & 2 deletions src/proxyWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ window.scrollX = window.scrollY = 0; // TODO: proxy these

window.WebGLRenderingContext = WebGLWorker;

window.requestAnimationFrame = (function() {
window.requestAnimationFrame = (() => {
// similar to Browser.requestAnimationFrame
var nextRAF = 0;
return function(func) {
return (func) => {
// try to keep 60fps between calls to here
var now = Date.now();
if (nextRAF === 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/runtime_debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

// Endianness check
#if !SUPPORT_BIG_ENDIAN
(function() {
(() => {
var h16 = new Int16Array(1);
var h8 = new Int8Array(h16.buffer);
h16[0] = 0x6373;
Expand Down
10 changes: 5 additions & 5 deletions src/webGLWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -723,10 +723,10 @@ function WebGLWorker() {
source = source.replace(/\n/g, '|\n'); // barrier between lines, to make regexing easier
var newItems = source.match(new RegExp(type + '\\s+\\w+\\s+[\\w,\\s\[\\]]+;', 'g'));
if (!newItems) return;
newItems.forEach(function(item) {
newItems.forEach((item) => {
var m = new RegExp(type + '\\s+(\\w+)\\s+([\\w,\\s\[\\]]+);').exec(item);
assert(m);
m[2].split(',').map(function(name) { name = name.trim(); return name.search(/\s/) >= 0 ? '' : name }).filter(function(name) { return !!name }).forEach(function(name) {
m[2].split(',').map((name) => { name = name.trim(); return name.search(/\s/) >= 0 ? '' : name }).filter((name) => !!name).forEach((name) => {
var size = 1;
var open = name.indexOf('[');
var fullname = name;
Expand Down Expand Up @@ -754,7 +754,7 @@ function WebGLWorker() {

var existingAttributes = {};

program.shaders.forEach(function(shader) {
program.shaders.forEach((shader) => {
parseElementType(shader, 'uniform', program.uniforms, program.uniformVec);
parseElementType(shader, 'attribute', existingAttributes, null);
});
Expand Down Expand Up @@ -1153,8 +1153,8 @@ function WebGLWorker() {
Browser.doSwapBuffers = postRAF;

var trueRAF = window.requestAnimationFrame;
window.requestAnimationFrame = function(func) {
trueRAF(function() {
window.requestAnimationFrame = (func) => {
trueRAF(() => {
if (preRAF() === false) {
window.requestAnimationFrame(func); // skip this frame, do it later
return;
Expand Down
8 changes: 4 additions & 4 deletions test/code_size/embind_hello_wasm.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.html": 552,
"a.html.gz": 380,
"a.js": 9920,
"a.js.gz": 4354,
"a.js": 9910,
"a.js.gz": 4352,
"a.wasm": 7715,
"a.wasm.gz": 3512,
"total": 18187,
"total_gz": 8246
"total": 18177,
"total_gz": 8244
}
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_ctors1.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20836
20821
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_ctors2.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8510
8511
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_ctors2.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20804
20789
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_except.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9541
9542
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_except.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
24681
24666
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_except_wasm.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8483
8484
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_except_wasm.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20729
20715
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8483
8484
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20729
20715
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_lto.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8423
8422
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_lto.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20434
20420
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_mangle.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
24681
24666
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_noexcept.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20836
20821
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_wasmfs.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8678
8664
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_files_js_fs.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7652
7654
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_files_js_fs.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18737
18723
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_files_wasmfs.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2967
2966
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_files_wasmfs.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6314
6300
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_hello_O0.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7987
7983
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_hello_O0.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
21387
21358
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_hello_O1.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2785
2780
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_hello_O1.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6982
6953
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_hello_O2.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2466
2464
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_hello_O2.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5005
4991
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_hello_O3.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2381
2379
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_hello_O3.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4851
4837
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_hello_Os.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2381
2379
Loading

0 comments on commit 189d7a1

Please sign in to comment.