Diff
Modified: trunk/LayoutTests/ChangeLog (260130 => 260131)
--- trunk/LayoutTests/ChangeLog 2020-04-15 15:46:50 UTC (rev 260130)
+++ trunk/LayoutTests/ChangeLog 2020-04-15 15:48:11 UTC (rev 260131)
@@ -1,3 +1,30 @@
+2020-04-15 Yusuke Suzuki <ysuz...@apple.com>
+
+ import.meta.url: baseURL for a module script should be response URL, not request URL
+ https://bugs.webkit.org/show_bug.cgi?id=205294
+
+ Reviewed by Youenn Fablet.
+
+ AppleWin networking does not properly propagate fragment if redirect location clears it. This is a known issue[1].
+
+ [1]: See `http/tests/navigation/redirect-to-fragment2.html [ Failure ]` in platform/win/TestExpectations.
+
+ * http/wpt/html/semantics/scripting-1/the-script-element/module/module-meta-url-redirect-expected.txt: Added.
+ * http/wpt/html/semantics/scripting-1/the-script-element/module/module-meta-url-redirect-with-fragment-expected.txt: Added.
+ * http/wpt/html/semantics/scripting-1/the-script-element/module/module-meta-url-redirect-with-fragment.html: Added.
+ * http/wpt/html/semantics/scripting-1/the-script-element/module/module-meta-url-redirect.html: Added.
+ * http/wpt/html/semantics/scripting-1/the-script-element/module/module-meta-url-with-fragment-expected.txt: Added.
+ * http/wpt/html/semantics/scripting-1/the-script-element/module/module-meta-url-with-fragment.html: Added.
+ * http/wpt/html/semantics/scripting-1/the-script-element/module/resources/import-meta-url-expose.js: Added.
+ * http/wpt/resources/redirect.py: Added.
+ (main):
+ * http/wpt/service-workers/module-meta-url-fragment-worker.js: Added.
+ (async e):
+ * http/wpt/service-workers/module-meta-url-fragment.https-expected.txt: Added.
+ * http/wpt/service-workers/module-meta-url-fragment.https.html: Added.
+ * http/wpt/service-workers/resources/module-meta-url-fragment.html: Added.
+ * platform/win/http/wpt/html/semantics/scripting-1/the-script-element/module/module-meta-url-redirect-with-fragment-expected.txt: Added.
+
2020-04-15 Diego Pino Garcia <dp...@igalia.com>
[GTK] Gardening of flaky failures
Added: trunk/LayoutTests/http/wpt/html/semantics/scripting-1/the-script-element/module/module-meta-url-redirect-expected.txt (0 => 260131)
--- trunk/LayoutTests/http/wpt/html/semantics/scripting-1/the-script-element/module/module-meta-url-redirect-expected.txt (rev 0)
+++ trunk/LayoutTests/http/wpt/html/semantics/scripting-1/the-script-element/module/module-meta-url-redirect-expected.txt 2020-04-15 15:48:11 UTC (rev 260131)
@@ -0,0 +1,3 @@
+
+PASS import.meta.url should be redirected url
+
Added: trunk/LayoutTests/http/wpt/html/semantics/scripting-1/the-script-element/module/module-meta-url-redirect-with-fragment-expected.txt (0 => 260131)
--- trunk/LayoutTests/http/wpt/html/semantics/scripting-1/the-script-element/module/module-meta-url-redirect-with-fragment-expected.txt (rev 0)
+++ trunk/LayoutTests/http/wpt/html/semantics/scripting-1/the-script-element/module/module-meta-url-redirect-with-fragment-expected.txt 2020-04-15 15:48:11 UTC (rev 260131)
@@ -0,0 +1,12 @@
+
+PASS import-meta-url-expose.js#test1
+PASS import-meta-url-expose.js#test2
+PASS import-meta-url-expose.js#test4
+PASS import-meta-url-expose.js#testA
+PASS import-meta-url-expose.js
+PASS import-meta-url-expose.js#testC
+PASS import-meta-url-expose.js#testD
+PASS import-meta-url-expose.js#testCC
+PASS import-meta-url-expose.js#testEE
+PASS import-meta-url-expose.js#testGGG
+
Added: trunk/LayoutTests/http/wpt/html/semantics/scripting-1/the-script-element/module/module-meta-url-redirect-with-fragment.html (0 => 260131)
--- trunk/LayoutTests/http/wpt/html/semantics/scripting-1/the-script-element/module/module-meta-url-redirect-with-fragment.html (rev 0)
+++ trunk/LayoutTests/http/wpt/html/semantics/scripting-1/the-script-element/module/module-meta-url-redirect-with-fragment.html 2020-04-15 15:48:11 UTC (rev 260131)
@@ -0,0 +1,89 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>import.meta.url should be redirected url with fragment</title>
+<script src=""
+<script src=""
+</head>
+<body>
+<script>
+globalThis.metaURLs = [];
+
+function redirectTest(targetURL, expected)
+{
+ return new Promise(function (resolve, reject) {
+ let script = document.createElement('script');
+ script.type = 'module';
+ script.src = ""
+ script._onload_ = function () {
+ try {
+ assert_equals(globalThis.metaURLs.length, 1);
+ let url = ""
+ assert_equals(url, expected);
+ resolve();
+ } catch (error) {
+ reject(error);
+ }
+ };
+ script._onerror_ = reject;
+ document.body.appendChild(script);
+ });
+}
+
+const root = `http://${document.location.host}/WebKit`;
+const basename = `http://${document.location.host}/WebKit/html/semantics/scripting-1/the-script-element/module`;
+
+promise_test(() => {
+ return redirectTest('/WebKit/resources/redirect.py?location=' + encodeURIComponent(`${basename}/resources/import-meta-url-expose.js#test1`), `${basename}/resources/import-meta-url-expose.js#test1`);
+}, `import-meta-url-expose.js#test1`);
+
+promise_test(() => {
+ return redirectTest('/WebKit/resources/redirect.py?location=' + encodeURIComponent(`${basename}/resources/import-meta-url-expose.js`) + "#test2", `${basename}/resources/import-meta-url-expose.js#test2`);
+}, `import-meta-url-expose.js#test2`);
+
+promise_test(() => {
+ return redirectTest('/WebKit/resources/redirect.py?location=' + encodeURIComponent(`${basename}/resources/import-meta-url-expose.js#test4`) + "#test3", `${basename}/resources/import-meta-url-expose.js#test4`);
+}, `import-meta-url-expose.js#test4`);
+
+promise_test(() => {
+ return redirectTest('/WebKit/resources/redirect.py?location=' + encodeURIComponent(`${root}/resources/redirect.py?location=` + encodeURIComponent(`${basename}/resources/import-meta-url-expose.js#testA`)), `${basename}/resources/import-meta-url-expose.js#testA`);
+}, `import-meta-url-expose.js#testA`);
+
+// FIXME: This test pass once the following issue is fixed.
+// https://bugs.webkit.org/show_bug.cgi?id=158420
+// promise_test(() => {
+// return redirectTest('/WebKit/resources/redirect.py?location=' + encodeURIComponent(`${root}/resources/redirect.py?location=` + encodeURIComponent(`${basename}/resources/import-meta-url-expose.js`) + "#testB"), `${basename}/resources/import-meta-url-expose.js#testB`);
+// }, `import-meta-url-expose.js#testB`);
+
+promise_test(() => {
+ return redirectTest('/WebKit/resources/redirect.py?location=' + encodeURIComponent(`${root}/resources/redirect.py?location=` + encodeURIComponent(`${basename}/resources/import-meta-url-expose.js`)), `${basename}/resources/import-meta-url-expose.js`);
+}, `import-meta-url-expose.js`);
+
+promise_test(() => {
+ return redirectTest('/WebKit/resources/redirect.py?location=' + encodeURIComponent(`${root}/resources/redirect.py?location=` + encodeURIComponent(`${basename}/resources/import-meta-url-expose.js`)) + "#testC", `${basename}/resources/import-meta-url-expose.js#testC`);
+}, `import-meta-url-expose.js#testC`);
+
+promise_test(() => {
+ return redirectTest('/WebKit/resources/redirect.py?location=' + encodeURIComponent(`${root}/resources/redirect.py?location=` + encodeURIComponent(`${basename}/resources/import-meta-url-expose.js`)) + "#testD", `${basename}/resources/import-meta-url-expose.js#testD`);
+}, `import-meta-url-expose.js#testD`);
+
+// FIXME: This test pass once the following issue is fixed.
+// https://bugs.webkit.org/show_bug.cgi?id=158420
+// promise_test(() => {
+// return redirectTest('/WebKit/resources/redirect.py?location=' + encodeURIComponent(`${root}/resources/redirect.py?location=` + encodeURIComponent(`${basename}/resources/import-meta-url-expose.js`) + "#testAA") + "#testBB", `${basename}/resources/import-meta-url-expose.js#testAA`);
+// }, `import-meta-url-expose.js#testAA`);
+
+promise_test(() => {
+ return redirectTest('/WebKit/resources/redirect.py?location=' + encodeURIComponent(`${root}/resources/redirect.py?location=` + encodeURIComponent(`${basename}/resources/import-meta-url-expose.js#testCC`)) + "#testDD", `${basename}/resources/import-meta-url-expose.js#testCC`);
+}, `import-meta-url-expose.js#testCC`);
+
+promise_test(() => {
+ return redirectTest('/WebKit/resources/redirect.py?location=' + encodeURIComponent(`${root}/resources/redirect.py?location=` + encodeURIComponent(`${basename}/resources/import-meta-url-expose.js#testEE`) + "#testFF"), `${basename}/resources/import-meta-url-expose.js#testEE`);
+}, `import-meta-url-expose.js#testEE`);
+
+promise_test(() => {
+ return redirectTest('/WebKit/resources/redirect.py?location=' + encodeURIComponent(`${root}/resources/redirect.py?location=` + encodeURIComponent(`${basename}/resources/import-meta-url-expose.js#testGGG`) + "#testHHH") + "#testIII", `${basename}/resources/import-meta-url-expose.js#testGGG`);
+}, `import-meta-url-expose.js#testGGG`);
+</script>
+</body>
+</html>
Added: trunk/LayoutTests/http/wpt/html/semantics/scripting-1/the-script-element/module/module-meta-url-redirect.html (0 => 260131)
--- trunk/LayoutTests/http/wpt/html/semantics/scripting-1/the-script-element/module/module-meta-url-redirect.html (rev 0)
+++ trunk/LayoutTests/http/wpt/html/semantics/scripting-1/the-script-element/module/module-meta-url-redirect.html 2020-04-15 15:48:11 UTC (rev 260131)
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>import.meta.url should be redirected url</title>
+<script src=""
+<script src=""
+</head>
+<body>
+<script>
+globalThis.metaURLs = [];
+const basename = `http://${document.location.host}/WebKit/html/semantics/scripting-1/the-script-element/module`;
+promise_test(() => {
+ return new Promise(function (resolve, reject) {
+ let script = document.createElement('script');
+ script.type = 'module';
+ script.src = '' + encodeURIComponent(`${basename}/resources/import-meta-url-expose.js`);
+ script._onload_ = function () {
+ try {
+ assert_equals(globalThis.metaURLs.length, 1);
+ assert_equals(globalThis.metaURLs[0], `${basename}/resources/import-meta-url-expose.js`);
+ resolve();
+ } catch (e) {
+ reject(e);
+ }
+ };
+ script._onerror_ = reject;
+ document.body.appendChild(script);
+ });
+}, 'import.meta.url should be redirected url');
+</script>
+</body>
+</html>
Added: trunk/LayoutTests/http/wpt/html/semantics/scripting-1/the-script-element/module/module-meta-url-with-fragment-expected.txt (0 => 260131)
--- trunk/LayoutTests/http/wpt/html/semantics/scripting-1/the-script-element/module/module-meta-url-with-fragment-expected.txt (rev 0)
+++ trunk/LayoutTests/http/wpt/html/semantics/scripting-1/the-script-element/module/module-meta-url-with-fragment-expected.txt 2020-04-15 15:48:11 UTC (rev 260131)
@@ -0,0 +1,3 @@
+
+PASS import.meta.url should be have a fragment
+
Added: trunk/LayoutTests/http/wpt/html/semantics/scripting-1/the-script-element/module/module-meta-url-with-fragment.html (0 => 260131)
--- trunk/LayoutTests/http/wpt/html/semantics/scripting-1/the-script-element/module/module-meta-url-with-fragment.html (rev 0)
+++ trunk/LayoutTests/http/wpt/html/semantics/scripting-1/the-script-element/module/module-meta-url-with-fragment.html 2020-04-15 15:48:11 UTC (rev 260131)
@@ -0,0 +1,33 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>import.meta.url should have a fragment</title>
+<script src=""
+<script src=""
+</head>
+<body>
+<script>
+globalThis.metaURLs = [];
+const basename = `http://${document.location.host}/WebKit/html/semantics/scripting-1/the-script-element/module`;
+promise_test(() => {
+ return new Promise(function (resolve, reject) {
+ let script = document.createElement('script');
+ script.type = 'module';
+ script.src = ""
+ script._onload_ = function () {
+ try {
+ assert_equals(globalThis.metaURLs.length, 1);
+ let url = ""
+ assert_equals(url, `${basename}/resources/import-meta-url-expose.js#test`);
+ resolve();
+ } catch (e) {
+ reject(e);
+ }
+ };
+ script._onerror_ = reject;
+ document.body.appendChild(script);
+ });
+}, 'import.meta.url should be have a fragment');
+</script>
+</body>
+</html>
Added: trunk/LayoutTests/http/wpt/html/semantics/scripting-1/the-script-element/module/resources/import-meta-url-expose.js (0 => 260131)
--- trunk/LayoutTests/http/wpt/html/semantics/scripting-1/the-script-element/module/resources/import-meta-url-expose.js (rev 0)
+++ trunk/LayoutTests/http/wpt/html/semantics/scripting-1/the-script-element/module/resources/import-meta-url-expose.js 2020-04-15 15:48:11 UTC (rev 260131)
@@ -0,0 +1 @@
+globalThis.metaURLs.push(import.meta.url);
Added: trunk/LayoutTests/http/wpt/resources/redirect.py (0 => 260131)
--- trunk/LayoutTests/http/wpt/resources/redirect.py (rev 0)
+++ trunk/LayoutTests/http/wpt/resources/redirect.py 2020-04-15 15:48:11 UTC (rev 260131)
@@ -0,0 +1,5 @@
+def main(request, response):
+ headers = [("Cache-Control", "no-cache"),
+ ("Pragma", "no-cache"),
+ ("Location", request.GET['location'])]
+ return 302, headers, ""
Added: trunk/LayoutTests/http/wpt/service-workers/module-meta-url-fragment-worker.js (0 => 260131)
--- trunk/LayoutTests/http/wpt/service-workers/module-meta-url-fragment-worker.js (rev 0)
+++ trunk/LayoutTests/http/wpt/service-workers/module-meta-url-fragment-worker.js 2020-04-15 15:48:11 UTC (rev 260131)
@@ -0,0 +1,11 @@
+addEventListener("fetch", async (e) => {
+ if (e.request.url.indexOf("module-meta-url.js") !== -1) {
+ let blob = new Blob([`globalThis.metaURLs.push(import.meta.url);`], {
+ type: "application/_javascript_"
+ });
+ e.respondWith(new Response(blob, {
+ status: 200,
+ }));
+ return;
+ }
+});
Added: trunk/LayoutTests/http/wpt/service-workers/module-meta-url-fragment.https-expected.txt (0 => 260131)
--- trunk/LayoutTests/http/wpt/service-workers/module-meta-url-fragment.https-expected.txt (rev 0)
+++ trunk/LayoutTests/http/wpt/service-workers/module-meta-url-fragment.https-expected.txt 2020-04-15 15:48:11 UTC (rev 260131)
@@ -0,0 +1,5 @@
+
+PASS Setup worker
+PASS Frame to a registered scope
+PASS Clean-up
+
Added: trunk/LayoutTests/http/wpt/service-workers/module-meta-url-fragment.https.html (0 => 260131)
--- trunk/LayoutTests/http/wpt/service-workers/module-meta-url-fragment.https.html (rev 0)
+++ trunk/LayoutTests/http/wpt/service-workers/module-meta-url-fragment.https.html 2020-04-15 15:48:11 UTC (rev 260131)
@@ -0,0 +1,74 @@
+<html>
+<head>
+<title>Service Worker Fetch Modules Fragment of import.meta.url</title>
+<script src=""
+<script src=""
+</head>
+<body>
+<script>
+const scope = "resources/module-meta-url-fragment.html";
+let registration;
+
+function withFrame(url)
+{
+ return new Promise((resolve, reject) => {
+ let frame = document.createElement('iframe');
+ let counter = 0;
+ function next() {
+ if (++counter === 2)
+ resolve(frame);
+ }
+ window.addEventListener('message', function(ev) {
+ try {
+ if (ev.origin !== document.location.origin)
+ return;
+ let metaURLs = JSON.parse(ev.data);
+ assert_equals(metaURLs.length, 4);
+ // We are reusing Response#url from ServiceWorker directly without considering fragment propagation.
+ assert_equals(metaURLs[0], `https://localhost:9443/WebKit/service-workers/resources/module-meta-url.js#fragment`);
+ assert_equals(metaURLs[1], `https://localhost:9443/WebKit/service-workers/resources/module-meta-url.js#fragment`);
+ assert_equals(metaURLs[2], `https://localhost:9443/WebKit/service-workers/resources/module-meta-url.js#fragment`);
+ assert_equals(metaURLs[3], `https://localhost:9443/WebKit/service-workers/resources/module-meta-url.js#fragment`);
+ next();
+ } catch (error) {
+ reject(error);
+ }
+ }, false);
+ frame._onload_ = () => { next(); };
+ frame.src = ""
+ document.body.appendChild(frame);
+ });
+}
+
+async function registerServiceWorker(scope)
+{
+ let registration = await navigator.serviceWorker.register("module-meta-url-fragment-worker.js", { scope : scope });
+ let activeWorker = registration.active;
+ if (activeWorker)
+ return;
+ activeWorker = registration.installing;
+ return new Promise(resolve => {
+ activeWorker.addEventListener('statechange', () => {
+ if (activeWorker.state === "activated")
+ resolve(registration);
+ });
+ });
+}
+
+promise_test(async (test) => {
+ registration = await registerServiceWorker(scope);
+}, "Setup worker");
+
+promise_test(async (test) => {
+ let frame = await withFrame(scope);
+ assert_true(frame.contentWindow.navigator.serviceWorker.controller !== null);
+ frame.remove();
+}, "Frame to a registered scope");
+
+promise_test(async (test) => {
+ registration.unregister();
+}, "Clean-up");
+
+</script>
+</body>
+</html>
Added: trunk/LayoutTests/http/wpt/service-workers/resources/module-meta-url-fragment.html (0 => 260131)
--- trunk/LayoutTests/http/wpt/service-workers/resources/module-meta-url-fragment.html (rev 0)
+++ trunk/LayoutTests/http/wpt/service-workers/resources/module-meta-url-fragment.html 2020-04-15 15:48:11 UTC (rev 260131)
@@ -0,0 +1,12 @@
+<html>
+<head>
+<script>
+globalThis.metaURLs = [];
+</script>
+<script type="module" src=""
+<script type="module" src=""
+<script type="module" src=""
+<script type="module" src=""
+<script type="module">
+window.parent.postMessage(JSON.stringify(globalThis.metaURLs), "*");
+</script>
Added: trunk/LayoutTests/platform/win/http/wpt/html/semantics/scripting-1/the-script-element/module/module-meta-url-redirect-with-fragment-expected.txt (0 => 260131)
--- trunk/LayoutTests/platform/win/http/wpt/html/semantics/scripting-1/the-script-element/module/module-meta-url-redirect-with-fragment-expected.txt (rev 0)
+++ trunk/LayoutTests/platform/win/http/wpt/html/semantics/scripting-1/the-script-element/module/module-meta-url-redirect-with-fragment-expected.txt 2020-04-15 15:48:11 UTC (rev 260131)
@@ -0,0 +1,12 @@
+
+PASS import-meta-url-expose.js#test1
+FAIL import-meta-url-expose.js#test2 assert_equals: expected "http://localhost:8800/WebKit/html/semantics/scripting-1/the-script-element/module/resources/import-meta-url-expose.js#test2" but got "http://localhost:8800/WebKit/html/semantics/scripting-1/the-script-element/module/resources/import-meta-url-expose.js"
+PASS import-meta-url-expose.js#test4
+PASS import-meta-url-expose.js#testA
+PASS import-meta-url-expose.js
+FAIL import-meta-url-expose.js#testC assert_equals: expected "http://localhost:8800/WebKit/html/semantics/scripting-1/the-script-element/module/resources/import-meta-url-expose.js#testC" but got "http://localhost:8800/WebKit/html/semantics/scripting-1/the-script-element/module/resources/import-meta-url-expose.js"
+FAIL import-meta-url-expose.js#testD assert_equals: expected "http://localhost:8800/WebKit/html/semantics/scripting-1/the-script-element/module/resources/import-meta-url-expose.js#testD" but got "http://localhost:8800/WebKit/html/semantics/scripting-1/the-script-element/module/resources/import-meta-url-expose.js"
+PASS import-meta-url-expose.js#testCC
+PASS import-meta-url-expose.js#testEE
+PASS import-meta-url-expose.js#testGGG
+
Modified: trunk/Source/WebCore/ChangeLog (260130 => 260131)
--- trunk/Source/WebCore/ChangeLog 2020-04-15 15:46:50 UTC (rev 260130)
+++ trunk/Source/WebCore/ChangeLog 2020-04-15 15:48:11 UTC (rev 260131)
@@ -1,3 +1,20 @@
+2020-04-15 Yusuke Suzuki <ysuz...@apple.com>
+
+ import.meta.url: baseURL for a module script should be response URL, not request URL
+ https://bugs.webkit.org/show_bug.cgi?id=205294
+
+ Reviewed by Youenn Fablet.
+
+ The module should expose response URL as `import.meta.url` instead of request URL.
+ If redirection happens, this URL should be redirected one.
+
+ * bindings/js/ScriptModuleLoader.cpp:
+ (WebCore::ScriptModuleLoader::resolve):
+ (WebCore::ScriptModuleLoader::responseURLFromRequestURL):
+ (WebCore::ScriptModuleLoader::createImportMetaProperties):
+ (WebCore::ScriptModuleLoader::notifyFinished):
+ * bindings/js/ScriptModuleLoader.h:
+
2020-04-15 Jer Noble <jer.no...@apple.com>
isNullFunctionPointer() can fail for symbols not explicitly marked as weakly linked.
Modified: trunk/Source/WebCore/bindings/js/ScriptModuleLoader.cpp (260130 => 260131)
--- trunk/Source/WebCore/bindings/js/ScriptModuleLoader.cpp 2020-04-15 15:46:50 UTC (rev 260130)
+++ trunk/Source/WebCore/bindings/js/ScriptModuleLoader.cpp 2020-04-15 15:48:11 UTC (rev 260131)
@@ -104,19 +104,9 @@
String specifier = asString(moduleNameValue)->value(jsGlobalObject);
RETURN_IF_EXCEPTION(scope, { });
- URL baseURL;
- if (isRootModule(importerModuleKey))
- baseURL = m_document.baseURL();
- else {
- ASSERT(importerModuleKey.isString());
- URL importerModuleRequestURL(URL(), asString(importerModuleKey)->value(jsGlobalObject));
- ASSERT_WITH_MESSAGE(importerModuleRequestURL.isValid(), "Invalid module referrer never starts importing dependent modules.");
+ URL baseURL = responseURLFromRequestURL(*jsGlobalObject, importerModuleKey);
+ RETURN_IF_EXCEPTION(scope, { });
- auto iterator = m_requestURLToResponseURLMap.find(importerModuleRequestURL);
- ASSERT_WITH_MESSAGE(iterator != m_requestURLToResponseURLMap.end(), "Module referrer must register itself to the map before starting importing dependent modules.");
- baseURL = iterator->value;
- }
-
auto result = resolveModuleSpecifier(m_document, specifier, baseURL);
if (!result) {
JSC::throwTypeError(jsGlobalObject, scope, result.error());
@@ -192,6 +182,27 @@
return URL(URL(), asString(moduleKeyValue)->value(&jsGlobalObject));
}
+URL ScriptModuleLoader::responseURLFromRequestURL(JSC::JSGlobalObject& jsGlobalObject, JSC::JSValue moduleKeyValue)
+{
+ JSC::VM& vm = jsGlobalObject.vm();
+ auto scope = DECLARE_THROW_SCOPE(vm);
+
+ if (isRootModule(moduleKeyValue))
+ return m_document.baseURL();
+
+ ASSERT(!isRootModule(moduleKeyValue));
+ ASSERT(moduleKeyValue.isString());
+ String requestURL = asString(moduleKeyValue)->value(&jsGlobalObject);
+ RETURN_IF_EXCEPTION(scope, { });
+ ASSERT_WITH_MESSAGE(URL(URL(), requestURL).isValid(), "Invalid module referrer never starts importing dependent modules.");
+
+ auto iterator = m_requestURLToResponseURLMap.find(requestURL);
+ ASSERT_WITH_MESSAGE(iterator != m_requestURLToResponseURLMap.end(), "Module referrer must register itself to the map before starting importing dependent modules.");
+ URL result = iterator->value;
+ ASSERT(result.isValid());
+ return result;
+}
+
JSC::JSValue ScriptModuleLoader::evaluate(JSC::JSGlobalObject* jsGlobalObject, JSC::JSModuleLoader*, JSC::JSValue moduleKeyValue, JSC::JSValue moduleRecordValue, JSC::JSValue)
{
JSC::VM& vm = jsGlobalObject->vm();
@@ -265,15 +276,15 @@
auto& vm = jsGlobalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
- URL sourceURL = moduleURL(*jsGlobalObject, moduleKeyValue);
- ASSERT(sourceURL.isValid());
-
auto* metaProperties = JSC::constructEmptyObject(vm, jsGlobalObject->nullPrototypeObjectStructure());
RETURN_IF_EXCEPTION(scope, nullptr);
- metaProperties->putDirect(vm, JSC::Identifier::fromString(vm, "url"), JSC::jsString(vm, sourceURL.string()));
+ URL responseURL = responseURLFromRequestURL(*jsGlobalObject, moduleKeyValue);
RETURN_IF_EXCEPTION(scope, nullptr);
+ metaProperties->putDirect(vm, JSC::Identifier::fromString(vm, "url"), JSC::jsString(vm, responseURL.string()));
+ RETURN_IF_EXCEPTION(scope, nullptr);
+
return metaProperties;
}
@@ -318,7 +329,17 @@
}
}
- m_requestURLToResponseURLMap.add(WTFMove(sourceURL), cachedScript.response().url());
+ URL responseURL = cachedScript.response().url();
+ // If we do not have redirection, we must reserve the source URL's fragment explicitly here since ResourceResponse::url() is the one when we first cache it to MemoryCache.
+ // FIXME: We should track fragments through redirections.
+ // https://bugs.webkit.org/show_bug.cgi?id=158420
+ // https://bugs.webkit.org/show_bug.cgi?id=210490
+ if (!cachedScript.hasRedirections() && cachedScript.response().source() != ResourceResponse::Source::ServiceWorker) {
+ if (sourceURL.hasFragmentIdentifier())
+ responseURL.setFragmentIdentifier(sourceURL.fragmentIdentifier());
+ }
+
+ m_requestURLToResponseURLMap.add(sourceURL.string(), WTFMove(responseURL));
promise->resolveWithCallback([&] (JSDOMGlobalObject& jsGlobalObject) {
return JSC::JSSourceCode::create(jsGlobalObject.vm(),
JSC::SourceCode { ScriptSourceCode { &cachedScript, JSC::SourceProviderSourceType::Module, loader.scriptFetcher() }.jsSourceCode() });
Modified: trunk/Source/WebCore/bindings/js/ScriptModuleLoader.h (260130 => 260131)
--- trunk/Source/WebCore/bindings/js/ScriptModuleLoader.h 2020-04-15 15:46:50 UTC (rev 260130)
+++ trunk/Source/WebCore/bindings/js/ScriptModuleLoader.h 2020-04-15 15:48:11 UTC (rev 260131)
@@ -65,9 +65,10 @@
private:
void notifyFinished(CachedModuleScriptLoader&, RefPtr<DeferredPromise>) final;
URL moduleURL(JSC::JSGlobalObject&, JSC::JSValue);
+ URL responseURLFromRequestURL(JSC::JSGlobalObject&, JSC::JSValue);
Document& m_document;
- HashMap<URL, URL> m_requestURLToResponseURLMap;
+ HashMap<String, URL> m_requestURLToResponseURLMap;
HashSet<Ref<CachedModuleScriptLoader>> m_loaders;
};