Skip to content

Commit

Permalink
Use nullish coalescing assignment in shell.js. NFC (#22660)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbc100 authored Oct 1, 2024
1 parent 5b03ec9 commit f214d08
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions src/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,20 +317,13 @@ 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;
} else if (typeof arguments != 'undefined') {
arguments_ = arguments;
}
// v8 uses `arguments_` whereas spidermonkey uses `scriptArgs`
arguments_ = globalThis.arguments || globalThis.scriptArgs;

if (typeof quit == 'function') {
quit_ = (status, toThrow) => {
Expand Down Expand Up @@ -359,9 +352,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

0 comments on commit f214d08

Please sign in to comment.