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 var dart_library; |
| 8 var dart_library = | 8 if (!dart_library) { |
| 9 dart_library = | |
| 9 typeof module != "undefined" && module.exports || {}; | 10 typeof module != "undefined" && module.exports || {}; |
| 10 | 11 |
| 11 (function (dart_library) { | 12 (function (dart_library) { |
| 12 'use strict'; | 13 'use strict'; |
| 13 | 14 |
| 14 /** Note that we cannot use dart_utils.throwInternalError from here. */ | 15 /** Note that we cannot use dart_utils.throwInternalError from here. */ |
| 15 function throwLibraryError(message) { | 16 function throwLibraryError(message) { |
| 16 throw Error(message); | 17 throw Error(message); |
| 17 } | 18 } |
| 18 | 19 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 dart_library.debuggerLibraries = function() { | 87 dart_library.debuggerLibraries = function() { |
| 87 var debuggerLibraries = []; | 88 var debuggerLibraries = []; |
| 88 libraries.forEach(function (value, key, map) { | 89 libraries.forEach(function (value, key, map) { |
| 89 debuggerLibraries.push(value.load()); | 90 debuggerLibraries.push(value.load()); |
| 90 }); | 91 }); |
| 91 debuggerLibraries.__proto__ = null; | 92 debuggerLibraries.__proto__ = null; |
| 92 return debuggerLibraries; | 93 return debuggerLibraries; |
| 93 }; | 94 }; |
| 94 | 95 |
| 95 function library(name, defaultValue, imports, loader) { | 96 function library(name, defaultValue, imports, loader) { |
| 96 let result = new LibraryLoader(name, defaultValue, imports, loader); | 97 let result = libraries.get(name); |
| 98 if (result) { | |
| 99 console.warn('Already loaded ' + name); | |
| 100 return result; | |
| 101 } | |
| 102 result = new LibraryLoader(name, defaultValue, imports, loader); | |
| 97 libraries.set(name, result); | 103 libraries.set(name, result); |
| 98 return result; | 104 return result; |
| 99 } | 105 } |
| 100 dart_library.library = library; | 106 dart_library.library = library; |
| 101 | 107 |
| 102 function import_(libraryName) { | 108 function import_(libraryName) { |
| 103 bootstrap(); | 109 bootstrap(); |
| 104 let loader = libraries.get(libraryName); | 110 let loader = libraries.get(libraryName); |
| 105 // TODO(vsm): A user might call this directly from JS (as we do in tests). | 111 // TODO(vsm): A user might call this directly from JS (as we do in tests). |
| 106 // We may want a different error type. | 112 // We may want a different error type. |
| 107 if (!loader) throwLibraryError('Library not found: ' + libraryName); | 113 if (!loader) throwLibraryError('Library not found: ' + libraryName); |
| 108 return loader.load(); | 114 return loader.load(); |
| 109 } | 115 } |
| 110 dart_library.import = import_; | 116 dart_library.import = import_; |
| 111 | 117 |
| 118 var _currentIsolate = false; | |
| 119 | |
| 112 function start(moduleName, libraryName) { | 120 function start(moduleName, libraryName) { |
| 113 if (libraryName == null) libraryName = moduleName; | 121 if (libraryName == null) libraryName = moduleName; |
| 114 let library = import_(moduleName)[libraryName]; | 122 let library = import_(moduleName)[libraryName]; |
| 115 let dart_sdk = import_('dart_sdk'); | 123 let dart_sdk = import_('dart_sdk'); |
| 116 dart_sdk._isolate_helper.startRootIsolate(library.main, []); | 124 if (!_currentIsolate) { |
| 125 // Create isolate and run main | |
| 126 _currentIsolate = true; | |
| 127 dart_sdk._isolate_helper.startRootIsolate(library.main, []); | |
| 128 } else { | |
|
Jacob
2017/01/13 00:48:17
missing periods at the end of comments.
vsm
2017/01/13 16:02:20
Done.
| |
| 129 // Main isolate is already initialized - just run main | |
| 130 library.main(); | |
| 131 } | |
| 117 } | 132 } |
| 118 dart_library.start = start; | 133 dart_library.start = start; |
| 119 | 134 |
| 120 let _bootstrapped = false; | 135 let _bootstrapped = false; |
| 121 function bootstrap() { | 136 function bootstrap() { |
| 122 if (_bootstrapped) return; | 137 if (_bootstrapped) return; |
| 123 _bootstrapped = true; | 138 _bootstrapped = true; |
| 124 | 139 |
| 125 // Force import of core. | 140 // Force import of core. |
| 126 var dart_sdk = import_('dart_sdk'); | 141 var dart_sdk = import_('dart_sdk'); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 window.SourceBufferList = new MediaSource().sourceBuffers.constructor; | 187 window.SourceBufferList = new MediaSource().sourceBuffers.constructor; |
| 173 } | 188 } |
| 174 } | 189 } |
| 175 | 190 |
| 176 // This import is only needed for chrome debugging. We should provide an | 191 // This import is only needed for chrome debugging. We should provide an |
| 177 // option to compile without it. | 192 // option to compile without it. |
| 178 dart_sdk._debugger.registerDevtoolsFormatter(); | 193 dart_sdk._debugger.registerDevtoolsFormatter(); |
| 179 } | 194 } |
| 180 | 195 |
| 181 })(dart_library); | 196 })(dart_library); |
| 197 } | |
| OLD | NEW |