setTimeout / setInterval's string execution should inherit SourceOrigin correctly
authorutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 28 Jan 2017 00:49:01 +0000 (00:49 +0000)
committerutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 28 Jan 2017 00:49:01 +0000 (00:49 +0000)
https://bugs.webkit.org/show_bug.cgi?id=167097

Reviewed by Darin Adler.

Source/WebCore:

Tests: js/dom/modules/import-from-set-interval.html
       js/dom/modules/import-from-set-timeout.html

* bindings/js/ScriptController.cpp:
(WebCore::ScriptController::executeScriptInWorld):

LayoutTests:

We set the default SourceOrigin for the ScriptController::executeScriptInWorld.
The default SourceOrigin has the document baseURL and CachedScriptFetcher.

setTimeout and setInterval use this interface. And it uses the default SourceOrigin
for the document (Realm of the setTimeout / setInterval). This is the expected
behavior in the dynamic import proposal.

* js/dom/modules/import-from-set-interval-expected.txt: Added.
* js/dom/modules/import-from-set-interval.html: Added.
* js/dom/modules/import-from-set-timeout-expected.txt: Added.
* js/dom/modules/import-from-set-timeout.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/js/dom/modules/import-from-set-interval-expected.txt [new file with mode: 0644]
LayoutTests/js/dom/modules/import-from-set-interval.html [new file with mode: 0644]
LayoutTests/js/dom/modules/import-from-set-timeout-expected.txt [new file with mode: 0644]
LayoutTests/js/dom/modules/import-from-set-timeout.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/ScriptController.cpp

index ec3ad89..aabaf79 100644 (file)
@@ -1,3 +1,22 @@
+2017-01-27  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        setTimeout / setInterval's string execution should inherit SourceOrigin correctly
+        https://bugs.webkit.org/show_bug.cgi?id=167097
+
+        Reviewed by Darin Adler.
+
+        We set the default SourceOrigin for the ScriptController::executeScriptInWorld.
+        The default SourceOrigin has the document baseURL and CachedScriptFetcher.
+
+        setTimeout and setInterval use this interface. And it uses the default SourceOrigin
+        for the document (Realm of the setTimeout / setInterval). This is the expected
+        behavior in the dynamic import proposal.
+
+        * js/dom/modules/import-from-set-interval-expected.txt: Added.
+        * js/dom/modules/import-from-set-interval.html: Added.
+        * js/dom/modules/import-from-set-timeout-expected.txt: Added.
+        * js/dom/modules/import-from-set-timeout.html: Added.
+
 2017-01-27  Simon Fraser  <simon.fraser@apple.com>
 
         Tweak the test to avoid one pixel of difference on some hardware.
diff --git a/LayoutTests/js/dom/modules/import-from-set-interval-expected.txt b/LayoutTests/js/dom/modules/import-from-set-interval-expected.txt
new file mode 100644 (file)
index 0000000..e1bd811
--- /dev/null
@@ -0,0 +1,15 @@
+Test import from setInterval.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Module execution is confined in the module environment.
+PASS typeof cocoa is "undefined"
+PASS typeof exportedCocoa is "object"
+PASS exportedCocoa.taste() is "nice"
+PASS window.imported is true
+PASS window.passedCocoa is window.exportedCocoa
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/js/dom/modules/import-from-set-interval.html b/LayoutTests/js/dom/modules/import-from-set-interval.html
new file mode 100644 (file)
index 0000000..c1f1c9d
--- /dev/null
@@ -0,0 +1,30 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<script src="../../../resources/js-test-pre.js"></script>
+</head>
+<body>
+<script>
+description('Test import from setInterval.');
+
+// Module will be executed asynchronously.
+window.jsTestIsAsync = true;
+window.passedCocoa = null;
+window.id = null;
+
+function loaded(cocoa)
+{
+    window.passedCocoa = cocoa;
+    shouldBeTrue(`window.imported`);
+    shouldBe(`window.passedCocoa`, `window.exportedCocoa`);
+    finishJSTest();
+}
+</script>
+<script>
+</script>
+<script src="../../../resources/js-test-post.js"></script>
+<script type="module">
+window.id = setInterval(`clearInterval(window.id);import("./resources/import-src-simple.js").then((ns) => loaded(ns.ok));`, 0);
+</script>
+</body>
+</html>
diff --git a/LayoutTests/js/dom/modules/import-from-set-timeout-expected.txt b/LayoutTests/js/dom/modules/import-from-set-timeout-expected.txt
new file mode 100644 (file)
index 0000000..21f4c16
--- /dev/null
@@ -0,0 +1,15 @@
+Test import from setTimeout.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Module execution is confined in the module environment.
+PASS typeof cocoa is "undefined"
+PASS typeof exportedCocoa is "object"
+PASS exportedCocoa.taste() is "nice"
+PASS window.imported is true
+PASS window.passedCocoa is window.exportedCocoa
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/js/dom/modules/import-from-set-timeout.html b/LayoutTests/js/dom/modules/import-from-set-timeout.html
new file mode 100644 (file)
index 0000000..20a9452
--- /dev/null
@@ -0,0 +1,29 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<script src="../../../resources/js-test-pre.js"></script>
+</head>
+<body>
+<script>
+description('Test import from setTimeout.');
+
+// Module will be executed asynchronously.
+window.jsTestIsAsync = true;
+window.passedCocoa = null;
+
+function loaded(cocoa)
+{
+    window.passedCocoa = cocoa;
+    shouldBeTrue(`window.imported`);
+    shouldBe(`window.passedCocoa`, `window.exportedCocoa`);
+    finishJSTest();
+}
+</script>
+<script>
+</script>
+<script src="../../../resources/js-test-post.js"></script>
+<script type="module">
+setTimeout(`import("./resources/import-src-simple.js").then((ns) => loaded(ns.ok))`, 0);
+</script>
+</body>
+</html>
index 22706d5..a9dcb1a 100644 (file)
@@ -1,5 +1,18 @@
 2017-01-27  Yusuke Suzuki  <utatane.tea@gmail.com>
 
+        setTimeout / setInterval's string execution should inherit SourceOrigin correctly
+        https://bugs.webkit.org/show_bug.cgi?id=167097
+
+        Reviewed by Darin Adler.
+
+        Tests: js/dom/modules/import-from-set-interval.html
+               js/dom/modules/import-from-set-timeout.html
+
+        * bindings/js/ScriptController.cpp:
+        (WebCore::ScriptController::executeScriptInWorld):
+
+2017-01-27  Yusuke Suzuki  <utatane.tea@gmail.com>
+
         Merge CachedModuleScript and LoadableModuleScript
         https://bugs.webkit.org/show_bug.cgi?id=167500
 
index c0eb1ac..adbeaff 100644 (file)
@@ -649,7 +649,7 @@ void ScriptController::clearScriptObjects()
 JSValue ScriptController::executeScriptInWorld(DOMWrapperWorld& world, const String& script, bool forceUserGesture)
 {
     UserGestureIndicator gestureIndicator(forceUserGesture ? std::optional<ProcessingUserGestureState>(ProcessingUserGesture) : std::nullopt);
-    ScriptSourceCode sourceCode(script, m_frame.document()->url());
+    ScriptSourceCode sourceCode(script, m_frame.document()->url(), TextPosition(), JSC::SourceProviderSourceType::Program, CachedScriptFetcher::create(m_frame.document()->charset()));
 
     if (!canExecuteScripts(AboutToExecuteScript) || isPaused())
         return { };