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 13 matching lines...) Expand all Loading... |
24 */ | 24 */ |
25 | 25 |
26 #include "config.h" | 26 #include "config.h" |
27 #include "core/html/parser/HTMLScriptRunner.h" | 27 #include "core/html/parser/HTMLScriptRunner.h" |
28 | 28 |
29 #include "bindings/v8/ScriptSourceCode.h" | 29 #include "bindings/v8/ScriptSourceCode.h" |
30 #include "core/dom/Element.h" | 30 #include "core/dom/Element.h" |
31 #include "core/dom/Event.h" | 31 #include "core/dom/Event.h" |
32 #include "core/dom/IgnoreDestructiveWriteCountIncrementer.h" | 32 #include "core/dom/IgnoreDestructiveWriteCountIncrementer.h" |
33 #include "core/dom/Microtask.h" | 33 #include "core/dom/Microtask.h" |
34 #include "core/dom/ScriptElement.h" | 34 #include "core/dom/ScriptLoader.h" |
35 #include "core/html/parser/HTMLInputStream.h" | 35 #include "core/html/parser/HTMLInputStream.h" |
36 #include "core/html/parser/HTMLScriptRunnerHost.h" | 36 #include "core/html/parser/HTMLScriptRunnerHost.h" |
37 #include "core/html/parser/NestingLevelIncrementer.h" | 37 #include "core/html/parser/NestingLevelIncrementer.h" |
38 #include "core/loader/cache/CachedScript.h" | 38 #include "core/loader/cache/CachedScript.h" |
39 #include "core/page/Frame.h" | 39 #include "core/page/Frame.h" |
40 #include "core/platform/NotImplemented.h" | 40 #include "core/platform/NotImplemented.h" |
41 | 41 |
42 namespace WebCore { | 42 namespace WebCore { |
43 | 43 |
44 using namespace HTMLNames; | 44 using namespace HTMLNames; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 | 123 |
124 // Stop watching loads before executeScript to prevent recursion if the scri
pt reloads itself. | 124 // Stop watching loads before executeScript to prevent recursion if the scri
pt reloads itself. |
125 if (pendingScript.cachedScript() && pendingScript.watchingForLoad()) | 125 if (pendingScript.cachedScript() && pendingScript.watchingForLoad()) |
126 stopWatchingForLoad(pendingScript); | 126 stopWatchingForLoad(pendingScript); |
127 | 127 |
128 if (!isExecutingScript()) | 128 if (!isExecutingScript()) |
129 Microtask::performCheckpoint(); | 129 Microtask::performCheckpoint(); |
130 | 130 |
131 // Clear the pending script before possible rentrancy from executeScript() | 131 // Clear the pending script before possible rentrancy from executeScript() |
132 RefPtr<Element> element = pendingScript.releaseElementAndClear(); | 132 RefPtr<Element> element = pendingScript.releaseElementAndClear(); |
133 if (ScriptElement* scriptElement = toScriptElementIfPossible(element.get()))
{ | 133 if (ScriptLoader* scriptLoader = toScriptLoaderIfPossible(element.get())) { |
134 NestingLevelIncrementer nestingLevelIncrementer(m_scriptNestingLevel); | 134 NestingLevelIncrementer nestingLevelIncrementer(m_scriptNestingLevel); |
135 IgnoreDestructiveWriteCountIncrementer ignoreDestructiveWriteCountIncrem
enter(m_document); | 135 IgnoreDestructiveWriteCountIncrementer ignoreDestructiveWriteCountIncrem
enter(m_document); |
136 if (errorOccurred) | 136 if (errorOccurred) |
137 scriptElement->dispatchErrorEvent(); | 137 scriptLoader->dispatchErrorEvent(); |
138 else { | 138 else { |
139 ASSERT(isExecutingScript()); | 139 ASSERT(isExecutingScript()); |
140 scriptElement->executeScript(sourceCode); | 140 scriptLoader->executeScript(sourceCode); |
141 element->dispatchEvent(createScriptLoadEvent()); | 141 element->dispatchEvent(createScriptLoadEvent()); |
142 } | 142 } |
143 } | 143 } |
144 ASSERT(!isExecutingScript()); | 144 ASSERT(!isExecutingScript()); |
145 } | 145 } |
146 | 146 |
147 void HTMLScriptRunner::watchForLoad(PendingScript& pendingScript) | 147 void HTMLScriptRunner::watchForLoad(PendingScript& pendingScript) |
148 { | 148 { |
149 ASSERT(!pendingScript.watchingForLoad()); | 149 ASSERT(!pendingScript.watchingForLoad()); |
150 m_host->watchForLoad(pendingScript.cachedScript()); | 150 m_host->watchForLoad(pendingScript.cachedScript()); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 | 252 |
253 ASSERT(pendingScript.cachedScript()); | 253 ASSERT(pendingScript.cachedScript()); |
254 m_scriptsToExecuteAfterParsing.append(pendingScript); | 254 m_scriptsToExecuteAfterParsing.append(pendingScript); |
255 } | 255 } |
256 | 256 |
257 bool HTMLScriptRunner::requestPendingScript(PendingScript& pendingScript, Elemen
t* script) const | 257 bool HTMLScriptRunner::requestPendingScript(PendingScript& pendingScript, Elemen
t* script) const |
258 { | 258 { |
259 ASSERT(!pendingScript.element()); | 259 ASSERT(!pendingScript.element()); |
260 pendingScript.setElement(script); | 260 pendingScript.setElement(script); |
261 // This should correctly return 0 for empty or invalid srcValues. | 261 // This should correctly return 0 for empty or invalid srcValues. |
262 CachedScript* cachedScript = toScriptElementIfPossible(script)->cachedScript
().get(); | 262 CachedScript* cachedScript = toScriptLoaderIfPossible(script)->cachedScript(
).get(); |
263 if (!cachedScript) { | 263 if (!cachedScript) { |
264 notImplemented(); // Dispatch error event. | 264 notImplemented(); // Dispatch error event. |
265 return false; | 265 return false; |
266 } | 266 } |
267 pendingScript.setCachedScript(cachedScript); | 267 pendingScript.setCachedScript(cachedScript); |
268 return true; | 268 return true; |
269 } | 269 } |
270 | 270 |
271 // This method is meant to match the HTML5 definition of "running a script" | 271 // This method is meant to match the HTML5 definition of "running a script" |
272 // http://www.whatwg.org/specs/web-apps/current-work/multipage/scripting-1.html#
running-a-script | 272 // http://www.whatwg.org/specs/web-apps/current-work/multipage/scripting-1.html#
running-a-script |
273 void HTMLScriptRunner::runScript(Element* script, const TextPosition& scriptStar
tPosition) | 273 void HTMLScriptRunner::runScript(Element* script, const TextPosition& scriptStar
tPosition) |
274 { | 274 { |
275 ASSERT(m_document); | 275 ASSERT(m_document); |
276 ASSERT(!hasParserBlockingScript()); | 276 ASSERT(!hasParserBlockingScript()); |
277 { | 277 { |
278 ScriptElement* scriptElement = toScriptElementIfPossible(script); | 278 ScriptLoader* scriptLoader = toScriptLoaderIfPossible(script); |
279 | 279 |
280 // This contains both and ASSERTION and a null check since we should not | 280 // This contains both and ASSERTION and a null check since we should not |
281 // be getting into the case of a null script element, but seem to be fro
m | 281 // be getting into the case of a null script element, but seem to be fro
m |
282 // time to time. The assertion is left in to help find those cases and | 282 // time to time. The assertion is left in to help find those cases and |
283 // is being tracked by <https://bugs.webkit.org/show_bug.cgi?id=60559>. | 283 // is being tracked by <https://bugs.webkit.org/show_bug.cgi?id=60559>. |
284 ASSERT(scriptElement); | 284 ASSERT(scriptLoader); |
285 if (!scriptElement) | 285 if (!scriptLoader) |
286 return; | 286 return; |
287 | 287 |
288 // FIXME: This may be too agressive as we always deliver mutations at | 288 // FIXME: This may be too agressive as we always deliver mutations at |
289 // every script element, even if it's not ready to execute yet. There's | 289 // every script element, even if it's not ready to execute yet. There's |
290 // unfortuantely no obvious way to tell if prepareScript is going to | 290 // unfortuantely no obvious way to tell if prepareScript is going to |
291 // execute the script from out here. | 291 // execute the script from out here. |
292 if (!isExecutingScript()) | 292 if (!isExecutingScript()) |
293 Microtask::performCheckpoint(); | 293 Microtask::performCheckpoint(); |
294 | 294 |
295 InsertionPointRecord insertionPointRecord(m_host->inputStream()); | 295 InsertionPointRecord insertionPointRecord(m_host->inputStream()); |
296 NestingLevelIncrementer nestingLevelIncrementer(m_scriptNestingLevel); | 296 NestingLevelIncrementer nestingLevelIncrementer(m_scriptNestingLevel); |
297 | 297 |
298 scriptElement->prepareScript(scriptStartPosition); | 298 scriptLoader->prepareScript(scriptStartPosition); |
299 | 299 |
300 if (!scriptElement->willBeParserExecuted()) | 300 if (!scriptLoader->willBeParserExecuted()) |
301 return; | 301 return; |
302 | 302 |
303 if (scriptElement->willExecuteWhenDocumentFinishedParsing()) | 303 if (scriptLoader->willExecuteWhenDocumentFinishedParsing()) { |
304 requestDeferredScript(script); | 304 requestDeferredScript(script); |
305 else if (scriptElement->readyToBeParserExecuted()) { | 305 } else if (scriptLoader->readyToBeParserExecuted()) { |
306 if (m_scriptNestingLevel == 1) { | 306 if (m_scriptNestingLevel == 1) { |
307 m_parserBlockingScript.setElement(script); | 307 m_parserBlockingScript.setElement(script); |
308 m_parserBlockingScript.setStartingPosition(scriptStartPosition); | 308 m_parserBlockingScript.setStartingPosition(scriptStartPosition); |
309 } else { | 309 } else { |
310 ScriptSourceCode sourceCode(script->textContent(), documentURLFo
rScriptExecution(m_document), scriptStartPosition); | 310 ScriptSourceCode sourceCode(script->textContent(), documentURLFo
rScriptExecution(m_document), scriptStartPosition); |
311 scriptElement->executeScript(sourceCode); | 311 scriptLoader->executeScript(sourceCode); |
312 } | 312 } |
313 } else | 313 } else { |
314 requestParsingBlockingScript(script); | 314 requestParsingBlockingScript(script); |
| 315 } |
315 } | 316 } |
316 } | 317 } |
317 | 318 |
318 } | 319 } |
OLD | NEW |