Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use nullish coalescing assignment in shell.js. NFC #22660

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading