Skip to content

Commit 5a327e9

Browse files
authored
Make more use of optional chaining. NFC (#23521)
I found all these sites using: ``` $ git grep -n "if (\(.*\) && \1\>.*)" src/ ```
1 parent 0e9d6f6 commit 5a327e9

27 files changed

+31
-31
lines changed

src/lib/libbrowser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ var LibraryBrowser = {
552552
}
553553
var w = wNative;
554554
var h = hNative;
555-
if (Module['forcedAspectRatio'] && Module['forcedAspectRatio'] > 0) {
555+
if (Module['forcedAspectRatio'] > 0) {
556556
if (w/h < Module['forcedAspectRatio']) {
557557
w = Math.round(h * Module['forcedAspectRatio']);
558558
} else {

src/lib/libeventloop.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ LibraryJSEventLoop = {
489489
}
490490

491491
if (!noSetTiming) {
492-
if (fps && fps > 0) {
492+
if (fps > 0) {
493493
_emscripten_set_main_loop_timing({{{ cDefs.EM_TIMING_SETTIMEOUT }}}, 1000.0 / fps);
494494
} else {
495495
// Do rAF by rendering each frame (no decimating)

src/lib/libglemu.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3574,7 +3574,7 @@ var LibraryGLEmulation = {
35743574
for (var i = 0; i < n; i++) {
35753575
var id = {{{ makeGetValue('vaos', 'i*4', 'i32') }}};
35763576
GLEmulation.vaos[id] = null;
3577-
if (GLEmulation.currentVao && GLEmulation.currentVao.id == id) GLEmulation.currentVao = null;
3577+
if (GLEmulation.currentVao?.id == id) GLEmulation.currentVao = null;
35783578
}
35793579
},
35803580
$emulGlIsVertexArray: (array) => {

src/lib/libsdl.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,7 @@ var LibrarySDL = {
11081108
// since the browser engine handles that for us. Therefore, in JS we just
11091109
// maintain a list of channels and return IDs for them to the SDL consumer.
11101110
allocateChannels(num) { // called from Mix_AllocateChannels and init
1111-
if (SDL.numChannels && SDL.numChannels >= num && num != 0) return;
1111+
if (SDL.numChannels >= num && num != 0) return;
11121112
SDL.numChannels = num;
11131113
SDL.channels = [];
11141114
for (var i = 0; i < num; i++) {
@@ -3506,7 +3506,7 @@ var LibrarySDL = {
35063506
SDL_JoystickGetAxis__proxy: 'sync',
35073507
SDL_JoystickGetAxis: (joystick, axis) => {
35083508
var gamepad = SDL.getGamepad(joystick - 1);
3509-
if (gamepad && gamepad.axes.length > axis) {
3509+
if (gamepad?.axes.length > axis) {
35103510
return SDL.joystickAxisValueConversion(gamepad.axes[axis]);
35113511
}
35123512
return 0;
@@ -3519,7 +3519,7 @@ var LibrarySDL = {
35193519
SDL_JoystickGetButton__proxy: 'sync',
35203520
SDL_JoystickGetButton: (joystick, button) => {
35213521
var gamepad = SDL.getGamepad(joystick - 1);
3522-
if (gamepad && gamepad.buttons.length > button) {
3522+
if (gamepad?.buttons.length > button) {
35233523
return SDL.getJoystickButtonState(gamepad.buttons[button]) ? 1 : 0;
35243524
}
35253525
return 0;

src/lib/libstack_trace.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ var LibraryStackTrace = {
5050
var column = 0;
5151

5252
var parts = chromeRe.exec(line);
53-
if (parts && parts.length == 5) {
53+
if (parts?.length == 5) {
5454
symbolName = parts[1];
5555
file = parts[2];
5656
lineno = parts[3];
5757
column = parts[4];
5858
} else {
5959
parts = newFirefoxRe.exec(line) || firefoxRe.exec(line);
60-
if (parts && parts.length >= 4) {
60+
if (parts?.length >= 4) {
6161
symbolName = parts[1];
6262
file = parts[2];
6363
lineno = parts[3];

src/lib/libtrace.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ var LibraryTracing = {
9292
},
9393

9494
configureForGoogleWTF: () => {
95-
if (window && window['wtf']) {
95+
if (window?.['wtf']) {
9696
EmscriptenTrace.googleWTFEnabled = true;
9797
} else {
9898
out('GOOGLE WTF NOT AVAILABLE TO ENABLE');

src/lib/libtty.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ addToLibrary({
113113
}
114114
},
115115
fsync(tty) {
116-
if (tty.output && tty.output.length > 0) {
116+
if (tty.output?.length > 0) {
117117
out(UTF8ArrayToString(tty.output));
118118
tty.output = [];
119119
}
@@ -150,7 +150,7 @@ addToLibrary({
150150
}
151151
},
152152
fsync(tty) {
153-
if (tty.output && tty.output.length > 0) {
153+
if (tty.output?.length > 0) {
154154
err(UTF8ArrayToString(tty.output));
155155
tty.output = [];
156156
}

src/lib/libwebgl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1184,7 +1184,7 @@ for (/**@suppress{duplicate}*/var i = 0; i <= {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
11841184
}
11851185
// Make sure the canvas object no longer refers to the context object so
11861186
// there are no GC surprises.
1187-
if (GL.contexts[contextHandle] && GL.contexts[contextHandle].GLctx.canvas) {
1187+
if (GL.contexts[contextHandle]?.GLctx?.canvas) {
11881188
GL.contexts[contextHandle].GLctx.canvas.GLctxObject = undefined;
11891189
}
11901190
#if PTHREADS

src/polyfill/bigint64array.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ if (typeof globalThis.BigInt64Array === "undefined") {
2929
}
3030
var orig_array;
3131
if (!ArrayBuffer.isView(array)) {
32-
if (array.constructor && array.constructor.name === "ArrayBuffer") {
32+
if (array.constructor?.name === "ArrayBuffer") {
3333
array = new Uint32Array(array);
3434
} else {
3535
orig_array = array;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8353
1+
8350
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20285
1+
20267
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8335
1+
8333
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20253
1+
20235
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9352
1+
9351
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
24053
1+
24035
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8298
1+
8296
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20178
1+
20160
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8298
1+
8296
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20178
1+
20160
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8365
1+
8361
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20360
1+
20342
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9359
1+
9357
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
24053
1+
24035
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8353
1+
8350
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20285
1+
20267
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7661
1+
7657
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
18831
1+
18813

0 commit comments

Comments
 (0)