Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(212)

Side by Side Diff: sdk/lib/_internal/compiler/js_lib/js_helper.dart

Issue 562853002: Recompute librariesByName after loading a deferred library. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/js_lib/js_mirrors.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library _js_helper; 5 library _js_helper;
6 6
7 import 'shared/embedded_names.dart' show 7 import 'shared/embedded_names.dart' show
8 ALL_CLASSES, 8 ALL_CLASSES,
9 GET_ISOLATE_TAG, 9 GET_ISOLATE_TAG,
10 INTERCEPTED_NAMES, 10 INTERCEPTED_NAMES,
(...skipping 3239 matching lines...) Expand 10 before | Expand all | Expand 10 after
3250 3250
3251 typedef Future<Null> LoadLibraryFunctionType(); 3251 typedef Future<Null> LoadLibraryFunctionType();
3252 3252
3253 LoadLibraryFunctionType _loadLibraryWrapper(String loadId) { 3253 LoadLibraryFunctionType _loadLibraryWrapper(String loadId) {
3254 return () => loadDeferredLibrary(loadId); 3254 return () => loadDeferredLibrary(loadId);
3255 } 3255 }
3256 3256
3257 final Map<String, Future<Null>> _loadingLibraries = <String, Future<Null>>{}; 3257 final Map<String, Future<Null>> _loadingLibraries = <String, Future<Null>>{};
3258 final Set<String> _loadedLibraries = new Set<String>(); 3258 final Set<String> _loadedLibraries = new Set<String>();
3259 3259
3260 typedef void DeferredLoadCallback();
3261
3262 // Function that will be called every time a new deferred import is loaded.
3263 DeferredLoadCallback deferredLoadHook;
3264
3260 Future<Null> loadDeferredLibrary(String loadId) { 3265 Future<Null> loadDeferredLibrary(String loadId) {
3261 // For each loadId there is a list of hunk-uris to load, and a corresponding 3266 // For each loadId there is a list of hunk-uris to load, and a corresponding
3262 // list of hashes. These are stored in the app-global scope. 3267 // list of hashes. These are stored in the app-global scope.
3263 List<String> uris = JS('JSExtendableArray|Null', 3268 List<String> uris = JS('JSExtendableArray|Null',
3264 'init.deferredLibraryUris[#]', loadId); 3269 'init.deferredLibraryUris[#]', loadId);
3265 List<String> hashes = JS('JSExtendableArray|Null', 3270 List<String> hashes = JS('JSExtendableArray|Null',
3266 'init.deferredLibraryHashes[#]', loadId); 3271 'init.deferredLibraryHashes[#]', loadId);
3267 if (uris == null) return new Future.value(null); 3272 if (uris == null) return new Future.value(null);
3268 // The indices into `uris` and `hashes` that we want to load. 3273 // The indices into `uris` and `hashes` that we want to load.
3269 List<int> indices = new List.generate(uris.length, (i) => i); 3274 List<int> indices = new List.generate(uris.length, (i) => i);
3270 return Future.wait(indices 3275 return Future.wait(indices
3271 // Filter away indices for hunks that have already been loaded. 3276 // Filter away indices for hunks that have already been loaded.
3272 .where((int i) => !JS('bool','init.isHunkLoaded(#)', hashes[i])) 3277 .where((int i) => !JS('bool','init.isHunkLoaded(#)', hashes[i]))
3273 // Load the rest. 3278 // Load the rest.
3274 .map((int i) => _loadHunk(uris[i]))).then((_) { 3279 .map((int i) => _loadHunk(uris[i]))).then((_) {
3275 // Now all hunks have been loaded, we call all their initializers 3280 // Now all hunks have been loaded, we call all their initializers
3276 for (String hash in hashes) { 3281 for (String hash in hashes) {
3277 // TODO(floitsch): Replace unsafe access to embedded global. 3282 // TODO(floitsch): Replace unsafe access to embedded global.
3278 JS('void', 'init.initializeLoadedHunk(#)', hash); 3283 JS('void', 'init.initializeLoadedHunk(#)', hash);
3279 } 3284 }
3280 _loadedLibraries.add(loadId); 3285 bool updated = _loadedLibraries.add(loadId);
3286 if (updated && deferredLoadHook != null) {
3287 deferredLoadHook();
3288 }
3281 }); 3289 });
3282 } 3290 }
3283 3291
3284 Future<Null> _loadHunk(String hunkName) { 3292 Future<Null> _loadHunk(String hunkName) {
3285 // TODO(ahe): Validate libraryName. Kasper points out that you want 3293 // TODO(ahe): Validate libraryName. Kasper points out that you want
3286 // to be able to experiment with the effect of toggling @DeferLoad, 3294 // to be able to experiment with the effect of toggling @DeferLoad,
3287 // so perhaps we should silently ignore "bad" library names. 3295 // so perhaps we should silently ignore "bad" library names.
3288 Future<Null> future = _loadingLibraries[hunkName]; 3296 Future<Null> future = _loadingLibraries[hunkName];
3289 if (future != null) { 3297 if (future != null) {
3290 return future.then((_) => null); 3298 return future.then((_) => null);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
3385 throw new MainError("No top-level function named 'main'."); 3393 throw new MainError("No top-level function named 'main'.");
3386 } 3394 }
3387 3395
3388 void badMain() { 3396 void badMain() {
3389 throw new MainError("'main' is not a function."); 3397 throw new MainError("'main' is not a function.");
3390 } 3398 }
3391 3399
3392 void mainHasTooManyParameters() { 3400 void mainHasTooManyParameters() {
3393 throw new MainError("'main' expects too many parameters."); 3401 throw new MainError("'main' expects too many parameters.");
3394 } 3402 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/js_lib/js_mirrors.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698