Skip to content

Commit 421df76

Browse files
authored
Use for..of in a few places when it avoids an extra hasOwnProperty call. NFC (emscripten-core#20822)
1 parent 39290d8 commit 421df76

12 files changed

Lines changed: 27 additions & 39 deletions

src/library_dylink.js

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -286,10 +286,10 @@ var LibraryDylink = {
286286
#if DYLINK_DEBUG
287287
dbg('reportUndefinedSymbols');
288288
#endif
289-
for (var symName in GOT) {
290-
if (GOT[symName].value == 0) {
289+
for (var [symName, entry] of Object.entries(GOT)) {
290+
if (entry.value == 0) {
291291
var value = resolveGlobalSymbol(symName, true).sym;
292-
if (!value && !GOT[symName].required) {
292+
if (!value && !entry.required) {
293293
// Ignore undefined symbols that are imported as weak.
294294
#if DYLINK_DEBUG
295295
dbg(`ignoring undefined weak symbol: ${symName}`);
@@ -304,15 +304,15 @@ var LibraryDylink = {
304304
#endif
305305
if (typeof value == 'function') {
306306
/** @suppress {checkTypes} */
307-
GOT[symName].value = {{{ to64('addFunction(value, value.sig)') }}};
307+
entry.value = {{{ to64('addFunction(value, value.sig)') }}};
308308
#if DYLINK_DEBUG == 2
309-
dbg(`assigning table entry for : ${symName} -> ${GOT[symName].value}`);
309+
dbg(`assigning table entry for : ${symName} -> ${entry.value}`);
310310
#endif
311311
} else if (typeof value == 'number') {
312-
GOT[symName].value = {{{ to64('value') }}};
312+
entry.value = {{{ to64('value') }}};
313313
#if MEMORY64
314314
} else if (typeof value == 'bigint') {
315-
GOT[symName].value = value;
315+
entry.value = value;
316316
#endif
317317
} else {
318318
throw new Error(`bad export type for '${symName}': ${typeof value}`);
@@ -529,13 +529,10 @@ var LibraryDylink = {
529529
$mergeLibSymbols__deps: ['$isSymbolDefined'],
530530
$mergeLibSymbols: (exports, libName) => {
531531
// add symbols into global namespace TODO: weak linking etc.
532-
for (var sym in exports) {
533-
if (!exports.hasOwnProperty(sym)) {
534-
continue;
535-
}
532+
for (var [sym, exp] of Object.entries(exports)) {
536533
#if ASSERTIONS == 2
537534
if (isSymbolDefined(sym)) {
538-
var curr = wasmImports[sym], next = exports[sym];
535+
var curr = wasmImports[sym], next = exp;
539536
// don't warn on functions - might be odr, linkonce_odr, etc.
540537
if (!(typeof curr == 'function' && typeof next == 'function')) {
541538
err(`warning: symbol '${sym}' from '${libName}' already exists (duplicate symbol? or weak linking, which isn't supported yet?)`); // + [curr, ' vs ', next]);
@@ -552,11 +549,11 @@ var LibraryDylink = {
552549
const setImport = (target) => {
553550
#if ASYNCIFY
554551
if (target in asyncifyStubs) {
555-
asyncifyStubs[target] = exports[sym]
552+
asyncifyStubs[target] = exp;
556553
}
557554
#endif
558555
if (!isSymbolDefined(target)) {
559-
wasmImports[target] = exports[sym];
556+
wasmImports[target] = exp;
560557
}
561558
}
562559
setImport(sym);
@@ -575,7 +572,7 @@ var LibraryDylink = {
575572
#endif
576573

577574
if (sym.startsWith('dynCall_') && !Module.hasOwnProperty(sym)) {
578-
Module[sym] = exports[sym];
575+
Module[sym] = exp;
579576
}
580577
}
581578
},

src/library_memfs.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,7 @@ addToLibrary({
216216
},
217217
readdir(node) {
218218
var entries = ['.', '..'];
219-
for (var key in node.contents) {
220-
if (!node.contents.hasOwnProperty(key)) {
221-
continue;
222-
}
219+
for (var key of Object.keys(node.contents)) {
223220
entries.push(key);
224221
}
225222
return entries;

src/library_workerfs.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,7 @@ addToLibrary({
116116
},
117117
readdir(node) {
118118
var entries = ['.', '..'];
119-
for (var key in node.contents) {
120-
if (!node.contents.hasOwnProperty(key)) {
121-
continue;
122-
}
119+
for (var key of Object.keys(node.contents)) {
123120
entries.push(key);
124121
}
125122
return entries;

src/utility.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,11 @@ function dump(item) {
2323
return '// ' + JSON.stringify(item, null, ' ').replace(/\n/g, '\n// ');
2424
} catch (e) {
2525
const ret = [];
26-
for (const i in item) {
27-
if (Object.prototype.hasOwnProperty.call(item, i)) {
28-
const j = item[i];
29-
if (typeof j == 'string' || typeof j == 'number') {
30-
ret.push(`${i}: ${j}`);
31-
} else {
32-
ret.push(`${i}: [?]`);
33-
}
26+
for (const [i, j] of Object.entries(item)) {
27+
if (typeof j == 'string' || typeof j == 'number') {
28+
ret.push(`${i}: ${j}`);
29+
} else {
30+
ret.push(`${i}: [?]`);
3431
}
3532
}
3633
return ret.join(',\n');
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
24952
1+
24942
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
24920
1+
24910
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
29082
1+
29072
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
24727
1+
24717
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
29082
1+
29072
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
24952
1+
24942

0 commit comments

Comments
 (0)