Index: sdk/lib/_internal/lib/js_helper.dart |
diff --git a/sdk/lib/_internal/lib/js_helper.dart b/sdk/lib/_internal/lib/js_helper.dart |
index f56067bbaa904ed4191a2a2207fc02b42ad37340..556f255dc3b1e3e8aaa1074ed85e90f0d488fc08 100644 |
--- a/sdk/lib/_internal/lib/js_helper.dart |
+++ b/sdk/lib/_internal/lib/js_helper.dart |
@@ -3209,39 +3209,47 @@ String getIsolateAffinityTag(String name) { |
return JS('String', 'init.getIsolateTag(#)', name); |
} |
-typedef Future<bool> LoadLibraryFunctionType(); |
+typedef Future<Null> LoadLibraryFunctionType(); |
LoadLibraryFunctionType _loadLibraryWrapper(String loadId) { |
return () => loadDeferredLibrary(loadId); |
} |
-final Map<String, Future<bool>> _loadedLibraries = <String, Future<bool>>{}; |
+final Map<String, Future<Null>> _loadedLibraries = <String, Future<Null>>{}; |
Future<bool> loadDeferredLibrary(String loadId, [String uri]) { |
- List hunkNames = new List(); |
+ |
if (JS('bool', '\$.libraries_to_load[#] === undefined', loadId)) { |
- return new Future(() => false); |
+ return new Future(() => null); |
floitsch
2014/04/02 09:32:48
new Future.value(null);
sigurdm
2014/04/02 11:25:30
Done.
|
} |
+ List<List<String>> hunkLists = new List<List<String>>(); |
+ |
for (int index = 0; |
index < JS('int', '\$.libraries_to_load[#].length', loadId); |
floitsch
2014/04/02 09:32:48
Move the JS outside the loop. This way we can have
sigurdm
2014/04/02 11:25:30
Done.
|
++index) { |
- hunkNames.add(JS('String', '\$.libraries_to_load[#][#]', |
- loadId, index)); |
- } |
- Iterable<Future<bool>> allLoads = |
- hunkNames.map((hunkName) => _loadHunk(hunkName, uri)); |
- return Future.wait(allLoads).then((results) { |
- return results.any((x) => x); |
+ List<String> hunkNames = new List<String>(); |
+ hunkLists.add(hunkNames); |
+ for (int index2 = 0; |
+ index2 < JS('int', '\$.libraries_to_load[#][#].length', loadId, index); |
+ ++index2) { |
+ hunkNames.add(JS('String', '\$.libraries_to_load[#][#][#]', |
+ loadId, index, index2)); |
+ } |
+ } |
+ return Future.forEach(hunkLists, (hunkNames) { |
+ Iterable<Future<Null>> allLoads = |
+ hunkNames.map((hunkName) => _loadHunk(hunkName, uri)); |
floitsch
2014/04/02 09:32:48
indentation.
sigurdm
2014/04/02 11:25:30
Done.
|
+ return Future.wait(allLoads).then((_) => null); |
}); |
} |
-Future<bool> _loadHunk(String hunkName, String uri) { |
+Future<Null> _loadHunk(String hunkName, String uri) { |
// TODO(ahe): Validate libraryName. Kasper points out that you want |
// to be able to experiment with the effect of toggling @DeferLoad, |
// so perhaps we should silently ignore "bad" library names. |
- Future<bool> future = _loadedLibraries[hunkName]; |
+ Future<Null> future = _loadedLibraries[hunkName]; |
if (future != null) { |
- return future.then((_) => false); |
+ return future.then((_) => null); |
} |
if (uri == null) { |
@@ -3253,7 +3261,7 @@ Future<bool> _loadHunk(String hunkName, String uri) { |
if (Primitives.isJsshell || Primitives.isD8) { |
// TODO(ahe): Move this code to a JavaScript command helper script that is |
// not included in generated output. |
- return _loadedLibraries[hunkName] = new Future<bool>(() { |
+ return _loadedLibraries[hunkName] = new Future<Null>(() { |
try { |
// Create a new function to avoid getting access to current function |
// context. |
@@ -3261,14 +3269,14 @@ Future<bool> _loadHunk(String hunkName, String uri) { |
} catch (error, stackTrace) { |
throw new DeferredLoadException("Loading $uri failed."); |
} |
- return true; |
+ return null; |
}); |
} else if (isWorker()) { |
// We are in a web worker. Load the code with an XMLHttpRequest. |
- return _loadedLibraries[hunkName] = new Future<bool>(() { |
- Completer completer = new Completer<bool>(); |
+ return _loadedLibraries[hunkName] = new Future<Null>(() { |
+ Completer completer = new Completer<Null>(); |
enterJsAsync(); |
- Future<bool> leavingFuture = completer.future.whenComplete(() { |
+ Future<Null> leavingFuture = completer.future.whenComplete(() { |
leaveJsAsync(); |
}); |
@@ -3293,7 +3301,7 @@ Future<bool> _loadHunk(String hunkName, String uri) { |
new DeferredLoadException("Evaluating $uri failed.")); |
return; |
} |
- completer.complete(true); |
+ completer.complete(null); |
}, 1)); |
var fail = convertDartClosureToJS((event) { |
@@ -3307,15 +3315,15 @@ Future<bool> _loadHunk(String hunkName, String uri) { |
}); |
} |
// We are in a dom-context. |
- return _loadedLibraries[hunkName] = new Future<bool>(() { |
- Completer completer = new Completer<bool>(); |
+ return _loadedLibraries[hunkName] = new Future<Null>(() { |
+ Completer completer = new Completer<Null>(); |
// Inject a script tag. |
var script = JS('', 'document.createElement("script")'); |
JS('', '#.type = "text/javascript"', script); |
JS('', '#.src = #', script, uri); |
JS('', '#.addEventListener("load", #, false)', |
script, convertDartClosureToJS((event) { |
- completer.complete(true); |
+ completer.complete(null); |
}, 1)); |
JS('', '#.addEventListener("error", #, false)', |
script, convertDartClosureToJS((event) { |