| 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 var dart_library; | 7 var dart_library; |
| 8 if (!dart_library) { | 8 if (!dart_library) { |
| 9 dart_library = | 9 dart_library = |
| 10 typeof module != "undefined" && module.exports || {}; | 10 typeof module != "undefined" && module.exports || {}; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 this._imports = imports; | 69 this._imports = imports; |
| 70 this._loader = loader; | 70 this._loader = loader; |
| 71 | 71 |
| 72 // Cyclic import detection | 72 // Cyclic import detection |
| 73 this._state = LibraryLoader.NOT_LOADED; | 73 this._state = LibraryLoader.NOT_LOADED; |
| 74 } | 74 } |
| 75 | 75 |
| 76 loadImports() { | 76 loadImports() { |
| 77 let results = []; | 77 let results = []; |
| 78 for (let name of this._imports) { | 78 for (let name of this._imports) { |
| 79 results.push(import_(name)); | 79 let lib = libraries.get(name); |
| 80 if (!lib) { |
| 81 throwLibraryError('Library not available: ' + name); |
| 82 } |
| 83 results.push(lib.load()); |
| 80 } | 84 } |
| 81 return results; | 85 return results; |
| 82 } | 86 } |
| 83 | 87 |
| 84 load() { | 88 load() { |
| 85 // Check for cycles | 89 // Check for cycles |
| 86 if (this._state == LibraryLoader.LOADING) { | 90 if (this._state == LibraryLoader.LOADING) { |
| 87 throwLibraryError('Circular dependence on library: ' | 91 throwLibraryError('Circular dependence on library: ' |
| 88 + this._name); | 92 + this._name); |
| 89 } else if (this._state >= LibraryLoader.READY) { | 93 } else if (this._state >= LibraryLoader.READY) { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 if (result) { | 163 if (result) { |
| 160 console.log('Re-loading ' + name); | 164 console.log('Re-loading ' + name); |
| 161 _invalidateLibrary(name); | 165 _invalidateLibrary(name); |
| 162 } | 166 } |
| 163 result = new LibraryLoader(name, defaultValue, imports, loader); | 167 result = new LibraryLoader(name, defaultValue, imports, loader); |
| 164 _libraries.set(name, result); | 168 _libraries.set(name, result); |
| 165 return result; | 169 return result; |
| 166 } | 170 } |
| 167 dart_library.library = library; | 171 dart_library.library = library; |
| 168 | 172 |
| 173 <<<<<<< HEAD |
| 174 function import_(libraryName) { |
| 175 let loader = libraries.get(libraryName); |
| 176 // TODO(vsm): A user might call this directly from JS (as we do in tests). |
| 177 // We may want a different error type. |
| 178 if (!loader) throwLibraryError('Library not found: ' + libraryName); |
| 179 return loader.load(); |
| 180 ======= |
| 169 // Maintain a stack of active imports. If a requested library/module is not | 181 // Maintain a stack of active imports. If a requested library/module is not |
| 170 // available, print the stack to show where/how it was requested. | 182 // available, print the stack to show where/how it was requested. |
| 171 let _stack = []; | 183 let _stack = []; |
| 172 function import_(name) { | 184 function import_(name) { |
| 173 let lib = _libraries.get(name); | 185 let lib = _libraries.get(name); |
| 174 if (!lib) { | 186 if (!lib) { |
| 175 let message = 'Module ' + name + ' not loaded in the browser.'; | 187 let message = 'Module ' + name + ' not loaded in the browser.'; |
| 176 if (_stack != []) { | 188 if (_stack != []) { |
| 177 message += '\nDependency via:'; | 189 message += '\nDependency via:'; |
| 178 let indent = ''; | 190 let indent = ''; |
| 179 for (let last = _stack.length - 1; last >= 0; last--) { | 191 for (let last = _stack.length - 1; last >= 0; last--) { |
| 180 indent += ' '; | 192 indent += ' '; |
| 181 message += '\n' + indent + '- ' + _stack[last]; | 193 message += '\n' + indent + '- ' + _stack[last]; |
| 182 } | 194 } |
| 183 } | 195 } |
| 184 throwLibraryError(message); | 196 throwLibraryError(message); |
| 185 } | 197 } |
| 186 _stack.push(name); | 198 _stack.push(name); |
| 187 let result = lib.load(); | 199 let result = lib.load(); |
| 188 _stack.pop(); | 200 _stack.pop(); |
| 189 return result; | 201 return result; |
| 202 >>>>>>> origin/master |
| 190 } | 203 } |
| 191 dart_library.import = import_; | 204 dart_library.import = import_; |
| 192 | 205 |
| 193 var _currentIsolate = false; | 206 var _currentIsolate = false; |
| 194 | 207 |
| 195 function _restart() { | 208 function _restart() { |
| 196 start(_lastModuleName, _lastLibraryName, true); | 209 start(_lastModuleName, _lastLibraryName, true); |
| 197 } | 210 } |
| 198 | 211 |
| 199 function reload() { | 212 function reload() { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 } else { | 262 } else { |
| 250 // If not a reload then store the initial html to reset it on reload. | 263 // If not a reload then store the initial html to reset it on reload. |
| 251 _originalBody = document.body.cloneNode(true); | 264 _originalBody = document.body.cloneNode(true); |
| 252 } | 265 } |
| 253 library.main(); | 266 library.main(); |
| 254 } | 267 } |
| 255 dart_library.start = start; | 268 dart_library.start = start; |
| 256 | 269 |
| 257 })(dart_library); | 270 })(dart_library); |
| 258 } | 271 } |
| OLD | NEW |