Index: Source/bindings/core/dart/DartController.cpp |
diff --git a/Source/bindings/core/dart/DartController.cpp b/Source/bindings/core/dart/DartController.cpp |
index d6e56c4f297931cc458f9b013bf8f77b7dc15f04..2546d2523a45f209096ba4b5c39bd91ada6ea4b1 100644 |
--- a/Source/bindings/core/dart/DartController.cpp |
+++ b/Source/bindings/core/dart/DartController.cpp |
@@ -333,10 +333,10 @@ void DartController::clearWindowShell() |
DART_START_TIMER(); |
initVMIfNeeded(); |
DART_RECORD_TIMER("clearWindowShell::initVM took"); |
- m_documentsWithDart.clear(); |
- if (m_loader) { |
- m_loader = nullptr; |
- } |
+ m_loaders.clear(); |
+ m_usedNames.clear(); |
+ m_isolateNames.clear(); |
+ m_mainLoader.clear(); |
// Due to synchronous dispatch, we may be in an isolate corresponding to another frame. |
// If so, exit here but re-enter before returning. |
@@ -749,17 +749,16 @@ void DartController::loadAndRunScript(const String& url, Dart_Isolate isolate, P |
// Invoke only if this is the main document. |
ASSERT(scriptInfo->ownerDocument() == document); |
- |
- ASSERT(m_loader); |
+ RefPtr<DartApplicationLoader> loader = m_loaders.get(isolate); |
+ ASSERT(loader); |
// Due to deferred loading we might already be running Dart code on |
// an isolate and the library tag handler callback could result in a call |
// to this code, we skip the Enter/Exit Isolate calls in that case. |
if (isolate == Dart_CurrentIsolate()) { |
- m_loader->load(scriptInfo); |
+ loader->load(scriptInfo); |
} else { |
- Dart_EnterIsolate(isolate); |
- m_loader->load(scriptInfo); |
- Dart_ExitIsolate(); |
+ DartIsolateScope scope(isolate); |
+ loader->load(scriptInfo); |
} |
DART_RECORD_TIMER("DartController::loadAndRunScript took"); |
@@ -789,56 +788,40 @@ void DartController::evaluate(const ScriptSourceCode& sourceCode, ScriptLoader* |
return; |
} |
- Document* owner = scriptInfo->ownerDocument(); |
- if (m_documentsWithDart.contains(owner)) { |
+ RefPtr<DartApplicationLoader> currentLoader; |
+ |
+ // HTML Import case. |
+ if (m_mainLoader && document != scriptInfo->ownerDocument() && !m_mainLoader->uninitialized()) { |
int line = scriptInfo->startLineNumber().zeroBasedInt(); |
- DartUtilities::reportProblem(owner, "Only one Dart script tag allowed per document", line); |
+ DartUtilities::reportProblem(document, "Inline Darts scripts not supported after main script is invoked.", line); |
return; |
} |
- m_documentsWithDart.add(owner); |
- |
- if (m_loader) { |
- if (m_loader->running()) { |
- // Main has already been invoked. |
- String scriptURL = scriptInfo->sourceAttributeValue(); |
- |
- // Enforce that no new code is loaded. We've already invoked main at this point. |
- // Any referenced code must already be in the isolate. |
- if (scriptURL.isEmpty()) { |
- int line = scriptInfo->startLineNumber().zeroBasedInt(); |
- DartUtilities::reportProblem(document, "Inline Darts scripts not supported after main script is invoked.", line); |
- } else { |
- m_loader->validateUrlLoaded(scriptURL); |
- } |
- return; |
+ if (!m_mainLoader || (!m_mainLoader->uninitialized() && document == scriptInfo->ownerDocument())) { |
+ // FIXME: perhaps if loader->validateUrlLoaded(scriptURL) has been |
+ // called we are actually good to use the existing loader? |
+ currentLoader = DartApplicationLoader::create(document, true); |
+ if (!m_mainLoader) { |
+ m_mainLoader = currentLoader; |
} |
- if (m_loader->error()) { |
- return; |
- } |
- } |
- |
- if (!m_loader) { |
- m_loader = DartApplicationLoader::create(document, true); |
+ } else { |
+ currentLoader = m_mainLoader; |
} |
DART_RECORD_TIMER("evaluate::prep for loading took"); |
if (document == scriptInfo->ownerDocument()) { |
String url = scriptInfo->url(); |
- // FIXME: This should be the first DOM enabled isolate. There is a race condition |
- // however - m_loader above won't catch this if it hasn't been set yet. |
- // This problem goes away once we map each script to a separate isolate. |
- if (!m_isolates.isEmpty()) |
- return; |
DART_RECORD_TIMER("evaluate before createIsolate"); |
DEFINE_STATIC_LOCAL(const char*, packageRoot, (getenv("DART_PACKAGE_ROOT"))); |
Dart_Isolate isolate = createDOMEnabledIsolate(url, "main", packageRoot, document); |
+ m_loaders.add(isolate, currentLoader); |
DART_RECORD_TIMER("evaluate after createIsolate"); |
RefPtr<DartDomLoadCallback> callback = adoptRef(new DartDomLoadCallback(this, url, isolate, document, scriptInfo)); |
Dart_ExitIsolate(); |
- m_loader->processRequests(isolate, sourceCode, callback); |
+ currentLoader->processRequests(isolate, sourceCode, callback); |
DART_RECORD_TIMER("evaluate process request took"); |
} else { |
- m_loader->addRequest(scriptInfo); |
+ // Add all HTML import scripts into the first loader. |
+ m_mainLoader->addRequest(scriptInfo); |
} |
DART_RECORD_TIMER("evaluate took"); |
} |
@@ -930,7 +913,7 @@ DartScriptState* DartController::lookupScriptStateFromLibraryIdMap(Dart_Isolate |
DartScriptState* scriptState; |
if (libraryIter == libraryIdMap->end()) { |
V8ScriptState* v8ScriptState = V8ScriptState::from(v8Context); |
- RefPtr<DartScriptState> scriptStatePtr = DartScriptState::create(isolate, libraryId, v8ScriptState); |
+ RefPtr<DartScriptState> scriptStatePtr = DartScriptState::create(isolate, libraryId, v8ScriptState, isolateName(isolate)); |
libraryIdMap->set(libraryIdKey, scriptStatePtr); |
scriptState = scriptStatePtr.get(); |
} else { |
@@ -940,6 +923,33 @@ DartScriptState* DartController::lookupScriptStateFromLibraryIdMap(Dart_Isolate |
return scriptState; |
} |
+String DartController::isolateName(Dart_Isolate isolate) |
+{ |
+ if (m_isolateNames.contains(isolate)) { |
+ return m_isolateNames.get(isolate); |
+ } |
+ String fileName(""); |
+ String name; |
+ if (m_loaders.contains(isolate)) { |
+ const KURL& scriptUrl = m_loaders.get(isolate)->scriptUrl(); |
+ if (scriptUrl.isValid()) { |
+ String lastPathComponent = scriptUrl.lastPathComponent(); |
+ if (!lastPathComponent.isEmpty()) { |
+ fileName = scriptUrl.lastPathComponent(); |
+ } |
+ } |
+ } |
+ name = fileName; |
+ int i = 2; |
+ while (m_usedNames.contains(name)) { |
+ name = String::format("%s[%d]", fileName.utf8().data(), i); |
+ i++; |
+ } |
+ m_isolateNames.add(isolate, name); |
+ m_usedNames.add(name); |
+ return name; |
+} |
+ |
void DartController::collectScriptStatesForIsolate(Dart_Isolate isolate, v8::Handle<v8::Context> v8Context, Vector<DartScriptState*>& result) |
{ |
if (!isolate) |