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
+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.
--- /dev/null
+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
+
--- /dev/null
+<!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>
--- /dev/null
+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
+
--- /dev/null
+<!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>
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
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 { };