Skip to content
This repository has been archived by the owner on Apr 13, 2024. It is now read-only.

Commit

Permalink
Guard use of process with checks that we're running on Node
Browse files Browse the repository at this point in the history
`process` only exists when running in Node. Notably, `if (process)` is
still a ReferenceError, so the existing check in readline.js needs
modifying too. Unfortunately we don't have access to the platform name
there, so we just check if `process` exists.
  • Loading branch information
AtkinsSJ committed Apr 12, 2024
1 parent d20be49 commit 8ededf6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/ansi-shell/ANSIShell.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export class ANSIShell extends EventTarget {
}

async doPromptIteration() {
if ( globalThis.force_eot ) {
if ( globalThis.force_eot && this.ctx.platform.name === 'node' ) {
process.exit(0);
}
const { readline } = this.ctx.externs;
Expand Down
6 changes: 4 additions & 2 deletions src/ansi-shell/pipeline/Pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,10 @@ export class PreparedCommand {
// but for some reason Node crashes first, unless we set this handler,
// EVEN IF IT DOES NOTHING. I also can't find a place to safely remove it,
// so apologies if it makes debugging promises harder.
const rejectionCatcher = (reason, promise) => {};
process.on('unhandledRejection', rejectionCatcher);
if (ctx.platform.name === 'node') {
const rejectionCatcher = (reason, promise) => { };
process.on('unhandledRejection', rejectionCatcher);
}

let exit_code = 0;
try {
Expand Down
2 changes: 1 addition & 1 deletion src/ansi-shell/readline/readline.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const ReadlineProcessorBuilder = builder => builder
externs.out.write('^C\n');
// Exit if input line is empty
// FIXME: Check for 'process' is so we only do this on Node. How should we handle exiting in Puter terminal?
if ( process && ctx.vars.result.length === 0 ) {
if ( typeof process !== 'undefined' && ctx.vars.result.length === 0 ) {
process.exit(1);
return;
}
Expand Down

0 comments on commit 8ededf6

Please sign in to comment.