Add more module scope related tests with code evaluation by string
authorutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 24 Jan 2018 04:35:18 +0000 (04:35 +0000)
committerutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 24 Jan 2018 04:35:18 +0000 (04:35 +0000)
https://bugs.webkit.org/show_bug.cgi?id=181983

Reviewed by Sam Weinig.

JSTests:

Add more module scope related tests. When the original tests are landed,
we do not have browser integration. This patch adds more module scope tests
with dynamically created script evaluation. We add tests with Function
constructor, direct eval, indirect eval, setTimeout, setInterval, and event handlers.

* modules/scopes-eval.js: Added.
(shouldBe):
* modules/scopes.js:
(shouldBe):

LayoutTests:

* js/dom/modules/module-scope-event-handler-expected.txt: Added.
* js/dom/modules/module-scope-event-handler.html: Added.
* js/dom/modules/module-scope-set-interval-expected.txt: Added.
* js/dom/modules/module-scope-set-interval.html: Added.
* js/dom/modules/module-scope-set-timeout-expected.txt: Added.
* js/dom/modules/module-scope-set-timeout.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@227468 268f45cc-cd09-0410-ab3c-d52691b4dbfc

JSTests/ChangeLog
JSTests/modules/scopes-eval.js [new file with mode: 0644]
JSTests/modules/scopes.js
LayoutTests/ChangeLog
LayoutTests/js/dom/modules/module-scope-event-handler-expected.txt [new file with mode: 0644]
LayoutTests/js/dom/modules/module-scope-event-handler.html [new file with mode: 0644]
LayoutTests/js/dom/modules/module-scope-set-interval-expected.txt [new file with mode: 0644]
LayoutTests/js/dom/modules/module-scope-set-interval.html [new file with mode: 0644]
LayoutTests/js/dom/modules/module-scope-set-timeout-expected.txt [new file with mode: 0644]
LayoutTests/js/dom/modules/module-scope-set-timeout.html [new file with mode: 0644]

index 5b43d42..a2570b2 100644 (file)
@@ -1,3 +1,20 @@
+2018-01-23  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        Add more module scope related tests with code evaluation by string
+        https://bugs.webkit.org/show_bug.cgi?id=181983
+
+        Reviewed by Sam Weinig.
+
+        Add more module scope related tests. When the original tests are landed,
+        we do not have browser integration. This patch adds more module scope tests
+        with dynamically created script evaluation. We add tests with Function
+        constructor, direct eval, indirect eval, setTimeout, setInterval, and event handlers.
+
+        * modules/scopes-eval.js: Added.
+        (shouldBe):
+        * modules/scopes.js:
+        (shouldBe):
+
 2018-01-23  Filip Pizlo  <fpizlo@apple.com>
 
         Unreviewed, retire some microbenchmarks that are proportionately very slow. Benchmark running time should be proportional to their value. Microbenchmarks have little value, so they should be very fast.
diff --git a/JSTests/modules/scopes-eval.js b/JSTests/modules/scopes-eval.js
new file mode 100644 (file)
index 0000000..b50da3d
--- /dev/null
@@ -0,0 +1,24 @@
+import { Cappuccino } from "./scopes/drink.js"
+import { shouldBe } from "./resources/assert.js";
+
+// Separate test from scopes.js since direct eval can taint variables.
+var global = Function("return this")();
+var globalEval = (0, eval);
+global.Cappuccino = 'Global Scope';
+shouldBe(Cappuccino, 'Cappuccino');
+
+(function () {
+    let Cappuccino = 'Function Scope';
+    shouldBe(Cappuccino, 'Function Scope');
+    {
+        let Cappuccino = 'Block Scope';
+        {
+            (function () {
+                shouldBe(Cappuccino, 'Block Scope');
+                shouldBe(eval(`Cappuccino`), 'Block Scope');
+            }());
+        }
+    }
+    shouldBe(Object, global.Object);
+}());
+shouldBe(Object, global.Object)
index d20c65e..d679479 100644 (file)
@@ -1,26 +1,36 @@
 import { Cocoa, Cappuccino, Matcha } from "./scopes/drink.js"
 import { shouldBe } from "./resources/assert.js";
 
+var global = Function("return this")();
+var globalEval = (0, eval);
+global.Cappuccino = 'Global Scope';
+
 {
     let Cocoa = 42;
     shouldBe(Cocoa, 42);
 }
 shouldBe(Cocoa, 'Cocoa');
-shouldBe(Cappuccino, 'Cappuccino');
+shouldBe(Cappuccino, 'Cappuccino'); // Module Scope.
 shouldBe(Matcha, 'Matcha');
 
-var global = Function("return this")();
-
 (function () {
     var Cocoa = 42;
-    let Cappuccino = 'CPO';
+    let Cappuccino = 'Function Scope';
     shouldBe(Cocoa, 42);
-    shouldBe(Cappuccino, 'CPO');
+    shouldBe(Cappuccino, 'Function Scope');
     shouldBe(Matcha, 'Matcha');
     {
+        let Cappuccino = 'Block Scope';
         const Matcha = 50;
         shouldBe(Matcha, 50);
         shouldBe(Object, global.Object);
+        {
+            (function () {
+                shouldBe(Cappuccino, 'Block Scope');
+                shouldBe(globalEval(`Cappuccino`), 'Global Scope');
+                shouldBe(Function(`return Cappuccino`)(), 'Global Scope');
+            }());
+        }
     }
     shouldBe(Object, global.Object);
 }());
