Skip to content

Commit f214d08

Browse files
authored
Use nullish coalescing assignment in shell.js. NFC (#22660)
1 parent 5b03ec9 commit f214d08

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

src/shell.js

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -317,20 +317,13 @@ if (ENVIRONMENT_IS_SHELL) {
317317
});
318318
};
319319

320-
if (typeof clearTimeout == 'undefined') {
321-
globalThis.clearTimeout = (id) => {};
322-
}
320+
globalThis.clearTimeout ??= (id) => {};
323321

324-
if (typeof setTimeout == 'undefined') {
325-
// spidermonkey lacks setTimeout but we use it above in readAsync.
326-
globalThis.setTimeout = (f) => (typeof f == 'function') ? f() : abort();
327-
}
322+
// spidermonkey lacks setTimeout but we use it above in readAsync.
323+
globalThis.setTimeout ??= (f) => (typeof f == 'function') ? f() : abort();
328324

329-
if (typeof scriptArgs != 'undefined') {
330-
arguments_ = scriptArgs;
331-
} else if (typeof arguments != 'undefined') {
332-
arguments_ = arguments;
333-
}
325+
// v8 uses `arguments_` whereas spidermonkey uses `scriptArgs`
326+
arguments_ = globalThis.arguments || globalThis.scriptArgs;
334327

335328
if (typeof quit == 'function') {
336329
quit_ = (status, toThrow) => {
@@ -359,9 +352,9 @@ if (ENVIRONMENT_IS_SHELL) {
359352

360353
if (typeof print != 'undefined') {
361354
// Prefer to use print/printErr where they exist, as they usually work better.
362-
if (typeof console == 'undefined') console = /** @type{!Console} */({});
355+
globalThis.console ??= /** @type{!Console} */({});
363356
console.log = /** @type{!function(this:Console, ...*): undefined} */ (print);
364-
console.warn = console.error = /** @type{!function(this:Console, ...*): undefined} */ (typeof printErr != 'undefined' ? printErr : print);
357+
console.warn = console.error = /** @type{!function(this:Console, ...*): undefined} */ (globalThis.printErr ?? print);
365358
}
366359

367360
#if WASM == 2

0 commit comments

Comments
 (0)