Title: [238673] trunk
Revision
238673
Author
d...@apple.com
Date
2018-11-29 10:26:44 -0800 (Thu, 29 Nov 2018)

Log Message

[ES Modules] Allow .mjs content when loaded from file://
https://bugs.webkit.org/show_bug.cgi?id=192100
<rdar://problem/46320065>

Reviewed by Sam Weinig.

Source/WebCore:

Node JS requires ES Module files to be identified by the file
extension of ".mjs" (no relation to Maciej Stachowiak). This new
extension causes issues because it isn't recognised as a _javascript_
file. When using the script tag, the author is able to force the type
of the referenced file using an attribute, but this isn't possible
for the import() function or import statement.

Add a new entry into our table that maps file extensions to MIME types
so that when a .mjs file is loaded from a file:// reference it is
identified as _javascript_.

Test: js/dom/modules/import-mjs-module.html

* platform/network/mac/WebCoreURLResponse.mm: Add .mjs to the existing dictionary.
(WebCore::createExtensionToMIMETypeMap):
* platform/network/ios/WebCoreURLResponseIOS.mm: Add code just for .mjs.
(WebCore::createExtensionToMIMETypeMap):

Source/WebInspectorUI:

Add a mapping from .mjs to application/_javascript_.

* UserInterface/Base/MIMETypeUtilities.js:
(WI.mimeTypeForFileExtension):

LayoutTests:

Test for both import() function and the import statement loading
from .mjs files.

* js/dom/modules/import-mjs-module-expected.txt: Added.
* js/dom/modules/import-mjs-module.html: Added.
* js/dom/modules/resources/module-simple-A.mjs: Added.
* js/dom/modules/resources/module-simple-B.mjs: Added.
* platform/win/TestExpectations: Skip this on Windows. Just wait for Windows
  to recognise the extension.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (238672 => 238673)


--- trunk/LayoutTests/ChangeLog	2018-11-29 18:00:14 UTC (rev 238672)
+++ trunk/LayoutTests/ChangeLog	2018-11-29 18:26:44 UTC (rev 238673)
@@ -1,3 +1,21 @@
+2018-11-28  Dean Jackson  <d...@apple.com>
+
+        [ES Modules] Allow .mjs content when loaded from file://
+        https://bugs.webkit.org/show_bug.cgi?id=192100
+        <rdar://problem/46320065>
+
+        Reviewed by Sam Weinig.
+
+        Test for both import() function and the import statement loading
+        from .mjs files.
+
+        * js/dom/modules/import-mjs-module-expected.txt: Added.
+        * js/dom/modules/import-mjs-module.html: Added.
+        * js/dom/modules/resources/module-simple-A.mjs: Added.
+        * js/dom/modules/resources/module-simple-B.mjs: Added.
+        * platform/win/TestExpectations: Skip this on Windows. Just wait for Windows
+          to recognise the extension.
+
 2018-11-29  Guillaume Emont  <guijem...@igalia.com>
 
         Gardening: skip test that newly times out on Armv7

Added: trunk/LayoutTests/js/dom/modules/import-mjs-module-expected.txt (0 => 238673)


--- trunk/LayoutTests/js/dom/modules/import-mjs-module-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/js/dom/modules/import-mjs-module-expected.txt	2018-11-29 18:26:44 UTC (rev 238673)
@@ -0,0 +1,13 @@
+Test import of a .mjs module.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Module is not executed yet.
+Module B was imported.
+Module A was imported.
+Exported B was visible.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Property changes on: trunk/LayoutTests/js/dom/modules/import-mjs-module-expected.txt
___________________________________________________________________

Added: svn:eol-style

+native \ No newline at end of property

Added: svn:keywords

+Date Revision \ No newline at end of property

Added: svn:mime-type

+text/plain \ No newline at end of property

Added: trunk/LayoutTests/js/dom/modules/import-mjs-module.html (0 => 238673)


--- trunk/LayoutTests/js/dom/modules/import-mjs-module.html	                        (rev 0)
+++ trunk/LayoutTests/js/dom/modules/import-mjs-module.html	2018-11-29 18:26:44 UTC (rev 238673)
@@ -0,0 +1,29 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script>
+description("Test import of a .mjs module.");
+
+// Module will be executed asynchronously.
+window.jsTestIsAsync = true;
+</script>
+<script>
+</script>
+<script src=""
+<script>
+(async function() {
+    debug("Module is not executed yet.");
+    try {
+        await import("./resources/module-simple-A.mjs");
+    } catch (e) {
+        debug("Module import failed.");
+    } finally {
+        finishJSTest();
+    }
+}());
+</script>
+</body>
+</html>
Property changes on: trunk/LayoutTests/js/dom/modules/import-mjs-module.html
___________________________________________________________________

