Add the support for nomodule attribute on script element
authorutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 24 Jan 2017 06:52:49 +0000 (06:52 +0000)
committerutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 24 Jan 2017 06:52:49 +0000 (06:52 +0000)
commite18f41074de33cf569f932b60ed49735dd9d5cf8
tree008fc12a4be893a701201b4cee0c9cdc91e79e0e
parente76ce3e489fa9b5005fcb0f5c5020cf6c224cd7e
Add the support for nomodule attribute on script element
https://bugs.webkit.org/show_bug.cgi?id=166987

Reviewed by Sam Weinig.

Source/WebCore:

As discussed on https://github.com/whatwg/html/pull/2261, we should have
the way to suppress classic script execution when our user agent have
modules support. With such a feature, developers can write the code like,

    <script type="module" src="./app.js"></script>
    <script nomodule src="./bundled-app.js"></script>

In the above code, if the user agent does not support modules, the bundled-app.js
will be executed. On the other hand, if the user agent supports modules, we should
ignore the script tag which has the `nomodule` attribute.
This way allows us to support the legacy browsers while using modules.

In WebKit, we already support modules. Thus, we should ignore the classic script
attributed `nomodule`.

We also rename asyncAttributeValue and deferAttributeValue to hasAsyncAttribute and
hasDeferAttribute.

Tests: js/dom/modules/nomodule-has-no-effect-on-module-inline.html
       js/dom/modules/nomodule-has-no-effect-on-module-src.html
       js/dom/modules/nomodule-prevents-execution-classic-script-inline.html
       js/dom/modules/nomodule-prevents-execution-classic-script-src.html

* dom/ScriptElement.cpp:
(WebCore::ScriptElement::prepareScript):
* dom/ScriptElement.h:
* html/HTMLAttributeNames.in:
* html/HTMLScriptElement.cpp:
(WebCore::HTMLScriptElement::hasAsyncAttribute):
(WebCore::HTMLScriptElement::hasDeferAttribute):
(WebCore::HTMLScriptElement::hasNoModuleAttribute):
(WebCore::HTMLScriptElement::asyncAttributeValue): Deleted.
(WebCore::HTMLScriptElement::deferAttributeValue): Deleted.
* html/HTMLScriptElement.h:
* html/HTMLScriptElement.idl:
* svg/SVGScriptElement.cpp:
(WebCore::SVGScriptElement::hasAsyncAttribute):
(WebCore::SVGScriptElement::hasDeferAttribute):
(WebCore::SVGScriptElement::hasNoModuleAttribute):
(WebCore::SVGScriptElement::asyncAttributeValue): Deleted.
(WebCore::SVGScriptElement::deferAttributeValue): Deleted.
* svg/SVGScriptElement.h:

LayoutTests:

* js/dom/modules/nomodule-dynamic-classic-inline-expected.txt: Added.
* js/dom/modules/nomodule-dynamic-classic-inline.html: Added.
* js/dom/modules/nomodule-dynamic-classic-src-expected.txt: Added.
* js/dom/modules/nomodule-dynamic-classic-src.html: Added.
* js/dom/modules/nomodule-has-no-effect-on-module-inline-expected.txt: Added.
* js/dom/modules/nomodule-has-no-effect-on-module-inline.html: Added.
* js/dom/modules/nomodule-has-no-effect-on-module-src-expected.txt: Added.
* js/dom/modules/nomodule-has-no-effect-on-module-src.html: Added.
* js/dom/modules/nomodule-prevents-execution-classic-script-inline-expected.txt: Added.
* js/dom/modules/nomodule-prevents-execution-classic-script-inline.html: Added.
* js/dom/modules/nomodule-prevents-execution-classic-script-src-expected.txt: Added.
* js/dom/modules/nomodule-prevents-execution-classic-script-src.html: Added.
* js/dom/modules/nomodule-reflect-expected.txt: Added.
* js/dom/modules/nomodule-reflect.html: Added.
* js/dom/modules/script-tests/error-classic-script.js: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@211078 268f45cc-cd09-0410-ab3c-d52691b4dbfc
25 files changed:
LayoutTests/ChangeLog
LayoutTests/js/dom/modules/nomodule-dynamic-classic-inline-expected.txt [new file with mode: 0644]
LayoutTests/js/dom/modules/nomodule-dynamic-classic-inline.html [new file with mode: 0644]
LayoutTests/js/dom/modules/nomodule-dynamic-classic-src-expected.txt [new file with mode: 0644]
LayoutTests/js/dom/modules/nomodule-dynamic-classic-src.html [new file with mode: 0644]
LayoutTests/js/dom/modules/nomodule-has-no-effect-on-module-inline-expected.txt [new file with mode: 0644]
LayoutTests/js/dom/modules/nomodule-has-no-effect-on-module-inline.html [new file with mode: 0644]
LayoutTests/js/dom/modules/nomodule-has-no-effect-on-module-src-expected.txt [new file with mode: 0644]
LayoutTests/js/dom/modules/nomodule-has-no-effect-on-module-src.html [new file with mode: 0644]
LayoutTests/js/dom/modules/nomodule-prevents-execution-classic-script-inline-expected.txt [new file with mode: 0644]
LayoutTests/js/dom/modules/nomodule-prevents-execution-classic-script-inline.html [new file with mode: 0644]
LayoutTests/js/dom/modules/nomodule-prevents-execution-classic-script-src-expected.txt [new file with mode: 0644]
LayoutTests/js/dom/modules/nomodule-prevents-execution-classic-script-src.html [new file with mode: 0644]
LayoutTests/js/dom/modules/nomodule-reflect-expected.txt [new file with mode: 0644]
LayoutTests/js/dom/modules/nomodule-reflect.html [new file with mode: 0644]
LayoutTests/js/dom/modules/script-tests/error-classic-script.js [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/dom/ScriptElement.cpp
Source/WebCore/dom/ScriptElement.h
Source/WebCore/html/HTMLAttributeNames.in
Source/WebCore/html/HTMLScriptElement.cpp
Source/WebCore/html/HTMLScriptElement.h
Source/WebCore/html/HTMLScriptElement.idl
Source/WebCore/svg/SVGScriptElement.cpp
Source/WebCore/svg/SVGScriptElement.h