ScriptRunner should be driven by PendingScript rather than ScriptElement
authorutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 9 Sep 2016 05:20:17 +0000 (05:20 +0000)
committerutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 9 Sep 2016 05:20:17 +0000 (05:20 +0000)
commit2c904018d6e50d693f010f1725048d4c624da9fa
tree87939a04024d5a898801114b859984abec3a9cc7
parentf183e9de50e150088cf2e98e5984bd5a3de81077
ScriptRunner should be driven by PendingScript rather than ScriptElement
https://bugs.webkit.org/show_bug.cgi?id=161726

Reviewed by Ryosuke Niwa.

Source/WebCore:

Tests: js/dom/document-write-in-error-event.html
       js/dom/document-write-in-load-event.html

ScriptRunner is driven by ScriptElement::notifyFinished. While ScriptRunner is driven by this,
HTMLScriptRunner does not use it. Instead, HTMLScriptRunner uses PendingScriptClient. As a result,
ScriptElement::notifyFinished is used only when the script is annotated with "defer" or "async"
while all the external script will load the LoadableScript. It is confusing.
This patch removes ScriptElement::notifyFinished and use PendingScript's observability
in ScriptRunner instead.

This patch also fixes the behavior about ignore-destructive-writes counter[1]. When dispatching
the load and error events, this ignore-destructive-writes counter should not be incremeneted by
this execution. The added tests ensure this behavior.

[1]: https://html.spec.whatwg.org/multipage/scripting.html#execute-the-script-block

* dom/ScriptElement.cpp: Drop LoadableScriptClient interface.
(WebCore::ScriptElement::prepareScript): Do not use addClient. ScriptRunner use PendingScript::{setClient,clearClient} instead.
(WebCore::ScriptElement::executeScriptForScriptRunner): IgnoreDestructiveWriteCountIncrementer will be done in ScriptElement::executeScript.
So no need to do it here, that's duplicated.
(WebCore::ScriptElement::~ScriptElement): Deleted. ScriptElement does not use addClient/removeClient.
(WebCore::ScriptElement::stopLoadRequest): Deleted.
(WebCore::ScriptElement::executeScriptForHTMLScriptRunner): Deleted. executeScriptForHTMLScriptRunner and executeScriptForScriptRunner are
merged into executeScriptForRunner.
(WebCore::ScriptElement::notifyFinished): Deleted.
* dom/ScriptElement.h:
(WebCore::ScriptElement::~ScriptElement):
(WebCore::ScriptElement::willExecuteInOrder): Used in ScriptRunner to determine whether the script is async or defer.
(WebCore::ScriptElement::willExecuteWhenDocumentFinishedParsing): Deleted.
* dom/ScriptRunner.cpp:
(WebCore::ScriptRunner::~ScriptRunner): HashSet's iterator will return `const PendingScript&`.
Another option is using HashSet<RefPtr<PendingScript>>. Here, we use a little bit weired const_cast.
(WebCore::ScriptRunner::queueScriptForExecution): Use PendingScript::setClient to wait loading.
(WebCore::ScriptRunner::notifyFinished): Notify the script ready here.
(WebCore::ScriptRunner::timerFired): Use executeScriptForScriptRunner.
(WebCore::ScriptRunner::notifyScriptReady): Deleted.
* dom/ScriptRunner.h:
* html/parser/HTMLScriptRunner.cpp:
(WebCore::HTMLScriptRunner::executePendingScriptAndDispatchEvent): Use executeScriptForScriptRunner.

LayoutTests:

* js/dom/document-write-in-error-event-expected.txt: Added.
* js/dom/document-write-in-error-event.html: Added.
* js/dom/document-write-in-load-event-expected.txt: Added.
* js/dom/document-write-in-load-event.html: Added.
* js/dom/script-tests/dummy.js: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@205695 268f45cc-cd09-0410-ab3c-d52691b4dbfc
12 files changed:
LayoutTests/ChangeLog
LayoutTests/js/dom/document-write-in-error-event-expected.txt [new file with mode: 0644]
LayoutTests/js/dom/document-write-in-error-event.html [new file with mode: 0644]
LayoutTests/js/dom/document-write-in-load-event-expected.txt [new file with mode: 0644]
LayoutTests/js/dom/document-write-in-load-event.html [new file with mode: 0644]
LayoutTests/js/dom/script-tests/dummy.js [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/dom/ScriptElement.cpp
Source/WebCore/dom/ScriptElement.h
Source/WebCore/dom/ScriptRunner.cpp
Source/WebCore/dom/ScriptRunner.h
Source/WebCore/html/parser/HTMLScriptRunner.cpp