diff options
Diffstat (limited to 'cli')
-rw-r--r-- | cli/ops/worker_host.rs | 7 | ||||
-rw-r--r-- | cli/tests/integration_tests.rs | 10 | ||||
-rw-r--r-- | cli/tests/top_level_await_bug.js | 2 | ||||
-rw-r--r-- | cli/tests/top_level_await_bug.out | 1 | ||||
-rw-r--r-- | cli/tests/top_level_await_bug2.js | 15 | ||||
-rw-r--r-- | cli/tests/top_level_await_bug2.out | 4 | ||||
-rw-r--r-- | cli/tests/top_level_await_bug_nested.js | 5 | ||||
-rw-r--r-- | cli/worker.rs | 4 |
8 files changed, 46 insertions, 2 deletions
diff --git a/cli/ops/worker_host.rs b/cli/ops/worker_host.rs index 9175ca0f1..17e0e397f 100644 --- a/cli/ops/worker_host.rs +++ b/cli/ops/worker_host.rs @@ -155,6 +155,13 @@ fn run_worker_thread( if let Err(e) = result { let mut sender = worker.internal_channels.sender.clone(); + + // If sender is closed it means that worker has already been closed from + // within using "globalThis.close()" + if sender.is_closed() { + return; + } + sender .try_send(WorkerEvent::TerminalError(e)) .expect("Failed to post message to host"); diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index 8e2007b42..9ad7bac8c 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -2662,6 +2662,16 @@ itest!(ignore_require { exit_code: 0, }); +itest!(top_level_await_bug { + args: "run --allow-read top_level_await_bug.js", + output: "top_level_await_bug.out", +}); + +itest!(top_level_await_bug2 { + args: "run --allow-read top_level_await_bug2.js", + output: "top_level_await_bug2.out", +}); + #[test] fn cafile_env_fetch() { use deno_core::url::Url; diff --git a/cli/tests/top_level_await_bug.js b/cli/tests/top_level_await_bug.js new file mode 100644 index 000000000..3c6860a5b --- /dev/null +++ b/cli/tests/top_level_await_bug.js @@ -0,0 +1,2 @@ +const mod = await import("./top_level_await_bug_nested.js"); +console.log(mod); diff --git a/cli/tests/top_level_await_bug.out b/cli/tests/top_level_await_bug.out new file mode 100644 index 000000000..f0369645c --- /dev/null +++ b/cli/tests/top_level_await_bug.out @@ -0,0 +1 @@ +Module { default: 1, [Symbol(Symbol.toStringTag)]: "Module" } diff --git a/cli/tests/top_level_await_bug2.js b/cli/tests/top_level_await_bug2.js new file mode 100644 index 000000000..c847bbd34 --- /dev/null +++ b/cli/tests/top_level_await_bug2.js @@ -0,0 +1,15 @@ +const mod = await import("./top_level_await_bug_nested.js"); +console.log(mod); + +const sleep = (n) => new Promise((r) => setTimeout(r, n)); + +await sleep(100); +console.log("slept"); + +window.addEventListener("load", () => { + console.log("load event"); +}); + +setTimeout(() => { + console.log("timeout"); +}, 1000); diff --git a/cli/tests/top_level_await_bug2.out b/cli/tests/top_level_await_bug2.out new file mode 100644 index 000000000..509ee27c2 --- /dev/null +++ b/cli/tests/top_level_await_bug2.out @@ -0,0 +1,4 @@ +Module { default: 1, [Symbol(Symbol.toStringTag)]: "Module" } +slept +load event +timeout diff --git a/cli/tests/top_level_await_bug_nested.js b/cli/tests/top_level_await_bug_nested.js new file mode 100644 index 000000000..894f0de2d --- /dev/null +++ b/cli/tests/top_level_await_bug_nested.js @@ -0,0 +1,5 @@ +const sleep = (n) => new Promise((r) => setTimeout(r, n)); + +await sleep(100); + +export default 1; diff --git a/cli/worker.rs b/cli/worker.rs index 08ccd418e..47e5c4761 100644 --- a/cli/worker.rs +++ b/cli/worker.rs @@ -189,7 +189,7 @@ impl Worker { ) -> Result<(), AnyError> { let id = self.preload_module(module_specifier).await?; self.wait_for_inspector_session(); - self.isolate.mod_evaluate(id) + self.isolate.mod_evaluate(id).await } /// Loads, instantiates and executes provided source code @@ -204,7 +204,7 @@ impl Worker { .load_module(module_specifier, Some(code)) .await?; self.wait_for_inspector_session(); - self.isolate.mod_evaluate(id) + self.isolate.mod_evaluate(id).await } /// Returns a way to communicate with the Worker from other threads. |