Index: third_party/WebKit/Source/core/dom/ScriptLoader.cpp |
diff --git a/third_party/WebKit/Source/core/dom/ScriptLoader.cpp b/third_party/WebKit/Source/core/dom/ScriptLoader.cpp |
index e102a1f49468938db54d60c9986b76abed3bd3de..e51d27c405785cb074220a583303b483cbfd9348 100644 |
--- a/third_party/WebKit/Source/core/dom/ScriptLoader.cpp |
+++ b/third_party/WebKit/Source/core/dom/ScriptLoader.cpp |
@@ -60,6 +60,7 @@ namespace blink { |
ScriptLoader::ScriptLoader(Element* element, bool parserInserted, bool alreadyStarted) |
: m_element(element) |
, m_resource(0) |
+ , m_originWorld(nullptr) |
, m_startLineNumber(WTF::OrdinalNumber::beforeFirst()) |
, m_parserInserted(parserInserted) |
, m_isExternalScript(false) |
@@ -240,6 +241,11 @@ bool ScriptLoader::prepareScript(const TextPosition& scriptStartPosition, Legacy |
return false; |
} |
+ // Store the origin to apply when the script is done loading, as the script could be loaded in the main world. |
+ if (v8::Isolate::GetCurrent()->InContext()) { |
haraken
2016/01/21 10:16:15
v8::Isolate::GetCurrent() is deprecated. Use toIso
proberge
2016/01/29 18:00:48
Where is the deprecation notice? Neither api.cc no
|
+ m_originWorld = PassRefPtr<DOMWrapperWorld>(DOMWrapperWorld::current(v8::Isolate::GetCurrent()).originWorld()); |
haraken
2016/01/21 10:16:15
PassRefPtr<DOMWrapperWorld> wouldn't be needed.
haraken
2016/01/21 10:16:15
v8::Isolate::GetCurrent() is deprecated.
|
+ } |
+ |
if (client->hasSourceAttribute() && client->deferAttributeValue() && m_parserInserted && !client->asyncAttributeValue()) { |
m_willExecuteWhenDocumentFinishedParsing = true; |
m_willBeParserExecuted = true; |
@@ -415,6 +421,9 @@ bool ScriptLoader::executeScript(const ScriptSourceCode& sourceCode, double* com |
if (isHTMLScriptLoader(m_element)) |
contextDocument->pushCurrentScript(toHTMLScriptElement(m_element)); |
+ // Ensure the origin world gets propagated to the script and is reset afterwards. |
+ DOMWrapperWorld::OriginWorldPusher worldPusher(ScriptState::forMainWorld(frame)->world(), m_originWorld); |
+ |
// 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. |