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 'dart:_js_embedded_names' show | 7 import 'dart:_js_embedded_names' show |
8 ALL_CLASSES, | 8 ALL_CLASSES, |
9 GET_ISOLATE_TAG, | 9 GET_ISOLATE_TAG, |
10 INTERCEPTED_NAMES, | 10 INTERCEPTED_NAMES, |
11 INTERCEPTORS_BY_TAG, | 11 INTERCEPTORS_BY_TAG, |
12 LEAF_TAGS, | 12 LEAF_TAGS, |
13 METADATA, | 13 METADATA, |
14 DEFERRED_LIBRARY_URIS, | 14 DEFERRED_LIBRARY_URIS, |
15 DEFERRED_LIBRARY_HASHES, | 15 DEFERRED_LIBRARY_HASHES, |
16 INITIALIZE_LOADED_HUNK, | 16 INITIALIZE_LOADED_HUNK, |
17 IS_HUNK_LOADED, | 17 IS_HUNK_LOADED, |
| 18 IS_HUNK_INITIALIZED, |
18 NATIVE_SUPERCLASS_TAG_NAME; | 19 NATIVE_SUPERCLASS_TAG_NAME; |
19 | 20 |
20 import 'dart:collection'; | 21 import 'dart:collection'; |
21 import 'dart:_isolate_helper' show | 22 import 'dart:_isolate_helper' show |
22 IsolateNatives, | 23 IsolateNatives, |
23 leaveJsAsync, | 24 leaveJsAsync, |
24 enterJsAsync, | 25 enterJsAsync, |
25 isWorker; | 26 isWorker; |
26 | 27 |
27 import 'dart:async' show Future, DeferredLoadException, Completer; | 28 import 'dart:async' show Future, DeferredLoadException, Completer; |
(...skipping 3278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3306 // For each loadId there is a list of hunk-uris to load, and a corresponding | 3307 // For each loadId there is a list of hunk-uris to load, and a corresponding |
3307 // list of hashes. These are stored in the app-global scope. | 3308 // list of hashes. These are stored in the app-global scope. |
3308 var urisMap = JS_EMBEDDED_GLOBAL('', DEFERRED_LIBRARY_URIS); | 3309 var urisMap = JS_EMBEDDED_GLOBAL('', DEFERRED_LIBRARY_URIS); |
3309 List<String> uris = JS('JSExtendableArray|Null', '#[#]', urisMap, loadId); | 3310 List<String> uris = JS('JSExtendableArray|Null', '#[#]', urisMap, loadId); |
3310 var hashesMap = JS_EMBEDDED_GLOBAL('', DEFERRED_LIBRARY_HASHES); | 3311 var hashesMap = JS_EMBEDDED_GLOBAL('', DEFERRED_LIBRARY_HASHES); |
3311 List<String> hashes = JS('JSExtendableArray|Null', '#[#]', hashesMap, loadId); | 3312 List<String> hashes = JS('JSExtendableArray|Null', '#[#]', hashesMap, loadId); |
3312 if (uris == null) return new Future.value(null); | 3313 if (uris == null) return new Future.value(null); |
3313 // The indices into `uris` and `hashes` that we want to load. | 3314 // The indices into `uris` and `hashes` that we want to load. |
3314 List<int> indices = new List.generate(uris.length, (i) => i); | 3315 List<int> indices = new List.generate(uris.length, (i) => i); |
3315 var isHunkLoaded = JS_EMBEDDED_GLOBAL('', IS_HUNK_LOADED); | 3316 var isHunkLoaded = JS_EMBEDDED_GLOBAL('', IS_HUNK_LOADED); |
| 3317 var isHunkInitialized = JS_EMBEDDED_GLOBAL('', IS_HUNK_INITIALIZED); |
3316 // Filter away indices for hunks that have already been loaded. | 3318 // Filter away indices for hunks that have already been loaded. |
3317 List<int> indicesToLoad = indices | 3319 List<int> indicesToLoad = indices |
3318 .where((int i) => !JS('bool','#(#)', isHunkLoaded, hashes[i])) | 3320 .where((int i) => !JS('bool','#(#)', isHunkLoaded, hashes[i])) |
3319 .toList(); | 3321 .toList(); |
3320 // Load the needed hunks. | 3322 List<int> indicesToInitialize = indices |
| 3323 .where((int i) => !JS('bool','#(#)', isHunkInitialized, hashes[i])) |
| 3324 .toList(); // Load the needed hunks. |
3321 return Future.wait(indicesToLoad | 3325 return Future.wait(indicesToLoad |
3322 .map((int i) => _loadHunk(uris[i]))).then((_) { | 3326 .map((int i) => _loadHunk(uris[i]))).then((_) { |
3323 // Now all hunks have been loaded, we run the needed initializers. | 3327 // Now all hunks have been loaded, we run the needed initializers. |
3324 for (int i in indicesToLoad) { | 3328 for (int i in indicesToInitialize) { |
3325 var initializer = JS_EMBEDDED_GLOBAL('', INITIALIZE_LOADED_HUNK); | 3329 var initializer = JS_EMBEDDED_GLOBAL('', INITIALIZE_LOADED_HUNK); |
3326 JS('void', '#(#)', initializer, hashes[i]); | 3330 JS('void', '#(#)', initializer, hashes[i]); |
3327 } | 3331 } |
3328 bool updated = _loadedLibraries.add(loadId); | 3332 bool updated = _loadedLibraries.add(loadId); |
3329 if (updated && deferredLoadHook != null) { | 3333 if (updated && deferredLoadHook != null) { |
3330 deferredLoadHook(); | 3334 deferredLoadHook(); |
3331 } | 3335 } |
3332 }); | 3336 }); |
3333 } | 3337 } |
3334 | 3338 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3436 throw new MainError("No top-level function named 'main'."); | 3440 throw new MainError("No top-level function named 'main'."); |
3437 } | 3441 } |
3438 | 3442 |
3439 void badMain() { | 3443 void badMain() { |
3440 throw new MainError("'main' is not a function."); | 3444 throw new MainError("'main' is not a function."); |
3441 } | 3445 } |
3442 | 3446 |
3443 void mainHasTooManyParameters() { | 3447 void mainHasTooManyParameters() { |
3444 throw new MainError("'main' expects too many parameters."); | 3448 throw new MainError("'main' expects too many parameters."); |
3445 } | 3449 } |
OLD | NEW |