Added: svn:eol-style

+native \ No newline at end of property

Added: svn:keywords

+Date Revision \ No newline at end of property

Added: svn:mime-type

+text/html \ No newline at end of property

Added: trunk/LayoutTests/js/dom/modules/resources/module-simple-A.mjs (0 => 238673)


--- trunk/LayoutTests/js/dom/modules/resources/module-simple-A.mjs	                        (rev 0)
+++ trunk/LayoutTests/js/dom/modules/resources/module-simple-A.mjs	2018-11-29 18:26:44 UTC (rev 238673)
@@ -0,0 +1,5 @@
+import { B } from "./module-simple-B.mjs";
+debug("Module A was imported.");
+
+if (B == 42)
+    debug("Exported B was visible.");

Added: trunk/LayoutTests/js/dom/modules/resources/module-simple-B.mjs (0 => 238673)


--- trunk/LayoutTests/js/dom/modules/resources/module-simple-B.mjs	                        (rev 0)
+++ trunk/LayoutTests/js/dom/modules/resources/module-simple-B.mjs	2018-11-29 18:26:44 UTC (rev 238673)
@@ -0,0 +1,5 @@
+debug("Module B was imported.");
+
+export let B = 42;
+
+export { B as default };

Modified: trunk/LayoutTests/platform/win/TestExpectations (238672 => 238673)


--- trunk/LayoutTests/platform/win/TestExpectations	2018-11-29 18:00:14 UTC (rev 238672)
+++ trunk/LayoutTests/platform/win/TestExpectations	2018-11-29 18:26:44 UTC (rev 238673)
@@ -4269,3 +4269,7 @@
 webkit.org/b/192010 fast/inline/simple-inline-with-out-of-flow-descendant2.html [ Failure ]
 
 webkit.org/b/192011 svg/text/monospace-text-size-in-img.html [ ImageOnlyFailure ]
+
+# This only applies to file:// loading of ES6 Modules via the import syntax. When
+# Windows recognizes .mjs files as _javascript_, this will just work.
+js/dom/modules/import-mjs-module.html [ Skip ]

Modified: trunk/Source/WebCore/ChangeLog (238672 => 238673)


--- trunk/Source/WebCore/ChangeLog	2018-11-29 18:00:14 UTC (rev 238672)
+++ trunk/Source/WebCore/ChangeLog	2018-11-29 18:26:44 UTC (rev 238673)
@@ -1,3 +1,29 @@
+2018-11-28  Dean Jackson  <d...@apple.com>
+
+        [ES Modules] Allow .mjs content when loaded from file://
+        https://bugs.webkit.org/show_bug.cgi?id=192100
+        <rdar://problem/46320065>
+
+        Reviewed by Sam Weinig.
+
+        Node JS requires ES Module files to be identified by the file
+        extension of ".mjs" (no relation to Maciej Stachowiak). This new
+        extension causes issues because it isn't recognised as a _javascript_
+        file. When using the script tag, the author is able to force the type
+        of the referenced file using an attribute, but this isn't possible
+        for the import() function or import statement.
+
+        Add a new entry into our table that maps file extensions to MIME types
+        so that when a .mjs file is loaded from a file:// reference it is
+        identified as _javascript_.
+
+        Test: js/dom/modules/import-mjs-module.html
+
+        * platform/network/mac/WebCoreURLResponse.mm: Add .mjs to the existing dictionary.
+        (WebCore::createExtensionToMIMETypeMap):
+        * platform/network/ios/WebCoreURLResponseIOS.mm: Add code just for .mjs.
+        (WebCore::createExtensionToMIMETypeMap):
+
 2018-11-29  Zalan Bujtas  <za...@apple.com>
 
         [LFC][BFC][Quirk] Width does not need stretching quirk.

Modified: trunk/Source/WebCore/platform/network/ios/WebCoreURLResponseIOS.mm (238672 => 238673)


