Chromium Code Reviews

Side by Side Diff: lib/runtime/dart_library.js

Issue 1486473002: Convert dart_utils.js to input_sdk/lib/_internal/utils.dart (#310) (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Rebased Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
« no previous file with comments | « lib/runtime/dart/_utils.js ('k') | lib/runtime/dart_utils.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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. */
15 function throwLibraryError(message) {
16 throw Error(message);
17 }
18
14 // Module support. This is a simplified module system for Dart. 19 // Module support. This is a simplified module system for Dart.
15 // Longer term, we can easily migrate to an existing JS module system: 20 // Longer term, we can easily migrate to an existing JS module system:
16 // ES6, AMD, RequireJS, .... 21 // ES6, AMD, RequireJS, ....
17 22
18 class LibraryLoader { 23 class LibraryLoader {
19 constructor(name, defaultValue, imports, lazyImports, loader) { 24 constructor(name, defaultValue, imports, lazyImports, loader) {
20 this._name = name; 25 this._name = name;
21 this._library = defaultValue ? defaultValue : {}; 26 this._library = defaultValue ? defaultValue : {};
22 this._imports = imports; 27 this._imports = imports;
23 this._lazyImports = lazyImports; 28 this._lazyImports = lazyImports;
(...skipping 17 matching lines...)
41 46
42 loadLazyImports(pendingSet) { 47 loadLazyImports(pendingSet) {
43 return this.handleImports(pendingSet, (lib) => lib.load()); 48 return this.handleImports(pendingSet, (lib) => lib.load());
44 } 49 }
45 50
46 handleImports(list, handler) { 51 handleImports(list, handler) {
47 let results = []; 52 let results = [];
48 for (let name of list) { 53 for (let name of list) {
49 let lib = libraries[name]; 54 let lib = libraries[name];
50 if (!lib) { 55 if (!lib) {
51 dart_utils.throwInternalError('Library not available: ' + name); 56 throwLibraryError('Library not available: ' + name);
52 } 57 }
53 results.push(handler(lib)); 58 results.push(handler(lib));
54 } 59 }
55 return results; 60 return results;
56 } 61 }
57 62
58 load(inheritedPendingSet) { 63 load(inheritedPendingSet) {
59 // Check for cycles 64 // Check for cycles
60 if (this._state == LibraryLoader.LOADING) { 65 if (this._state == LibraryLoader.LOADING) {
61 dart_utils.throwInternalError('Circular dependence on library: ' 66 throwLibraryError('Circular dependence on library: '
62 + this._name); 67 + this._name);
63 } else if (this._state >= LibraryLoader.LOADED) { 68 } else if (this._state >= LibraryLoader.LOADED) {
64 return this._library; 69 return this._library;
65 } 70 }
66 this._state = LibraryLoader.LOADING; 71 this._state = LibraryLoader.LOADING;
67 72
68 // Handle imports and record lazy imports 73 // Handle imports and record lazy imports
69 let pendingSet = inheritedPendingSet ? inheritedPendingSet : new Set(); 74 let pendingSet = inheritedPendingSet ? inheritedPendingSet : new Set();
70 let args = this.loadImports(pendingSet); 75 let args = this.loadImports(pendingSet);
71 args = args.concat(this.deferLazyImports(pendingSet)); 76 args = args.concat(this.deferLazyImports(pendingSet));
(...skipping 28 matching lines...)
100 return libraries[name] = 105 return libraries[name] =
101 new LibraryLoader(name, defaultValue, imports, lazyImports, loader); 106 new LibraryLoader(name, defaultValue, imports, lazyImports, loader);
102 } 107 }
103 dart_library.library = library; 108 dart_library.library = library;
104 109
105 function import_(libraryName) { 110 function import_(libraryName) {
106 bootstrap(); 111 bootstrap();
107 let loader = libraries[libraryName]; 112 let loader = libraries[libraryName];
108 // TODO(vsm): A user might call this directly from JS (as we do in tests). 113 // TODO(vsm): A user might call this directly from JS (as we do in tests).
109 // We may want a different error type. 114 // We may want a different error type.
110 if (!loader) dart_utils.throwInternalError('Library not found: ' + libraryNa me); 115 if (!loader) throwLibraryError('Library not found: ' + libraryName);
111 return loader.load(); 116 return loader.load();
112 } 117 }
113 dart_library.import = import_; 118 dart_library.import = import_;
114 119
115 function start(libraryName) { 120 function start(libraryName) {
116 let library = import_(libraryName); 121 let library = import_(libraryName);
117 let _isolate_helper = import_('dart/_isolate_helper'); 122 let _isolate_helper = import_('dart/_isolate_helper');
118 _isolate_helper.startRootIsolate(library.main, []); 123 _isolate_helper.startRootIsolate(library.main, []);
119 } 124 }
120 dart_library.start = start; 125 dart_library.start = start;
(...skipping 15 matching lines...)
136 // See: https://github.com/dart-lang/dev_compiler/issues/173 141 // See: https://github.com/dart-lang/dev_compiler/issues/173
137 if (typeof NodeList !== "undefined") { 142 if (typeof NodeList !== "undefined") {
138 NodeList.prototype.get = function(i) { return this[i]; }; 143 NodeList.prototype.get = function(i) { return this[i]; };
139 NamedNodeMap.prototype.get = function(i) { return this[i]; }; 144 NamedNodeMap.prototype.get = function(i) { return this[i]; };
140 DOMTokenList.prototype.get = function(i) { return this[i]; }; 145 DOMTokenList.prototype.get = function(i) { return this[i]; };
141 HTMLCollection.prototype.get = function(i) { return this[i]; }; 146 HTMLCollection.prototype.get = function(i) { return this[i]; };
142 } 147 }
143 } 148 }
144 149
145 })(dart_library); 150 })(dart_library);
OLDNEW
« no previous file with comments | « lib/runtime/dart/_utils.js ('k') | lib/runtime/dart_utils.js » ('j') | no next file with comments »

Powered by Google App Engine