| 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..e4d440be01a34d94dc2ccec95ad29ed9ad278ca9 100644
|
| --- a/sdk/lib/_internal/lib/js_helper.dart
|
| +++ b/sdk/lib/_internal/lib/js_helper.dart
|
| @@ -3223,39 +3223,34 @@ 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);
|
| - }
|
| - 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);
|
| +
|
| + List<List<String>> hunkLists = JS('JSExtendableArray|Null',
|
| + '\$.libraries_to_load[#]', loadId);
|
| + if (hunkLists == null) return new Future.value(null);
|
| +
|
| + 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 +3262,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 +3270,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 +3302,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 +3316,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) {
|
|
|