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

Unified Diff: Source/core/dom/ScriptElement.cpp

Issue 14852011: Implement document.currentScript (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebase Created 7 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/dom/Document.idl ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/ScriptElement.cpp
diff --git a/Source/core/dom/ScriptElement.cpp b/Source/core/dom/ScriptElement.cpp
index a49e985e0cd71b63074f6e285ed175b32ad3a761..22a1db41c7b0b49f843335ed3055fc1df014bd32 100644
--- a/Source/core/dom/ScriptElement.cpp
+++ b/Source/core/dom/ScriptElement.cpp
@@ -275,6 +275,11 @@ bool ScriptElement::requestScript(const String& sourceUrl)
return false;
}
+bool isHTMLScriptElement(Element* element)
+{
+ return element->isHTMLElement() && element->hasTagName(HTMLNames::scriptTag);
abarth-chromium 2013/06/11 17:45:20 The isHTMLElement check isn't redundant with hasTa
+}
+
void ScriptElement::executeScript(const ScriptSourceCode& sourceCode)
{
ASSERT(m_alreadyStarted);
@@ -298,10 +303,19 @@ void ScriptElement::executeScript(const ScriptSourceCode& sourceCode)
if (frame) {
{
IgnoreDestructiveWriteCountIncrementer ignoreDesctructiveWriteCountIncrementer(m_isExternalScript ? document.get() : 0);
+
+ if (isHTMLScriptElement(m_element))
+ document->pushCurrentScript(static_cast<HTMLScriptElement*>(m_element));
abarth-chromium 2013/06/11 17:45:20 We should have a toHTMLScriptElement that contains
+
// Create a script from the script element node, using the script
// block's source and the script block's type.
// Note: This is where the script is compiled and actually executed.
frame->script()->executeScriptInMainWorld(sourceCode);
+
+ if (isHTMLScriptElement(m_element)) {
+ ASSERT(document->currentScript() == m_element);
+ document->popCurrentScript();
+ }
}
}
}
@@ -410,7 +424,7 @@ String ScriptElement::scriptContent() const
ScriptElement* toScriptElementIfPossible(Element* element)
{
- if (element->isHTMLElement() && element->hasTagName(HTMLNames::scriptTag))
+ if (isHTMLScriptElement(element))
return static_cast<HTMLScriptElement*>(element);
if (element->isSVGElement() && element->hasTagName(SVGNames::scriptTag))
« no previous file with comments | « Source/core/dom/Document.idl ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698