OLD | NEW |
---|---|
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 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
47 : m_document(document) | 47 : m_document(document) |
48 , m_host(host) | 48 , m_host(host) |
49 , m_scriptNestingLevel(0) | 49 , m_scriptNestingLevel(0) |
50 , m_hasScriptsWaitingForResources(false) | 50 , m_hasScriptsWaitingForResources(false) |
51 { | 51 { |
52 ASSERT(m_host); | 52 ASSERT(m_host); |
53 } | 53 } |
54 | 54 |
55 HTMLScriptRunner::~HTMLScriptRunner() | 55 HTMLScriptRunner::~HTMLScriptRunner() |
56 { | 56 { |
57 // FIXME: Should we be passed a "done loading/parsing" callback sooner than destruction? | 57 #if ENABLE(OILPAN) |
58 if (m_parserBlockingScript.resource() && m_parserBlockingScript.watchingForL oad()) | 58 // If the document is destructed without having explicitly |
59 stopWatchingForLoad(m_parserBlockingScript); | 59 // detached the parser (and this script runner object), |
60 | 60 // perform detach steps now. |
61 while (!m_scriptsToExecuteAfterParsing.isEmpty()) { | 61 detach(); |
eseidel
2014/05/28 22:43:38
Isn't this a bug in ~Document()?
haraken
2014/05/29 01:46:08
Agreed, I guess the Document should always call ex
sof
2014/05/29 06:02:07
I've tried to improve the comment to clarify. If t
| |
62 PendingScript pendingScript = m_scriptsToExecuteAfterParsing.takeFirst() ; | 62 #else |
63 if (pendingScript.resource() && pendingScript.watchingForLoad()) | 63 // Verify that detach() has been called. |
64 stopWatchingForLoad(pendingScript); | 64 ASSERT(!m_document); |
65 } | 65 #endif |
66 } | 66 } |
67 | 67 |
68 void HTMLScriptRunner::detach() | 68 void HTMLScriptRunner::detach() |
69 { | 69 { |
70 m_document = 0; | 70 if (m_document) { |
eseidel
2014/05/28 22:43:38
Early return is better.
haraken
2014/05/29 01:46:08
Does this check mean that detach() can be called t
sof
2014/05/29 06:02:07
Yes it does. How would you distinguish between an
sof
2014/05/29 06:02:07
Thanks, done.
| |
71 if (m_parserBlockingScript.resource() && m_parserBlockingScript.watching ForLoad()) | |
72 stopWatchingForLoad(m_parserBlockingScript); | |
73 | |
74 while (!m_scriptsToExecuteAfterParsing.isEmpty()) { | |
75 PendingScript pendingScript = m_scriptsToExecuteAfterParsing.takeFir st(); | |
eseidel
2014/05/28 22:43:38
Why can't PendingScript just do this in its destru
haraken
2014/05/29 01:46:08
That's a good question.
I think that in this CL w
sof
2014/05/29 06:02:07
Can't ever guarantee the "always" bit, destruction
| |
76 if (pendingScript.resource() && pendingScript.watchingForLoad()) | |
77 stopWatchingForLoad(pendingScript); | |
78 } | |
79 m_document = nullptr; | |
80 } | |
71 } | 81 } |
72 | 82 |
73 static KURL documentURLForScriptExecution(Document* document) | 83 static KURL documentURLForScriptExecution(Document* document) |
74 { | 84 { |
75 if (!document) | 85 if (!document) |
76 return KURL(); | 86 return KURL(); |
77 | 87 |
78 if (!document->frame()) { | 88 if (!document->frame()) { |
79 if (document->importsController()) | 89 if (document->importsController()) |
80 return document->url(); | 90 return document->url(); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
135 Microtask::performCheckpoint(); | 145 Microtask::performCheckpoint(); |
136 if (pendingScriptType == PendingScriptBlockingParser) { | 146 if (pendingScriptType == PendingScriptBlockingParser) { |
137 m_hasScriptsWaitingForResources = !m_document->isScriptExecutionRead y(); | 147 m_hasScriptsWaitingForResources = !m_document->isScriptExecutionRead y(); |
138 // The parser cannot be unblocked as a microtask requested another r esource | 148 // The parser cannot be unblocked as a microtask requested another r esource |
139 if (m_hasScriptsWaitingForResources) | 149 if (m_hasScriptsWaitingForResources) |
140 return; | 150 return; |
141 } | 151 } |
142 } | 152 } |
143 | 153 |
144 // Clear the pending script before possible rentrancy from executeScript() | 154 // Clear the pending script before possible rentrancy from executeScript() |
145 RefPtr<Element> element = pendingScript.releaseElementAndClear(); | 155 RefPtrWillBeRawPtr<Element> element = pendingScript.releaseElementAndClear() ; |
146 if (ScriptLoader* scriptLoader = toScriptLoaderIfPossible(element.get())) { | 156 if (ScriptLoader* scriptLoader = toScriptLoaderIfPossible(element.get())) { |
147 NestingLevelIncrementer nestingLevelIncrementer(m_scriptNestingLevel); | 157 NestingLevelIncrementer nestingLevelIncrementer(m_scriptNestingLevel); |
148 IgnoreDestructiveWriteCountIncrementer ignoreDestructiveWriteCountIncrem enter(m_document); | 158 IgnoreDestructiveWriteCountIncrementer ignoreDestructiveWriteCountIncrem enter(m_document); |
149 if (errorOccurred) | 159 if (errorOccurred) |
150 scriptLoader->dispatchErrorEvent(); | 160 scriptLoader->dispatchErrorEvent(); |
151 else { | 161 else { |
152 ASSERT(isExecutingScript()); | 162 ASSERT(isExecutingScript()); |
153 scriptLoader->executeScript(sourceCode); | 163 scriptLoader->executeScript(sourceCode); |
154 element->dispatchEvent(createScriptLoadEvent()); | 164 element->dispatchEvent(createScriptLoadEvent()); |
155 } | 165 } |
156 } | 166 } |
157 ASSERT(!isExecutingScript()); | 167 ASSERT(!isExecutingScript()); |
158 } | 168 } |
159 | 169 |
160 void HTMLScriptRunner::watchForLoad(PendingScript& pendingScript) | 170 void HTMLScriptRunner::watchForLoad(PendingScript& pendingScript) |
161 { | 171 { |
162 ASSERT(!pendingScript.watchingForLoad()); | 172 ASSERT(!pendingScript.watchingForLoad()); |
163 m_host->watchForLoad(pendingScript.resource()); | 173 ASSERT(!pendingScript.resource()->isLoaded()); |
174 // addClient() will call notifyFinished() if the load is complete. | |
175 // Callers do not expect to be re-entered from this call, so they | |
176 // should not become a client of an already-loaded Resource. | |
177 pendingScript.resource()->addClient(this); | |
eseidel
2014/05/28 22:43:38
Bleh. Manual add/remove calls are nasty. They're
| |
164 pendingScript.setWatchingForLoad(true); | 178 pendingScript.setWatchingForLoad(true); |
165 } | 179 } |
166 | 180 |
167 void HTMLScriptRunner::stopWatchingForLoad(PendingScript& pendingScript) | 181 void HTMLScriptRunner::stopWatchingForLoad(PendingScript& pendingScript) |
168 { | 182 { |
169 ASSERT(pendingScript.watchingForLoad()); | 183 ASSERT(pendingScript.watchingForLoad()); |
170 m_host->stopWatchingForLoad(pendingScript.resource()); | 184 pendingScript.resource()->removeClient(this); |
171 pendingScript.setWatchingForLoad(false); | 185 pendingScript.setWatchingForLoad(false); |
172 } | 186 } |
173 | 187 |
188 void HTMLScriptRunner::notifyFinished(Resource* cachedResource) | |
189 { | |
190 m_host->notifyScriptLoaded(cachedResource); | |
191 } | |
192 | |
174 // Implements the steps for 'An end tag whose tag name is "script"' | 193 // Implements the steps for 'An end tag whose tag name is "script"' |
175 // http://whatwg.org/html#scriptEndTag | 194 // http://whatwg.org/html#scriptEndTag |
176 // Script handling lives outside the tree builder to keep each class simple. | 195 // Script handling lives outside the tree builder to keep each class simple. |
177 void HTMLScriptRunner::execute(PassRefPtr<Element> scriptElement, const TextPosi tion& scriptStartPosition) | 196 void HTMLScriptRunner::execute(PassRefPtrWillBeRawPtr<Element> scriptElement, co nst TextPosition& scriptStartPosition) |
178 { | 197 { |
179 ASSERT(scriptElement); | 198 ASSERT(scriptElement); |
180 // FIXME: If scripting is disabled, always just return. | 199 // FIXME: If scripting is disabled, always just return. |
181 | 200 |
182 bool hadPreloadScanner = m_host->hasPreloadScanner(); | 201 bool hadPreloadScanner = m_host->hasPreloadScanner(); |
183 | 202 |
184 // Try to execute the script given to us. | 203 // Try to execute the script given to us. |
185 runScript(scriptElement.get(), scriptStartPosition); | 204 runScript(scriptElement.get(), scriptStartPosition); |
186 | 205 |
187 if (hasParserBlockingScript()) { | 206 if (hasParserBlockingScript()) { |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
321 } else { | 340 } else { |
322 ScriptSourceCode sourceCode(script->textContent(), documentURLFo rScriptExecution(m_document), scriptStartPosition); | 341 ScriptSourceCode sourceCode(script->textContent(), documentURLFo rScriptExecution(m_document), scriptStartPosition); |
323 scriptLoader->executeScript(sourceCode); | 342 scriptLoader->executeScript(sourceCode); |
324 } | 343 } |
325 } else { | 344 } else { |
326 requestParsingBlockingScript(script); | 345 requestParsingBlockingScript(script); |
327 } | 346 } |
328 } | 347 } |
329 } | 348 } |
330 | 349 |
350 void HTMLScriptRunner::trace(Visitor* visitor) | |
351 { | |
352 visitor->trace(m_document); | |
353 visitor->trace(m_parserBlockingScript); | |
354 visitor->trace(m_scriptsToExecuteAfterParsing); | |
331 } | 355 } |
356 | |
357 } | |
OLD | NEW |