| 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 || {}; |
| 11 | 11 |
| 12 (function (dart_library) { | 12 (function (dart_library) { |
| 13 'use strict'; | 13 'use strict'; |
| 14 | 14 |
| 15 /** Note that we cannot use dart_utils.throwInternalError from here. */ | 15 /** Note that we cannot use dart_utils.throwInternalError from here. */ |
| 16 function throwLibraryError(message) { | 16 function throwLibraryError(message) { |
| 17 throw Error(message); | 17 throw Error(message); |
| 18 } | 18 } |
| 19 | 19 |
| 20 const dartLibraryName = Symbol('dartLibraryName'); | |
| 21 dart_library.dartLibraryName = dartLibraryName; | |
| 22 | |
| 23 const libraryImports = Symbol('libraryImports'); | 20 const libraryImports = Symbol('libraryImports'); |
| 24 dart_library.libraryImports = libraryImports; | 21 dart_library.libraryImports = libraryImports; |
| 25 | 22 |
| 26 // Module support. This is a simplified module system for Dart. | 23 // Module support. This is a simplified module system for Dart. |
| 27 // Longer term, we can easily migrate to an existing JS module system: | 24 // Longer term, we can easily migrate to an existing JS module system: |
| 28 // ES6, AMD, RequireJS, .... | 25 // ES6, AMD, RequireJS, .... |
| 29 | 26 |
| 30 // Returns a proxy that delegates to the underlying loader. | 27 // Returns a proxy that delegates to the underlying loader. |
| 31 // This defers loading of a module until a library is actually used. | 28 // This defers loading of a module until a library is actually used. |
| 32 const loadedModule = Symbol('loadedModule'); | 29 const loadedModule = Symbol('loadedModule'); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 return this._library; | 85 return this._library; |
| 89 } | 86 } |
| 90 this._state = LibraryLoader.LOADING; | 87 this._state = LibraryLoader.LOADING; |
| 91 | 88 |
| 92 // Handle imports | 89 // Handle imports |
| 93 let args = this.loadImports(); | 90 let args = this.loadImports(); |
| 94 | 91 |
| 95 // Load the library | 92 // Load the library |
| 96 let loader = this; | 93 let loader = this; |
| 97 let library = this._library; | 94 let library = this._library; |
| 98 library[dartLibraryName] = this._name; | 95 |
| 99 library[libraryImports] = this._imports; | 96 library[libraryImports] = this._imports; |
| 100 library[loadedModule] = library; | 97 library[loadedModule] = library; |
| 101 args.unshift(library); | 98 args.unshift(library); |
| 102 | 99 |
| 103 if (this._name == 'dart_sdk') { | 100 if (this._name == 'dart_sdk') { |
| 104 // Eagerly load the SDK. | 101 // Eagerly load the SDK. |
| 105 this._loader.apply(null, args); | 102 this._loader.apply(null, args); |
| 106 loader._loader = null; | 103 loader._loader = null; |
| 107 } else { | 104 } else { |
| 108 // Load / parse other modules on demand. | 105 // Load / parse other modules on demand. |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 | 177 |
| 181 library.main(); | 178 library.main(); |
| 182 } | 179 } |
| 183 dart_library.start = start; | 180 dart_library.start = start; |
| 184 | 181 |
| 185 let _bootstrapped = false; | 182 let _bootstrapped = false; |
| 186 function bootstrap() { | 183 function bootstrap() { |
| 187 if (_bootstrapped) return; | 184 if (_bootstrapped) return; |
| 188 _bootstrapped = true; | 185 _bootstrapped = true; |
| 189 | 186 |
| 190 // Force import of core. | |
| 191 var dart_sdk = import_('dart_sdk'); | |
| 192 | |
| 193 // This import is only needed for chrome debugging. We should provide an | 187 // This import is only needed for chrome debugging. We should provide an |
| 194 // option to compile without it. | 188 // option to compile without it. |
| 195 dart_sdk._debugger.registerDevtoolsFormatter(); | 189 dart_sdk._debugger.registerDevtoolsFormatter(); |
| 196 } | 190 } |
| 197 | 191 |
| 198 })(dart_library); | 192 })(dart_library); |
| 199 } | 193 } |
| OLD | NEW |