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 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'; |
| 11 import 'dart:html' as html; | 11 import 'dart:html' as html; |
| 12 | 12 |
| 13 /// Config object to pass to devtools to signal that an object should not be | 13 /// Config String to pass to devtools to signal that an object should not be |
| 14 /// formatted by the Dart formatter. This is used to specify that an Object | 14 /// formatted by the Dart formatter. This is used to specify that an Object |
| 15 /// should just be displayed using the regular JavaScript view instead of a | 15 /// should just be displayed using the regular JavaScript view instead of a |
| 16 /// custom Dart view. For example, this is used to display the JavaScript view | 16 /// custom Dart view. For example, this is used to display the JavaScript view |
| 17 /// of a Dart Function as a child of the regular Function object. | 17 /// of a Dart Function as a child of the regular Function object. |
| 18 const skipDartConfig = const Object(); | 18 const skipDartConfig = "skipDartConfig"; |
| 19 | |
| 20 /// Config String to pass to devtools to signal that a map key object should | |
| 21 /// have its toString() displayed by the Dart formatter. | |
| 22 const keyToStringConfig = "keyToStringConfig"; | |
|
Jacob
2016/06/03 23:11:50
A cleaner solution would be to have an
enum of co
priscillalee
2016/06/07 22:58:01
Used a class JsonMLConfig that simulated an enum i
| |
| 23 | |
| 19 final int maxIterableChildrenToDisplay = 50; | 24 final int maxIterableChildrenToDisplay = 50; |
| 20 | 25 |
| 21 var _devtoolsFormatter = new JsonMLFormatter(new DartFormatter()); | 26 var _devtoolsFormatter = new JsonMLFormatter(new DartFormatter()); |
| 22 | 27 |
| 23 String _typeof(object) => JS('String', 'typeof #', object); | 28 String _typeof(object) => JS('String', 'typeof #', object); |
| 24 | 29 |
| 25 List<String> getOwnPropertyNames(object) => JS('List<String>', | 30 List<String> getOwnPropertyNames(object) => JS('List<String>', |
| 26 'dart.list(Object.getOwnPropertyNames(#), #)', object, String); | 31 'dart.list(Object.getOwnPropertyNames(#), #)', object, String); |
| 27 | 32 |
| 28 List getOwnPropertySymbols(object) => | 33 List getOwnPropertySymbols(object) => |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 78 bool hasMethod(object, String name) { | 83 bool hasMethod(object, String name) { |
| 79 try { | 84 try { |
| 80 return dart.hasMethod(object, name); | 85 return dart.hasMethod(object, name); |
| 81 } catch (e) { | 86 } catch (e) { |
| 82 return false; | 87 return false; |
| 83 } | 88 } |
| 84 } | 89 } |
| 85 | 90 |
| 86 /// [JsonMLFormatter] consumes [NameValuePair] objects and | 91 /// [JsonMLFormatter] consumes [NameValuePair] objects and |
| 87 class NameValuePair { | 92 class NameValuePair { |
| 88 NameValuePair({this.name, this.value, bool skipDart}) | 93 NameValuePair({this.name, this.value, bool skipDart, bool keyToString}) |
|
Jacob
2016/06/03 23:11:50
change this to just take an entry of the
enum Jso
priscillalee
2016/06/07 22:58:01
Done.
| |
| 89 : skipDart = skipDart == true; | 94 : skipDart = skipDart == true, |
| 95 keyToString = keyToString == true; | |
| 90 | 96 |
| 91 // Define equality and hashCode so that NameValuePair can be used | 97 // Define equality and hashCode so that NameValuePair can be used |
| 92 // in a Set to dedupe entries with duplicate names. | 98 // in a Set to dedupe entries with duplicate names. |
| 93 operator ==(other) => other is NameValuePair && other.name == name; | 99 operator ==(other) => other is NameValuePair && other.name == name; |
| 94 int get hashCode => name.hashCode; | 100 int get hashCode => name.hashCode; |
| 95 | 101 |
| 96 final String name; | 102 final String name; |
| 97 final Object value; | 103 final Object value; |
| 98 final bool skipDart; | 104 final bool skipDart; |
| 105 final bool keyToString; | |
| 99 } | 106 } |
| 100 | 107 |
| 101 class MapEntry { | 108 class MapEntry { |
| 102 MapEntry({this.key, this.value}); | 109 MapEntry({this.key, this.value}); |
| 103 | 110 |
| 104 final String key; | 111 final Object key; |
| 105 final Object value; | 112 final Object value; |
| 106 } | 113 } |
| 107 | 114 |
| 108 class ClassMetadata { | 115 class ClassMetadata { |
| 109 ClassMetadata(this.object); | 116 ClassMetadata(this.object); |
| 110 | 117 |
| 111 final Object object; | 118 final Object object; |
| 112 } | 119 } |
| 113 | 120 |
| 114 class HeritageClause { | 121 class HeritageClause { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 // TODO(jacobr): define a SimpleFormatter base class that DartFormatter | 193 // TODO(jacobr): define a SimpleFormatter base class that DartFormatter |
| 187 // implements if we decide to use this class elsewhere. We specify that the | 194 // implements if we decide to use this class elsewhere. We specify that the |
| 188 // type is DartFormatter here purely to get type checking benefits not because | 195 // type is DartFormatter here purely to get type checking benefits not because |
| 189 // this class is really intended to only support instances of type | 196 // this class is really intended to only support instances of type |
| 190 // DartFormatter. | 197 // DartFormatter. |
| 191 DartFormatter _simpleFormatter; | 198 DartFormatter _simpleFormatter; |
| 192 | 199 |
| 193 JsonMLFormatter(this._simpleFormatter); | 200 JsonMLFormatter(this._simpleFormatter); |
| 194 | 201 |
| 195 header(object, config) { | 202 header(object, config) { |
| 196 if (identical(config, skipDartConfig) || isNativeJavaScriptObject(object)) { | 203 if (identical(config, skipDartConfig) || isNativeJavaScriptObject(object)) { |
|
Jacob
2016/06/03 23:11:50
switch to using == once you switch to an enum
priscillalee
2016/06/07 22:58:01
Done.
| |
| 197 return null; | 204 return null; |
| 198 } | 205 } |
| 199 | 206 |
| 200 var c = _simpleFormatter.preview(object); | 207 var c = _simpleFormatter.preview(object); |
| 201 if (c == null) return null; | 208 if (c == null) return null; |
| 202 | 209 |
| 210 if (identical(config, keyToStringConfig)) { | |
|
Jacob
2016/06/03 23:11:50
switch to using == instead of identical
priscillalee
2016/06/07 22:58:01
Done.
| |
| 211 c = object.toString(); | |
| 212 } | |
| 213 | |
| 203 // Indicate this is a Dart Object by using a Dart background color. | 214 // Indicate this is a Dart Object by using a Dart background color. |
| 204 // This is stylistically a bit ugly but it eases distinguishing Dart and | 215 // This is stylistically a bit ugly but it eases distinguishing Dart and |
| 205 // JS objects. | 216 // JS objects. |
| 206 var element = new JsonMLElement('span') | 217 var element = new JsonMLElement('span') |
| 207 ..setStyle('background-color: #d9edf7') | 218 ..setStyle('background-color: #d9edf7') |
| 208 ..createTextChild(c); | 219 ..createTextChild(c); |
| 209 return element.toJsonML(); | 220 return element.toJsonML(); |
| 210 } | 221 } |
| 211 | 222 |
| 212 bool hasBody(object) => _simpleFormatter.hasChildren(object); | 223 bool hasBody(object) => _simpleFormatter.hasChildren(object); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 226 ..setStyle('color: rgb(136, 19, 145);'); | 237 ..setStyle('color: rgb(136, 19, 145);'); |
| 227 if (_typeof(child.value) == 'object' || | 238 if (_typeof(child.value) == 'object' || |
| 228 _typeof(child.value) == 'function') { | 239 _typeof(child.value) == 'function') { |
| 229 nameSpan.addStyle("padding-left: 13px;"); | 240 nameSpan.addStyle("padding-left: 13px;"); |
| 230 | 241 |
| 231 li.appendChild(nameSpan); | 242 li.appendChild(nameSpan); |
| 232 var objectTag = li.createObjectTag(child.value); | 243 var objectTag = li.createObjectTag(child.value); |
| 233 if (child.skipDart) { | 244 if (child.skipDart) { |
| 234 objectTag.addAttribute('config', skipDartConfig); | 245 objectTag.addAttribute('config', skipDartConfig); |
| 235 } | 246 } |
| 247 if (child.keyToString) { | |
| 248 objectTag.addAttribute('config', keyToStringConfig); | |
| 249 } | |
| 236 if (!_simpleFormatter.hasChildren(child.value)) { | 250 if (!_simpleFormatter.hasChildren(child.value)) { |
| 237 li.setStyle("padding-left: 13px;"); | 251 li.setStyle("padding-left: 13px;"); |
| 238 } | 252 } |
| 239 } else { | 253 } else { |
| 240 li.setStyle("padding-left: 13px;"); | 254 li.setStyle("padding-left: 13px;"); |
| 241 li.createChild('span') | 255 li.createChild('span') |
| 242 ..appendChild(nameSpan) | 256 ..appendChild(nameSpan) |
| 243 ..createTextChild(safePreview(child.value)); | 257 ..createTextChild(safePreview(child.value)); |
| 244 } | 258 } |
| 245 } | 259 } |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 554 accept(object) => object is MapEntry; | 568 accept(object) => object is MapEntry; |
| 555 | 569 |
| 556 String preview(object) { | 570 String preview(object) { |
| 557 MapEntry entry = object; | 571 MapEntry entry = object; |
| 558 return '${safePreview(entry.key)} => ${safePreview(entry.value)}'; | 572 return '${safePreview(entry.key)} => ${safePreview(entry.value)}'; |
| 559 } | 573 } |
| 560 | 574 |
| 561 bool hasChildren(object) => true; | 575 bool hasChildren(object) => true; |
| 562 | 576 |
| 563 List<NameValuePair> children(object) => <NameValuePair>[ | 577 List<NameValuePair> children(object) => <NameValuePair>[ |
| 564 new NameValuePair(name: 'key', value: object.key), | 578 new NameValuePair(name: 'key', value: object.key, keyToString: true), |
| 565 new NameValuePair(name: 'value', value: object.value) | 579 new NameValuePair(name: 'value', value: object.value) |
| 566 ]; | 580 ]; |
| 567 } | 581 } |
| 568 | 582 |
| 569 /// Formatter for Dart Iterable objects including List and Set. | 583 /// Formatter for Dart Iterable objects including List and Set. |
| 570 class HeritageClauseFormatter implements Formatter { | 584 class HeritageClauseFormatter implements Formatter { |
| 571 bool accept(object) => object is HeritageClause; | 585 bool accept(object) => object is HeritageClause; |
| 572 | 586 |
| 573 String preview(object) { | 587 String preview(object) { |
| 574 HeritageClause clause = object; | 588 HeritageClause clause = object; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 587 return ret; | 601 return ret; |
| 588 } | 602 } |
| 589 } | 603 } |
| 590 | 604 |
| 591 /// This entry point is automatically invoked by the code generated by | 605 /// This entry point is automatically invoked by the code generated by |
| 592 /// Dart Dev Compiler | 606 /// Dart Dev Compiler |
| 593 registerDevtoolsFormatter() { | 607 registerDevtoolsFormatter() { |
| 594 var formatters = [_devtoolsFormatter]; | 608 var formatters = [_devtoolsFormatter]; |
| 595 JS('', 'dart.global.devtoolsFormatters = #', formatters); | 609 JS('', 'dart.global.devtoolsFormatters = #', formatters); |
| 596 } | 610 } |
| OLD | NEW |