Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(154)

Side by Side Diff: third_party/WebKit/Source/core/dom/PendingScript.h

Issue 2695713015: WIP: Reland CompiledScript, prototype compiling in a separate task.
Patch Set: allow compile to fail, disallow restreaming (hack) Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google, Inc. All Rights Reserved. 2 * Copyright (C) 2010 Google, Inc. All Rights Reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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 PendingScript_h 26 #ifndef PendingScript_h
27 #define PendingScript_h 27 #define PendingScript_h
28 28
29 #include "bindings/core/v8/CompiledScript.h"
29 #include "bindings/core/v8/ScriptStreamer.h" 30 #include "bindings/core/v8/ScriptStreamer.h"
30 #include "core/CoreExport.h" 31 #include "core/CoreExport.h"
31 #include "core/loader/resource/ScriptResource.h" 32 #include "core/loader/resource/ScriptResource.h"
32 #include "platform/MemoryCoordinator.h" 33 #include "platform/MemoryCoordinator.h"
33 #include "platform/heap/Handle.h" 34 #include "platform/heap/Handle.h"
34 #include "platform/loader/fetch/ResourceOwner.h" 35 #include "platform/loader/fetch/ResourceOwner.h"
35 #include "wtf/Noncopyable.h" 36 #include "wtf/Noncopyable.h"
36 #include "wtf/text/TextPosition.h" 37 #include "wtf/text/TextPosition.h"
37 38
38 namespace blink { 39 namespace blink {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 91
91 void watchForLoad(PendingScriptClient*); 92 void watchForLoad(PendingScriptClient*);
92 void stopWatchingForLoad(); 93 void stopWatchingForLoad();
93 94
94 Element* element() const; 95 Element* element() const;
95 96
96 DECLARE_TRACE(); 97 DECLARE_TRACE();
97 98
98 ScriptSourceCode getSource(const KURL& documentURL, 99 ScriptSourceCode getSource(const KURL& documentURL,
99 bool& errorOccurred) const; 100 bool& errorOccurred) const;
101 CompiledScript* getCompiledScript() const { return m_compiledScript.get(); }
100 102
101 void setStreamer(ScriptStreamer*); 103 void setStreamer(ScriptStreamer*);
102 void streamingFinished(); 104 void streamingFinished();
103 105
104 bool isReady() const; 106 // TODO(jbroman): disambiguate what "ready" means
107 bool isReady() const; // { return m_isReady; }
105 bool errorOccurred() const; 108 bool errorOccurred() const;
106 109
107 void dispose(); 110 void dispose();
108 111
109 private: 112 private:
110 PendingScript(Element*, 113 PendingScript(Element*,
111 ScriptResource*, 114 ScriptResource*,
112 const TextPosition&, 115 const TextPosition&,
113 bool isForTesting = false); 116 bool isForTesting = false);
114 PendingScript() = delete; 117 PendingScript() = delete;
115 118
119 // Called when the final source is available (i.e. the resource has loaded,
120 // and streaming, if applicable, has completed).
121 void fetchFinished();
122
123 // Called when the script compile step is complete or determined unnecessary.
124 void compileFinished();
125
116 void checkState() const; 126 void checkState() const;
117 127
118 // ScriptResourceClient 128 // ScriptResourceClient
119 void notifyFinished(Resource*) override; 129 void notifyFinished(Resource*) override;
120 String debugName() const override { return "PendingScript"; } 130 String debugName() const override { return "PendingScript"; }
121 void notifyAppendData(ScriptResource*) override; 131 void notifyAppendData(ScriptResource*) override;
122 132
123 // MemoryCoordinatorClient 133 // MemoryCoordinatorClient
124 void onPurgeMemory() override; 134 void onPurgeMemory() override;
125 135
126 bool m_watchingForLoad; 136 bool m_watchingForLoad;
127 137
138 enum ReadyState {
139 kWaitingForResource,
140 kWaitingForStreaming,
141 kWaitingForCompile,
142 kReady,
143 };
144 void advanceReadyState(ReadyState readyState) {
145 CHECK_GT(readyState, m_readyState) << this;
146 m_readyState = readyState;
147
148 if (resource()) {
149 CHECK_EQ(m_readyState > kWaitingForResource, resource()->isLoaded());
150 CHECK_EQ(
151 m_readyState > kWaitingForStreaming,
152 resource()->isLoaded() && (!m_streamer || m_streamer->isFinished()))
153 << "readystate=" << m_readyState << ' ' << resource()->isLoaded()
154 << ' ' << (m_streamer ? (m_streamer->isFinished() ? 'y' : 'n') : '-');
155 } else {
156 CHECK_EQ(m_readyState, kReady);
157 }
158 }
159 ReadyState m_readyState;
160
128 // |m_element| must points to the corresponding ScriptLoader's element and 161 // |m_element| must points to the corresponding ScriptLoader's element and
129 // thus must be non-null before dispose() is called (except for unit tests). 162 // thus must be non-null before dispose() is called (except for unit tests).
130 Member<Element> m_element; 163 Member<Element> m_element;
131 164
132 TextPosition m_startingPosition; // Only used for inline script tags. 165 TextPosition m_startingPosition; // Only used for inline script tags.
133 bool m_integrityFailure; 166 bool m_integrityFailure;
134 double m_parserBlockingLoadStartTime; 167 double m_parserBlockingLoadStartTime;
135 168
136 Member<ScriptStreamer> m_streamer; 169 Member<ScriptStreamer> m_streamer;
137 Member<PendingScriptClient> m_client; 170 Member<PendingScriptClient> m_client;
138 171
172 Member<CompiledScript> m_compiledScript;
173
139 // This flag is used to skip non-null checks of |m_element| in unit tests, 174 // This flag is used to skip non-null checks of |m_element| in unit tests,
140 // because |m_element| can be null in unit tests. 175 // because |m_element| can be null in unit tests.
141 const bool m_isForTesting; 176 const bool m_isForTesting;
142 }; 177 };
143 178
144 } // namespace blink 179 } // namespace blink
145 180
146 #endif // PendingScript_h 181 #endif // PendingScript_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698