Document.currentScript does not work for SVGScriptElements
authorweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 12 Jun 2020 14:28:43 +0000 (14:28 +0000)
committerweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 12 Jun 2020 14:28:43 +0000 (14:28 +0000)
commit5772e2a6221a37c56f2b564b86bcea74e2f912e0
tree7f9677edda33f44d9e09f9fbca436ed51dd5151a
parentf2c7140cb6da6132c53e572b8b06250eef6fa6c4
Document.currentScript does not work for SVGScriptElements
https://bugs.webkit.org/show_bug.cgi?id=213104

Reviewed by Yusuke Suzuki.

LayoutTests/imported/w3c:

* web-platform-tests/html/dom/documents/dom-tree-accessors/Document.currentScript-expected.txt:
Update test results after making currentScript work with SVGScriptElements.

* web-platform-tests/content-security-policy/nonce-hiding/svgscript-nonces-hidden-meta.tentative.sub-expected.txt:
* web-platform-tests/content-security-policy/nonce-hiding/svgscript-nonces-hidden.tentative-expected.txt:
Update results. Not passing, but getting further.

Source/WebCore:

Updates results for existing tests.

* WebCore.xcodeproj/project.pbxproj:
Add CurrentScriptIncrementer.h to the Xcode project as it was missing.

* dom/CurrentScriptIncrementer.h:
(WebCore::CurrentScriptIncrementer::CurrentScriptIncrementer):
(WebCore::CurrentScriptIncrementer::~CurrentScriptIncrementer):
Re-work using ScriptElement, removing the HTMLScriptElement checks. Also changes
scriptType check to explicitly check that against classic scripts, as they are
the only supported type, and if any types other than modules are added in the
future, we would not want this to change behavior.

* dom/Document.cpp:
(WebCore::Document::pushCurrentScript):
* dom/Document.h:
(WebCore::Document::currentScript const):
Use an Element, rather than an HTMLScriptElement for currentScript/currentScriptStack
so that either an HTMLScriptElement or an SVGScriptElement can be stored. Using a
ScriptElement would be possible, but would complicate the implementation unnecessarily
by requiring currentScript to have an additional checks before extracting the Element.
Variant<RefPtr<HTMLScriptElement>, RefPtr<SVGScriptElement>> could also have been used
but also would unnecessarily complicated the interface and caused more memory to be used.

* dom/Document.idl:
Update interface to use Element rather HTMLScriptElement with a comment explaining why we
are not using HTMLOrSVGScriptElement but retaining the same observable behavior.

* dom/ScriptElement.cpp:
(WebCore::ScriptElement::executeClassicScript):
(WebCore::ScriptElement::executeModuleScript):
Pass *this directly to CurrentScriptIncrementer to simplify implementation.

Source/WebKit:

* WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMDocumentGtk.cpp:
(webkit_dom_document_get_current_script):
Update to account for change in Document::currentScript() now returning an
Element* that can be either an HTMLScriptElement or an SVGScriptElement. To
keep API compatibility, only return non-null for HTMLScriptElements.

Source/WebKitLegacy/mac:

* DOM/DOMDocument.mm:
(-[DOMDocument currentScript]):
Update to account for change in Document::currentScript() now returning an
Element* that can be either an HTMLScriptElement or an SVGScriptElement. To
keep API compatibility, only return non-null for HTMLScriptElements.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@262945 268f45cc-cd09-0410-ab3c-d52691b4dbfc
15 files changed:
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/content-security-policy/nonce-hiding/svgscript-nonces-hidden-meta.tentative.sub-expected.txt
LayoutTests/imported/w3c/web-platform-tests/content-security-policy/nonce-hiding/svgscript-nonces-hidden.tentative-expected.txt
LayoutTests/imported/w3c/web-platform-tests/html/dom/documents/dom-tree-accessors/Document.currentScript-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/dom/CurrentScriptIncrementer.h
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Document.h
Source/WebCore/dom/Document.idl
Source/WebCore/dom/ScriptElement.cpp
Source/WebKit/ChangeLog
Source/WebKit/WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMDocumentGtk.cpp
Source/WebKitLegacy/mac/ChangeLog
Source/WebKitLegacy/mac/DOM/DOMDocument.mm