index d3acaf7..733f13c 100644 (file)
@@ -1,3 +1,17 @@
+2018-01-23  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        Add more module scope related tests with code evaluation by string
+        https://bugs.webkit.org/show_bug.cgi?id=181983
+
+        Reviewed by Sam Weinig.
+
+        * js/dom/modules/module-scope-event-handler-expected.txt: Added.
+        * js/dom/modules/module-scope-event-handler.html: Added.
+        * js/dom/modules/module-scope-set-interval-expected.txt: Added.
+        * js/dom/modules/module-scope-set-interval.html: Added.
+        * js/dom/modules/module-scope-set-timeout-expected.txt: Added.
+        * js/dom/modules/module-scope-set-timeout.html: Added.
+
 2018-01-23  Matt Lewis  <jlewis3@apple.com>
 
         Marked http/tests/resourceLoadStatistics/non-prevalent-resources-can-access-cookies-in-a-third-party-context.html as flaky.
diff --git a/LayoutTests/js/dom/modules/module-scope-event-handler-expected.txt b/LayoutTests/js/dom/modules/module-scope-event-handler-expected.txt
new file mode 100644 (file)
index 0000000..8099ef8
--- /dev/null
@@ -0,0 +1,13 @@
+Test relationship between module scope and event handlers
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Module is not executed yet.
+PASS visibleAtATime is "Module Scope"
+PASS visibleAtATime is "Module Scope"
+PASS visibleAtATime is "Global Scope"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/js/dom/modules/module-scope-event-handler.html b/LayoutTests/js/dom/modules/module-scope-event-handler.html
new file mode 100644 (file)
index 0000000..3d2bf65
--- /dev/null
@@ -0,0 +1,32 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<script src="../../../resources/js-test-pre.js"></script>
+</head>
+<body>
+<div id="target"></div>
+<div id="target2" onclick="window.visibleAtATime = cocoa; shouldBeEqualToString('visibleAtATime', 'Global Scope'); finishJSTest();"></div>
+<script>
+description("Test relationship between module scope and event handlers");
+
+window.jsTestIsAsync = true;
+debug("Module is not executed yet.");
+window.cocoa = 'Global Scope'
+window.visibleAtATime = null;
+</script>
+<script type="module">
+var cocoa = 'Module Scope';
+window.visibleAtATime = cocoa;
+shouldBeEqualToString("visibleAtATime", "Module Scope");
+var target = document.getElementById('target');
+target.onclick = function () {
+    window.visibleAtATime = cocoa;
+    shouldBeEqualToString("visibleAtATime", "Module Scope");
+    var target2 = document.getElementById('target2');
+    target2.click();
+};
+target.click();
+</script>
+<script src="../../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/js/dom/modules/module-scope-set-interval-expected.txt b/LayoutTests/js/dom/modules/module-scope-set-interval-expected.txt
new file mode 100644 (file)
index 0000000..8c757c9
--- /dev/null
@@ -0,0 +1,13 @@
+Test relationship between module scope and setInterval
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Module is not executed yet.
+PASS visibleAtATime is "Module Scope"
+PASS visibleAtATime is "Module Scope"
+PASS visibleAtATime is "Global Scope"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/js/dom/modules/module-scope-set-interval.html b/LayoutTests/js/dom/modules/module-scope-set-interval.html
new file mode 100644 (file)
index 0000000..1fd07af
--- /dev/null
@@ -0,0 +1,34 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<script src="../../../resources/js-test-pre.js"></script>
+</head>
+<body>
+<script>
+description("Test relationship between module scope and setInterval");
+
+window.jsTestIsAsync = true;
+debug("Module is not executed yet.");
+window.cocoa = 'Global Scope'
+window.visibleAtATime = null;
+window.token = null;
+</script>
+<script type="module">
+var cocoa = 'Module Scope';
+window.visibleAtATime = cocoa;
+shouldBeEqualToString("visibleAtATime", "Module Scope");
+token = setInterval(function () {
+    clearInterval(token);
+    window.visibleAtATime = cocoa;
+    shouldBeEqualToString("visibleAtATime", "Module Scope");
+    token = setInterval(`
+        clearInterval(token);
+        window.visibleAtATime = cocoa;
+        shouldBeEqualToString("visibleAtATime", "Global Scope");
+        finishJSTest();
+    `, 0);
+}, 0);
+</script>
+<script src="../../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/js/dom/modules/module-scope-set-timeout-expected.txt b/LayoutTests/js/dom/modules/module-scope-set-timeout-expected.txt
new file mode 100644 (file)
index 0000000..5425e52
--- /dev/null
@@ -0,0 +1,13 @@
+Test relationship between module scope and setTimeout
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Module is not executed yet.
+PASS visibleAtATime is "Module Scope"
+PASS visibleAtATime is "Module Scope"
+PASS visibleAtATime is "Global Scope"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/js/dom/modules/module-scope-set-timeout.html b/LayoutTests/js/dom/modules/module-scope-set-timeout.html
new file mode 100644 (file)
index 0000000..c39b817
--- /dev/null
@@ -0,0 +1,31 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<script src="../../../resources/js-test-pre.js"></script>
+</head>
+<body>
+<script>
+description("Test relationship between module scope and setTimeout");
+
+window.jsTestIsAsync = true;
+debug("Module is not executed yet.");
+window.cocoa = 'Global Scope'
+window.visibleAtATime = null;
+</script>
+<script type="module">
+var cocoa = 'Module Scope';
+window.visibleAtATime = cocoa;
+shouldBeEqualToString("visibleAtATime", "Module Scope");
+setTimeout(function () {
+    window.visibleAtATime = cocoa;
+    shouldBeEqualToString("visibleAtATime", "Module Scope");
+    setTimeout(`
+        window.visibleAtATime = cocoa;
+        shouldBeEqualToString("visibleAtATime", "Global Scope");
+        finishJSTest();
+    `, 0);
+}, 0);
+</script>
+<script src="../../../resources/js-test-post.js"></script>
+</body>
+</html>