OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
4 * (C) 2001 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserv ed. | 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserv ed. |
6 * Copyright (C) 2008 Nikolas Zimmermann <zimmermann@kde.org> | 6 * Copyright (C) 2008 Nikolas Zimmermann <zimmermann@kde.org> |
7 * | 7 * |
8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
71 , m_forceAsync(!parserInserted) | 71 , m_forceAsync(!parserInserted) |
72 , m_willExecuteInOrder(false) | 72 , m_willExecuteInOrder(false) |
73 { | 73 { |
74 ASSERT(m_element); | 74 ASSERT(m_element); |
75 if (parserInserted && element->document().scriptableDocumentParser() && !ele ment->document().isInDocumentWrite()) | 75 if (parserInserted && element->document().scriptableDocumentParser() && !ele ment->document().isInDocumentWrite()) |
76 m_startLineNumber = element->document().scriptableDocumentParser()->line Number(); | 76 m_startLineNumber = element->document().scriptableDocumentParser()->line Number(); |
77 } | 77 } |
78 | 78 |
79 ScriptLoader::~ScriptLoader() | 79 ScriptLoader::~ScriptLoader() |
80 { | 80 { |
81 m_pendingScript.stopWatchingForLoad(this); | 81 #if !ENABLE(OILPAN) |
82 dispose(); | |
haraken
2016/01/12 00:22:52
I think it's better to call detach() (i.e., it's n
Nate Chapin
2016/01/13 20:36:33
Done.
| |
83 #endif | |
84 } | |
85 | |
86 void ScriptLoader::dispose() | |
87 { | |
88 if (m_pendingScript) { | |
89 m_pendingScript->stopWatchingForLoad(this); | |
90 m_pendingScript = nullptr; | |
91 } | |
82 } | 92 } |
83 | 93 |
84 DEFINE_TRACE(ScriptLoader) | 94 DEFINE_TRACE(ScriptLoader) |
85 { | 95 { |
86 visitor->trace(m_element); | 96 visitor->trace(m_element); |
87 visitor->trace(m_pendingScript); | 97 visitor->trace(m_pendingScript); |
88 } | 98 } |
89 | 99 |
90 void ScriptLoader::didNotifySubtreeInsertionsToDocument() | 100 void ScriptLoader::didNotifySubtreeInsertionsToDocument() |
91 { | 101 { |
(...skipping 15 matching lines...) Expand all Loading... | |
107 prepareScript(); // FIXME: Provide a real starting line number here. | 117 prepareScript(); // FIXME: Provide a real starting line number here. |
108 } | 118 } |
109 | 119 |
110 void ScriptLoader::handleAsyncAttribute() | 120 void ScriptLoader::handleAsyncAttribute() |
111 { | 121 { |
112 m_forceAsync = false; | 122 m_forceAsync = false; |
113 } | 123 } |
114 | 124 |
115 void ScriptLoader::detach() | 125 void ScriptLoader::detach() |
116 { | 126 { |
117 m_pendingScript.stopWatchingForLoad(this); | 127 if (!m_pendingScript) |
118 m_pendingScript.releaseElementAndClear(); | 128 return; |
129 m_pendingScript->stopWatchingForLoad(this); | |
130 m_pendingScript->releaseElementAndClear(); | |
131 m_pendingScript = nullptr; | |
119 } | 132 } |
120 | 133 |
121 // Helper function | 134 // Helper function |
122 static bool isLegacySupportedJavaScriptLanguage(const String& language) | 135 static bool isLegacySupportedJavaScriptLanguage(const String& language) |
123 { | 136 { |
124 // Mozilla 1.8 accepts javascript1.0 - javascript1.7, but WinIE 7 accepts on ly javascript1.1 - javascript1.3. | 137 // Mozilla 1.8 accepts javascript1.0 - javascript1.7, but WinIE 7 accepts on ly javascript1.1 - javascript1.3. |
125 // Mozilla 1.8 and WinIE 7 both accept javascript and livescript. | 138 // Mozilla 1.8 and WinIE 7 both accept javascript and livescript. |
126 // WinIE 7 accepts ecmascript and jscript, but Mozilla 1.8 doesn't. | 139 // WinIE 7 accepts ecmascript and jscript, but Mozilla 1.8 doesn't. |
127 // Neither Mozilla 1.8 nor WinIE 7 accept leading or trailing whitespace. | 140 // Neither Mozilla 1.8 nor WinIE 7 accept leading or trailing whitespace. |
128 // We want to accept all the values that either of these browsers accept, bu t not other values. | 141 // We want to accept all the values that either of these browsers accept, bu t not other values. |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
243 if (client->hasSourceAttribute() && client->deferAttributeValue() && m_parse rInserted && !client->asyncAttributeValue()) { | 256 if (client->hasSourceAttribute() && client->deferAttributeValue() && m_parse rInserted && !client->asyncAttributeValue()) { |
244 m_willExecuteWhenDocumentFinishedParsing = true; | 257 m_willExecuteWhenDocumentFinishedParsing = true; |
245 m_willBeParserExecuted = true; | 258 m_willBeParserExecuted = true; |
246 } else if (client->hasSourceAttribute() && m_parserInserted && !client->asyn cAttributeValue()) { | 259 } else if (client->hasSourceAttribute() && m_parserInserted && !client->asyn cAttributeValue()) { |
247 m_willBeParserExecuted = true; | 260 m_willBeParserExecuted = true; |
248 } else if (!client->hasSourceAttribute() && m_parserInserted && !elementDocu ment.isRenderingReady()) { | 261 } else if (!client->hasSourceAttribute() && m_parserInserted && !elementDocu ment.isRenderingReady()) { |
249 m_willBeParserExecuted = true; | 262 m_willBeParserExecuted = true; |
250 m_readyToBeParserExecuted = true; | 263 m_readyToBeParserExecuted = true; |
251 } else if (client->hasSourceAttribute() && !client->asyncAttributeValue() && !m_forceAsync) { | 264 } else if (client->hasSourceAttribute() && !client->asyncAttributeValue() && !m_forceAsync) { |
252 m_willExecuteInOrder = true; | 265 m_willExecuteInOrder = true; |
253 m_pendingScript = PendingScript(m_element, m_resource.get()); | 266 m_pendingScript = PendingScript::create(m_element, m_resource.get()); |
254 contextDocument->scriptRunner()->queueScriptForExecution(this, ScriptRun ner::IN_ORDER_EXECUTION); | 267 contextDocument->scriptRunner()->queueScriptForExecution(this, ScriptRun ner::IN_ORDER_EXECUTION); |
255 // Note that watchForLoad can immediately call notifyFinished. | 268 // Note that watchForLoad can immediately call notifyFinished. |
256 m_pendingScript.watchForLoad(this); | 269 m_pendingScript->watchForLoad(this); |
257 } else if (client->hasSourceAttribute()) { | 270 } else if (client->hasSourceAttribute()) { |
258 m_pendingScript = PendingScript(m_element, m_resource.get()); | 271 m_pendingScript = PendingScript::create(m_element, m_resource.get()); |
259 LocalFrame* frame = m_element->document().frame(); | 272 LocalFrame* frame = m_element->document().frame(); |
260 if (frame) { | 273 if (frame) { |
261 ScriptState* scriptState = ScriptState::forMainWorld(frame); | 274 ScriptState* scriptState = ScriptState::forMainWorld(frame); |
262 if (scriptState) | 275 if (scriptState) |
263 ScriptStreamer::startStreaming(m_pendingScript, PendingScript::A sync, frame->settings(), scriptState, frame->frameScheduler()->loadingTaskRunner ()); | 276 ScriptStreamer::startStreaming(m_pendingScript.get(), PendingScr ipt::Async, frame->settings(), scriptState, frame->frameScheduler()->loadingTask Runner()); |
264 } | 277 } |
265 contextDocument->scriptRunner()->queueScriptForExecution(this, ScriptRun ner::ASYNC_EXECUTION); | 278 contextDocument->scriptRunner()->queueScriptForExecution(this, ScriptRun ner::ASYNC_EXECUTION); |
266 // Note that watchForLoad can immediately call notifyFinished. | 279 // Note that watchForLoad can immediately call notifyFinished. |
267 m_pendingScript.watchForLoad(this); | 280 m_pendingScript->watchForLoad(this); |
268 } else { | 281 } else { |
269 // Reset line numbering for nested writes. | 282 // Reset line numbering for nested writes. |
270 TextPosition position = elementDocument.isInDocumentWrite() ? TextPositi on() : scriptStartPosition; | 283 TextPosition position = elementDocument.isInDocumentWrite() ? TextPositi on() : scriptStartPosition; |
271 KURL scriptURL = (!elementDocument.isInDocumentWrite() && m_parserInsert ed) ? elementDocument.url() : KURL(); | 284 KURL scriptURL = (!elementDocument.isInDocumentWrite() && m_parserInsert ed) ? elementDocument.url() : KURL(); |
272 if (!executeScript(ScriptSourceCode(scriptContent(), scriptURL, position ))) { | 285 if (!executeScript(ScriptSourceCode(scriptContent(), scriptURL, position ))) { |
273 dispatchErrorEvent(); | 286 dispatchErrorEvent(); |
274 return false; | 287 return false; |
275 } | 288 } |
276 } | 289 } |
277 | 290 |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
422 ASSERT(contextDocument->currentScript() == m_element); | 435 ASSERT(contextDocument->currentScript() == m_element); |
423 contextDocument->popCurrentScript(); | 436 contextDocument->popCurrentScript(); |
424 } | 437 } |
425 | 438 |
426 return true; | 439 return true; |
427 } | 440 } |
428 | 441 |
429 void ScriptLoader::execute() | 442 void ScriptLoader::execute() |
430 { | 443 { |
431 ASSERT(!m_willBeParserExecuted); | 444 ASSERT(!m_willBeParserExecuted); |
432 ASSERT(m_pendingScript.resource()); | 445 ASSERT(m_pendingScript->resource()); |
433 bool errorOccurred = false; | 446 bool errorOccurred = false; |
434 ScriptSourceCode source = m_pendingScript.getSource(KURL(), errorOccurred); | 447 ScriptSourceCode source = m_pendingScript->getSource(KURL(), errorOccurred); |
435 RefPtrWillBeRawPtr<Element> element = m_pendingScript.releaseElementAndClear (); | 448 RefPtrWillBeRawPtr<Element> element = m_pendingScript->releaseElementAndClea r(); |
436 ALLOW_UNUSED_LOCAL(element); | 449 ALLOW_UNUSED_LOCAL(element); |
437 if (errorOccurred) { | 450 if (errorOccurred) { |
438 dispatchErrorEvent(); | 451 dispatchErrorEvent(); |
439 } else if (!m_resource->wasCanceled()) { | 452 } else if (!m_resource->wasCanceled()) { |
440 if (executeScript(source)) | 453 if (executeScript(source)) |
441 dispatchLoadEvent(); | 454 dispatchLoadEvent(); |
442 else | 455 else |
443 dispatchErrorEvent(); | 456 dispatchErrorEvent(); |
444 } | 457 } |
445 m_resource = 0; | 458 m_resource = 0; |
(...skipping 16 matching lines...) Expand all Loading... | |
462 // dispatchErrorEvent might move the HTMLScriptElement to a new | 475 // dispatchErrorEvent might move the HTMLScriptElement to a new |
463 // document. In that case, we must notify the ScriptRunner of the new | 476 // document. In that case, we must notify the ScriptRunner of the new |
464 // document, not the ScriptRunner of the old docuemnt. | 477 // document, not the ScriptRunner of the old docuemnt. |
465 contextDocument = m_element->document().contextDocument().get(); | 478 contextDocument = m_element->document().contextDocument().get(); |
466 if (!contextDocument) | 479 if (!contextDocument) |
467 return; | 480 return; |
468 contextDocument->scriptRunner()->notifyScriptLoadError(this, runOrder); | 481 contextDocument->scriptRunner()->notifyScriptLoadError(this, runOrder); |
469 return; | 482 return; |
470 } | 483 } |
471 contextDocument->scriptRunner()->notifyScriptReady(this, runOrder); | 484 contextDocument->scriptRunner()->notifyScriptReady(this, runOrder); |
472 m_pendingScript.stopWatchingForLoad(this); | 485 m_pendingScript->stopWatchingForLoad(this); |
473 } | 486 } |
474 | 487 |
475 bool ScriptLoader::ignoresLoadRequest() const | 488 bool ScriptLoader::ignoresLoadRequest() const |
476 { | 489 { |
477 return m_alreadyStarted || m_isExternalScript || m_parserInserted || !elemen t() || !element()->inDocument(); | 490 return m_alreadyStarted || m_isExternalScript || m_parserInserted || !elemen t() || !element()->inDocument(); |
478 } | 491 } |
479 | 492 |
480 bool ScriptLoader::isScriptForEventSupported() const | 493 bool ScriptLoader::isScriptForEventSupported() const |
481 { | 494 { |
482 String eventAttribute = client()->eventAttributeValue(); | 495 String eventAttribute = client()->eventAttributeValue(); |
(...skipping 30 matching lines...) Expand all Loading... | |
513 if (isHTMLScriptLoader(element)) | 526 if (isHTMLScriptLoader(element)) |
514 return toHTMLScriptElement(element)->loader(); | 527 return toHTMLScriptElement(element)->loader(); |
515 | 528 |
516 if (isSVGScriptLoader(element)) | 529 if (isSVGScriptLoader(element)) |
517 return toSVGScriptElement(element)->loader(); | 530 return toSVGScriptElement(element)->loader(); |
518 | 531 |
519 return 0; | 532 return 0; |
520 } | 533 } |
521 | 534 |
522 } // namespace blink | 535 } // namespace blink |
OLD | NEW |