| 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) => JS('List<String>', |
| 25 dart.list(JS('List', 'Object.getOwnPropertyNames(#)', object), String); | 25 'dart.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, JS('Type', '#', Object)); |
| 42 } | 42 } |
| 43 | 43 |
| 44 String getObjectTypeName(object) { | 44 String getObjectTypeName(object) { |
| 45 var realRuntimeType = dart.realRuntimeType(object); | 45 var reifiedType = dart.getReifiedType(object); |
| 46 if (realRuntimeType == null) { | 46 if (reifiedType == 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(reifiedType); |
| 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> |
| 58 // TODO(jacobr): it would be nice if there was a way we could distinguish | 58 // TODO(jacobr): it would be nice if there was a way we could distinguish |
| 59 // between a List<dynamic> created from Dart and an Array passed in from | 59 // between a List<dynamic> created from Dart and an Array passed in from |
| 60 // JavaScript. | 60 // JavaScript. |
| 61 if (name == 'JSArray<dynamic>' || | 61 if (name == 'JSArray<dynamic>' || |
| 62 name == 'JSObject<Array>') return 'List<dynamic>'; | 62 name == 'JSObject<Array>') return 'List<dynamic>'; |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 | 294 |
| 295 String preview(object) => getObjectTypeName(object); | 295 String preview(object) => getObjectTypeName(object); |
| 296 | 296 |
| 297 bool hasChildren(object) => true; | 297 bool hasChildren(object) => true; |
| 298 | 298 |
| 299 /// Helper to add members walking up the prototype chain being careful | 299 /// Helper to add members walking up the prototype chain being careful |
| 300 /// to avoid properties that are Dart methods. | 300 /// to avoid properties that are Dart methods. |
| 301 _addMembers(current, object, List<NameValuePair> properties) { | 301 _addMembers(current, object, List<NameValuePair> properties) { |
| 302 // TODO(jacobr): optionally distinguish properties and fields so that | 302 // TODO(jacobr): optionally distinguish properties and fields so that |
| 303 // it is safe to expand untrusted objects without side effects. | 303 // it is safe to expand untrusted objects without side effects. |
| 304 var className = dart.realRuntimeType(current).name; | 304 var className = dart.getReifiedType(current).name; |
| 305 for (var name in getOwnPropertyNames(current)) { | 305 for (var name in getOwnPropertyNames(current)) { |
| 306 if (name == 'constructor' || | 306 if (name == 'constructor' || |
| 307 name == '__proto__' || | 307 name == '__proto__' || |
| 308 name == className) continue; | 308 name == className) continue; |
| 309 if (hasMethod(object, name)) { | 309 if (hasMethod(object, name)) { |
| 310 continue; | 310 continue; |
| 311 } | 311 } |
| 312 var value; | 312 var value; |
| 313 try { | 313 try { |
| 314 value = JSNative.getProperty(object, name); | 314 value = JSNative.getProperty(object, name); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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.getReifiedType(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.getReifiedType(object)); |
| 367 } | 367 } |
| 368 | 368 |
| 369 List<NameValuePair> children(object) => <NameValuePair>[ | 369 List<NameValuePair> children(object) => <NameValuePair>[ |
| 370 new NameValuePair(name: 'signature', value: preview(object)), | 370 new NameValuePair(name: 'signature', value: preview(object)), |
| 371 new NameValuePair( | 371 new NameValuePair( |
| 372 name: 'JavaScript Function', value: object, skipDart: true) | 372 name: 'JavaScript Function', value: object, skipDart: true) |
| 373 ]; | 373 ]; |
| 374 } | 374 } |
| 375 | 375 |
| 376 /// Formatter for Dart Map objects. | 376 /// Formatter for Dart Map objects. |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 return ret; | 441 return ret; |
| 442 } | 442 } |
| 443 } | 443 } |
| 444 | 444 |
| 445 // This class does double duting displaying metadata for | 445 // This class does double duting displaying metadata for |
| 446 class ClassMetadataFormatter implements Formatter { | 446 class ClassMetadataFormatter implements Formatter { |
| 447 accept(object) => object is ClassMetadata; | 447 accept(object) => object is ClassMetadata; |
| 448 | 448 |
| 449 _getType(object) { | 449 _getType(object) { |
| 450 if (object is Type) return object; | 450 if (object is Type) return object; |
| 451 return dart.realRuntimeType(object); | 451 return dart.getReifiedType(object); |
| 452 } | 452 } |
| 453 | 453 |
| 454 String preview(object) { | 454 String preview(object) { |
| 455 ClassMetadata entry = object; | 455 ClassMetadata entry = object; |
| 456 return getTypeName(_getType(entry.object)); | 456 return getTypeName(_getType(entry.object)); |
| 457 } | 457 } |
| 458 | 458 |
| 459 bool hasChildren(object) => true; | 459 bool hasChildren(object) => true; |
| 460 | 460 |
| 461 List<NameValuePair> children(object) { | 461 List<NameValuePair> children(object) { |
| (...skipping 69 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('', 'dart.global.devtoolsFormatters = #', formatters); | 539 JS('', 'dart.global.devtoolsFormatters = #', formatters); |
| 540 } | 540 } |
| OLD | NEW |