void HTMLScriptRunner::executePendingScriptAndDispatchEvent(PendingScript& pendingScript) { bool errorOccurred = false; ScriptSourceCode sourceCode = sourceFromPendingScript(pendingScript, errorOccurred); // Stop watching loads before executeScript to prevent recursion if the script reloads itself. if (pendingScript.cachedScript() && pendingScript.watchingForLoad()) stopWatchingForLoad(pendingScript); // WebERA: Insert HB relation between the execution of a pending script and the load of the script if (HBIsCurrentEventActionValid() && pendingScript.cachedScript() && pendingScript.cachedScript()->isLoaded() && pendingScript.cachedScript()->getLoadingEventAction() != 0) { HBAddExplicitArc(pendingScript.cachedScript()->getLoadingEventAction(), HBCurrentEventAction()); } // Clear the pending script before possible rentrancy from executeScript() RefPtr<Element> element = pendingScript.releaseElementAndClear(); if (ScriptElement* scriptElement = toScriptElement(element.get())) { NestingLevelIncrementer nestingLevelIncrementer(m_scriptNestingLevel); IgnoreDestructiveWriteCountIncrementer ignoreDestructiveWriteCountIncrementer(m_document); if (errorOccurred) scriptElement->dispatchErrorEvent(); else { ASSERT(isExecutingScript()); scriptElement->executeScript(sourceCode); element->dispatchEvent(createScriptLoadEvent()); } } ASSERT(!m_scriptNestingLevel); }
bool HTMLScriptRunner::isPendingScriptReady(const PendingScript& script) { m_hasScriptsWaitingForStylesheets = !m_document->haveStylesheetsLoaded(); if (m_hasScriptsWaitingForStylesheets) return false; if (script.cachedScript() && !script.cachedScript()->isLoaded()) return false; return true; }
ScriptSourceCode HTMLScriptRunner::sourceFromPendingScript(const PendingScript& script, bool& errorOccurred) const { if (script.cachedScript()) { errorOccurred = script.cachedScript()->errorOccurred(); ASSERT(script.cachedScript()->isLoaded()); return ScriptSourceCode(script.cachedScript()); } errorOccurred = false; return ScriptSourceCode(script.element()->textContent(), documentURLForScriptExecution(m_document), script.startingPosition()); }
void HTMLScriptRunner::executePendingScriptAndDispatchEvent(PendingScript& pendingScript) { bool errorOccurred = false; ScriptSourceCode sourceCode = sourceFromPendingScript(pendingScript, errorOccurred); // Stop watching loads before executeScript to prevent recursion if the script reloads itself. if (pendingScript.cachedScript() && pendingScript.watchingForLoad()) stopWatchingForLoad(pendingScript); if (!isExecutingScript()) { #if ENABLE(CUSTOM_ELEMENTS) CustomElementRegistry::deliverAllLifecycleCallbacks(); #endif MutationObserver::deliverAllMutations(); } // Clear the pending script before possible rentrancy from executeScript() RefPtr<Element> element = pendingScript.releaseElementAndClear(); if (ScriptElement* scriptElement = toScriptElement(element.get())) { NestingLevelIncrementer nestingLevelIncrementer(m_scriptNestingLevel); IgnoreDestructiveWriteCountIncrementer ignoreDestructiveWriteCountIncrementer(m_document); if (errorOccurred) scriptElement->dispatchErrorEvent(); else { ASSERT(isExecutingScript()); scriptElement->executeScript(sourceCode); element->dispatchEvent(createScriptLoadEvent()); } } ASSERT(!isExecutingScript()); }
void HTMLScriptRunner::requestDeferredScript(Element* element) { PendingScript pendingScript; if (!requestPendingScript(pendingScript, element)) return; ASSERT(pendingScript.cachedScript()); m_scriptsToExecuteAfterParsing.append(pendingScript); }
HTMLScriptRunner::~HTMLScriptRunner() { // FIXME: Should we be passed a "done loading/parsing" callback sooner than destruction? if (m_parsingBlockingScript.cachedScript() && m_parsingBlockingScript.watchingForLoad()) stopWatchingForLoad(m_parsingBlockingScript); while (!m_scriptsToExecuteAfterParsing.isEmpty()) { PendingScript pendingScript = m_scriptsToExecuteAfterParsing.takeFirst(); if (pendingScript.cachedScript() && pendingScript.watchingForLoad()) stopWatchingForLoad(pendingScript); } }
void HTMLScriptRunner::executePendingScriptAndDispatchEvent(PendingScript& pendingScript) { bool errorOccurred = false; ScriptSourceCode sourceCode = sourceFromPendingScript(pendingScript, errorOccurred); // Stop watching loads before executeScript to prevent recursion if the script reloads itself. if (pendingScript.cachedScript() && pendingScript.watchingForLoad()) stopWatchingForLoad(pendingScript); // Clear the pending script before possible rentrancy from executeScript() RefPtr<Element> element = pendingScript.releaseElementAndClear(); if (ScriptElement* scriptElement = toScriptElement(element.get())) { NestingLevelIncrementer nestingLevelIncrementer(m_scriptNestingLevel); IgnoreDestructiveWriteCountIncrementer ignoreDestructiveWriteCountIncrementer(m_document); if (errorOccurred) element->dispatchEvent(createScriptErrorEvent()); else { ASSERT(isExecutingScript()); scriptElement->executeScript(sourceCode); element->dispatchEvent(createScriptLoadEvent()); } } ASSERT(!m_scriptNestingLevel); }
void HTMLScriptRunner::stopWatchingForLoad(PendingScript& pendingScript) { ASSERT(pendingScript.watchingForLoad()); m_host->stopWatchingForLoad(pendingScript.cachedScript()); pendingScript.setWatchingForLoad(false); }
void HTMLScriptRunner::watchForLoad(PendingScript& pendingScript) { ASSERT(!pendingScript.watchingForLoad()); m_host->watchForLoad(pendingScript.cachedScript()); pendingScript.setWatchingForLoad(true); }