| 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 | 10 |
| 11 /// Config object to pass to devtools to signal that an object should not be | 11 /// Config object to pass to devtools to signal that an object should not be |
| 12 /// formatted by the Dart formatter. This is used to specify that an Object | 12 /// formatted by the Dart formatter. This is used to specify that an Object |
| 13 /// should just be displayed using the regular JavaScript view instead of a | 13 /// should just be displayed using the regular JavaScript view instead of a |
| 14 /// custom Dart view. For example, this is used to display the JavaScript view | 14 /// custom Dart view. For example, this is used to display the JavaScript view |
| 15 /// of a Dart Function as a child of the regular Function object. | 15 /// of a Dart Function as a child of the regular Function object. |
| 16 const skipDartConfig = const Object(); | 16 const skipDartConfig = const Object(); |
| 17 final int maxIterableChildrenToDisplay = 50; | 17 final int maxIterableChildrenToDisplay = 50; |
| 18 | 18 |
| 19 var _devtoolsFormatter = new JsonMLFormatter(new DartFormatter()); | 19 var _devtoolsFormatter = new JsonMLFormatter(new DartFormatter()); |
| 20 | 20 |
| 21 String typeof(object) => JS('String', 'typeof #', object); | 21 String _typeof(object) => JS('String', 'typeof #', object); |
| 22 bool instanceof(object, clazz) => JS('bool', '# instanceof #', object, clazz); | 22 bool _instanceof(object, clazz) => JS('bool', '# instanceof #', object, clazz); |
| 23 | 23 |
| 24 List<String> getOwnPropertyNames(object) => | 24 List<String> getOwnPropertyNames(object) => |
| 25 dart.list(JS('List', 'Object.getOwnPropertyNames(#)', object), String); | 25 dart.list(JS('List', 'Object.getOwnPropertyNames(#)', object), String); |
| 26 | 26 |
| 27 List getOwnPropertySymbols(object) => | 27 List getOwnPropertySymbols(object) => |
| 28 JS('List', 'Object.getOwnPropertySymbols(#)', object); | 28 JS('List', 'Object.getOwnPropertySymbols(#)', object); |
| 29 | 29 |
| 30 // TODO(jacobr): move this to dart:js and fully implement. | 30 // TODO(jacobr): move this to dart:js and fully implement. |
| 31 class JSNative { | 31 class JSNative { |
| 32 // Name may be a String or a Symbol. | 32 // Name may be a String or a Symbol. |
| 33 static getProperty(object, name) => JS('', '#[#]', object, name); | 33 static getProperty(object, name) => JS('', '#[#]', object, name); |
| 34 // Name may be a String or a Symbol. | 34 // Name may be a String or a Symbol. |
| 35 static setProperty(object, name, value) => | 35 static setProperty(object, name, value) => |
| 36 JS('', '#[#]=#', object, name, value); | 36 JS('', '#[#]=#', object, name, value); |
| 37 } | 37 } |
| 38 | 38 |
| 39 bool isRegularDartObject(object) { | 39 bool isRegularDartObject(object) { |
| 40 if (typeof(object) == 'function') return false; | 40 if (_typeof(object) == 'function') return false; |
| 41 return instanceof(object, Object); | 41 return _instanceof(object, Object); |
| 42 } | 42 } |
| 43 | 43 |
| 44 String getObjectTypeName(object) { | 44 String getObjectTypeName(object) { |
| 45 var realRuntimeType = dart.realRuntimeType(object); | 45 var realRuntimeType = dart.realRuntimeType(object); |
| 46 if (realRuntimeType == null) { | 46 if (realRuntimeType == null) { |
| 47 if (typeof(object) == 'function') { | 47 if (_typeof(object) == 'function') { |
| 48 return '[[Raw JavaScript Function]]'; | 48 return '[[Raw JavaScript Function]]'; |
| 49 } | 49 } |
| 50 return '<Error getting type name>'; | 50 return '<Error getting type name>'; |
| 51 } | 51 } |
| 52 return getTypeName(realRuntimeType); | 52 return getTypeName(realRuntimeType); |
| 53 } | 53 } |
| 54 | 54 |
| 55 String getTypeName(Type type) { | 55 String getTypeName(Type type) { |
| 56 var name = dart.typeName(type); | 56 var name = dart.typeName(type); |
| 57 // Hack to cleanup names for List<dynamic> | 57 // Hack to cleanup names for List<dynamic> |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 'padding-left: 0px;' | 202 'padding-left: 0px;' |
| 203 'margin-top: 0px;' | 203 'margin-top: 0px;' |
| 204 'margin-bottom: 0px;' | 204 'margin-bottom: 0px;' |
| 205 'margin-left: 12px'); | 205 'margin-left: 12px'); |
| 206 var children = _simpleFormatter.children(object); | 206 var children = _simpleFormatter.children(object); |
| 207 for (NameValuePair child in children) { | 207 for (NameValuePair child in children) { |
| 208 var li = body.createChild('li'); | 208 var li = body.createChild('li'); |
| 209 var nameSpan = new JsonMLElement('span') | 209 var nameSpan = new JsonMLElement('span') |
| 210 ..createTextChild(child.name != null ? child.name + ': ' : '') | 210 ..createTextChild(child.name != null ? child.name + ': ' : '') |
| 211 ..setStyle('color: rgb(136, 19, 145);'); | 211 ..setStyle('color: rgb(136, 19, 145);'); |
| 212 if (typeof(child.value) == 'object' || | 212 if (_typeof(child.value) == 'object' || |
| 213 typeof(child.value) == 'function') { | 213 _typeof(child.value) == 'function') { |
| 214 nameSpan.addStyle("padding-left: 13px;"); | 214 nameSpan.addStyle("padding-left: 13px;"); |
| 215 | 215 |
| 216 li.appendChild(nameSpan); | 216 li.appendChild(nameSpan); |
| 217 var objectTag = li.createObjectTag(child.value); | 217 var objectTag = li.createObjectTag(child.value); |
| 218 if (child.skipDart) { | 218 if (child.skipDart) { |
| 219 objectTag.addAttribute('config', skipDartConfig); | 219 objectTag.addAttribute('config', skipDartConfig); |
| 220 } | 220 } |
| 221 if (!_simpleFormatter.hasChildren(child.value)) { | 221 if (!_simpleFormatter.hasChildren(child.value)) { |
| 222 li.setStyle("padding-left: 13px;"); | 222 li.setStyle("padding-left: 13px;"); |
| 223 } | 223 } |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 new NameValuePair(name: '[[class]]', value: new ClassMetadata(object))); | 349 new NameValuePair(name: '[[class]]', value: new ClassMetadata(object))); |
| 350 } | 350 } |
| 351 } | 351 } |
| 352 | 352 |
| 353 /// Formatter for Dart Function objects. | 353 /// Formatter for Dart Function objects. |
| 354 /// Dart functions happen to be regular JavaScript Function objects but | 354 /// Dart functions happen to be regular JavaScript Function objects but |
| 355 /// we can distinguish them based on whether they have been tagged with | 355 /// we can distinguish them based on whether they have been tagged with |
| 356 /// runtime type information. | 356 /// runtime type information. |
| 357 class FunctionFormatter extends Formatter { | 357 class FunctionFormatter extends Formatter { |
| 358 accept(object) { | 358 accept(object) { |
| 359 if (typeof(object) != 'function') return false; | 359 if (_typeof(object) != 'function') return false; |
| 360 return dart.realRuntimeType(object) != null; | 360 return dart.realRuntimeType(object) != null; |
| 361 } | 361 } |
| 362 | 362 |
| 363 bool hasChildren(object) => true; | 363 bool hasChildren(object) => true; |
| 364 | 364 |
| 365 String preview(object) { | 365 String preview(object) { |
| 366 return dart.typeName(dart.realRuntimeType(object)); | 366 return dart.typeName(dart.realRuntimeType(object)); |
| 367 } | 367 } |
| 368 | 368 |
| 369 List<NameValuePair> children(object) => <NameValuePair>[ | 369 List<NameValuePair> children(object) => <NameValuePair>[ |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 return ret; | 531 return ret; |
| 532 } | 532 } |
| 533 } | 533 } |
| 534 | 534 |
| 535 /// This entry point is automatically invoked by the code generated by | 535 /// This entry point is automatically invoked by the code generated by |
| 536 /// Dart Dev Compiler | 536 /// Dart Dev Compiler |
| 537 registerDevtoolsFormatter() { | 537 registerDevtoolsFormatter() { |
| 538 var formatters = [_devtoolsFormatter]; | 538 var formatters = [_devtoolsFormatter]; |
| 539 JS('', 'window.devtoolsFormatters = #', formatters); | 539 JS('', 'window.devtoolsFormatters = #', formatters); |
| 540 } | 540 } |
| OLD | NEW |