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