OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 /* This file defines the module loader for the dart runtime. | 5 /* This file defines the module loader for the dart runtime. |
6 */ | 6 */ |
7 | 7 |
8 var dart_library = | 8 var dart_library = |
9 typeof module != "undefined" && module.exports || {}; | 9 typeof module != "undefined" && module.exports || {}; |
10 | 10 |
(...skipping 30 matching lines...) Expand all Loading... |
41 | 41 |
42 loadLazyImports(pendingSet) { | 42 loadLazyImports(pendingSet) { |
43 return this.handleImports(pendingSet, (lib) => lib.load()); | 43 return this.handleImports(pendingSet, (lib) => lib.load()); |
44 } | 44 } |
45 | 45 |
46 handleImports(list, handler) { | 46 handleImports(list, handler) { |
47 let results = []; | 47 let results = []; |
48 for (let name of list) { | 48 for (let name of list) { |
49 let lib = libraries[name]; | 49 let lib = libraries[name]; |
50 if (!lib) { | 50 if (!lib) { |
51 dart_utils.throwError('Library not available: ' + name); | 51 dart_utils.throwInternalError('Library not available: ' + name); |
52 } | 52 } |
53 results.push(handler(lib)); | 53 results.push(handler(lib)); |
54 } | 54 } |
55 return results; | 55 return results; |
56 } | 56 } |
57 | 57 |
58 load(inheritedPendingSet) { | 58 load(inheritedPendingSet) { |
59 // Check for cycles | 59 // Check for cycles |
60 if (this._state == LibraryLoader.LOADING) { | 60 if (this._state == LibraryLoader.LOADING) { |
61 dart_utils.throwError('Circular dependence on library: ' | 61 dart_utils.throwInternalError('Circular dependence on library: ' |
62 + this._name); | 62 + this._name); |
63 } else if (this._state >= LibraryLoader.LOADED) { | 63 } else if (this._state >= LibraryLoader.LOADED) { |
64 return this._library; | 64 return this._library; |
65 } | 65 } |
66 this._state = LibraryLoader.LOADING; | 66 this._state = LibraryLoader.LOADING; |
67 | 67 |
68 // Handle imports and record lazy imports | 68 // Handle imports and record lazy imports |
69 let pendingSet = inheritedPendingSet ? inheritedPendingSet : new Set(); | 69 let pendingSet = inheritedPendingSet ? inheritedPendingSet : new Set(); |
70 let args = this.loadImports(pendingSet); | 70 let args = this.loadImports(pendingSet); |
71 args = args.concat(this.deferLazyImports(pendingSet)); | 71 args = args.concat(this.deferLazyImports(pendingSet)); |
(...skipping 26 matching lines...) Expand all Loading... |
98 | 98 |
99 function library(name, defaultValue, imports, lazyImports, loader) { | 99 function library(name, defaultValue, imports, lazyImports, loader) { |
100 return libraries[name] = | 100 return libraries[name] = |
101 new LibraryLoader(name, defaultValue, imports, lazyImports, loader); | 101 new LibraryLoader(name, defaultValue, imports, lazyImports, loader); |
102 } | 102 } |
103 dart_library.library = library; | 103 dart_library.library = library; |
104 | 104 |
105 function import_(libraryName) { | 105 function import_(libraryName) { |
106 bootstrap(); | 106 bootstrap(); |
107 let loader = libraries[libraryName]; | 107 let loader = libraries[libraryName]; |
108 if (!loader) dart_utils.throwError('Library not found: ' + libraryName); | 108 // TODO(vsm): A user might call this directly from JS (as we do in tests). |
| 109 // We may want a different error type. |
| 110 if (!loader) dart_utils.throwInternalError('Library not found: ' + libraryNa
me); |
109 return loader.load(); | 111 return loader.load(); |
110 } | 112 } |
111 dart_library.import = import_; | 113 dart_library.import = import_; |
112 | 114 |
113 function start(libraryName) { | 115 function start(libraryName) { |
114 let library = import_(libraryName); | 116 let library = import_(libraryName); |
115 let _isolate_helper = import_('dart/_isolate_helper'); | 117 let _isolate_helper = import_('dart/_isolate_helper'); |
116 _isolate_helper.startRootIsolate(library.main, []); | 118 _isolate_helper.startRootIsolate(library.main, []); |
117 } | 119 } |
118 dart_library.start = start; | 120 dart_library.start = start; |
(...skipping 15 matching lines...) Expand all Loading... |
134 // See: https://github.com/dart-lang/dev_compiler/issues/173 | 136 // See: https://github.com/dart-lang/dev_compiler/issues/173 |
135 if (typeof NodeList !== "undefined") { | 137 if (typeof NodeList !== "undefined") { |
136 NodeList.prototype.get = function(i) { return this[i]; }; | 138 NodeList.prototype.get = function(i) { return this[i]; }; |
137 NamedNodeMap.prototype.get = function(i) { return this[i]; }; | 139 NamedNodeMap.prototype.get = function(i) { return this[i]; }; |
138 DOMTokenList.prototype.get = function(i) { return this[i]; }; | 140 DOMTokenList.prototype.get = function(i) { return this[i]; }; |
139 HTMLCollection.prototype.get = function(i) { return this[i]; }; | 141 HTMLCollection.prototype.get = function(i) { return this[i]; }; |
140 } | 142 } |
141 } | 143 } |
142 | 144 |
143 })(dart_library); | 145 })(dart_library); |
OLD | NEW |