From f602d63f48067851716d46184746ce26b2e674ba Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Fri, 1 Oct 2021 00:25:58 +0900 Subject: [PATCH] fix(repl): avoid panic when assigned to globalThis (#12273) --- cli/tests/integration/repl_tests.rs | 11 +++++++++++ cli/tools/repl.rs | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/cli/tests/integration/repl_tests.rs b/cli/tests/integration/repl_tests.rs index a8f3545988..3dd5699c64 100644 --- a/cli/tests/integration/repl_tests.rs +++ b/cli/tests/integration/repl_tests.rs @@ -134,6 +134,17 @@ fn pty_ignore_symbols() { }); } +#[test] +fn pty_assign_global_this() { + util::with_pty(&["repl"], |mut console| { + console.write_line("globalThis = 42;"); + console.write_line("close();"); + + let output = console.read_all_output(); + assert!(!output.contains("panicked")); + }); +} + #[test] fn console_log() { let (out, err) = util::run_and_collect_output( diff --git a/cli/tools/repl.rs b/cli/tools/repl.rs index 219ee35022..0144db6605 100644 --- a/cli/tools/repl.rs +++ b/cli/tools/repl.rs @@ -485,7 +485,7 @@ impl ReplSession { pub async fn is_closing(&mut self) -> Result { let closed = self - .evaluate_expression("(globalThis.closed)") + .evaluate_expression("(this.closed)") .await? .get("result") .unwrap()