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

Side by Side Diff: lib/runtime/dart/_debugger.js

Issue 1879373004: Implement modular compilation (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 4 years, 8 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 | « lib/devc.dart ('k') | lib/runtime/dart/_foreign_helper.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 dart_library.library('dart/_debugger', null, /* Imports */[
2 'dart/_runtime',
3 'dart/core'
4 ], /* Lazy imports */[
5 ], function(exports, dart, core) {
6 'use strict';
7 let dartx = dart.dartx;
8 const skipDartConfig = dart.const(new core.Object());
9 exports.maxIterableChildrenToDisplay = 50;
10 dart.defineLazyProperties(exports, {
11 get _devtoolsFormatter() {
12 return new JsonMLFormatter(new DartFormatter());
13 },
14 set _devtoolsFormatter(_) {}
15 });
16 function _typeof(object) {
17 return typeof object;
18 }
19 dart.fn(_typeof, core.String, [dart.dynamic]);
20 function _instanceof(object, clazz) {
21 return object instanceof clazz;
22 }
23 dart.fn(_instanceof, core.bool, [dart.dynamic, dart.dynamic]);
24 function getOwnPropertyNames(object) {
25 return dart.as(dart.list(Object.getOwnPropertyNames(object), core.String), c ore.List$(core.String));
26 }
27 dart.fn(getOwnPropertyNames, core.List$(core.String), [dart.dynamic]);
28 function getOwnPropertySymbols(object) {
29 return Object.getOwnPropertySymbols(object);
30 }
31 dart.fn(getOwnPropertySymbols, core.List, [dart.dynamic]);
32 class JSNative extends core.Object {
33 static getProperty(object, name) {
34 return object[name];
35 }
36 static setProperty(object, name, value) {
37 return object[name] = value;
38 }
39 }
40 dart.setSignature(JSNative, {
41 statics: () => ({
42 getProperty: [dart.dynamic, [dart.dynamic, dart.dynamic]],
43 setProperty: [dart.dynamic, [dart.dynamic, dart.dynamic, dart.dynamic]]
44 }),
45 names: ['getProperty', 'setProperty']
46 });
47 function isRegularDartObject(object) {
48 if (_typeof(object) == 'function') return false;
49 return _instanceof(object, core.Object);
50 }
51 dart.fn(isRegularDartObject, core.bool, [dart.dynamic]);
52 function getObjectTypeName(object) {
53 let realRuntimeType = dart.realRuntimeType(object);
54 if (realRuntimeType == null) {
55 if (_typeof(object) == 'function') {
56 return '[[Raw JavaScript Function]]';
57 }
58 return '<Error getting type name>';
59 }
60 return getTypeName(dart.as(realRuntimeType, core.Type));
61 }
62 dart.fn(getObjectTypeName, core.String, [dart.dynamic]);
63 function getTypeName(type) {
64 let name = dart.typeName(type);
65 if (dart.equals(name, 'JSArray<dynamic>') || dart.equals(name, 'JSObject<Arr ay>')) return 'List<dynamic>';
66 return dart.as(name, core.String);
67 }
68 dart.fn(getTypeName, core.String, [core.Type]);
69 const _simpleFormatter = Symbol('_simpleFormatter');
70 function safePreview(object) {
71 try {
72 let preview = exports._devtoolsFormatter[_simpleFormatter].preview(object) ;
73 if (preview != null) return preview;
74 return dart.toString(object);
75 } catch (e) {
76 return '<Exception thrown>';
77 }
78
79 }
80 dart.fn(safePreview, core.String, [dart.dynamic]);
81 function symbolName(symbol) {
82 let name = dart.toString(symbol);
83 dart.assert(name[dartx.startsWith]('Symbol('));
84 return name[dartx.substring]('Symbol('[dartx.length], dart.notNull(name[dart x.length]) - 1);
85 }
86 dart.fn(symbolName, core.String, [dart.dynamic]);
87 function hasMethod(object, name) {
88 try {
89 return dart.as(dart.hasMethod(object, name), core.bool);
90 } catch (e) {
91 return false;
92 }
93
94 }
95 dart.fn(hasMethod, core.bool, [dart.dynamic, core.String]);
96 class NameValuePair extends core.Object {
97 NameValuePair(opts) {
98 let name = opts && 'name' in opts ? opts.name : null;
99 let value = opts && 'value' in opts ? opts.value : null;
100 let skipDart = opts && 'skipDart' in opts ? opts.skipDart : null;
101 this.name = name;
102 this.value = value;
103 this.skipDart = skipDart == true;
104 }
105 }
106 dart.setSignature(NameValuePair, {
107 constructors: () => ({NameValuePair: [NameValuePair, [], {name: core.String, value: core.Object, skipDart: core.bool}]})
108 });
109 class MapEntry extends core.Object {
110 MapEntry(opts) {
111 let key = opts && 'key' in opts ? opts.key : null;
112 let value = opts && 'value' in opts ? opts.value : null;
113 this.key = key;
114 this.value = value;
115 }
116 }
117 dart.setSignature(MapEntry, {
118 constructors: () => ({MapEntry: [MapEntry, [], {key: core.String, value: cor e.Object}]})
119 });
120 class ClassMetadata extends core.Object {
121 ClassMetadata(object) {
122 this.object = object;
123 }
124 }
125 dart.setSignature(ClassMetadata, {
126 constructors: () => ({ClassMetadata: [ClassMetadata, [core.Object]]})
127 });
128 class HeritageClause extends core.Object {
129 HeritageClause(name, types) {
130 this.name = name;
131 this.types = types;
132 }
133 }
134 dart.setSignature(HeritageClause, {
135 constructors: () => ({HeritageClause: [HeritageClause, [core.String, core.Li st]]})
136 });
137 const _attributes = Symbol('_attributes');
138 const _jsonML = Symbol('_jsonML');
139 class JsonMLElement extends core.Object {
140 JsonMLElement(tagName) {
141 this[_attributes] = null;
142 this[_jsonML] = null;
143 this[_attributes] = {};
144 this[_jsonML] = [tagName, this[_attributes]];
145 }
146 appendChild(element) {
147 this[_jsonML][dartx.add](dart.dsend(element, 'toJsonML'));
148 }
149 createChild(tagName) {
150 let c = new JsonMLElement(tagName);
151 this[_jsonML][dartx.add](c.toJsonML());
152 return c;
153 }
154 createObjectTag(object) {
155 return (() => {
156 let _ = this.createChild('object');
157 _.addAttribute('object', object);
158 return _;
159 })();
160 }
161 setStyle(style) {
162 dart.dput(this[_attributes], 'style', style);
163 }
164 addStyle(style) {
165 if (dart.dload(this[_attributes], 'style') == null) {
166 dart.dput(this[_attributes], 'style', style);
167 } else {
168 let o = this[_attributes];
169 dart.dput(o, 'style', dart.dsend(dart.dload(o, 'style'), '+', style));
170 }
171 }
172 addAttribute(key, value) {
173 JSNative.setProperty(this[_attributes], key, value);
174 }
175 createTextChild(text) {
176 this[_jsonML][dartx.add](text);
177 }
178 toJsonML() {
179 return this[_jsonML];
180 }
181 }
182 dart.setSignature(JsonMLElement, {
183 constructors: () => ({JsonMLElement: [JsonMLElement, [dart.dynamic]]}),
184 methods: () => ({
185 appendChild: [dart.dynamic, [dart.dynamic]],
186 createChild: [JsonMLElement, [core.String]],
187 createObjectTag: [JsonMLElement, [dart.dynamic]],
188 setStyle: [dart.void, [core.String]],
189 addStyle: [dart.dynamic, [core.String]],
190 addAttribute: [dart.dynamic, [dart.dynamic, dart.dynamic]],
191 createTextChild: [dart.dynamic, [core.String]],
192 toJsonML: [dart.dynamic, []]
193 })
194 });
195 class JsonMLFormatter extends core.Object {
196 JsonMLFormatter(simpleFormatter) {
197 this[_simpleFormatter] = simpleFormatter;
198 }
199 header(object, config) {
200 if (core.identical(config, skipDartConfig)) return null;
201 let c = this[_simpleFormatter].preview(object);
202 if (c == null) return null;
203 let element = new JsonMLElement('span');
204 element.setStyle('background-color: #d9edf7');
205 element.createTextChild(c);
206 return element.toJsonML();
207 }
208 hasBody(object) {
209 return this[_simpleFormatter].hasChildren(object);
210 }
211 body(object) {
212 let body = new JsonMLElement('ol');
213 body.setStyle('list-style-type: none;' + 'padding-left: 0px;' + 'margin-to p: 0px;' + 'margin-bottom: 0px;' + 'margin-left: 12px');
214 let children = this[_simpleFormatter].children(object);
215 for (let child of children) {
216 let li = body.createChild('li');
217 let nameSpan = new JsonMLElement('span');
218 nameSpan.createTextChild(child.name != null ? dart.notNull(child.name) + ': ' : '');
219 nameSpan.setStyle('color: rgb(136, 19, 145);');
220 if (_typeof(child.value) == 'object' || _typeof(child.value) == 'functio n') {
221 nameSpan.addStyle("padding-left: 13px;");
222 li.appendChild(nameSpan);
223 let objectTag = li.createObjectTag(child.value);
224 if (dart.notNull(child.skipDart)) {
225 objectTag.addAttribute('config', skipDartConfig);
226 }
227 if (!dart.notNull(this[_simpleFormatter].hasChildren(child.value))) {
228 li.setStyle("padding-left: 13px;");
229 }
230 } else {
231 li.setStyle("padding-left: 13px;");
232 let _ = li.createChild('span');
233 _.appendChild(nameSpan);
234 _.createTextChild(safePreview(child.value));
235 }
236 }
237 return body.toJsonML();
238 }
239 }
240 dart.setSignature(JsonMLFormatter, {
241 constructors: () => ({JsonMLFormatter: [JsonMLFormatter, [DartFormatter]]}),
242 methods: () => ({
243 header: [dart.dynamic, [dart.dynamic, dart.dynamic]],
244 hasBody: [core.bool, [dart.dynamic]],
245 body: [dart.dynamic, [dart.dynamic]]
246 })
247 });
248 class Formatter extends core.Object {}
249 const _formatters = Symbol('_formatters');
250 class DartFormatter extends core.Object {
251 DartFormatter() {
252 this[_formatters] = null;
253 this[_formatters] = dart.list([new FunctionFormatter(), new MapFormatter() , new IterableFormatter(), new MapEntryFormatter(), new ClassMetadataFormatter() , new HeritageClauseFormatter(), new ObjectFormatter()], Formatter);
254 }
255 preview(object) {
256 if (object == null) return 'null';
257 if (typeof object == 'number') return dart.toString(object);
258 if (typeof object == 'string') return `"${object}"`;
259 for (let formatter of this[_formatters]) {
260 if (dart.notNull(formatter.accept(object))) return formatter.preview(obj ect);
261 }
262 return null;
263 }
264 hasChildren(object) {
265 if (object == null) return false;
266 for (let formatter of this[_formatters]) {
267 if (dart.notNull(formatter.accept(object))) return formatter.hasChildren (object);
268 }
269 return false;
270 }
271 children(object) {
272 if (object != null) {
273 for (let formatter of this[_formatters]) {
274 if (dart.notNull(formatter.accept(object))) return formatter.children( object);
275 }
276 }
277 return dart.list([], NameValuePair);
278 }
279 }
280 dart.setSignature(DartFormatter, {
281 constructors: () => ({DartFormatter: [DartFormatter, []]}),
282 methods: () => ({
283 preview: [core.String, [dart.dynamic]],
284 hasChildren: [core.bool, [dart.dynamic]],
285 children: [core.List$(NameValuePair), [dart.dynamic]]
286 })
287 });
288 const _addMembers = Symbol('_addMembers');
289 class ObjectFormatter extends Formatter {
290 accept(object) {
291 return isRegularDartObject(object);
292 }
293 preview(object) {
294 return getObjectTypeName(object);
295 }
296 hasChildren(object) {
297 return true;
298 }
299 [_addMembers](current, object, properties) {
300 let className = dart.dload(dart.realRuntimeType(current), 'name');
301 for (let name of getOwnPropertyNames(current)) {
302 if (name == 'constructor' || name == '__proto__' || dart.equals(name, cl assName)) continue;
303 if (dart.notNull(hasMethod(object, name))) {
304 continue;
305 }
306 let value = null;
307 try {
308 value = JSNative.getProperty(object, name);
309 } catch (e) {
310 value = '<Exception thrown>';
311 }
312
313 properties[dartx.add](new NameValuePair({name: name, value: value}));
314 }
315 for (let symbol of getOwnPropertySymbols(current)) {
316 let dartName = symbolName(symbol);
317 if (dart.notNull(hasMethod(object, dartName))) {
318 continue;
319 }
320 let value = null;
321 try {
322 value = JSNative.getProperty(object, symbol);
323 } catch (e) {
324 value = '<Exception thrown>';
325 }
326
327 properties[dartx.add](new NameValuePair({name: dartName, value: value})) ;
328 }
329 let base = JSNative.getProperty(current, '__proto__');
330 if (base == null) return;
331 if (dart.notNull(isRegularDartObject(base))) {
332 this[_addMembers](base, object, properties);
333 }
334 }
335 children(object) {
336 let properties = dart.list([], NameValuePair);
337 this.addMetadataChildren(object, properties);
338 this[_addMembers](object, object, properties);
339 return properties;
340 }
341 addMetadataChildren(object, ret) {
342 ret[dartx.add](new NameValuePair({name: '[[class]]', value: new ClassMetad ata(object)}));
343 }
344 }
345 dart.setSignature(ObjectFormatter, {
346 methods: () => ({
347 accept: [core.bool, [dart.dynamic]],
348 preview: [core.String, [dart.dynamic]],
349 hasChildren: [core.bool, [dart.dynamic]],
350 [_addMembers]: [dart.dynamic, [dart.dynamic, dart.dynamic, core.List$(Name ValuePair)]],
351 children: [core.List$(NameValuePair), [dart.dynamic]],
352 addMetadataChildren: [dart.dynamic, [dart.dynamic, core.List$(NameValuePai r)]]
353 })
354 });
355 class FunctionFormatter extends Formatter {
356 accept(object) {
357 if (_typeof(object) != 'function') return false;
358 return dart.realRuntimeType(object) != null;
359 }
360 hasChildren(object) {
361 return true;
362 }
363 preview(object) {
364 return dart.as(dart.typeName(dart.realRuntimeType(object)), core.String);
365 }
366 children(object) {
367 return dart.list([new NameValuePair({name: 'signature', value: this.previe w(object)}), new NameValuePair({name: 'JavaScript Function', value: object, skip Dart: true})], NameValuePair);
368 }
369 }
370 dart.setSignature(FunctionFormatter, {
371 methods: () => ({
372 accept: [core.bool, [dart.dynamic]],
373 hasChildren: [core.bool, [dart.dynamic]],
374 preview: [core.String, [dart.dynamic]],
375 children: [core.List$(NameValuePair), [dart.dynamic]]
376 })
377 });
378 class MapFormatter extends ObjectFormatter {
379 accept(object) {
380 return dart.is(object, core.Map);
381 }
382 hasChildren(object) {
383 return true;
384 }
385 preview(object) {
386 let map = dart.as(object, core.Map);
387 return `${getObjectTypeName(map)} length ${map[dartx.length]}`;
388 }
389 children(object) {
390 let map = dart.as(object, core.Map);
391 let keys = map[dartx.keys][dartx.toList]();
392 let entries = dart.list([], NameValuePair);
393 map[dartx.forEach](dart.fn((key, value) => {
394 let entryWrapper = new MapEntry({key: dart.as(key, core.String), value: value});
395 entries[dartx.add](new NameValuePair({name: dart.toString(entries[dartx. length]), value: entryWrapper}));
396 }, dart.void, [dart.dynamic, dart.dynamic]));
397 this.addMetadataChildren(object, entries);
398 return entries;
399 }
400 }
401 class IterableFormatter extends ObjectFormatter {
402 accept(object) {
403 return dart.is(object, core.Iterable);
404 }
405 preview(object) {
406 let iterable = dart.as(object, core.Iterable);
407 try {
408 let length = iterable[dartx.length];
409 return `${getObjectTypeName(iterable)} length ${length}`;
410 } catch (_) {
411 return `${getObjectTypeName(iterable)}`;
412 }
413
414 }
415 hasChildren(object) {
416 return true;
417 }
418 children(object) {
419 let iterable = dart.as(object, core.Iterable);
420 let ret = dart.list([], NameValuePair);
421 let i = 0;
422 for (let entry of iterable) {
423 if (i > dart.notNull(exports.maxIterableChildrenToDisplay)) {
424 ret[dartx.add](new NameValuePair({name: 'Warning', value: 'Truncated I terable display'}));
425 break;
426 }
427 ret[dartx.add](new NameValuePair({name: dart.toString(i), value: entry}) );
428 i++;
429 }
430 this.addMetadataChildren(object, ret);
431 return ret;
432 }
433 }
434 const _getType = Symbol('_getType');
435 class ClassMetadataFormatter extends core.Object {
436 accept(object) {
437 return dart.is(object, ClassMetadata);
438 }
439 [_getType](object) {
440 if (dart.is(object, core.Type)) return object;
441 return dart.realRuntimeType(object);
442 }
443 preview(object) {
444 let entry = dart.as(object, ClassMetadata);
445 return getTypeName(dart.as(this[_getType](entry.object), core.Type));
446 }
447 hasChildren(object) {
448 return true;
449 }
450 children(object) {
451 let entry = dart.as(object, ClassMetadata);
452 let type = this[_getType](entry.object);
453 let ret = dart.list([], NameValuePair);
454 let implements$ = dart.getImplements(type);
455 if (implements$ != null) {
456 ret[dartx.add](new NameValuePair({name: '[[Implements]]', value: new Her itageClause('implements', dart.as(dart.dcall(implements$), core.List))}));
457 }
458 let mixins = dart.getMixins(type);
459 if (mixins != null) {
460 ret[dartx.add](new NameValuePair({name: '[[Mixins]]', value: new Heritag eClause('mixins', dart.as(dart.dcall(mixins), core.List))}));
461 }
462 ret[dartx.add](new NameValuePair({name: '[[JavaScript View]]', value: entr y.object, skipDart: true}));
463 if (!dart.is(entry.object, core.Type)) {
464 ret[dartx.add](new NameValuePair({name: '[[JavaScript Constructor]]', va lue: JSNative.getProperty(entry.object, 'constructor'), skipDart: true}));
465 }
466 return ret;
467 }
468 }
469 ClassMetadataFormatter[dart.implements] = () => [Formatter];
470 dart.setSignature(ClassMetadataFormatter, {
471 methods: () => ({
472 accept: [core.bool, [dart.dynamic]],
473 [_getType]: [dart.dynamic, [dart.dynamic]],
474 preview: [core.String, [dart.dynamic]],
475 hasChildren: [core.bool, [dart.dynamic]],
476 children: [core.List$(NameValuePair), [dart.dynamic]]
477 })
478 });
479 class MapEntryFormatter extends core.Object {
480 accept(object) {
481 return dart.is(object, MapEntry);
482 }
483 preview(object) {
484 let entry = dart.as(object, MapEntry);
485 return `${safePreview(entry.key)} => ${safePreview(entry.value)}`;
486 }
487 hasChildren(object) {
488 return true;
489 }
490 children(object) {
491 return dart.list([new NameValuePair({name: 'key', value: dart.dload(object , 'key')}), new NameValuePair({name: 'value', value: dart.dload(object, 'value') })], NameValuePair);
492 }
493 }
494 MapEntryFormatter[dart.implements] = () => [Formatter];
495 dart.setSignature(MapEntryFormatter, {
496 methods: () => ({
497 accept: [core.bool, [dart.dynamic]],
498 preview: [core.String, [dart.dynamic]],
499 hasChildren: [core.bool, [dart.dynamic]],
500 children: [core.List$(NameValuePair), [dart.dynamic]]
501 })
502 });
503 class HeritageClauseFormatter extends core.Object {
504 accept(object) {
505 return dart.is(object, HeritageClause);
506 }
507 preview(object) {
508 let clause = dart.as(object, HeritageClause);
509 let typeNames = clause.types[dartx.map](dart.fn(type => getTypeName(dart.a s(type, core.Type)), core.String, [dart.dynamic]));
510 return `${clause.name} ${typeNames[dartx.join](", ")}`;
511 }
512 hasChildren(object) {
513 return true;
514 }
515 children(object) {
516 let clause = dart.as(object, HeritageClause);
517 let ret = dart.list([], NameValuePair);
518 for (let type of clause.types) {
519 ret[dartx.add](new NameValuePair({value: new ClassMetadata(type)}));
520 }
521 return ret;
522 }
523 }
524 HeritageClauseFormatter[dart.implements] = () => [Formatter];
525 dart.setSignature(HeritageClauseFormatter, {
526 methods: () => ({
527 accept: [core.bool, [dart.dynamic]],
528 preview: [core.String, [dart.dynamic]],
529 hasChildren: [core.bool, [dart.dynamic]],
530 children: [core.List$(NameValuePair), [dart.dynamic]]
531 })
532 });
533 function registerDevtoolsFormatter() {
534 let formatters = dart.list([exports._devtoolsFormatter], JsonMLFormatter);
535 dart.global.devtoolsFormatters = formatters;
536 }
537 dart.fn(registerDevtoolsFormatter);
538 // Exports:
539 exports.skipDartConfig = skipDartConfig;
540 exports.getOwnPropertyNames = getOwnPropertyNames;
541 exports.getOwnPropertySymbols = getOwnPropertySymbols;
542 exports.JSNative = JSNative;
543 exports.isRegularDartObject = isRegularDartObject;
544 exports.getObjectTypeName = getObjectTypeName;
545 exports.getTypeName = getTypeName;
546 exports.safePreview = safePreview;
547 exports.symbolName = symbolName;
548 exports.hasMethod = hasMethod;
549 exports.NameValuePair = NameValuePair;
550 exports.MapEntry = MapEntry;
551 exports.ClassMetadata = ClassMetadata;
552 exports.HeritageClause = HeritageClause;
553 exports.JsonMLElement = JsonMLElement;
554 exports.JsonMLFormatter = JsonMLFormatter;
555 exports.Formatter = Formatter;
556 exports.DartFormatter = DartFormatter;
557 exports.ObjectFormatter = ObjectFormatter;
558 exports.FunctionFormatter = FunctionFormatter;
559 exports.MapFormatter = MapFormatter;
560 exports.IterableFormatter = IterableFormatter;
561 exports.ClassMetadataFormatter = ClassMetadataFormatter;
562 exports.MapEntryFormatter = MapEntryFormatter;
563 exports.HeritageClauseFormatter = HeritageClauseFormatter;
564 exports.registerDevtoolsFormatter = registerDevtoolsFormatter;
565 });
OLDNEW
« no previous file with comments | « lib/devc.dart ('k') | lib/runtime/dart/_foreign_helper.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698