summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoruki00a <uki00a@gmail.com>2020-05-20 02:33:11 +0900
committerGitHub <noreply@github.com>2020-05-19 13:33:11 -0400
commitcdc9323cccdee544562712018f722026bdfbbd6c (patch)
tree45a8698cc74ffe27bfef3484c3f752a7cac0398d
parent1be7ec47ac3b6e63be2b03245a26e060b8268b5e (diff)
fix: REPL does not exit properly when close() is called (#5451)
-rw-r--r--cli/js/repl.ts15
-rw-r--r--cli/tests/integration_tests.rs4
2 files changed, 17 insertions, 2 deletions
diff --git a/cli/js/repl.ts b/cli/js/repl.ts
index 138b30c3e..c84be68b1 100644
--- a/cli/js/repl.ts
+++ b/cli/js/repl.ts
@@ -32,6 +32,13 @@ function isRecoverableError(e: Error): boolean {
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
type Value = any;
@@ -45,7 +52,9 @@ function evaluate(code: string): boolean {
const [result, errInfo] = core.evalContext(code);
if (!errInfo) {
lastEvalResult = result;
- replLog(result);
+ if (!isCloseCalled()) {
+ replLog(result);
+ }
} else if (errInfo.isCompileError && isRecoverableError(errInfo.thrown)) {
// Recoverable compiler error
return false; // don't consume code.
@@ -110,6 +119,10 @@ export async function replLoop(): Promise<void> {
replLog("exit using ctrl+d or close()");
while (true) {
+ if (isCloseCalled()) {
+ quitRepl(0);
+ }
+
let code = "";
// Top level read
try {
diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs
index 476a08224..45c3a011f 100644
--- a/cli/tests/integration_tests.rs
+++ b/cli/tests/integration_tests.rs
@@ -696,13 +696,15 @@ const REPL_MSG: &str = "exit using ctrl+d or close()\n";
#[test]
fn repl_test_close_command() {
- let (_out, err) = util::run_and_collect_output(
+ let (out, err) = util::run_and_collect_output(
true,
"repl",
Some(vec!["close()", "'ignored'"]),
None,
false,
);
+
+ assert!(!out.contains("ignored"));
assert!(err.is_empty());
}