Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

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

Issue 2164763005: Library custom formatters (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Revert test files Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | lib/runtime/dart_sdk.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. */ 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');
20 dart_library.dartLibraryName = dartLibraryName;
21
19 // Module support. This is a simplified module system for Dart. 22 // Module support. This is a simplified module system for Dart.
20 // Longer term, we can easily migrate to an existing JS module system: 23 // Longer term, we can easily migrate to an existing JS module system:
21 // ES6, AMD, RequireJS, .... 24 // ES6, AMD, RequireJS, ....
22 25
23 class LibraryLoader { 26 class LibraryLoader {
27
24 constructor(name, defaultValue, imports, loader) { 28 constructor(name, defaultValue, imports, loader) {
25 this._name = name; 29 this._name = name;
26 this._library = defaultValue ? defaultValue : {}; 30 this._library = defaultValue ? defaultValue : {};
27 this._imports = imports; 31 this._imports = imports;
28 this._loader = loader; 32 this._loader = loader;
29 33
30 // Cyclic import detection 34 // Cyclic import detection
31 this._state = LibraryLoader.NOT_LOADED; 35 this._state = LibraryLoader.NOT_LOADED;
32 } 36 }
33 37
(...skipping 19 matching lines...) Expand all
53 } 57 }
54 this._state = LibraryLoader.LOADING; 58 this._state = LibraryLoader.LOADING;
55 59
56 // Handle imports 60 // Handle imports
57 let args = this.loadImports(); 61 let args = this.loadImports();
58 62
59 // Load the library 63 // Load the library
60 args.unshift(this._library); 64 args.unshift(this._library);
61 this._loader.apply(null, args); 65 this._loader.apply(null, args);
62 this._state = LibraryLoader.READY; 66 this._state = LibraryLoader.READY;
63 this._library._name = this._name; 67 this._library[dartLibraryName] = this._name;
64 return this._library; 68 return this._library;
65 } 69 }
66 70
67 stub() { 71 stub() {
68 return this._library; 72 return this._library;
69 } 73 }
70 } 74 }
71 LibraryLoader.NOT_LOADED = 0; 75 LibraryLoader.NOT_LOADED = 0;
72 LibraryLoader.LOADING = 1; 76 LibraryLoader.LOADING = 1;
73 LibraryLoader.READY = 2; 77 LibraryLoader.READY = 2;
74 78
75 // Map from name to LibraryLoader 79 // Map from name to LibraryLoader
76 let libraries = new Map(); 80 let libraries = new Map();
77 dart_library.libraries = function() { return libraries.keys(); }; 81 dart_library.libraries = function() { return libraries.keys(); };
82 dart_library.debuggerLibraries = function() {
83 var debuggerLibraries = [];
84 libraries.forEach(function (value, key, map) {
85 debuggerLibraries.push(value.load());
86 });
87 return debuggerLibraries;
88 };
78 89
79 function library(name, defaultValue, imports, loader) { 90 function library(name, defaultValue, imports, loader) {
80 let result = new LibraryLoader(name, defaultValue, imports, loader); 91 let result = new LibraryLoader(name, defaultValue, imports, loader);
81 libraries.set(name, result); 92 libraries.set(name, result);
82 return result; 93 return result;
83 } 94 }
84 dart_library.library = library; 95 dart_library.library = library;
85 96
86 function import_(libraryName) { 97 function import_(libraryName) {
87 bootstrap(); 98 bootstrap();
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 window.SourceBufferList = new MediaSource().sourceBuffers.constructor; 154 window.SourceBufferList = new MediaSource().sourceBuffers.constructor;
144 } 155 }
145 } 156 }
146 157
147 // This import is only needed for chrome debugging. We should provide an 158 // This import is only needed for chrome debugging. We should provide an
148 // option to compile without it. 159 // option to compile without it.
149 dart_sdk._debugger.registerDevtoolsFormatter(); 160 dart_sdk._debugger.registerDevtoolsFormatter();
150 } 161 }
151 162
152 })(dart_library); 163 })(dart_library);
OLDNEW
« no previous file with comments | « no previous file | lib/runtime/dart_sdk.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698