summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/lib.rs7
-rw-r--r--cli/tests/034_onload.out4
-rw-r--r--cli/tests/034_onload/imported.ts15
-rw-r--r--cli/tests/034_onload/main.ts21
-rw-r--r--cli/tests/034_onload/nest_imported.ts15
-rw-r--r--cli/tests/034_onload_imported.ts1
6 files changed, 43 insertions, 20 deletions
diff --git a/cli/lib.rs b/cli/lib.rs
index 1e598e262..09134dcdb 100644
--- a/cli/lib.rs
+++ b/cli/lib.rs
@@ -371,12 +371,17 @@ fn run_script(flags: DenoFlags, argv: Vec<String>) {
js_check(worker.execute("denoMain()"));
debug!("main_module {}", main_module);
+ let mut worker_ = worker.clone();
+
worker
.execute_mod_async(&main_module, false)
.and_then(move |()| {
js_check(worker.execute("window.dispatchEvent(new Event('load'))"));
- worker.then(|result| {
+ worker.then(move |result| {
js_check(result);
+ js_check(
+ worker_.execute("window.dispatchEvent(new Event('unload'))"),
+ );
Ok(())
})
})
diff --git a/cli/tests/034_onload.out b/cli/tests/034_onload.out
index 0939be8cd..c9556e991 100644
--- a/cli/tests/034_onload.out
+++ b/cli/tests/034_onload.out
@@ -5,3 +5,7 @@ got load event in onload function
got load event in event handler (nest_imported)
got load event in event handler (imported)
got load event in event handler (main)
+got unload event in onunload function
+got unload event in event handler (nest_imported)
+got unload event in event handler (imported)
+got unload event in event handler (main)
diff --git a/cli/tests/034_onload/imported.ts b/cli/tests/034_onload/imported.ts
index 5cf2d7b4c..d71f9d654 100644
--- a/cli/tests/034_onload/imported.ts
+++ b/cli/tests/034_onload/imported.ts
@@ -1,8 +1,11 @@
+import { assert } from "../../../js/deps/https/deno.land/std/testing/asserts.ts";
import "./nest_imported.ts";
-window.addEventListener(
- "load",
- (e: Event): void => {
- console.log(`got ${e.type} event in event handler (imported)`);
- }
-);
+
+const handler = (e: Event): void => {
+ assert(!e.cancelable);
+ console.log(`got ${e.type} event in event handler (imported)`);
+};
+
+window.addEventListener("load", handler);
+window.addEventListener("unload", handler);
console.log("log from imported script");
diff --git a/cli/tests/034_onload/main.ts b/cli/tests/034_onload/main.ts
index 68851950a..c3c6bdcc9 100644
--- a/cli/tests/034_onload/main.ts
+++ b/cli/tests/034_onload/main.ts
@@ -1,14 +1,23 @@
+import { assert } from "../../../js/deps/https/deno.land/std/testing/asserts.ts";
import "./imported.ts";
-window.addEventListener(
- "load",
- (e: Event): void => {
- console.log(`got ${e.type} event in event handler (main)`);
- }
-);
+const eventHandler = (e: Event): void => {
+ assert(!e.cancelable);
+ console.log(`got ${e.type} event in event handler (main)`);
+};
+
+window.addEventListener("load", eventHandler);
+
+window.addEventListener("unload", eventHandler);
window.onload = (e: Event): void => {
+ assert(!e.cancelable);
console.log(`got ${e.type} event in onload function`);
};
+window.onunload = (e: Event): void => {
+ assert(!e.cancelable);
+ console.log(`got ${e.type} event in onunload function`);
+};
+
console.log("log from main");
diff --git a/cli/tests/034_onload/nest_imported.ts b/cli/tests/034_onload/nest_imported.ts
index 2e2bee1d5..3c4b1d96a 100644
--- a/cli/tests/034_onload/nest_imported.ts
+++ b/cli/tests/034_onload/nest_imported.ts
@@ -1,7 +1,10 @@
-window.addEventListener(
- "load",
- (e: Event): void => {
- console.log(`got ${e.type} event in event handler (nest_imported)`);
- }
-);
+import { assert } from "../../../js/deps/https/deno.land/std/testing/asserts.ts";
+
+const handler = (e: Event): void => {
+ assert(!e.cancelable);
+ console.log(`got ${e.type} event in event handler (nest_imported)`);
+};
+
+window.addEventListener("load", handler);
+window.addEventListener("unload", handler);
console.log("log from nest_imported script");
diff --git a/cli/tests/034_onload_imported.ts b/cli/tests/034_onload_imported.ts
deleted file mode 100644
index d97aabeca..000000000
--- a/cli/tests/034_onload_imported.ts
+++ /dev/null
@@ -1 +0,0 @@
-console.log("from imported script");