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

Side by Side Diff: tool/input_sdk/private/debugger.dart

Issue 2176233002: Library children object fix (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Generic iteration loop Created 4 years, 4 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/runtime/dart_sdk.js ('k') | tool/sdk_expected_errors.txt » ('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 library dart._debugger; 5 library dart._debugger;
6 6
7 import 'dart:_foreign_helper' show JS; 7 import 'dart:_foreign_helper' show JS;
8 import 'dart:_runtime' as dart; 8 import 'dart:_runtime' as dart;
9 import 'dart:core'; 9 import 'dart:core';
10 import 'dart:collection'; 10 import 'dart:collection';
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 } 202 }
203 203
204 Object safeGetProperty(Object protoChain, String name) { 204 Object safeGetProperty(Object protoChain, String name) {
205 try { 205 try {
206 return JSNative.getProperty(protoChain, name); 206 return JSNative.getProperty(protoChain, name);
207 } catch (e) { 207 } catch (e) {
208 return '<Exception thrown> $e'; 208 return '<Exception thrown> $e';
209 } 209 }
210 } 210 }
211 211
212 safeProperties(object) => new Map.fromIterable(
213 getOwnPropertyNames(object)
214 .where((each) => safeGetProperty(object, each) != null),
215 key: (name) => name,
216 value: (name) => safeGetProperty(object, name));
217
212 /// Class to simplify building the JsonML objects expected by the 218 /// Class to simplify building the JsonML objects expected by the
213 /// Devtools Formatter API. 219 /// Devtools Formatter API.
214 class JsonMLElement { 220 class JsonMLElement {
215 dynamic _attributes; 221 dynamic _attributes;
216 List _jsonML; 222 List _jsonML;
217 223
218 JsonMLElement(tagName) { 224 JsonMLElement(tagName) {
219 _attributes = JS('', '{}'); 225 _attributes = JS('', '{}');
220 _jsonML = [tagName, _attributes]; 226 _jsonML = [tagName, _attributes];
221 } 227 }
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 name = '${name.replaceAll("__", "/")}.dart'; 539 name = '${name.replaceAll("__", "/")}.dart';
534 children.add(new NameValuePair( 540 children.add(new NameValuePair(
535 name: name, value: new Library(name, value), hideName: true)); 541 name: name, value: new Library(name, value), hideName: true));
536 } 542 }
537 return children.toList(); 543 return children.toList();
538 } 544 }
539 } 545 }
540 546
541 /// Formatter for Dart Library objects. 547 /// Formatter for Dart Library objects.
542 class LibraryFormatter extends ObjectFormatter { 548 class LibraryFormatter extends ObjectFormatter {
543 String genericName; 549 var genericParameters = new HashMap<String, String>();
544 String genericArguments;
545 550
546 accept(object) => object is Library; 551 accept(object) => object is Library;
547 552
548 bool hasChildren(object) => true; 553 bool hasChildren(object) => true;
549 554
550 String preview(object) => object.name; 555 String preview(object) => object.name;
551 556
552 List<NameValuePair> children(object) { 557 List<NameValuePair> children(object) {
553 var children = new LinkedHashSet<NameValuePair>(); 558 var children = new LinkedHashSet<NameValuePair>();
554 var entry = object.object; 559 var nonGenericProperties = new LinkedHashMap<String, Object>();
555 for (var name in getOwnPropertyNames(entry)) { 560 var objectProperties = safeProperties(object.object);
556 var value = safeGetProperty(entry, name); 561 objectProperties.forEach((name, value) {
557 if (value != null) { 562 var genericTypeConstructor = dart.getGenericTypeCtor(value);
558 var genericTypeConstructor = dart.getGenericTypeCtor(value); 563 if (genericTypeConstructor != null) {
559 if (genericTypeConstructor != null) { 564 recordGenericParameters(name, genericTypeConstructor);
560 genericName = name; 565 } else {
561 // Using JS toString() eliminates the leading metadata that is generat ed 566 nonGenericProperties[name] = value;
562 // with the toString function provided in operations.dart.
563 // Splitting by => and taking the first element gives the list of
564 // arguments in the constructor.
565 genericArguments =
566 JS('String', '#.toString()', genericTypeConstructor)
567 .split(' =>')
568 .first
569 .replaceAll(new RegExp(r'[(|)]'), '');
570 } else if (value is Type) {
571 var typeName = getTypeName(value);
572 // Generic class names are generated with a $ at the end, so the
573 // corresponding non-generic class can be identified by adding $.
574 if ('$name\$' == genericName) {
575 typeName = '$typeName<$genericArguments>';
576 }
577 children.add(new NameValuePair(
578 name: typeName, value: new ClassMetadata(value, name: typeName)));
579 } else {
580 children.add(
581 new NameValuePair(name: name, value: new ClassMetadata(value)));
582 }
583 } 567 }
568 });
569 nonGenericProperties.forEach((name, value) {
570 if (value is Type) {
571 children.add(classChild(name, value));
572 } else {
573 children.add(new NameValuePair(name: name, value: value));
574 }
575 });
576 return children.toList();
577 }
578
579 recordGenericParameters(String name, Object genericTypeConstructor) {
580 // Using JS toString() eliminates the leading metadata that is generated
581 // with the toString function provided in operations.dart.
582 // Splitting by => and taking the first element gives the list of
583 // arguments in the constructor.
584 genericParameters[name] =
585 JS('String', '#.toString()', genericTypeConstructor)
586 .split(' =>')
587 .first
588 .replaceAll(new RegExp(r'[(|)]'), '');
589 }
590
591 classChild(String name, Object child) {
592 var typeName = getTypeName(child);
593 // Generic class names are generated with a $ at the end, so the
594 // corresponding non-generic class can be identified by adding $.
595 var parameterName = '$name\$';
596 if (genericParameters.keys.contains(parameterName)) {
597 typeName = '$typeName<${genericParameters[parameterName]}>';
584 } 598 }
585 return children.toList(); 599 return new NameValuePair(
600 name: typeName, value: new ClassMetadata(child, name: typeName));
586 } 601 }
587 } 602 }
588 603
589 /// Formatter for Dart Function objects. 604 /// Formatter for Dart Function objects.
590 /// Dart functions happen to be regular JavaScript Function objects but 605 /// Dart functions happen to be regular JavaScript Function objects but
591 /// we can distinguish them based on whether they have been tagged with 606 /// we can distinguish them based on whether they have been tagged with
592 /// runtime type information. 607 /// runtime type information.
593 class FunctionFormatter extends Formatter { 608 class FunctionFormatter extends Formatter {
594 accept(object) { 609 accept(object) {
595 if (_typeof(object) != 'function') return false; 610 if (_typeof(object) != 'function') return false;
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 834
820 List<NameValuePair> children(object) => object.children(); 835 List<NameValuePair> children(object) => object.children();
821 } 836 }
822 837
823 /// This entry point is automatically invoked by the code generated by 838 /// This entry point is automatically invoked by the code generated by
824 /// Dart Dev Compiler 839 /// Dart Dev Compiler
825 registerDevtoolsFormatter() { 840 registerDevtoolsFormatter() {
826 var formatters = [_devtoolsFormatter]; 841 var formatters = [_devtoolsFormatter];
827 JS('', 'dart.global.devtoolsFormatters = #', formatters); 842 JS('', 'dart.global.devtoolsFormatters = #', formatters);
828 } 843 }
OLDNEW
« no previous file with comments | « lib/runtime/dart_sdk.js ('k') | tool/sdk_expected_errors.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698