| 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 |
| 11 (function (dart_library) { | 11 (function (dart_library) { |
| 12 'use strict'; | 12 'use strict'; |
| 13 | 13 |
| 14 /** Note that we cannot use dart_utils.throwInternalError from here. */ | 14 /** Note that we cannot use dart_utils.throwInternalError from here. */ |
| 15 function throwLibraryError(message) { | 15 function throwLibraryError(message) { |
| 16 throw Error(message); | 16 throw Error(message); |
| 17 } | 17 } |
| 18 | 18 |
| 19 const dartLibraryName = Symbol('dartLibraryName'); | 19 const dartLibraryName = Symbol('dartLibraryName'); |
| 20 dart_library.dartLibraryName = dartLibraryName; | 20 dart_library.dartLibraryName = dartLibraryName; |
| 21 | 21 |
| 22 const libraryImports = Symbol('libraryImports'); |
| 23 dart_library.libraryImports = libraryImports; |
| 24 |
| 22 // Module support. This is a simplified module system for Dart. | 25 // Module support. This is a simplified module system for Dart. |
| 23 // Longer term, we can easily migrate to an existing JS module system: | 26 // Longer term, we can easily migrate to an existing JS module system: |
| 24 // ES6, AMD, RequireJS, .... | 27 // ES6, AMD, RequireJS, .... |
| 25 | 28 |
| 26 class LibraryLoader { | 29 class LibraryLoader { |
| 27 | 30 |
| 28 constructor(name, defaultValue, imports, loader) { | 31 constructor(name, defaultValue, imports, loader) { |
| 29 this._name = name; | 32 this._name = name; |
| 30 this._library = defaultValue ? defaultValue : {}; | 33 this._library = defaultValue ? defaultValue : {}; |
| 31 this._imports = imports; | 34 this._imports = imports; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 58 this._state = LibraryLoader.LOADING; | 61 this._state = LibraryLoader.LOADING; |
| 59 | 62 |
| 60 // Handle imports | 63 // Handle imports |
| 61 let args = this.loadImports(); | 64 let args = this.loadImports(); |
| 62 | 65 |
| 63 // Load the library | 66 // Load the library |
| 64 args.unshift(this._library); | 67 args.unshift(this._library); |
| 65 this._loader.apply(null, args); | 68 this._loader.apply(null, args); |
| 66 this._state = LibraryLoader.READY; | 69 this._state = LibraryLoader.READY; |
| 67 this._library[dartLibraryName] = this._name; | 70 this._library[dartLibraryName] = this._name; |
| 71 this._library[libraryImports] = this._imports; |
| 68 return this._library; | 72 return this._library; |
| 69 } | 73 } |
| 70 | 74 |
| 71 stub() { | 75 stub() { |
| 72 return this._library; | 76 return this._library; |
| 73 } | 77 } |
| 74 } | 78 } |
| 75 LibraryLoader.NOT_LOADED = 0; | 79 LibraryLoader.NOT_LOADED = 0; |
| 76 LibraryLoader.LOADING = 1; | 80 LibraryLoader.LOADING = 1; |
| 77 LibraryLoader.READY = 2; | 81 LibraryLoader.READY = 2; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 window.SourceBufferList = new MediaSource().sourceBuffers.constructor; | 159 window.SourceBufferList = new MediaSource().sourceBuffers.constructor; |
| 156 } | 160 } |
| 157 } | 161 } |
| 158 | 162 |
| 159 // This import is only needed for chrome debugging. We should provide an | 163 // This import is only needed for chrome debugging. We should provide an |
| 160 // option to compile without it. | 164 // option to compile without it. |
| 161 dart_sdk._debugger.registerDevtoolsFormatter(); | 165 dart_sdk._debugger.registerDevtoolsFormatter(); |
| 162 } | 166 } |
| 163 | 167 |
| 164 })(dart_library); | 168 })(dart_library); |
| OLD | NEW |