Skip to content

Commit

Permalink
Use nullish coalescing assignment in shell.js. NFC
Browse files Browse the repository at this point in the history
  • Loading branch information
sbc100 committed Sep 30, 2024
1 parent a17e9d1 commit 8810ceb
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 13 deletions.
14 changes: 5 additions & 9 deletions src/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,14 +323,10 @@ if (ENVIRONMENT_IS_SHELL) {
});
};

if (typeof clearTimeout == 'undefined') {
globalThis.clearTimeout = (id) => {};
}
globalThis.clearTimeout ??= (id) => {};

if (typeof setTimeout == 'undefined') {
// spidermonkey lacks setTimeout but we use it above in readAsync.
globalThis.setTimeout = (f) => (typeof f == 'function') ? f() : abort();
}
// spidermonkey lacks setTimeout but we use it above in readAsync.
globalThis.setTimeout ??= (f) => (typeof f == 'function') ? f() : abort();

if (typeof scriptArgs != 'undefined') {
arguments_ = scriptArgs;
Expand Down Expand Up @@ -365,9 +361,9 @@ if (ENVIRONMENT_IS_SHELL) {

if (typeof print != 'undefined') {
// Prefer to use print/printErr where they exist, as they usually work better.
if (typeof console == 'undefined') console = /** @type{!Console} */({});
globalThis.console ??= /** @type{!Console} */({});
console.log = /** @type{!function(this:Console, ...*): undefined} */ (print);
console.warn = console.error = /** @type{!function(this:Console, ...*): undefined} */ (typeof printErr != 'undefined' ? printErr : print);
console.warn = console.error = /** @type{!function(this:Console, ...*): undefined} */ (globalThis.printErr ?? print);
}

#if WASM == 2
Expand Down
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 @@
8018
8026
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 @@
21410
21406
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_minimal_O0.gzsize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6564
6567
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_minimal_O0.jssize
Original file line number Diff line number Diff line change
@@ -1 +1 @@
17560
17556

0 comments on commit 8810ceb

Please sign in to comment.