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'; |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 /// maxPowerOfSubsetSize of 2, so the list will be broken up into 1 | 139 /// maxPowerOfSubsetSize of 2, so the list will be broken up into 1 |
| 140 /// 10000-length subset and 1 1-length subset. | 140 /// 10000-length subset and 1 1-length subset. |
| 141 int get maxPowerOfSubsetSize => | 141 int get maxPowerOfSubsetSize => |
| 142 (log(length - .5) / log(_maxSpanLength)).truncate(); | 142 (log(length - .5) / log(_maxSpanLength)).truncate(); |
| 143 int get subsetSize => pow(_maxSpanLength, maxPowerOfSubsetSize); | 143 int get subsetSize => pow(_maxSpanLength, maxPowerOfSubsetSize); |
| 144 | 144 |
| 145 Map<int, dynamic> asMap() => | 145 Map<int, dynamic> asMap() => |
| 146 iterable.skip(start).take(length).toList().asMap(); | 146 iterable.skip(start).take(length).toList().asMap(); |
| 147 | 147 |
| 148 List<NameValuePair> children() { | 148 List<NameValuePair> children() { |
| 149 var ret = <NameValuePair>[]; | 149 var children = <NameValuePair>[]; |
| 150 if (length <= _maxSpanLength) { | 150 if (length <= _maxSpanLength) { |
| 151 asMap().forEach((i, element) { | 151 asMap().forEach((i, element) { |
| 152 ret.add( | 152 children.add( |
| 153 new NameValuePair(name: (i + start).toString(), value: element)); | 153 new NameValuePair(name: (i + start).toString(), value: element)); |
| 154 }); | 154 }); |
| 155 } else { | 155 } else { |
| 156 for (var i = start; i < end; i += subsetSize) { | 156 for (var i = start; i < end; i += subsetSize) { |
| 157 var subSpan = new IterableSpan(i, min(end, subsetSize + i), iterable); | 157 var subSpan = new IterableSpan(i, min(end, subsetSize + i), iterable); |
| 158 if (subSpan.length == 1) { | 158 if (subSpan.length == 1) { |
| 159 ret.add(new NameValuePair( | 159 children.add(new NameValuePair( |
| 160 name: i.toString(), value: iterable.elementAt(i))); | 160 name: i.toString(), value: iterable.elementAt(i))); |
| 161 } else { | 161 } else { |
| 162 ret.add(new NameValuePair( | 162 children.add(new NameValuePair( |
| 163 name: '[${i}...${subSpan.end - 1}]', | 163 name: '[${i}...${subSpan.end - 1}]', |
| 164 value: subSpan, | 164 value: subSpan, |
| 165 hideName: true)); | 165 hideName: true)); |
| 166 } | 166 } |
| 167 } | 167 } |
| 168 } | 168 } |
| 169 return ret; | 169 return children; |
| 170 } | 170 } |
| 171 } | 171 } |
| 172 | 172 |
| 173 class ClassMetadata { | 173 class Library { |
| 174 ClassMetadata(this.object); | 174 Library(this.name, this.object); |
| 175 | |
| 176 final String name; | |
| 177 final Object object; | |
| 178 } | |
| 179 | |
| 180 class NamedConstructor { | |
| 181 NamedConstructor(this.object); | |
| 175 | 182 |
| 176 final Object object; | 183 final Object object; |
| 177 } | 184 } |
| 178 | 185 |
| 186 class ClassMetadata { | |
| 187 ClassMetadata(this.object, {this.name}); | |
| 188 | |
| 189 final Object object; | |
| 190 final String name; | |
| 191 | |
| 192 String get typeName { | |
| 193 return name == null | |
|
Jacob
2016/07/22 19:17:50
nit: dart now has a ?? operator that can simplify
bmilligan
2016/07/22 20:10:24
So cool!
| |
| 194 ? getTypeName(object is Type ? object : dart.getReifiedType(object)) | |
| 195 : name; | |
| 196 } | |
| 197 } | |
| 198 | |
| 179 class HeritageClause { | 199 class HeritageClause { |
| 180 HeritageClause(this.name, this.types); | 200 HeritageClause(this.name, this.types); |
| 181 | 201 |
| 182 final String name; | 202 final String name; |
| 183 final List types; | 203 final List types; |
| 184 } | 204 } |
| 185 | 205 |
| 206 Object safeGetProperty(Object protoChain, String name) { | |
| 207 var property; | |
| 208 try { | |
| 209 property = JSNative.getProperty(protoChain, name); | |
|
Jacob
2016/07/22 19:17:50
nit: cleaner to just return within the try and wit
bmilligan
2016/07/22 20:10:24
Done.
| |
| 210 } catch (e) { | |
| 211 property = '<Exception thrown> $e'; | |
| 212 } | |
| 213 return property; | |
| 214 } | |
| 215 | |
| 186 /// Class to simplify building the JsonML objects expected by the | 216 /// Class to simplify building the JsonML objects expected by the |
| 187 /// Devtools Formatter API. | 217 /// Devtools Formatter API. |
| 188 class JsonMLElement { | 218 class JsonMLElement { |
| 189 dynamic _attributes; | 219 dynamic _attributes; |
| 190 List _jsonML; | 220 List _jsonML; |
| 191 | 221 |
| 192 JsonMLElement(tagName) { | 222 JsonMLElement(tagName) { |
| 193 _attributes = JS('', '{}'); | 223 _attributes = JS('', '{}'); |
| 194 _jsonML = [tagName, _attributes]; | 224 _jsonML = [tagName, _attributes]; |
| 195 } | 225 } |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 326 bool accept(object); | 356 bool accept(object); |
| 327 String preview(object); | 357 String preview(object); |
| 328 bool hasChildren(object); | 358 bool hasChildren(object); |
| 329 List<NameValuePair> children(object); | 359 List<NameValuePair> children(object); |
| 330 } | 360 } |
| 331 | 361 |
| 332 class DartFormatter { | 362 class DartFormatter { |
| 333 List<Formatter> _formatters; | 363 List<Formatter> _formatters; |
| 334 | 364 |
| 335 DartFormatter() { | 365 DartFormatter() { |
| 336 // The order of formatters matters as formatters later in the list take | 366 // The order of formatters matters as formatters earlier in the list take |
| 337 // precidence. | 367 // precedence. |
| 338 _formatters = [ | 368 _formatters = [ |
| 369 new NamedConstructorFormatter(), | |
| 339 new FunctionFormatter(), | 370 new FunctionFormatter(), |
| 340 new MapFormatter(), | 371 new MapFormatter(), |
| 341 new IterableFormatter(), | 372 new IterableFormatter(), |
| 342 new MapEntryFormatter(), | 373 new MapEntryFormatter(), |
| 343 new IterableSpanFormatter(), | 374 new IterableSpanFormatter(), |
| 344 new ClassMetadataFormatter(), | 375 new ClassMetadataFormatter(), |
| 345 new HeritageClauseFormatter(), | 376 new HeritageClauseFormatter(), |
| 377 new LibraryModuleFormatter(), | |
| 378 new LibraryFormatter(), | |
| 346 new ObjectFormatter(), | 379 new ObjectFormatter(), |
| 347 ]; | 380 ]; |
| 348 } | 381 } |
| 349 | 382 |
| 350 String preview(object) { | 383 String preview(object) { |
| 351 try { | 384 try { |
| 352 if (object == null || | 385 if (object == null || |
| 353 object is num || | 386 object is num || |
| 354 object is String || | 387 object is String || |
| 355 isNativeJavaScriptObject(object)) { | 388 isNativeJavaScriptObject(object)) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 407 | 440 |
| 408 String preview(object) => getObjectTypeName(object); | 441 String preview(object) => getObjectTypeName(object); |
| 409 | 442 |
| 410 bool hasChildren(object) => true; | 443 bool hasChildren(object) => true; |
| 411 | 444 |
| 412 List<NameValuePair> children(object) { | 445 List<NameValuePair> children(object) { |
| 413 var properties = new LinkedHashSet<NameValuePair>(); | 446 var properties = new LinkedHashSet<NameValuePair>(); |
| 414 // Set of property names used to avoid duplicates. | 447 // Set of property names used to avoid duplicates. |
| 415 addMetadataChildren(object, properties); | 448 addMetadataChildren(object, properties); |
| 416 | 449 |
| 450 var current = object; | |
| 451 | |
| 417 /// Helper to add members walking up the prototype chain being careful | 452 /// Helper to add members walking up the prototype chain being careful |
| 418 /// to avoid properties that are Dart methods. | 453 /// to avoid properties that are Dart methods. |
| 419 var protoChain = <Object>[]; | 454 var protoChain = <Object>[]; |
| 420 var current = object; | |
| 421 while (current != null && | 455 while (current != null && |
| 422 !isNativeJavaScriptObject(current) && | 456 !isNativeJavaScriptObject(current) && |
| 423 JS("bool", "# !== Object.prototype", current)) { | 457 JS("bool", "# !== Object.prototype", current)) { |
| 424 protoChain.add(current); | 458 protoChain.add(current); |
| 425 current = JSNative.getProperty(current, '__proto__'); | 459 current = safeGetProperty(current, '__proto__'); |
| 426 } | 460 } |
| 427 | 461 |
| 428 // We walk the prototype chain for symbol properties because they take | 462 // We walk the prototype chain for symbol properties because they take |
| 429 // priority and are accessed instead of Dart properties according to Dart | 463 // priority and are accessed instead of Dart properties according to Dart |
| 430 // calling conventions. | 464 // calling conventions. |
| 431 // TODO(jacobr): where possible use the data stored by dart.setSignature | 465 // TODO(jacobr): where possible use the data stored by dart.setSignature |
| 432 // instead of walking the JavaScript object directly. | 466 // instead of walking the JavaScript object directly. |
| 433 for (current in protoChain) { | 467 for (current in protoChain) { |
| 434 for (var symbol in getOwnPropertySymbols(current)) { | 468 for (var symbol in getOwnPropertySymbols(current)) { |
| 435 var dartName = symbolName(symbol); | 469 var dartName = symbolName(symbol); |
| 436 if (hasMethod(object, dartName)) { | 470 if (hasMethod(object, dartName)) { |
| 437 continue; | 471 continue; |
| 438 } | 472 } |
| 439 // TODO(jacobr): find a cleaner solution than checking for dartx | 473 // TODO(jacobr): find a cleaner solution than checking for dartx |
| 440 String dartXPrefix = 'dartx.'; | 474 String dartXPrefix = 'dartx.'; |
| 441 if (dartName.startsWith(dartXPrefix)) { | 475 if (dartName.startsWith(dartXPrefix)) { |
| 442 dartName = dartName.substring(dartXPrefix.length); | 476 dartName = dartName.substring(dartXPrefix.length); |
| 443 } else if (!dartName.startsWith('_')) { | 477 } else if (!dartName.startsWith('_')) { |
| 444 // Dart method extension names should either be from dartx or should | 478 // Dart method extension names should either be from dartx or should |
| 445 // start with an _ | 479 // start with an _ |
| 446 continue; | 480 continue; |
| 447 } | 481 } |
| 448 var value; | 482 var value = safeGetProperty(object, symbol); |
| 449 try { | |
| 450 value = JSNative.getProperty(object, symbol); | |
| 451 } catch (e) { | |
| 452 value = '<Exception thrown> $e'; | |
| 453 } | |
| 454 properties.add(new NameValuePair(name: dartName, value: value)); | 483 properties.add(new NameValuePair(name: dartName, value: value)); |
| 455 } | 484 } |
| 456 } | 485 } |
| 457 | 486 |
| 458 for (current in protoChain) { | 487 for (current in protoChain) { |
| 459 // TODO(jacobr): optionally distinguish properties and fields so that | 488 // TODO(jacobr): optionally distinguish properties and fields so that |
| 460 // it is safe to expand untrusted objects without side effects. | 489 // it is safe to expand untrusted objects without side effects. |
| 461 var className = dart.getReifiedType(current).name; | 490 var className = dart.getReifiedType(current).name; |
| 462 for (var name in getOwnPropertyNames(current)) { | 491 for (var name in getOwnPropertyNames(current)) { |
| 463 if (_customNames.contains(name) || name == className) continue; | 492 if (_customNames.contains(name) || name == className) continue; |
| 464 if (hasMethod(object, name)) { | 493 if (hasMethod(object, name)) { |
| 465 continue; | 494 continue; |
| 466 } | 495 } |
| 467 var value; | 496 var value = safeGetProperty(object, name); |
| 468 try { | |
| 469 value = JSNative.getProperty(object, name); | |
| 470 } catch (e) { | |
| 471 value = '<Exception thrown> $e'; | |
| 472 } | |
| 473 properties.add(new NameValuePair(name: name, value: value)); | 497 properties.add(new NameValuePair(name: name, value: value)); |
| 474 } | 498 } |
| 475 } | 499 } |
| 476 | 500 |
| 477 return properties.toList(); | 501 return properties.toList(); |
| 478 } | 502 } |
| 479 | 503 |
| 480 addMetadataChildren(object, Set<NameValuePair> ret) { | 504 addMetadataChildren(object, Set<NameValuePair> ret) { |
| 481 ret.add( | 505 var child = new ClassMetadata(object); |
| 482 new NameValuePair(name: '[[class]]', value: new ClassMetadata(object))); | 506 ret.add(new NameValuePair(name: child.typeName, value: child)); |
| 483 } | 507 } |
| 484 } | 508 } |
| 485 | 509 |
| 510 /// Formatter for module Dart Library objects. | |
| 511 class LibraryModuleFormatter extends ObjectFormatter { | |
| 512 String libraryName; | |
| 513 | |
| 514 accept(object) { | |
| 515 libraryName = dart.getDartLibraryName(object); | |
| 516 return libraryName != null; | |
| 517 } | |
| 518 | |
| 519 bool hasChildren(object) => true; | |
| 520 | |
| 521 String preview(object) { | |
| 522 var libraryNames = libraryName.split('/'); | |
| 523 // Library names are received with a repeat directory name, so strip the | |
| 524 // last directory entry here to make the path cleaner. For example, the | |
| 525 // library "third_party/dart/utf/utf" shoud display as | |
| 526 // "third_party/dart/utf/". | |
| 527 if (libraryNames.length > 1) { | |
| 528 libraryNames[libraryNames.length - 1] = ''; | |
| 529 } | |
| 530 return 'Library Module: ${libraryNames.join('/')}'; | |
| 531 } | |
| 532 | |
| 533 List<NameValuePair> children(object) { | |
| 534 var children = new LinkedHashSet<NameValuePair>(); | |
| 535 for (var name in getOwnPropertyNames(object)) { | |
| 536 var value = safeGetProperty(object, name); | |
| 537 // Replace __ with / to make file paths more readable. Then | |
| 538 // 'src__result__error' becomes 'src/result/error'. | |
| 539 name = '${name.replaceAll("__", "/")}.dart'; | |
| 540 children.add(new NameValuePair( | |
| 541 name: name, value: new Library(name, value), hideName: true)); | |
| 542 } | |
| 543 return children.toList(); | |
| 544 } | |
| 545 } | |
| 546 | |
| 547 /// Formatter for Dart Library objects. | |
| 548 class LibraryFormatter extends ObjectFormatter { | |
| 549 String genericName; | |
| 550 String genericTypes; | |
| 551 | |
| 552 accept(object) => object is Library; | |
| 553 | |
| 554 bool hasChildren(object) => true; | |
| 555 | |
| 556 String preview(object) => object.name; | |
| 557 | |
| 558 List<NameValuePair> children(object) { | |
| 559 var children = new LinkedHashSet<NameValuePair>(); | |
| 560 var entry = object.object; | |
| 561 for (var name in getOwnPropertyNames(entry)) { | |
| 562 var value = safeGetProperty(entry, name); | |
| 563 var genericTypeConstructor = dart.getGenericTypeCtor(value); | |
| 564 if (genericTypeConstructor != null) { | |
| 565 genericName = name; | |
| 566 // Using JS toString() eliminates the leading metadata that is generated | |
| 567 // with the toString function provided in operations.dart. | |
| 568 // Splitting by => and taking the first element gives the list of | |
| 569 // arguments in the constructor. | |
| 570 genericTypes = JS('String', '#.toString()', genericTypeConstructor) | |
| 571 .split(' =>')[0] | |
|
Jacob
2016/07/22 19:17:50
[0] --> .first
bmilligan
2016/07/22 20:10:24
Done.
| |
| 572 .replaceAll('(', '') | |
|
Jacob
2016/07/22 19:17:50
can combine these two call to replaceAll
bmilligan
2016/07/22 20:10:24
Done.
| |
| 573 .replaceAll(')', ''); | |
| 574 } else if (value is Type) { | |
| 575 var typeName = getTypeName(value); | |
| 576 // Generic class names are generated with a $ at the end, so the | |
| 577 // corresponding non-generic class can be identified by adding $. | |
| 578 if ('$name\$' == genericName) { | |
| 579 typeName = '$typeName<$genericTypes>'; | |
| 580 } | |
| 581 children.add(new NameValuePair( | |
| 582 name: typeName, value: new ClassMetadata(value, name: typeName))); | |
| 583 } else { | |
| 584 children.add( | |
| 585 new NameValuePair(name: name, value: new ClassMetadata(value))); | |
| 586 } | |
| 587 } | |
| 588 return children.toList(); | |
| 589 } | |
| 590 } | |
| 591 | |
| 486 /// Formatter for Dart Function objects. | 592 /// Formatter for Dart Function objects. |
| 487 /// Dart functions happen to be regular JavaScript Function objects but | 593 /// Dart functions happen to be regular JavaScript Function objects but |
| 488 /// we can distinguish them based on whether they have been tagged with | 594 /// we can distinguish them based on whether they have been tagged with |
| 489 /// runtime type information. | 595 /// runtime type information. |
| 490 class FunctionFormatter extends Formatter { | 596 class FunctionFormatter extends Formatter { |
| 491 accept(object) { | 597 accept(object) { |
| 492 if (_typeof(object) != 'function') return false; | 598 if (_typeof(object) != 'function') return false; |
| 493 return dart.getReifiedType(object) != null; | 599 return dart.getReifiedType(object) != null; |
| 494 } | 600 } |
| 495 | 601 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 549 } | 655 } |
| 550 } | 656 } |
| 551 | 657 |
| 552 bool hasChildren(object) => true; | 658 bool hasChildren(object) => true; |
| 553 | 659 |
| 554 List<NameValuePair> children(object) { | 660 List<NameValuePair> children(object) { |
| 555 // TODO(jacobr): be lazier about enumerating contents of Iterables that | 661 // TODO(jacobr): be lazier about enumerating contents of Iterables that |
| 556 // are not the built in Set or List types. | 662 // are not the built in Set or List types. |
| 557 // TODO(jacobr): handle large Iterables better. | 663 // TODO(jacobr): handle large Iterables better. |
| 558 // TODO(jacobr): consider only using numeric indices | 664 // TODO(jacobr): consider only using numeric indices |
| 559 var ret = new LinkedHashSet<NameValuePair>(); | 665 var children = new LinkedHashSet<NameValuePair>(); |
| 560 ret.addAll((new IterableSpan(0, object.length, object)).children()); | 666 children.addAll(new IterableSpan(0, object.length, object).children()); |
| 561 // TODO(jacobr): provide a link to show regular class properties here. | 667 // TODO(jacobr): provide a link to show regular class properties here. |
| 562 // required for subclasses of iterable, etc. | 668 // required for subclasses of iterable, etc. |
| 563 addMetadataChildren(object, ret); | 669 addMetadataChildren(object, children); |
| 564 return ret.toList(); | 670 return children.toList(); |
| 565 } | 671 } |
| 566 } | 672 } |
| 567 | 673 |
| 568 // This class does double duting displaying metadata for | 674 // This class does double duting displaying metadata for |
| 569 class ClassMetadataFormatter implements Formatter { | 675 class ClassMetadataFormatter implements Formatter { |
| 570 accept(object) => object is ClassMetadata; | 676 accept(object) => object is ClassMetadata; |
| 571 | 677 |
| 572 _getType(object) { | 678 Object _getType(object) { |
| 573 if (object is Type) return object; | 679 if (object is Type) return object; |
| 574 return dart.getReifiedType(object); | 680 return dart.getReifiedType(object); |
| 575 } | 681 } |
| 576 | 682 |
| 577 String preview(object) { | 683 String preview(object) { |
| 578 ClassMetadata entry = object; | 684 ClassMetadata entry = object; |
| 579 return getTypeName(_getType(entry.object)); | 685 var type = |
| 686 entry.object is Type ? entry.object : dart.getReifiedType(entry.object); | |
| 687 var implements = dart.getImplements(type); | |
| 688 if (implements != null) { | |
| 689 var typeNames = implements().map(getTypeName); | |
| 690 return '${entry.typeName} implements ${typeNames.join(", ")}'; | |
| 691 } else { | |
| 692 return entry.typeName; | |
| 693 } | |
| 580 } | 694 } |
| 581 | 695 |
| 582 bool hasChildren(object) => true; | 696 bool hasChildren(object) => true; |
| 583 | 697 |
| 584 List<NameValuePair> children(object) { | 698 List<NameValuePair> children(object) { |
| 585 ClassMetadata entry = object; | 699 ClassMetadata entry = object; |
| 700 var classObject = entry.object; | |
| 586 // TODO(jacobr): add other entries describing the class such as | 701 // TODO(jacobr): add other entries describing the class such as |
| 587 // links to the superclass, mixins, implemented interfaces, and methods. | 702 // links to the superclass, mixins, implemented interfaces, and methods. |
| 588 var type = _getType(entry.object); | 703 var type = _getType(classObject); |
| 589 var ret = <NameValuePair>[]; | 704 var children = <NameValuePair>[]; |
| 590 var implements = dart.getImplements(type); | 705 |
| 591 if (implements != null) { | |
| 592 ret.add(new NameValuePair( | |
| 593 name: '[[Implements]]', | |
| 594 value: new HeritageClause('implements', implements()))); | |
| 595 } | |
| 596 var mixins = dart.getMixins(type); | 706 var mixins = dart.getMixins(type); |
| 597 if (mixins != null && mixins.isNotEmpty) { | 707 if (mixins != null && mixins.isNotEmpty) { |
| 598 ret.add(new NameValuePair( | 708 children.add(new NameValuePair( |
| 599 name: '[[Mixins]]', value: new HeritageClause('mixins', mixins))); | 709 name: '[[Mixins]]', value: new HeritageClause('mixins', mixins))); |
| 600 } | 710 } |
| 601 ret.add(new NameValuePair( | |
| 602 name: '[[JavaScript View]]', | |
| 603 value: entry.object, | |
| 604 config: JsonMLConfig.skipDart)); | |
| 605 | 711 |
| 712 var hiddenProperties = ['length', 'name', 'prototype']; | |
| 713 // Addition of NameValuePairs for static variables and named constructors. | |
| 714 for (var name in getOwnPropertyNames(classObject)) { | |
| 715 // TODO(bmilligan): Perform more principled checks to filter out spurious | |
| 716 // members. | |
| 717 if (hiddenProperties.contains(name)) continue; | |
| 718 var value = safeGetProperty(classObject, name); | |
| 719 if (value != null && dart.getIsNamedConstructor(value) != null) { | |
| 720 value = new NamedConstructor(value); | |
| 721 name = '${entry.typeName}.$name'; | |
| 722 } | |
| 723 children.add(new NameValuePair(name: name, value: value)); | |
| 724 } | |
| 725 | |
| 726 // TODO(bmilligan): Replace the hard coding of $identityHash. | |
| 727 var hiddenPrototypeProperties = ['constructor', 'new', r'$identityHash']; | |
| 728 // Addition of class methods. | |
| 729 var prototype = JS('var', '#["prototype"]', classObject); | |
| 730 if (prototype != null) { | |
| 731 for (var name in getOwnPropertyNames(prototype)) { | |
| 732 if (hiddenPrototypeProperties.contains(name)) continue; | |
| 733 // Simulate dart.bind by using dart.tag and tear off the function | |
| 734 // so it will be recognized by the FunctionFormatter. | |
| 735 var function = safeGetProperty(prototype, name); | |
| 736 var constructor = safeGetProperty(prototype, 'constructor'); | |
| 737 var sigObj = dart.getMethodSig(constructor); | |
| 738 if (sigObj != null) { | |
| 739 var value = safeGetProperty(sigObj, name); | |
| 740 if (getTypeName(dart.getReifiedType(value)) != 'Null') { | |
| 741 dart.tag(function, value); | |
| 742 children.add(new NameValuePair(name: name, value: function)); | |
| 743 } | |
| 744 } | |
| 745 } | |
| 746 } | |
| 606 // TODO(jacobr): provide a link to the base class or perhaps the entire | 747 // TODO(jacobr): provide a link to the base class or perhaps the entire |
| 607 // base class hierarchy as a flat list. | 748 // base class hierarchy as a flat list. |
| 749 // TODO(jacobr): add constructors, methods, extended class, and static | |
| 750 return children; | |
| 751 } | |
| 752 } | |
| 608 | 753 |
| 609 if (entry.object is! Type) { | 754 class NamedConstructorFormatter implements Formatter { |
| 610 ret.add(new NameValuePair( | 755 accept(object) => object is NamedConstructor; |
| 611 name: '[[JavaScript Constructor]]', | 756 |
| 612 value: JSNative.getProperty(entry.object, 'constructor'), | 757 // TODO(bmilligan): Display the signature of the named constructor as the |
| 613 config: JsonMLConfig.skipDart)); | 758 // preview. |
| 614 // TODO(jacobr): add constructors, methods, extended class, and static | 759 String preview(object) => 'Named Constructor'; |
| 615 } | 760 |
| 616 return ret; | 761 bool hasChildren(object) => true; |
| 617 } | 762 |
| 763 List<NameValuePair> children(object) => <NameValuePair>[ | |
| 764 new NameValuePair( | |
| 765 name: 'JavaScript Function', | |
| 766 value: object, | |
| 767 config: JsonMLConfig.skipDart) | |
| 768 ]; | |
| 618 } | 769 } |
| 619 | 770 |
| 620 /// Formatter for synthetic MapEntry objects used to display contents of a Map | 771 /// Formatter for synthetic MapEntry objects used to display contents of a Map |
| 621 /// cleanly. | 772 /// cleanly. |
| 622 class MapEntryFormatter implements Formatter { | 773 class MapEntryFormatter implements Formatter { |
| 623 accept(object) => object is MapEntry; | 774 accept(object) => object is MapEntry; |
| 624 | 775 |
| 625 String preview(object) { | 776 String preview(object) { |
| 626 MapEntry entry = object; | 777 MapEntry entry = object; |
| 627 return '${safePreview(entry.key)} => ${safePreview(entry.value)}'; | 778 return '${safePreview(entry.key)} => ${safePreview(entry.value)}'; |
| 628 } | 779 } |
| 629 | 780 |
| 630 bool hasChildren(object) => true; | 781 bool hasChildren(object) => true; |
| 631 | 782 |
| 632 List<NameValuePair> children(object) => <NameValuePair>[ | 783 List<NameValuePair> children(object) => <NameValuePair>[ |
| 633 new NameValuePair( | 784 new NameValuePair( |
| 634 name: 'key', value: object.key, config: JsonMLConfig.keyToString), | 785 name: 'key', value: object.key, config: JsonMLConfig.keyToString), |
| 635 new NameValuePair(name: 'value', value: object.value) | 786 new NameValuePair(name: 'value', value: object.value) |
| 636 ]; | 787 ]; |
| 637 } | 788 } |
| 638 | 789 |
| 639 /// Formatter for Dart Iterable objects including List and Set. | 790 /// Formatter for Dart Iterable objects including List and Set. |
| 640 class HeritageClauseFormatter implements Formatter { | 791 class HeritageClauseFormatter implements Formatter { |
| 641 bool accept(object) => object is HeritageClause; | 792 bool accept(object) => object is HeritageClause; |
| 642 | 793 |
| 643 String preview(object) { | 794 String preview(object) { |
| 644 HeritageClause clause = object; | 795 HeritageClause clause = object; |
| 645 var typeNames = clause.types.map((type) => getTypeName(type)); | 796 var typeNames = clause.types.map(getTypeName); |
| 646 return '${clause.name} ${typeNames.join(", ")}'; | 797 return '${clause.name} ${typeNames.join(", ")}'; |
| 647 } | 798 } |
| 648 | 799 |
| 649 bool hasChildren(object) => true; | 800 bool hasChildren(object) => true; |
| 650 | 801 |
| 651 List<NameValuePair> children(object) { | 802 List<NameValuePair> children(object) { |
| 652 HeritageClause clause = object; | 803 HeritageClause clause = object; |
| 653 var ret = <NameValuePair>[]; | 804 var children = <NameValuePair>[]; |
| 654 for (var type in clause.types) { | 805 for (var type in clause.types) { |
| 655 ret.add(new NameValuePair(value: new ClassMetadata(type))); | 806 children.add(new NameValuePair(value: new ClassMetadata(type))); |
| 656 } | 807 } |
| 657 return ret; | 808 return children; |
| 658 } | 809 } |
| 659 } | 810 } |
| 660 | 811 |
| 661 /// Formatter for synthetic IterableSpan objects used to display contents of | 812 /// Formatter for synthetic IterableSpan objects used to display contents of |
| 662 /// an Iterable cleanly. | 813 /// an Iterable cleanly. |
| 663 class IterableSpanFormatter implements Formatter { | 814 class IterableSpanFormatter implements Formatter { |
| 664 accept(object) => object is IterableSpan; | 815 accept(object) => object is IterableSpan; |
| 665 | 816 |
| 666 String preview(object) { | 817 String preview(object) { |
| 667 return '[${object.start}...${object.end-1}]'; | 818 return '[${object.start}...${object.end-1}]'; |
| 668 } | 819 } |
| 669 | 820 |
| 670 bool hasChildren(object) => true; | 821 bool hasChildren(object) => true; |
| 671 | 822 |
| 672 List<NameValuePair> children(object) => object.children(); | 823 List<NameValuePair> children(object) => object.children(); |
| 673 } | 824 } |
| 674 | 825 |
| 675 /// This entry point is automatically invoked by the code generated by | 826 /// This entry point is automatically invoked by the code generated by |
| 676 /// Dart Dev Compiler | 827 /// Dart Dev Compiler |
| 677 registerDevtoolsFormatter() { | 828 registerDevtoolsFormatter() { |
| 678 var formatters = [_devtoolsFormatter]; | 829 var formatters = [_devtoolsFormatter]; |
| 679 JS('', 'dart.global.devtoolsFormatters = #', formatters); | 830 JS('', 'dart.global.devtoolsFormatters = #', formatters); |
| 680 } | 831 } |
| OLD | NEW |