Chromium Code Reviews| 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 76d615f6fbb893eff708514ede31bea01d1e04a3..88cb33f3dbea1ec6955e3cc54aea5eacfc25d95b 100644 |
| --- a/sdk/lib/_internal/lib/js_helper.dart |
| +++ b/sdk/lib/_internal/lib/js_helper.dart |
| @@ -3223,39 +3223,36 @@ 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)) { |
|
floitsch
2014/04/03 09:05:20
libraries_to_load[#] is also a list. right?
List<
sigurdm
2014/04/03 09:44:51
This works great
|
| - return new Future(() => false); |
| - } |
| - for (int index = 0; |
| - index < JS('int', '\$.libraries_to_load[#].length', loadId); |
| - ++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); |
| + return new Future.value(null); |
| + } |
| + List<List<String>> hunkLists = |
| + new JSArray.markFixed(JS('=Object', '\$.libraries_to_load[#]', loadId)); |
|
floitsch
2014/04/03 09:05:20
Why do you want to mark it as fixed?
sigurdm
2014/04/03 09:44:51
Done.
|
| + |
| + return Future.forEach(hunkLists, (hunkNames) { |
| + Iterable<Future<Null>> allLoads = |
| + hunkNames.map((hunkName) => _loadHunk(hunkName, uri)); |
| + 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) { |
| @@ -3267,7 +3264,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. |
| @@ -3275,14 +3272,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(); |
| }); |
| @@ -3307,7 +3304,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) { |
| @@ -3321,15 +3318,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) { |