Changeset 205581 in webkit
- Timestamp:
- Sep 7, 2016 6:49:49 PM (8 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 1 added
- 12 edited
- 4 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/CMakeLists.txt
r205551 r205581 1438 1438 dom/KeyboardEvent.cpp 1439 1439 dom/LiveNodeList.cpp 1440 dom/LoadableClassicScript.cpp 1441 dom/LoadableScript.cpp 1440 1442 dom/MessageChannel.cpp 1441 1443 dom/MessageEvent.cpp -
trunk/Source/WebCore/ChangeLog
r205580 r205581 1 2016-09-07 Yusuke Suzuki <utatane.tea@gmail.com> 2 3 Introduce abstract class LoadableScript for classic script and module graph 4 https://bugs.webkit.org/show_bug.cgi?id=161674 5 6 Reviewed by Ryosuke Niwa. 7 8 To prepare for ScriptModuleGraph, we introduce the abstract class over the classic script 9 and the module script, LoadableScript. 10 11 No behavior change. 12 13 * CMakeLists.txt: 14 * WebCore.xcodeproj/project.pbxproj: 15 * dom/LoadableClassicScript.cpp: Added. LoadableClassicScript is the derived class from the 16 LoadableScript. In the module patch, we will introduce LoadableScriptModuleGraph which is also 17 the derived class from the LoadableScript. It is used for the external classic script. 18 A CachedResourceHandle used here alone does not prevent the underlying CachedResource from purging its 19 data buffer. This LoadableClassicScript holds a client until this class is destroyed in order to 20 guarantee that the data buffer will not be purged. 21 (WebCore::LoadableClassicScript::create): 22 (WebCore::LoadableClassicScript::LoadableClassicScript): 23 (WebCore::LoadableClassicScript::~LoadableClassicScript): 24 (WebCore::LoadableClassicScript::isLoaded): 25 (WebCore::LoadableClassicScript::wasErrored): Beyond the boolean value, this can return the detail 26 of the error. This detailed information will be used to report it to the inspector in the ScriptElement. 27 (WebCore::LoadableClassicScript::wasCanceled): 28 (WebCore::LoadableClassicScript::notifyFinished): Nosniff and cross-origin loading errors are handled here, 29 instead of exposing CachedScript*. 30 (WebCore::LoadableClassicScript::execute): Execute the cached script by using the given ScriptElement. 31 * dom/LoadableClassicScript.h: Copied from Source/WebCore/dom/PendingScript.h. 32 (isType): 33 * dom/LoadableScript.cpp: Copied from Source/WebCore/dom/ScriptRunner.h. New wrapper for CachedScript 34 and ScriptModuleGraph. We introduce a new wrapper to handle the above 2 things in the same way. 35 We take the way to introduce a new wrapper instead of introducing a new interface that is inherited by 36 CachedScript and ScriptModuleGraph. This is because ScriptModuleGraph is ref-counted while CachedScript 37 is managed by CachedResourceHandle. While this patch does not contain ScriptModuleGraph part, this 38 should be added in the module patch and at that time, this should be managed by this LoadableScript's 39 subclass. And we introduce TypeCasts traits for LoadableScript to allow `is<>` and `downcast<>`. 40 (WebCore::LoadableScript::addClient): 41 (WebCore::LoadableScript::removeClient): 42 (WebCore::LoadableScript::notifyClientFinished): 43 * dom/LoadableScript.h: Copied from Source/WebCore/dom/ScriptRunner.h. 44 (WebCore::LoadableScript::~LoadableScript): 45 (WebCore::LoadableScript::isClassicScript): 46 (WebCore::LoadableScript::isModuleGraph): 47 * dom/LoadableScriptClient.h: Copied from Source/WebCore/dom/ScriptRunner.h. 48 (WebCore::LoadableScriptClient::~LoadableScriptClient): 49 * dom/PendingScript.cpp: Use LoadableScript instead of CachedScript. 50 (WebCore::PendingScript::create): 51 (WebCore::PendingScript::PendingScript): 52 (WebCore::PendingScript::~PendingScript): 53 (WebCore::PendingScript::loadableScript): 54 (WebCore::PendingScript::notifyFinished): 55 (WebCore::PendingScript::isLoaded): 56 (WebCore::PendingScript::wasErrored): 57 (WebCore::PendingScript::cachedScript): Deleted. 58 * dom/PendingScript.h: 59 * dom/ScriptElement.cpp: 60 (WebCore::ScriptElement::ScriptElement): 61 (WebCore::ScriptElement::handleSourceAttribute): Change sourceUrl to sourceURL to be consistent. 62 (WebCore::ScriptElement::prepareScript): 63 (WebCore::ScriptElement::requestClassicScript): requestScript is renamed to requestClassicScript. 64 (WebCore::ScriptElement::requestScriptWithCache): Extract the code requesting the 65 CachedScript from requestScript. This will also be used by the module fetcher. 66 (WebCore::ScriptElement::executeScript): Now inspector error reporting is also done in this function. 67 When an error occurs, LoadableScript::wasErrored() returns the error which may include the information 68 to report the error to the inspector. nosniff and cross-origin loading errors are now detected by the 69 LoadableClassicScript and reported through this wasErrored(). 70 (WebCore::ScriptElement::stopLoadRequest): 71 (WebCore::ScriptElement::executeScriptAndDispatchEvent): 72 (WebCore::ScriptElement::executeScriptForScriptRunner): Move the code from ScriptRunner. This function 73 calls removeClient(*this) because ScriptRunner is driven by the ScriptElement's notification. Only when using 74 ScriptRunner, we call addClient(*this) for ScriptElement. This is tricky, we should refactor this in the separated 75 bug (https://bugs.webkit.org/show_bug.cgi?id=161726). 76 (WebCore::ScriptElement::executeScriptForHTMLScriptRunner): Move the code from HTMLScriptRunner. 77 (WebCore::ScriptElement::notifyFinished): 78 (WebCore::ScriptElement::requestScript): Deleted. 79 (WebCore::ScriptElement::execute): Deleted. 80 * dom/ScriptElement.h: 81 (WebCore::ScriptElement::loadableScript): 82 (WebCore::ScriptElement::cachedScript): Deleted. 83 * dom/ScriptRunner.cpp: 84 (WebCore::ScriptRunner::queueScriptForExecution): 85 (WebCore::ScriptRunner::timerFired): Use ScriptElement::executeScriptForScriptRunner. 86 * dom/ScriptRunner.h: 87 * html/parser/HTMLScriptRunner.cpp: 88 (WebCore::HTMLScriptRunner::executePendingScriptAndDispatchEvent): 89 (WebCore::requestPendingScript): 90 (WebCore::HTMLScriptRunner::requestParsingBlockingScript): 91 (WebCore::HTMLScriptRunner::sourceFromPendingScript): Deleted. 92 * html/parser/HTMLScriptRunner.h: Use ScriptElement::executeScriptForHTMLScriptRunner. 93 * xml/parser/XMLDocumentParserLibxml2.cpp: Currently, we do nothing about XMLDocument in this patch. 94 We should support the module script, but before that, we should refactor this pending script handling. 95 (WebCore::XMLDocumentParser::endElementNs): 96 1 97 2016-09-07 Alex Christensen <achristensen@webkit.org> 2 98 -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r205551 r205581 6101 6101 E38838981BAD145F00D62EE3 /* ScriptModuleLoader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E38838941BAD145F00D62EE3 /* ScriptModuleLoader.cpp */; }; 6102 6102 E38838991BAD145F00D62EE3 /* ScriptModuleLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = E38838951BAD145F00D62EE3 /* ScriptModuleLoader.h */; }; 6103 E3B2F0EB1D7F4C9D00B0C9D1 /* LoadableClassicScript.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E3B2F0E31D7F35EC00B0C9D1 /* LoadableClassicScript.cpp */; }; 6104 E3B2F0EC1D7F4CA100B0C9D1 /* LoadableScript.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E3B2F0E91D7F3D3C00B0C9D1 /* LoadableScript.cpp */; }; 6105 E3B2F0ED1D7F4CA300B0C9D1 /* LoadableScript.h in Headers */ = {isa = PBXBuildFile; fileRef = E3B2F0E71D7F35EC00B0C9D1 /* LoadableScript.h */; settings = {ATTRIBUTES = (Private, ); }; }; 6106 E3B2F0EE1D7F4CA900B0C9D1 /* LoadableScriptClient.h in Headers */ = {isa = PBXBuildFile; fileRef = E3B2F0E81D7F35EC00B0C9D1 /* LoadableScriptClient.h */; settings = {ATTRIBUTES = (Private, ); }; }; 6107 E3B2F0F01D7F4CB500B0C9D1 /* LoadableClassicScript.h in Headers */ = {isa = PBXBuildFile; fileRef = E3B2F0E41D7F35EC00B0C9D1 /* LoadableClassicScript.h */; settings = {ATTRIBUTES = (Private, ); }; }; 6103 6108 E3FA38641D71812D00AA5950 /* PendingScriptClient.h in Headers */ = {isa = PBXBuildFile; fileRef = E3FA38611D716E7600AA5950 /* PendingScriptClient.h */; }; 6104 6109 E401C27517CE53EC00C41A35 /* ElementIteratorAssertions.h in Headers */ = {isa = PBXBuildFile; fileRef = E401C27417CE53EC00C41A35 /* ElementIteratorAssertions.h */; settings = {ATTRIBUTES = (Private, ); }; }; … … 13678 13683 E38838941BAD145F00D62EE3 /* ScriptModuleLoader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScriptModuleLoader.cpp; sourceTree = "<group>"; }; 13679 13684 E38838951BAD145F00D62EE3 /* ScriptModuleLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptModuleLoader.h; sourceTree = "<group>"; }; 13685 E3B2F0E31D7F35EC00B0C9D1 /* LoadableClassicScript.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LoadableClassicScript.cpp; sourceTree = "<group>"; }; 13686 E3B2F0E41D7F35EC00B0C9D1 /* LoadableClassicScript.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LoadableClassicScript.h; sourceTree = "<group>"; }; 13687 E3B2F0E71D7F35EC00B0C9D1 /* LoadableScript.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LoadableScript.h; sourceTree = "<group>"; }; 13688 E3B2F0E81D7F35EC00B0C9D1 /* LoadableScriptClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LoadableScriptClient.h; sourceTree = "<group>"; }; 13689 E3B2F0E91D7F3D3C00B0C9D1 /* LoadableScript.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LoadableScript.cpp; sourceTree = "<group>"; }; 13680 13690 E3FA38611D716E7600AA5950 /* PendingScriptClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PendingScriptClient.h; sourceTree = "<group>"; }; 13681 13691 E401C27417CE53EC00C41A35 /* ElementIteratorAssertions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ElementIteratorAssertions.h; sourceTree = "<group>"; }; … … 23038 23048 BC7FA61E0D1F0CBD00DB22A9 /* LiveNodeList.cpp */, 23039 23049 BC7FA61F0D1F0CBD00DB22A9 /* LiveNodeList.h */, 23050 E3B2F0E31D7F35EC00B0C9D1 /* LoadableClassicScript.cpp */, 23051 E3B2F0E41D7F35EC00B0C9D1 /* LoadableClassicScript.h */, 23052 E3B2F0E91D7F3D3C00B0C9D1 /* LoadableScript.cpp */, 23053 E3B2F0E71D7F35EC00B0C9D1 /* LoadableScript.h */, 23054 E3B2F0E81D7F35EC00B0C9D1 /* LoadableScriptClient.h */, 23040 23055 BC9A6144146859D9006057FD /* make_dom_exceptions.pl */, 23041 23056 BC9A6145146859D9006057FD /* make_event_factory.pl */, … … 24945 24960 BC64649811D82349006455B0 /* JSDOMStringMap.h in Headers */, 24946 24961 7694563D1214D97C0007CBAE /* JSDOMTokenList.h in Headers */, 24962 E3B2F0F01D7F4CB500B0C9D1 /* LoadableClassicScript.h in Headers */, 24947 24963 2E37E00612DBC5A400A6B233 /* JSDOMURL.h in Headers */, 24948 24964 BC6932740D7E293900AE44D1 /* JSDOMWindowBase.h in Headers */, … … 25331 25347 B2FA3DF30AB75A6F000E5AC4 /* JSSVGScriptElement.h in Headers */, 25332 25348 B2FA3DF50AB75A6F000E5AC4 /* JSSVGSetElement.h in Headers */, 25349 E3B2F0EE1D7F4CA900B0C9D1 /* LoadableScriptClient.h in Headers */, 25333 25350 B2FA3DF70AB75A6F000E5AC4 /* JSSVGStopElement.h in Headers */, 25334 25351 B2FA3DF90AB75A6F000E5AC4 /* JSSVGStringList.h in Headers */, … … 26942 26959 44A20DB90F84166C00B3E1FE /* WebCoreURLResponseIOS.h in Headers */, 26943 26960 93F199F008245E59001E9ABC /* WebCoreView.h in Headers */, 26961 E3B2F0ED1D7F4CA300B0C9D1 /* LoadableScript.h in Headers */, 26944 26962 A5E616741894581F009ADF50 /* WebDebuggerAgent.h in Headers */, 26945 26963 FE0D84E910484348001A179E /* WebEvent.h in Headers */, … … 27667 27685 26E944D81AC4B2DD007B85B5 /* CombinedURLFilters.cpp in Sources */, 27668 27686 A584FE341864D5AF00843B10 /* CommandLineAPIHost.cpp in Sources */, 27687 E3B2F0EB1D7F4C9D00B0C9D1 /* LoadableClassicScript.cpp in Sources */, 27669 27688 A584FE2B1863870F00843B10 /* CommandLineAPIModule.cpp in Sources */, 27670 27689 6550B6A1099DF0270090D781 /* Comment.cpp in Sources */, … … 27765 27784 BC274B31140EBED800EADFA6 /* CSSBorderImageSliceValue.cpp in Sources */, 27766 27785 49AE2D8E134EE50C0072920A /* CSSCalculationValue.cpp in Sources */, 27786 E3B2F0EC1D7F4CA100B0C9D1 /* LoadableScript.cpp in Sources */, 27767 27787 BC604A430DB5634E00204739 /* CSSCanvasValue.cpp in Sources */, 27768 27788 E1EBBBD40AAC9B87001FE8E2 /* CSSCharsetRule.cpp in Sources */, -
trunk/Source/WebCore/dom/LoadableClassicScript.h
r205580 r205581 1 1 /* 2 * Copyright (C) 201 0 Google, Inc. All Rights Reserved.2 * Copyright (C) 2016 Apple, Inc. All Rights Reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 21 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 24 */ 25 25 … … 28 28 #include "CachedResourceClient.h" 29 29 #include "CachedResourceHandle.h" 30 #include <wtf/Ref.h> 31 #include <wtf/RefCounted.h> 32 #include <wtf/text/TextPosition.h> 30 #include "CachedScript.h" 31 #include "LoadableScript.h" 32 #include "LoadableScriptClient.h" 33 #include "SecurityOrigin.h" 34 #include <wtf/TypeCasts.h> 33 35 34 36 namespace WebCore { 35 37 36 class CachedScript; 37 class Element; 38 class PendingScriptClient; 38 // A CachedResourceHandle alone does not prevent the underlying CachedResource 39 // from purging its data buffer. This class holds a client until this class is 40 // destroyed in order to guarantee that the data buffer will not be purged. 41 class LoadableClassicScript final : public LoadableScript, private CachedResourceClient { 42 public: 43 ~LoadableClassicScript(); 39 44 40 // A container for an external script which may be loaded and executed. 41 // 42 // A CachedResourceHandle alone does not prevent the underlying CachedResource 43 // from purging its data buffer. This class holds a dummy client open for its 44 // lifetime in order to guarantee that the data buffer will not be purged. 45 class PendingScript final : public RefCounted<PendingScript>, public CachedResourceClient { 46 public: 47 static Ref<PendingScript> create(Element&, CachedScript&); 48 static Ref<PendingScript> create(Element&, TextPosition scriptStartPosition); 45 static Ref<LoadableClassicScript> create(CachedResourceHandle<CachedScript>&&, const String& crossOriginMode, SecurityOrigin&); 46 bool isLoaded() const override; 47 Optional<Error> wasErrored() const override; 48 bool wasCanceled() const override; 49 49 50 virtual ~PendingScript(); 50 CachedScript& cachedScript() { return *m_cachedScript; } 51 bool isClassicScript() const final { return true; } 51 52 52 TextPosition startingPosition() const { return m_startingPosition; } 53 void setStartingPosition(const TextPosition& position) { m_startingPosition = position; } 53 void execute(ScriptElement&) override; 54 54 55 bool watchingForLoad() const { return needsLoading() && m_client; } 56 57 Element& element() { return m_element.get(); } 58 const Element& element() const { return m_element.get(); } 59 60 CachedScript* cachedScript() const; 61 bool needsLoading() const { return cachedScript(); } 62 63 bool isLoaded() const; 55 private: 56 LoadableClassicScript(CachedResourceHandle<CachedScript>&&, const String& crossOriginMode, SecurityOrigin&); 64 57 65 58 void notifyFinished(CachedResource*) override; 66 59 67 void setClient(PendingScriptClient*);68 void clearClient();69 70 private:71 PendingScript(Element&, CachedScript&);72 PendingScript(Element&, TextPosition startingPosition);73 74 void notifyClientFinished();75 76 Ref<Element> m_element;77 TextPosition m_startingPosition; // Only used for inline script tags.78 60 CachedResourceHandle<CachedScript> m_cachedScript; 79 PendingScriptClient* m_client { nullptr }; 61 Ref<SecurityOrigin> m_securityOrigin; 62 Optional<Error> m_error { Nullopt }; 63 bool m_requestUsesAccessControl; 80 64 }; 81 65 82 66 } 67 68 SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::LoadableClassicScript) 69 static bool isType(const WebCore::LoadableScript& script) { return script.isClassicScript(); } 70 SPECIALIZE_TYPE_TRAITS_END() -
trunk/Source/WebCore/dom/LoadableScript.cpp
r205580 r205581 1 1 /* 2 * Copyright (C) 201 0 Google, Inc. All Rights Reserved.2 * Copyright (C) 2016 Apple, Inc. All Rights Reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 21 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 24 */ 25 25 26 #i fndef ScriptRunner_h27 # define ScriptRunner_h26 #include "config.h" 27 #include "LoadableScript.h" 28 28 29 #include "CachedResourceHandle.h" 30 #include "Timer.h" 31 #include <wtf/HashMap.h> 32 #include <wtf/Noncopyable.h> 33 #include <wtf/Vector.h> 29 #include "LoadableScriptClient.h" 34 30 35 31 namespace WebCore { 36 32 37 class CachedScript; 38 class Document; 39 class PendingScript; 40 class ScriptElement; 33 void LoadableScript::addClient(LoadableScriptClient& client) 34 { 35 m_clients.add(&client); 36 if (isLoaded()) { 37 Ref<LoadableScript> protectedThis(*this); 38 client.notifyFinished(*this); 39 } 40 } 41 41 42 class ScriptRunner { 43 WTF_MAKE_NONCOPYABLE(ScriptRunner); WTF_MAKE_FAST_ALLOCATED; 44 public: 45 explicit ScriptRunner(Document&); 46 ~ScriptRunner(); 42 void LoadableScript::removeClient(LoadableScriptClient& client) 43 { 44 m_clients.remove(&client); 45 } 47 46 48 enum ExecutionType { ASYNC_EXECUTION, IN_ORDER_EXECUTION }; 49 void queueScriptForExecution(ScriptElement*, CachedResourceHandle<CachedScript>, ExecutionType); 50 bool hasPendingScripts() const { return !m_scriptsToExecuteSoon.isEmpty() || !m_scriptsToExecuteInOrder.isEmpty() || !m_pendingAsyncScripts.isEmpty(); } 51 void suspend(); 52 void resume(); 53 void notifyScriptReady(ScriptElement*, ExecutionType); 47 void LoadableScript::notifyClientFinished() 48 { 49 RefPtr<LoadableScript> protectedThis(this); 54 50 55 private: 56 void timerFired(); 57 58 Document& m_document; 59 Vector<Ref<PendingScript>> m_scriptsToExecuteInOrder; 60 Vector<RefPtr<PendingScript>> m_scriptsToExecuteSoon; // http://www.whatwg.org/specs/web-apps/current-work/#set-of-scripts-that-will-execute-as-soon-as-possible 61 HashMap<ScriptElement*, Ref<PendingScript>> m_pendingAsyncScripts; 62 Timer m_timer; 63 }; 51 Vector<LoadableScriptClient*> vector; 52 for (auto& pair : m_clients) 53 vector.append(pair.key); 54 for (auto& client : vector) 55 client->notifyFinished(*this); 56 } 64 57 65 58 } 66 67 #endif -
trunk/Source/WebCore/dom/LoadableScript.h
r205580 r205581 1 1 /* 2 * Copyright (C) 201 0 Google, Inc. All Rights Reserved.2 * Copyright (C) 2016 Apple, Inc. All Rights Reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 21 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 24 */ 25 25 26 #ifndef ScriptRunner_h 27 #define ScriptRunner_h 26 #pragma once 28 27 29 #include "CachedResourceHandle.h" 30 #include "Timer.h" 31 #include <wtf/HashMap.h> 32 #include <wtf/Noncopyable.h> 33 #include <wtf/Vector.h> 28 #include <runtime/ConsoleTypes.h> 29 #include <wtf/HashCountedSet.h> 30 #include <wtf/RefCounted.h> 31 #include <wtf/text/WTFString.h> 34 32 35 33 namespace WebCore { 36 34 37 class CachedScript; 38 class Document; 39 class PendingScript; 35 class LoadableScriptClient; 40 36 class ScriptElement; 41 37 42 class ScriptRunner { 43 WTF_MAKE_NONCOPYABLE(ScriptRunner); WTF_MAKE_FAST_ALLOCATED; 38 class LoadableScript : public RefCounted<LoadableScript> { 44 39 public: 45 explicit ScriptRunner(Document&); 46 ~ScriptRunner(); 40 enum class ErrorType { 41 CachedScript, 42 CrossOriginLoad, 43 Nosniff, 44 }; 47 45 48 enum ExecutionType { ASYNC_EXECUTION, IN_ORDER_EXECUTION }; 49 void queueScriptForExecution(ScriptElement*, CachedResourceHandle<CachedScript>, ExecutionType); 50 bool hasPendingScripts() const { return !m_scriptsToExecuteSoon.isEmpty() || !m_scriptsToExecuteInOrder.isEmpty() || !m_pendingAsyncScripts.isEmpty(); } 51 void suspend(); 52 void resume(); 53 void notifyScriptReady(ScriptElement*, ExecutionType); 46 struct ConsoleMessage { 47 MessageSource source; 48 MessageLevel level; 49 String message; 50 }; 51 52 struct Error { 53 ErrorType type; 54 Optional<ConsoleMessage> consoleMessage; 55 }; 56 57 virtual ~LoadableScript() { } 58 59 virtual bool isLoaded() const = 0; 60 virtual Optional<Error> wasErrored() const = 0; 61 virtual bool wasCanceled() const = 0; 62 63 virtual void execute(ScriptElement&) = 0; 64 65 void addClient(LoadableScriptClient&); 66 void removeClient(LoadableScriptClient&); 67 68 virtual bool isClassicScript() const { return false; } 69 virtual bool isModuleGraph() const { return false; } 70 71 protected: 72 void notifyClientFinished(); 54 73 55 74 private: 56 void timerFired(); 57 58 Document& m_document; 59 Vector<Ref<PendingScript>> m_scriptsToExecuteInOrder; 60 Vector<RefPtr<PendingScript>> m_scriptsToExecuteSoon; // http://www.whatwg.org/specs/web-apps/current-work/#set-of-scripts-that-will-execute-as-soon-as-possible 61 HashMap<ScriptElement*, Ref<PendingScript>> m_pendingAsyncScripts; 62 Timer m_timer; 75 HashCountedSet<LoadableScriptClient*> m_clients; 63 76 }; 64 77 65 78 } 66 67 #endif -
trunk/Source/WebCore/dom/LoadableScriptClient.h
r205580 r205581 1 1 /* 2 * Copyright (C) 201 0 Google, Inc. All Rights Reserved.2 * Copyright (C) 2016 Apple, Inc. All Rights Reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 21 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 24 */ 25 25 26 #ifndef ScriptRunner_h 27 #define ScriptRunner_h 28 29 #include "CachedResourceHandle.h" 30 #include "Timer.h" 31 #include <wtf/HashMap.h> 32 #include <wtf/Noncopyable.h> 33 #include <wtf/Vector.h> 26 #pragma once 34 27 35 28 namespace WebCore { 36 29 37 class CachedScript; 38 class Document; 39 class PendingScript; 40 class ScriptElement; 30 class LoadableScript; 41 31 42 class ScriptRunner { 43 WTF_MAKE_NONCOPYABLE(ScriptRunner); WTF_MAKE_FAST_ALLOCATED; 32 class LoadableScriptClient { 44 33 public: 45 explicit ScriptRunner(Document&); 46 ~ScriptRunner(); 34 virtual ~LoadableScriptClient() { } 47 35 48 enum ExecutionType { ASYNC_EXECUTION, IN_ORDER_EXECUTION }; 49 void queueScriptForExecution(ScriptElement*, CachedResourceHandle<CachedScript>, ExecutionType); 50 bool hasPendingScripts() const { return !m_scriptsToExecuteSoon.isEmpty() || !m_scriptsToExecuteInOrder.isEmpty() || !m_pendingAsyncScripts.isEmpty(); } 51 void suspend(); 52 void resume(); 53 void notifyScriptReady(ScriptElement*, ExecutionType); 54 55 private: 56 void timerFired(); 57 58 Document& m_document; 59 Vector<Ref<PendingScript>> m_scriptsToExecuteInOrder; 60 Vector<RefPtr<PendingScript>> m_scriptsToExecuteSoon; // http://www.whatwg.org/specs/web-apps/current-work/#set-of-scripts-that-will-execute-as-soon-as-possible 61 HashMap<ScriptElement*, Ref<PendingScript>> m_pendingAsyncScripts; 62 Timer m_timer; 36 virtual void notifyFinished(LoadableScript&) = 0; 63 37 }; 64 38 65 39 } 66 67 #endif -
trunk/Source/WebCore/dom/PendingScript.cpp
r205218 r205581 27 27 #include "PendingScript.h" 28 28 29 #include "CachedScript.h"30 29 #include "Element.h" 31 30 #include "PendingScriptClient.h" … … 33 32 namespace WebCore { 34 33 35 Ref<PendingScript> PendingScript::create(Element& element, CachedScript& cachedScript)34 Ref<PendingScript> PendingScript::create(Element& element, LoadableScript& loadableScript) 36 35 { 37 Ref<PendingScript> pendingScript = adoptRef(*new PendingScript(element, cachedScript));38 cachedScript.addClient(&pendingScript.get());36 Ref<PendingScript> pendingScript = adoptRef(*new PendingScript(element, loadableScript)); 37 loadableScript.addClient(pendingScript.get()); 39 38 return pendingScript; 40 39 } … … 51 50 } 52 51 53 PendingScript::PendingScript(Element& element, CachedScript& cachedScript)52 PendingScript::PendingScript(Element& element, LoadableScript& loadableScript) 54 53 : m_element(element) 55 , m_ cachedScript(&cachedScript)54 , m_loadableScript(&loadableScript) 56 55 { 57 56 } … … 59 58 PendingScript::~PendingScript() 60 59 { 61 if (m_ cachedScript)62 m_ cachedScript->removeClient(this);60 if (m_loadableScript) 61 m_loadableScript->removeClient(*this); 63 62 } 64 63 65 CachedScript* PendingScript::cachedScript() const64 LoadableScript* PendingScript::loadableScript() const 66 65 { 67 return m_ cachedScript.get();66 return m_loadableScript.get(); 68 67 } 69 68 … … 75 74 } 76 75 77 void PendingScript::notifyFinished( CachedResource*)76 void PendingScript::notifyFinished(LoadableScript&) 78 77 { 79 78 notifyClientFinished(); … … 82 81 bool PendingScript::isLoaded() const 83 82 { 84 return m_cachedScript && m_cachedScript->isLoaded(); 83 return m_loadableScript && m_loadableScript->isLoaded(); 84 } 85 86 bool PendingScript::wasErrored() const 87 { 88 return m_loadableScript && m_loadableScript->wasErrored(); 85 89 } 86 90 -
trunk/Source/WebCore/dom/PendingScript.h
r205218 r205581 26 26 #pragma once 27 27 28 #include " CachedResourceClient.h"29 #include " CachedResourceHandle.h"28 #include "LoadableScript.h" 29 #include "LoadableScriptClient.h" 30 30 #include <wtf/Ref.h> 31 31 #include <wtf/RefCounted.h> … … 38 38 class PendingScriptClient; 39 39 40 // A container for an external script which may be loaded and executed. 41 // 42 // A CachedResourceHandle alone does not prevent the underlying CachedResource 43 // from purging its data buffer. This class holds a dummy client open for its 44 // lifetime in order to guarantee that the data buffer will not be purged. 45 class PendingScript final : public RefCounted<PendingScript>, public CachedResourceClient { 40 // A container for scripts which may be loaded and executed. 41 // This can hold LoadableScript and non external inline script. 42 class PendingScript final : public RefCounted<PendingScript>, public LoadableScriptClient { 46 43 public: 47 static Ref<PendingScript> create(Element&, CachedScript&);44 static Ref<PendingScript> create(Element&, LoadableScript&); 48 45 static Ref<PendingScript> create(Element&, TextPosition scriptStartPosition); 49 46 … … 58 55 const Element& element() const { return m_element.get(); } 59 56 60 CachedScript* cachedScript() const;61 bool needsLoading() const { return cachedScript(); }57 LoadableScript* loadableScript() const; 58 bool needsLoading() const { return loadableScript(); } 62 59 63 60 bool isLoaded() const; 61 bool wasErrored() const; 64 62 65 void notifyFinished( CachedResource*) override;63 void notifyFinished(LoadableScript&) override; 66 64 67 65 void setClient(PendingScriptClient*); … … 69 67 70 68 private: 71 PendingScript(Element&, CachedScript&);69 PendingScript(Element&, LoadableScript&); 72 70 PendingScript(Element&, TextPosition startingPosition); 73 71 … … 76 74 Ref<Element> m_element; 77 75 TextPosition m_startingPosition; // Only used for inline script tags. 78 CachedResourceHandle<CachedScript> m_cachedScript;76 RefPtr<LoadableScript> m_loadableScript; 79 77 PendingScriptClient* m_client { nullptr }; 80 78 }; -
trunk/Source/WebCore/dom/ScriptElement.cpp
r204221 r205581 38 38 #include "HTMLParserIdioms.h" 39 39 #include "IgnoreDestructiveWriteCountIncrementer.h" 40 #include "LoadableClassicScript.h" 40 41 #include "MIMETypeRegistry.h" 41 42 #include "Page.h" 43 #include "PendingScript.h" 42 44 #include "SVGNames.h" 43 45 #include "SVGScriptElement.h" … … 69 71 , m_forceAsync(!parserInserted) 70 72 , m_willExecuteInOrder(false) 71 , m_requestUsesAccessControl(false)72 73 { 73 74 if (parserInserted && m_element.document().scriptableDocumentParser() && !m_element.document().isInDocumentWrite()) … … 97 98 } 98 99 99 void ScriptElement::handleSourceAttribute(const String& sourceU rl)100 { 101 if (ignoresLoadRequest() || sourceU rl.isEmpty())100 void ScriptElement::handleSourceAttribute(const String& sourceURL) 101 { 102 if (ignoresLoadRequest() || sourceURL.isEmpty()) 102 103 return; 103 104 … … 228 229 m_characterEncoding = document.charset(); 229 230 230 if (hasSourceAttribute()) 231 if (!request Script(sourceAttributeValue()))231 if (hasSourceAttribute()) { 232 if (!requestClassicScript(sourceAttributeValue())) 232 233 return false; 234 } 233 235 234 236 if (hasSourceAttribute() && deferAttributeValue() && m_parserInserted && !asyncAttributeValue()) { … … 241 243 m_readyToBeParserExecuted = true; 242 244 } else if (hasSourceAttribute() && !asyncAttributeValue() && !m_forceAsync) { 245 ASSERT(m_loadableScript); 243 246 m_willExecuteInOrder = true; 244 document.scriptRunner()->queueScriptForExecution(this, m_cachedScript, ScriptRunner::IN_ORDER_EXECUTION);245 m_ cachedScript->addClient(this);247 document.scriptRunner()->queueScriptForExecution(this, *m_loadableScript, ScriptRunner::IN_ORDER_EXECUTION); 248 m_loadableScript->addClient(*this); 246 249 } else if (hasSourceAttribute()) { 247 m_element.document().scriptRunner()->queueScriptForExecution(this, m_cachedScript, ScriptRunner::ASYNC_EXECUTION); 248 m_cachedScript->addClient(this); 250 ASSERT(m_loadableScript); 251 m_element.document().scriptRunner()->queueScriptForExecution(this, *m_loadableScript, ScriptRunner::ASYNC_EXECUTION); 252 m_loadableScript->addClient(*this); 249 253 } else { 250 254 // Reset line numbering for nested writes. … … 256 260 } 257 261 258 bool ScriptElement::request Script(const String& sourceUrl)262 bool ScriptElement::requestClassicScript(const String& sourceURL) 259 263 { 260 264 Ref<Document> originalDocument(m_element.document()); 261 if (!m_element.dispatchBeforeLoadEvent(sourceUrl)) 262 return false; 263 if (!m_element.inDocument() || &m_element.document() != originalDocument.ptr()) 264 return false; 265 266 ASSERT(!m_cachedScript); 267 if (!stripLeadingAndTrailingHTMLSpaces(sourceUrl).isEmpty()) { 268 bool hasKnownNonce = m_element.document().contentSecurityPolicy()->allowScriptWithNonce(m_element.attributeWithoutSynchronization(HTMLNames::nonceAttr), m_element.isInUserAgentShadowTree()); 269 ResourceLoaderOptions options = CachedResourceLoader::defaultCachedResourceOptions(); 270 options.contentSecurityPolicyImposition = hasKnownNonce ? ContentSecurityPolicyImposition::SkipPolicyCheck : ContentSecurityPolicyImposition::DoPolicyCheck; 271 272 CachedResourceRequest request(ResourceRequest(m_element.document().completeURL(sourceUrl)), options); 273 274 m_element.document().contentSecurityPolicy()->upgradeInsecureRequestIfNeeded(request.mutableResourceRequest(), ContentSecurityPolicy::InsecureRequestType::Load); 275 265 if (!m_element.dispatchBeforeLoadEvent(sourceURL)) 266 return false; 267 bool didEventListenerDisconnectThisElement = !m_element.inDocument() || &m_element.document() != originalDocument.ptr(); 268 if (didEventListenerDisconnectThisElement) 269 return false; 270 271 ASSERT(!m_loadableScript); 272 if (!stripLeadingAndTrailingHTMLSpaces(sourceURL).isEmpty()) { 276 273 String crossOriginMode = m_element.attributeWithoutSynchronization(HTMLNames::crossoriginAttr); 277 if (!crossOriginMode.isNull()) { 278 m_requestUsesAccessControl = true; 279 StoredCredentials allowCredentials = equalLettersIgnoringASCIICase(crossOriginMode, "use-credentials") ? AllowStoredCredentials : DoNotAllowStoredCredentials; 280 ASSERT(m_element.document().securityOrigin()); 281 updateRequestForAccessControl(request.mutableResourceRequest(), *m_element.document().securityOrigin(), allowCredentials); 274 auto request = requestScriptWithCache(m_element.document().completeURL(sourceURL), m_element.attributeWithoutSynchronization(HTMLNames::nonceAttr), crossOriginMode); 275 if (request) { 276 m_loadableScript = LoadableClassicScript::create(WTFMove(request), crossOriginMode, *m_element.document().securityOrigin()); 277 m_isExternalScript = true; 282 278 } 283 request.setCharset(scriptCharset()); 284 request.setInitiator(&element()); 285 286 m_cachedScript = m_element.document().cachedResourceLoader().requestScript(request); 287 m_isExternalScript = true; 288 } 289 290 if (m_cachedScript) 279 } 280 281 if (m_loadableScript) 291 282 return true; 292 283 … … 295 286 }); 296 287 return false; 288 } 289 290 CachedResourceHandle<CachedScript> ScriptElement::requestScriptWithCache(const URL& sourceURL, const String& nonceAttribute, const String& crossOriginMode) 291 { 292 bool hasKnownNonce = m_element.document().contentSecurityPolicy()->allowScriptWithNonce(nonceAttribute, m_element.isInUserAgentShadowTree()); 293 ResourceLoaderOptions options = CachedResourceLoader::defaultCachedResourceOptions(); 294 options.contentSecurityPolicyImposition = hasKnownNonce ? ContentSecurityPolicyImposition::SkipPolicyCheck : ContentSecurityPolicyImposition::DoPolicyCheck; 295 296 CachedResourceRequest request(ResourceRequest(sourceURL), options); 297 298 m_element.document().contentSecurityPolicy()->upgradeInsecureRequestIfNeeded(request.mutableResourceRequest(), ContentSecurityPolicy::InsecureRequestType::Load); 299 300 if (!crossOriginMode.isNull()) { 301 StoredCredentials allowCredentials = equalLettersIgnoringASCIICase(crossOriginMode, "use-credentials") ? AllowStoredCredentials : DoNotAllowStoredCredentials; 302 ASSERT(m_element.document().securityOrigin()); 303 updateRequestForAccessControl(request.mutableResourceRequest(), *m_element.document().securityOrigin(), allowCredentials); 304 } 305 306 request.setCharset(scriptCharset()); 307 request.setInitiator(&element()); 308 309 return m_element.document().cachedResourceLoader().requestScript(request); 297 310 } 298 311 … … 312 325 } 313 326 314 #if ENABLE(NOSNIFF)315 if (m_isExternalScript && m_cachedScript && !m_cachedScript->mimeTypeAllowedByNosniff()) {316 m_element.document().addConsoleMessage(MessageSource::Security, MessageLevel::Error, "Refused to execute script from '" + m_cachedScript->url().stringCenterEllipsizedToLength() + "' because its MIME type ('" + m_cachedScript->mimeType() + "') is not executable, and strict MIME type checking is enabled.");317 return;318 }319 #endif320 321 327 Ref<Document> document(m_element.document()); 322 328 if (Frame* frame = document->frame()) { … … 333 339 void ScriptElement::stopLoadRequest() 334 340 { 335 if (m_ cachedScript) {341 if (m_loadableScript) { 336 342 if (!m_willBeParserExecuted) 337 m_cachedScript->removeClient(this); 338 m_cachedScript = nullptr; 339 } 340 } 341 342 void ScriptElement::execute(CachedScript* cachedScript) 343 m_loadableScript->removeClient(*this); 344 m_loadableScript = nullptr; 345 } 346 } 347 348 void ScriptElement::executeScriptAndDispatchEvent(LoadableScript& loadableScript) 349 { 350 if (Optional<LoadableScript::Error> error = loadableScript.wasErrored()) { 351 if (Optional<LoadableScript::ConsoleMessage> message = error->consoleMessage) 352 m_element.document().addConsoleMessage(message->source, message->level, message->message); 353 dispatchErrorEvent(); 354 } else if (!loadableScript.wasCanceled()) { 355 ASSERT(!loadableScript.wasErrored()); 356 loadableScript.execute(*this); 357 dispatchLoadEvent(); 358 } 359 } 360 361 void ScriptElement::executeScriptForScriptRunner(LoadableScript& loadableScript) 343 362 { 344 363 ASSERT(!m_willBeParserExecuted); 345 ASSERT(cachedScript); 346 if (cachedScript->errorOccurred()) 347 dispatchErrorEvent(); 348 else if (!cachedScript->wasCanceled()) { 349 executeScript(ScriptSourceCode(cachedScript)); 364 executeScriptAndDispatchEvent(loadableScript); 365 loadableScript.removeClient(*this); 366 } 367 368 void ScriptElement::executeScriptForHTMLScriptRunner(PendingScript& pendingScript) 369 { 370 IgnoreDestructiveWriteCountIncrementer ignoreDestructiveWriteCountIncrementer(&m_element.document()); 371 if (auto* loadableScript = pendingScript.loadableScript()) 372 executeScriptAndDispatchEvent(*loadableScript); 373 else { 374 ASSERT(!pendingScript.wasErrored()); 375 executeScript(ScriptSourceCode(scriptContent(), m_element.document().url(), pendingScript.startingPosition())); 350 376 dispatchLoadEvent(); 351 377 } 352 cachedScript->removeClient(this); 353 } 354 355 void ScriptElement::notifyFinished(CachedResource* resource) 378 } 379 380 void ScriptElement::notifyFinished(LoadableScript&) 356 381 { 357 382 ASSERT(!m_willBeParserExecuted); 358 383 359 // CachedResourcepossibly invokes this notifyFinished() more than384 // LoadableScript possibly invokes this notifyFinished() more than 360 385 // once because ScriptElement doesn't unsubscribe itself from 361 // CachedResource here and does it in execute() instead. 362 // We use m_cachedScript to check if this function is already called. 363 ASSERT_UNUSED(resource, resource == m_cachedScript); 364 if (!m_cachedScript) 386 // LoadableScript here and does it in execute() instead. 387 // We use m_loadableScript to check if this function is already called. 388 if (!m_loadableScript) 365 389 return; 366 367 if (m_requestUsesAccessControl && !m_cachedScript->passesSameOriginPolicyCheck(*m_element.document().securityOrigin())) {368 dispatchErrorEvent();369 static NeverDestroyed<String> consoleMessage(ASCIILiteral("Cross-origin script load denied by Cross-Origin Resource Sharing policy."));370 m_element.document().addConsoleMessage(MessageSource::JS, MessageLevel::Error, consoleMessage);371 return;372 }373 390 374 391 if (m_willExecuteInOrder) … … 377 394 m_element.document().scriptRunner()->notifyScriptReady(this, ScriptRunner::ASYNC_EXECUTION); 378 395 379 m_ cachedScript = nullptr;396 m_loadableScript = nullptr; 380 397 } 381 398 -
trunk/Source/WebCore/dom/ScriptElement.h
r204717 r205581 19 19 */ 20 20 21 #ifndef ScriptElement_h 22 #define ScriptElement_h 21 #pragma once 23 22 24 23 #include "CachedResourceClient.h" 25 24 #include "CachedResourceHandle.h" 25 #include "LoadableScript.h" 26 #include "LoadableScriptClient.h" 26 27 #include "Timer.h" 28 #include "URL.h" 27 29 #include <wtf/text/TextPosition.h> 28 30 #include <wtf/text/WTFString.h> … … 33 35 class ContainerNode; 34 36 class Element; 37 class PendingScript; 35 38 class ScriptElement; 36 39 class ScriptSourceCode; 37 40 38 class ScriptElement : private CachedResourceClient {41 class ScriptElement : private LoadableScriptClient { 39 42 public: 40 43 virtual ~ScriptElement(); … … 49 52 WEBCORE_EXPORT String scriptContent() const; 50 53 void executeScript(const ScriptSourceCode&); 51 void execute(CachedScript*); 54 55 void executeScriptForScriptRunner(LoadableScript&); 56 void executeScriptForHTMLScriptRunner(PendingScript&); 52 57 53 58 // XML parser calls these … … 59 64 bool readyToBeParserExecuted() const { return m_readyToBeParserExecuted; } 60 65 bool willExecuteWhenDocumentFinishedParsing() const { return m_willExecuteWhenDocumentFinishedParsing; } 61 CachedResourceHandle<CachedScript> cachedScript() { return m_cachedScript; }66 LoadableScript* loadableScript() { return m_loadableScript.get(); } 62 67 63 68 protected: … … 73 78 void finishedInsertingSubtree(); 74 79 void childrenChanged(); 75 void handleSourceAttribute(const String& sourceU rl);80 void handleSourceAttribute(const String& sourceURL); 76 81 void handleAsyncAttribute(); 77 82 78 83 private: 84 void executeScriptAndDispatchEvent(LoadableScript&); 85 79 86 // https://html.spec.whatwg.org/multipage/scripting.html#concept-script-type 80 87 enum class ScriptType { Classic, Module }; … … 83 90 bool isScriptForEventSupported() const; 84 91 85 bool requestScript(const String& sourceUrl); 92 CachedResourceHandle<CachedScript> requestScriptWithCache(const URL&, const String& nonceAttribute, const String& crossoriginAttribute); 93 94 bool requestClassicScript(const String& sourceURL); 86 95 void stopLoadRequest(); 87 96 88 void notifyFinished( CachedResource*) override;97 void notifyFinished(LoadableScript&) override; 89 98 90 99 virtual String sourceAttributeValue() const = 0; … … 99 108 100 109 Element& m_element; 101 CachedResourceHandle<CachedScript> m_cachedScript;102 110 WTF::OrdinalNumber m_startLineNumber; 103 111 bool m_parserInserted : 1; … … 110 118 bool m_forceAsync : 1; 111 119 bool m_willExecuteInOrder : 1; 112 bool m_requestUsesAccessControl : 1;113 120 String m_characterEncoding; 114 121 String m_fallbackCharacterEncoding; 122 RefPtr<LoadableScript> m_loadableScript; 115 123 }; 116 124 … … 119 127 120 128 } 121 122 #endif -
trunk/Source/WebCore/dom/ScriptRunner.cpp
r205218 r205581 27 27 #include "ScriptRunner.h" 28 28 29 #include "CachedScript.h"30 29 #include "Element.h" 31 30 #include "PendingScript.h" … … 50 49 } 51 50 52 void ScriptRunner::queueScriptForExecution(ScriptElement* scriptElement, CachedResourceHandle<CachedScript> cachedScript, ExecutionType executionType)51 void ScriptRunner::queueScriptForExecution(ScriptElement* scriptElement, LoadableScript& loadableScript, ExecutionType executionType) 53 52 { 54 53 ASSERT(scriptElement); 55 ASSERT(cachedScript.get());56 54 57 55 Element& element = scriptElement->element(); … … 62 60 switch (executionType) { 63 61 case ASYNC_EXECUTION: 64 m_pendingAsyncScripts.add(scriptElement, PendingScript::create(element, *cachedScript));62 m_pendingAsyncScripts.add(scriptElement, PendingScript::create(element, loadableScript)); 65 63 break; 66 64 67 65 case IN_ORDER_EXECUTION: 68 m_scriptsToExecuteInOrder.append(PendingScript::create(element, *cachedScript));66 m_scriptsToExecuteInOrder.append(PendingScript::create(element, loadableScript)); 69 67 break; 70 68 } … … 118 116 auto* scriptElement = toScriptElementIfPossible(&script->element()); 119 117 ASSERT(scriptElement); 120 scriptElement->execute(script->cachedScript()); 118 ASSERT(script->needsLoading()); 119 scriptElement->executeScriptForScriptRunner(*script->loadableScript()); 121 120 m_document.decrementLoadEventDelayCount(); 122 121 } -
trunk/Source/WebCore/dom/ScriptRunner.h
r205218 r205581 24 24 */ 25 25 26 #ifndef ScriptRunner_h 27 #define ScriptRunner_h 26 #pragma once 28 27 29 #include "CachedResourceHandle.h"30 28 #include "Timer.h" 31 29 #include <wtf/HashMap.h> … … 35 33 namespace WebCore { 36 34 37 class CachedScript;38 35 class Document; 39 36 class PendingScript; 40 37 class ScriptElement; 38 class LoadableScript; 41 39 42 40 class ScriptRunner { … … 47 45 48 46 enum ExecutionType { ASYNC_EXECUTION, IN_ORDER_EXECUTION }; 49 void queueScriptForExecution(ScriptElement*, CachedResourceHandle<CachedScript>, ExecutionType);47 void queueScriptForExecution(ScriptElement*, LoadableScript&, ExecutionType); 50 48 bool hasPendingScripts() const { return !m_scriptsToExecuteSoon.isEmpty() || !m_scriptsToExecuteInOrder.isEmpty() || !m_pendingAsyncScripts.isEmpty(); } 51 49 void suspend(); … … 64 62 65 63 } 66 67 #endif -
trunk/Source/WebCore/html/parser/HTMLScriptRunner.cpp
r205218 r205581 27 27 #include "HTMLScriptRunner.h" 28 28 29 #include "CachedScript.h"30 #include "CachedResourceLoader.h"31 29 #include "Element.h" 32 30 #include "Event.h" … … 90 88 } 91 89 92 ScriptSourceCode HTMLScriptRunner::sourceFromPendingScript(const PendingScript& script, bool& errorOccurred) const93 {94 if (script.cachedScript()) {95 errorOccurred = script.cachedScript()->errorOccurred();96 ASSERT(script.cachedScript()->isLoaded());97 return ScriptSourceCode(script.cachedScript());98 }99 errorOccurred = false;100 return ScriptSourceCode(script.element().textContent(), documentURLForScriptExecution(m_document), script.startingPosition());101 }102 103 90 bool HTMLScriptRunner::isPendingScriptReady(const PendingScript& script) 104 91 { … … 126 113 void HTMLScriptRunner::executePendingScriptAndDispatchEvent(RefPtr<PendingScript> pendingScript) 127 114 { 128 bool errorOccurred = false;129 ScriptSourceCode sourceCode = sourceFromPendingScript(*pendingScript, errorOccurred);130 131 115 // Stop watching loads before executeScript to prevent recursion if the script reloads itself. 132 116 if (pendingScript->watchingForLoad()) … … 138 122 if (auto* scriptElement = toScriptElementIfPossible(&pendingScript->element())) { 139 123 NestingLevelIncrementer nestingLevelIncrementer(m_scriptNestingLevel); 140 IgnoreDestructiveWriteCountIncrementer ignoreDestructiveWriteCountIncrementer(m_document); 141 if (errorOccurred) 142 scriptElement->dispatchErrorEvent(); 143 else { 144 ASSERT(isExecutingScript()); 145 scriptElement->executeScript(sourceCode); 146 pendingScript->element().dispatchEvent(createScriptLoadEvent()); 147 } 124 scriptElement->executeScriptForHTMLScriptRunner(*pendingScript); 148 125 } 149 126 ASSERT(!isExecutingScript()); … … 237 214 auto& scriptElement = *toScriptElementIfPossible(script); 238 215 ASSERT(scriptElement.willBeParserExecuted()); 239 ASSERT(scriptElement. cachedScript());240 return PendingScript::create(*script, *scriptElement. cachedScript());216 ASSERT(scriptElement.loadableScript()); 217 return PendingScript::create(*script, *scriptElement.loadableScript()); 241 218 } 242 219 … … 247 224 ASSERT(m_parserBlockingScript->needsLoading()); 248 225 249 // We only care about a load callback if cachedScript is not already226 // We only care about a load callback if LoadableScript is not already 250 227 // in the cache. Callers will attempt to run the m_parserBlockingScript 251 228 // if possible before returning control to the parser. -
trunk/Source/WebCore/html/parser/HTMLScriptRunner.h
r205218 r205581 33 33 namespace WebCore { 34 34 35 class CachedResource;36 class CachedScript;37 35 class Document; 38 36 class Element; -
trunk/Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp
r205411 r205581 46 46 #include "HTMLStyleElement.h" 47 47 #include "HTMLTemplateElement.h" 48 #include "LoadableClassicScript.h" 48 49 #include "Page.h" 49 50 #include "ProcessingInstruction.h" … … 921 922 if (scriptElement->readyToBeParserExecuted()) 922 923 scriptElement->executeScript(ScriptSourceCode(scriptElement->scriptContent(), document()->url(), m_scriptStartPosition)); 923 else if (scriptElement->willBeParserExecuted()) { 924 m_pendingScript = scriptElement->cachedScript(); 924 else if (scriptElement->willBeParserExecuted() && scriptElement->loadableScript() && is<LoadableClassicScript>(*scriptElement->loadableScript())) { 925 // FIXME: Allow "module" scripts for XML documents. 926 // https://bugs.webkit.org/show_bug.cgi?id=161651 927 m_pendingScript = &downcast<LoadableClassicScript>(*scriptElement->loadableScript()).cachedScript(); 925 928 m_scriptElement = &element; 926 929 m_pendingScript->addClient(this);
Note: See TracChangeset
for help on using the changeset viewer.