[ES Modules] Allow .mjs content when loaded from file://
authordino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 29 Nov 2018 18:26:44 +0000 (18:26 +0000)
committerdino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 29 Nov 2018 18:26:44 +0000 (18:26 +0000)
commit814753a48175d1931af1b7f5fd43b876c5c2d8d6
tree7a111d24430d62fefcb9b9a1c5981e3b9e6bc78e
parenta39b7778fc985f2ad351d22658f4426c10dad953
[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.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@238673 268f45cc-cd09-0410-ab3c-d52691b4dbfc
LayoutTests/ChangeLog
LayoutTests/js/dom/modules/import-mjs-module-expected.txt [new file with mode: 0644]
LayoutTests/js/dom/modules/import-mjs-module.html [new file with mode: 0644]
LayoutTests/js/dom/modules/resources/module-simple-A.mjs [new file with mode: 0644]
LayoutTests/js/dom/modules/resources/module-simple-B.mjs [new file with mode: 0644]
LayoutTests/platform/win/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/platform/network/ios/WebCoreURLResponseIOS.mm
Source/WebCore/platform/network/mac/WebCoreURLResponse.mm
Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Base/MIMETypeUtilities.js