| OLD | NEW |
| 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 3275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3286 // For each loadId there is a list of hunk-uris to load, and a corresponding | 3286 // For each loadId there is a list of hunk-uris to load, and a corresponding |
| 3287 // list of hashes. These are stored in the app-global scope. | 3287 // list of hashes. These are stored in the app-global scope. |
| 3288 var urisMap = JS_EMBEDDED_GLOBAL('', DEFERRED_LIBRARY_URIS); | 3288 var urisMap = JS_EMBEDDED_GLOBAL('', DEFERRED_LIBRARY_URIS); |
| 3289 List<String> uris = JS('JSExtendableArray|Null', '#[#]', urisMap, loadId); | 3289 List<String> uris = JS('JSExtendableArray|Null', '#[#]', urisMap, loadId); |
| 3290 var hashesMap = JS_EMBEDDED_GLOBAL('', DEFERRED_LIBRARY_HASHES); | 3290 var hashesMap = JS_EMBEDDED_GLOBAL('', DEFERRED_LIBRARY_HASHES); |
| 3291 List<String> hashes = JS('JSExtendableArray|Null', '#[#]', hashesMap, loadId); | 3291 List<String> hashes = JS('JSExtendableArray|Null', '#[#]', hashesMap, loadId); |
| 3292 if (uris == null) return new Future.value(null); | 3292 if (uris == null) return new Future.value(null); |
| 3293 // The indices into `uris` and `hashes` that we want to load. | 3293 // The indices into `uris` and `hashes` that we want to load. |
| 3294 List<int> indices = new List.generate(uris.length, (i) => i); | 3294 List<int> indices = new List.generate(uris.length, (i) => i); |
| 3295 var isHunkLoaded = JS_EMBEDDED_GLOBAL('', IS_HUNK_LOADED); | 3295 var isHunkLoaded = JS_EMBEDDED_GLOBAL('', IS_HUNK_LOADED); |
| 3296 return Future.wait(indices | 3296 // Filter away indices for hunks that have already been loaded. |
| 3297 // Filter away indices for hunks that have already been loaded. | 3297 List<int> indicesToLoad = indices |
| 3298 .where((int i) => !JS('bool','#(#)', isHunkLoaded, hashes[i])) | 3298 .where((int i) => !JS('bool','#(#)', isHunkLoaded, hashes[i])) |
| 3299 // Load the rest. | 3299 .toList(); |
| 3300 // Load the needed hunks. |
| 3301 return Future.wait(indicesToLoad |
| 3300 .map((int i) => _loadHunk(uris[i]))).then((_) { | 3302 .map((int i) => _loadHunk(uris[i]))).then((_) { |
| 3301 // Now all hunks have been loaded, we call all their initializers | 3303 // Now all hunks have been loaded, we run the needed initializers. |
| 3302 for (String hash in hashes) { | 3304 for (int i in indicesToLoad) { |
| 3303 var initializer = JS_EMBEDDED_GLOBAL('', INITIALIZE_LOADED_HUNK); | 3305 var initializer = JS_EMBEDDED_GLOBAL('', INITIALIZE_LOADED_HUNK); |
| 3304 JS('void', '#(#)', initializer, hash); | 3306 JS('void', '#(#)', initializer, hashes[i]); |
| 3305 } | 3307 } |
| 3306 bool updated = _loadedLibraries.add(loadId); | 3308 bool updated = _loadedLibraries.add(loadId); |
| 3307 if (updated && deferredLoadHook != null) { | 3309 if (updated && deferredLoadHook != null) { |
| 3308 deferredLoadHook(); | 3310 deferredLoadHook(); |
| 3309 } | 3311 } |
| 3310 }); | 3312 }); |
| 3311 } | 3313 } |
| 3312 | 3314 |
| 3313 Future<Null> _loadHunk(String hunkName) { | 3315 Future<Null> _loadHunk(String hunkName) { |
| 3314 // TODO(ahe): Validate libraryName. Kasper points out that you want | 3316 // TODO(ahe): Validate libraryName. Kasper points out that you want |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3414 throw new MainError("No top-level function named 'main'."); | 3416 throw new MainError("No top-level function named 'main'."); |
| 3415 } | 3417 } |
| 3416 | 3418 |
| 3417 void badMain() { | 3419 void badMain() { |
| 3418 throw new MainError("'main' is not a function."); | 3420 throw new MainError("'main' is not a function."); |
| 3419 } | 3421 } |
| 3420 | 3422 |
| 3421 void mainHasTooManyParameters() { | 3423 void mainHasTooManyParameters() { |
| 3422 throw new MainError("'main' expects too many parameters."); | 3424 throw new MainError("'main' expects too many parameters."); |
| 3423 } | 3425 } |
| OLD | NEW |