--- trunk/Source/WebCore/platform/network/ios/WebCoreURLResponseIOS.mm	2018-11-29 18:00:14 UTC (rev 238672)
+++ trunk/Source/WebCore/platform/network/ios/WebCoreURLResponseIOS.mm	2018-11-29 18:26:44 UTC (rev 238673)
@@ -39,6 +39,21 @@
 
 namespace WebCore {
 
+// <rdar://problem/46332893> Register .mjs files as whatever UTI indicates _javascript_
+static CFDictionaryRef createExtensionToMIMETypeMap()
+{
+    CFStringRef keys[] = {
+        CFSTR("mjs")
+    };
+
+    CFStringRef values[] = {
+        CFSTR("application/_javascript_")
+    };
+
+    ASSERT(sizeof(keys) == sizeof(values));
+    return CFDictionaryCreate(kCFAllocatorDefault, (const void**)&keys, (const void**)&values, sizeof(keys) / sizeof(CFStringRef), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
+}
+
 void adjustMIMETypeIfNecessary(CFURLResponseRef cfResponse, bool isMainResourceLoad)
 {
     RetainPtr<CFStringRef> mimeType = CFURLResponseGetMIMEType(cfResponse);
@@ -46,6 +61,21 @@
     if (!updatedMIMEType)
         updatedMIMEType = defaultMIMEType().createCFString();
 
+    // <rdar://problem/46332893> Register .mjs files as whatever UTI indicates _javascript_
+    if (!mimeType) {
+        auto url = ""
+        if ([(__bridge NSURL *)url isFileURL]) {
+            RetainPtr<CFStringRef> extension = adoptCF(CFURLCopyPathExtension(url));
+            if (extension) {
+                static CFDictionaryRef extensionMap = createExtensionToMIMETypeMap();
+                CFMutableStringRef mutableExtension = CFStringCreateMutableCopy(kCFAllocatorDefault, 0, extension.get());
+                CFStringLowercase(mutableExtension, NULL);
+                extension = adoptCF(mutableExtension);
+                updatedMIMEType = (CFStringRef)CFDictionaryGetValue(extensionMap, extension.get());
+            }
+        }
+    }
+
 #if USE(QUICK_LOOK)
     // We must ensure that the MIME type is correct, so that QuickLook's web plugin is called when needed.
     // We filter the basic MIME types so that we don't do unnecessary work in standard browsing situations.

Modified: trunk/Source/WebCore/platform/network/mac/WebCoreURLResponse.mm (238672 => 238673)


--- trunk/Source/WebCore/platform/network/mac/WebCoreURLResponse.mm	2018-11-29 18:00:14 UTC (rev 238672)
+++ trunk/Source/WebCore/platform/network/mac/WebCoreURLResponse.mm	2018-11-29 18:26:44 UTC (rev 238673)
@@ -92,6 +92,7 @@
         CFSTR("me"),
         CFSTR("mesh"),
         CFSTR("mif"),
+        CFSTR("mjs"),
         CFSTR("movie"),
         CFSTR("mp2"),
         CFSTR("mpga"),
@@ -211,6 +212,7 @@
         CFSTR("application/x-troff-me"),
         CFSTR("model/mesh"),
         CFSTR("application/vnd.mif"),
+        CFSTR("application/_javascript_"),
         CFSTR("video/x-sgi-movie"),
         CFSTR("audio/mpeg"),
         CFSTR("audio/mpeg"),

Modified: trunk/Source/WebInspectorUI/ChangeLog (238672 => 238673)


--- trunk/Source/WebInspectorUI/ChangeLog	2018-11-29 18:00:14 UTC (rev 238672)
+++ trunk/Source/WebInspectorUI/ChangeLog	2018-11-29 18:26:44 UTC (rev 238673)
@@ -1,3 +1,16 @@
+2018-11-28  Dean Jackson  <d...@apple.com>
+
+        [ES Modules] Allow .mjs content when loaded from file://
+        https://bugs.webkit.org/show_bug.cgi?id=192100
+        <rdar://problem/46320065>
+
+        Reviewed by Sam Weinig.
+
+        Add a mapping from .mjs to application/_javascript_.
+
+        * UserInterface/Base/MIMETypeUtilities.js:
+        (WI.mimeTypeForFileExtension):
+
 2018-11-29  Matt Baker  <mattba...@apple.com>
 
         Web Inspector: Elements: selecting more than one DOM node causes the scope highlight to contrast

Modified: trunk/Source/WebInspectorUI/UserInterface/Base/MIMETypeUtilities.js (238672 => 238673)


--- trunk/Source/WebInspectorUI/UserInterface/Base/MIMETypeUtilities.js	2018-11-29 18:00:14 UTC (rev 238672)
+++ trunk/Source/WebInspectorUI/UserInterface/Base/MIMETypeUtilities.js	2018-11-29 18:26:44 UTC (rev 238673)
@@ -49,6 +49,7 @@
 
         // Script types.
         "js": "application/_javascript_",
+        "mjs": "application/_javascript_",
         "json": "application/json",
         "clj": "text/x-clojure",
         "coffee": "text/x-coffeescript",
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to