mirror of
https://github.com/denoland/deno
synced 2024-09-17 23:22:46 +00:00
fix: REPL does not exit properly when close() is called (#5451)
This commit is contained in:
parent
1be7ec47ac
commit
cdc9323ccc
|
@ -32,6 +32,13 @@ function isRecoverableError(e: Error): boolean {
|
||||||
return recoverableErrorMessages.includes(e.message);
|
return recoverableErrorMessages.includes(e.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns `true` if `close()` is called in REPL.
|
||||||
|
// We should quit the REPL when this function returns `true`.
|
||||||
|
function isCloseCalled(): boolean {
|
||||||
|
// @ts-ignore
|
||||||
|
return globalThis.closed;
|
||||||
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
type Value = any;
|
type Value = any;
|
||||||
|
|
||||||
|
@ -45,7 +52,9 @@ function evaluate(code: string): boolean {
|
||||||
const [result, errInfo] = core.evalContext(code);
|
const [result, errInfo] = core.evalContext(code);
|
||||||
if (!errInfo) {
|
if (!errInfo) {
|
||||||
lastEvalResult = result;
|
lastEvalResult = result;
|
||||||
replLog(result);
|
if (!isCloseCalled()) {
|
||||||
|
replLog(result);
|
||||||
|
}
|
||||||
} else if (errInfo.isCompileError && isRecoverableError(errInfo.thrown)) {
|
} else if (errInfo.isCompileError && isRecoverableError(errInfo.thrown)) {
|
||||||
// Recoverable compiler error
|
// Recoverable compiler error
|
||||||
return false; // don't consume code.
|
return false; // don't consume code.
|
||||||
|
@ -110,6 +119,10 @@ export async function replLoop(): Promise<void> {
|
||||||
replLog("exit using ctrl+d or close()");
|
replLog("exit using ctrl+d or close()");
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
if (isCloseCalled()) {
|
||||||
|
quitRepl(0);
|
||||||
|
}
|
||||||
|
|
||||||
let code = "";
|
let code = "";
|
||||||
// Top level read
|
// Top level read
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -696,13 +696,15 @@ const REPL_MSG: &str = "exit using ctrl+d or close()\n";
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn repl_test_close_command() {
|
fn repl_test_close_command() {
|
||||||
let (_out, err) = util::run_and_collect_output(
|
let (out, err) = util::run_and_collect_output(
|
||||||
true,
|
true,
|
||||||
"repl",
|
"repl",
|
||||||
Some(vec!["close()", "'ignored'"]),
|
Some(vec!["close()", "'ignored'"]),
|
||||||
None,
|
None,
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
assert!(!out.contains("ignored"));
|
||||||
assert!(err.is_empty());
|
assert!(err.is_empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue