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 | 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"); | |
|
bmilligan
2016/07/21 01:59:27
John - Not sure where this Symbol should go.
| |
| 20 | |
| 19 // Module support. This is a simplified module system for Dart. | 21 // Module support. This is a simplified module system for Dart. |
| 20 // Longer term, we can easily migrate to an existing JS module system: | 22 // Longer term, we can easily migrate to an existing JS module system: |
| 21 // ES6, AMD, RequireJS, .... | 23 // ES6, AMD, RequireJS, .... |
| 22 | 24 |
| 23 class LibraryLoader { | 25 class LibraryLoader { |
| 24 constructor(name, defaultValue, imports, loader) { | 26 constructor(name, defaultValue, imports, loader) { |
| 25 this._name = name; | 27 this._name = name; |
| 26 this._library = defaultValue ? defaultValue : {}; | 28 this._library = defaultValue ? defaultValue : {}; |
| 27 this._imports = imports; | 29 this._imports = imports; |
| 28 this._loader = loader; | 30 this._loader = loader; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 53 } | 55 } |
| 54 this._state = LibraryLoader.LOADING; | 56 this._state = LibraryLoader.LOADING; |
| 55 | 57 |
| 56 // Handle imports | 58 // Handle imports |
| 57 let args = this.loadImports(); | 59 let args = this.loadImports(); |
| 58 | 60 |
| 59 // Load the library | 61 // Load the library |
| 60 args.unshift(this._library); | 62 args.unshift(this._library); |
| 61 this._loader.apply(null, args); | 63 this._loader.apply(null, args); |
| 62 this._state = LibraryLoader.READY; | 64 this._state = LibraryLoader.READY; |
| 63 this._library._name = this._name; | 65 this._library[dartLibraryName] = this._name; |
| 64 return this._library; | 66 return this._library; |
| 65 } | 67 } |
| 66 | 68 |
| 67 stub() { | 69 stub() { |
| 68 return this._library; | 70 return this._library; |
| 69 } | 71 } |
| 70 } | 72 } |
| 71 LibraryLoader.NOT_LOADED = 0; | 73 LibraryLoader.NOT_LOADED = 0; |
| 72 LibraryLoader.LOADING = 1; | 74 LibraryLoader.LOADING = 1; |
| 73 LibraryLoader.READY = 2; | 75 LibraryLoader.READY = 2; |
| 74 | 76 |
| 75 // Map from name to LibraryLoader | 77 // Map from name to LibraryLoader |
| 76 let libraries = new Map(); | 78 let libraries = new Map(); |
| 77 dart_library.libraries = function() { return libraries.keys(); }; | 79 dart_library.libraries = function() { return libraries.keys(); }; |
| 80 dart_library.debuggerLibraries = function() { | |
| 81 var debuggerLibraries = []; | |
| 82 libraries.forEach(function (value, key, map) { | |
| 83 debuggerLibraries.push(value.load()); | |
| 84 }); | |
| 85 return debuggerLibraries; | |
| 86 }; | |
| 78 | 87 |
| 79 function library(name, defaultValue, imports, loader) { | 88 function library(name, defaultValue, imports, loader) { |
| 80 let result = new LibraryLoader(name, defaultValue, imports, loader); | 89 let result = new LibraryLoader(name, defaultValue, imports, loader); |
| 81 libraries.set(name, result); | 90 libraries.set(name, result); |
| 82 return result; | 91 return result; |
| 83 } | 92 } |
| 84 dart_library.library = library; | 93 dart_library.library = library; |
| 85 | 94 |
| 86 function import_(libraryName) { | 95 function import_(libraryName) { |
| 87 bootstrap(); | 96 bootstrap(); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 window.SourceBufferList = new MediaSource().sourceBuffers.constructor; | 152 window.SourceBufferList = new MediaSource().sourceBuffers.constructor; |
| 144 } | 153 } |
| 145 } | 154 } |
| 146 | 155 |
| 147 // This import is only needed for chrome debugging. We should provide an | 156 // This import is only needed for chrome debugging. We should provide an |
| 148 // option to compile without it. | 157 // option to compile without it. |
| 149 dart_sdk._debugger.registerDevtoolsFormatter(); | 158 dart_sdk._debugger.registerDevtoolsFormatter(); |
| 150 } | 159 } |
| 151 | 160 |
| 152 })(dart_library); | 161 })(dart_library); |
| OLD | NEW |