Chromium Code Reviews| 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 |
| 23 // We need to load this symbol from the dart-sdk once it is loaded. | |
| 24 let dartLibraryName = null; | |
| 25 | |
| 26 // Module support. This is a simplified module system for Dart. | 26 // Module support. This is a simplified module system for Dart. |
| 27 // Longer term, we can easily migrate to an existing JS module system: | 27 // Longer term, we can easily migrate to an existing JS module system: |
| 28 // ES6, AMD, RequireJS, .... | 28 // ES6, AMD, RequireJS, .... |
| 29 | 29 |
| 30 // Returns a proxy that delegates to the underlying loader. | 30 // Returns a proxy that delegates to the underlying loader. |
| 31 // This defers loading of a module until a library is actually used. | 31 // This defers loading of a module until a library is actually used. |
| 32 const loadedModule = Symbol('loadedModule'); | 32 const loadedModule = Symbol('loadedModule'); |
| 33 dart_library.defer = function(module, name, patch) { | 33 dart_library.defer = function(module, name, patch) { |
| 34 let done = false; | 34 let done = false; |
| 35 function loadDeferred() { | 35 function loadDeferred() { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 return this._library; | 88 return this._library; |
| 89 } | 89 } |
| 90 this._state = LibraryLoader.LOADING; | 90 this._state = LibraryLoader.LOADING; |
| 91 | 91 |
| 92 // Handle imports | 92 // Handle imports |
| 93 let args = this.loadImports(); | 93 let args = this.loadImports(); |
| 94 | 94 |
| 95 // Load the library | 95 // Load the library |
| 96 let loader = this; | 96 let loader = this; |
| 97 let library = this._library; | 97 let library = this._library; |
| 98 library[dartLibraryName] = this._name; | 98 if (dartLibraryName !== null) { |
| 99 this._library[dartLibraryName] = this._name; | |
|
vsm
2017/02/21 14:33:00
Can this be moved to code_generator.dart - _emitMo
| |
| 100 } | |
| 101 | |
| 99 library[libraryImports] = this._imports; | 102 library[libraryImports] = this._imports; |
| 100 library[loadedModule] = library; | 103 library[loadedModule] = library; |
| 101 args.unshift(library); | 104 args.unshift(library); |
| 102 | 105 |
| 103 if (this._name == 'dart_sdk') { | 106 if (this._name == 'dart_sdk') { |
| 104 // Eagerly load the SDK. | 107 // Eagerly load the SDK. |
| 105 this._loader.apply(null, args); | 108 this._loader.apply(null, args); |
| 106 loader._loader = null; | 109 loader._loader = null; |
| 107 } else { | 110 } else { |
| 108 // Load / parse other modules on demand. | 111 // Load / parse other modules on demand. |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 } | 185 } |
| 183 dart_library.start = start; | 186 dart_library.start = start; |
| 184 | 187 |
| 185 let _bootstrapped = false; | 188 let _bootstrapped = false; |
| 186 function bootstrap() { | 189 function bootstrap() { |
| 187 if (_bootstrapped) return; | 190 if (_bootstrapped) return; |
| 188 _bootstrapped = true; | 191 _bootstrapped = true; |
| 189 | 192 |
| 190 // Force import of core. | 193 // Force import of core. |
| 191 var dart_sdk = import_('dart_sdk'); | 194 var dart_sdk = import_('dart_sdk'); |
| 195 dartLibraryName = dart_sdk.dart.dartLibraryName; | |
| 192 | 196 |
| 193 // This import is only needed for chrome debugging. We should provide an | 197 // This import is only needed for chrome debugging. We should provide an |
| 194 // option to compile without it. | 198 // option to compile without it. |
| 195 dart_sdk._debugger.registerDevtoolsFormatter(); | 199 dart_sdk._debugger.registerDevtoolsFormatter(); |
| 196 } | 200 } |
| 197 | 201 |
| 198 })(dart_library); | 202 })(dart_library); |
| 199 } | 203 } |
| OLD | NEW |