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

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

Issue 14852011: Implement document.currentScript (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: tests Created 7 years, 7 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
« Source/core/dom/Document.cpp ('K') | « 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 6b5873893dd4efd1916cd66ccff94a1ac14bf5ad..d86592f5e9184a6ca57376160749d05a26c63ee9 100644
--- a/Source/core/dom/ScriptElement.cpp
+++ b/Source/core/dom/ScriptElement.cpp
@@ -282,6 +282,11 @@ bool ScriptElement::requestScript(const String& sourceUrl)
return false;
}
+bool isHTMLScriptElement(Element* element)
+{
+ return element->isHTMLElement() && element->hasTagName(HTMLNames::scriptTag);
+}
+
void ScriptElement::executeScript(const ScriptSourceCode& sourceCode)
{
ASSERT(m_alreadyStarted);
@@ -307,10 +312,16 @@ void ScriptElement::executeScript(const ScriptSourceCode& sourceCode)
if (frame) {
{
IgnoreDestructiveWriteCountIncrementer ignoreDesctructiveWriteCountIncrementer(m_isExternalScript ? document.get() : 0);
+
+ if (isHTMLScriptElement(m_element))
+ document->setCurrentScript(static_cast<HTMLScriptElement*>(m_element));
+
// 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()->evaluate(sourceCode);
+
+ document->clearCurrentScript();
esprehn 2013/05/15 16:08:16 You're sure this is safe without checking if (docu
arv (Not doing code reviews) 2013/05/15 16:18:11 There is a case where this will fail. When you doc
}
}
}
@@ -417,7 +428,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 ENABLE(SVG)
« Source/core/dom/Document.cpp ('K') | « Source/core/dom/Document.idl ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698