summaryrefslogtreecommitdiff
path: root/cli/tests/tla
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2020-10-14 14:04:09 +0200
committerGitHub <noreply@github.com>2020-10-14 14:04:09 +0200
commit135053486c4bd112ebd7d0b25c94a8dd346472e6 (patch)
tree24eae514d8de332a0968de869172f651b30b5078 /cli/tests/tla
parent10654fa95553866c63a56a7f84c7ec47fb7aac9c (diff)
fix: top-level-await module execution (#7946)
This commit changes implementation of top-level-await in "deno_core". Previously promise returned from module evaluation was not awaited, leading to out-of-order execution of modules that have TLA. It's been fixed by changing "JsRuntime::mod_evaluate" to be an async function that resolves when the promise returned from module evaluation also resolves. When waiting for promise resolution event loop is polled repeatedly, until there are no more dynamic imports or pending ops.
Diffstat (limited to 'cli/tests/tla')
-rw-r--r--cli/tests/tla/a.js3
-rw-r--r--cli/tests/tla/b.js7
-rw-r--r--cli/tests/tla/c.js3
-rw-r--r--cli/tests/tla/d.js6
-rw-r--r--cli/tests/tla/order.js1
-rw-r--r--cli/tests/tla/parent.js9
6 files changed, 29 insertions, 0 deletions
diff --git a/cli/tests/tla/a.js b/cli/tests/tla/a.js
new file mode 100644
index 000000000..c3ef3f7db
--- /dev/null
+++ b/cli/tests/tla/a.js
@@ -0,0 +1,3 @@
+import order from "./order.js";
+
+order.push("b");
diff --git a/cli/tests/tla/b.js b/cli/tests/tla/b.js
new file mode 100644
index 000000000..3271c92d8
--- /dev/null
+++ b/cli/tests/tla/b.js
@@ -0,0 +1,7 @@
+import order from "./order.js";
+
+await new Promise((resolve) => {
+ setTimeout(resolve, 200);
+});
+
+order.push("a");
diff --git a/cli/tests/tla/c.js b/cli/tests/tla/c.js
new file mode 100644
index 000000000..806eb0a8b
--- /dev/null
+++ b/cli/tests/tla/c.js
@@ -0,0 +1,3 @@
+import order from "./order.js";
+
+order.push("c");
diff --git a/cli/tests/tla/d.js b/cli/tests/tla/d.js
new file mode 100644
index 000000000..2b5fd3c45
--- /dev/null
+++ b/cli/tests/tla/d.js
@@ -0,0 +1,6 @@
+import order from "./order.js";
+
+const end = Date.now() + 500;
+while (end < Date.now()) {}
+
+order.push("d");
diff --git a/cli/tests/tla/order.js b/cli/tests/tla/order.js
new file mode 100644
index 000000000..f213a562c
--- /dev/null
+++ b/cli/tests/tla/order.js
@@ -0,0 +1 @@
+export default ["order"];
diff --git a/cli/tests/tla/parent.js b/cli/tests/tla/parent.js
new file mode 100644
index 000000000..1ecc15463
--- /dev/null
+++ b/cli/tests/tla/parent.js
@@ -0,0 +1,9 @@
+import order from "./order.js";
+import "./a.js";
+import "./b.js";
+import "./c.js";
+import "./d.js";
+
+order.push("parent");
+
+export default order;