| OLD | NEW | 
|---|
|  | (Empty) | 
| 1 // Copyright (c) 2013, the Dart project authors.  Please see the AUTHORS file |  | 
| 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. |  | 
| 4 |  | 
| 5 library service_ref_element; |  | 
| 6 |  | 
| 7 import 'dart:html'; |  | 
| 8 |  | 
| 9 import 'package:logging/logging.dart'; |  | 
| 10 import 'package:observatory/service.dart'; |  | 
| 11 import 'package:observatory/repositories.dart'; |  | 
| 12 import 'package:polymer/polymer.dart'; |  | 
| 13 |  | 
| 14 import 'helpers/any_ref.dart'; |  | 
| 15 import 'observatory_element.dart'; |  | 
| 16 |  | 
| 17 class ServiceRefElement extends ObservatoryElement { |  | 
| 18   @published ServiceObject ref; |  | 
| 19   @published bool internal = false; |  | 
| 20   @published String expandKey; |  | 
| 21   ServiceRefElement.created() : super.created(); |  | 
| 22 |  | 
| 23   void refChanged(oldValue) { |  | 
| 24     notifyPropertyChange(#url, "", url); |  | 
| 25     notifyPropertyChange(#name, [], name); |  | 
| 26     notifyPropertyChange(#nameIsEmpty, 0, 1); |  | 
| 27     notifyPropertyChange(#hoverText, "", hoverText); |  | 
| 28   } |  | 
| 29 |  | 
| 30   String get url { |  | 
| 31     if (ref == null) { |  | 
| 32       return 'NULL REF'; |  | 
| 33     } |  | 
| 34     return gotoLink('/inspect', ref); |  | 
| 35   } |  | 
| 36 |  | 
| 37   String get serviceId { |  | 
| 38     if (ref == null) { |  | 
| 39       return 'NULL REF'; |  | 
| 40     } |  | 
| 41     return ref.id; |  | 
| 42   } |  | 
| 43 |  | 
| 44   String get hoverText { |  | 
| 45     if (ref == null) { |  | 
| 46       return 'NULL REF'; |  | 
| 47     } |  | 
| 48     return ref.vmName; |  | 
| 49   } |  | 
| 50 |  | 
| 51   String get name { |  | 
| 52     if (ref == null) { |  | 
| 53       return 'NULL REF'; |  | 
| 54     } |  | 
| 55     return ref.name; |  | 
| 56   } |  | 
| 57 |  | 
| 58   // Workaround isEmpty not being useable due to missing @MirrorsUsed. |  | 
| 59   bool get nameIsEmpty { |  | 
| 60     return (name == null) || name.isEmpty; |  | 
| 61   } |  | 
| 62 |  | 
| 63 |  | 
| 64   @published bool expanded = false; |  | 
| 65   dynamic expander() { |  | 
| 66     return expandEvent; |  | 
| 67   } |  | 
| 68   void expandEvent(bool expand, Function onDone) { |  | 
| 69     if (expand) { |  | 
| 70       ref.reload().then((result) { |  | 
| 71         ref = result; |  | 
| 72         notifyPropertyChange(#ref, 0, 1); |  | 
| 73         expanded = true; |  | 
| 74       }).whenComplete(onDone); |  | 
| 75     } else { |  | 
| 76       expanded = false; |  | 
| 77       onDone(); |  | 
| 78     } |  | 
| 79   } |  | 
| 80 } |  | 
| 81 |  | 
| 82 |  | 
| 83 @CustomTag('any-service-ref') |  | 
| 84 class AnyServiceRefElement extends ObservatoryElement { |  | 
| 85   @published ServiceObject ref; |  | 
| 86   @published String expandKey; |  | 
| 87   @published bool asValue = false; |  | 
| 88   AnyServiceRefElement.created() : super.created(); |  | 
| 89 |  | 
| 90   refChanged(oldValue) { |  | 
| 91     // Remove the current view. |  | 
| 92     children.clear(); |  | 
| 93     if (ref == null) { |  | 
| 94       Logger.root.info('Viewing null object.'); |  | 
| 95       return; |  | 
| 96     } |  | 
| 97     var obj; |  | 
| 98     if (ref is Guarded) { |  | 
| 99       var g = ref as Guarded; |  | 
| 100       obj = g.asValue ?? g.asSentinel; |  | 
| 101     } else { |  | 
| 102       obj = ref; |  | 
| 103     } |  | 
| 104     var element; |  | 
| 105     switch (obj.type) { |  | 
| 106       case 'Class': |  | 
| 107         if (asValue) { |  | 
| 108           element = new Element.tag('class-ref-as-value'); |  | 
| 109           element.ref = obj; |  | 
| 110         } else { |  | 
| 111           element = new Element.tag('class-ref'); |  | 
| 112           element.ref = obj; |  | 
| 113         } |  | 
| 114         break; |  | 
| 115       case 'Code': |  | 
| 116         element = new Element.tag('code-ref'); |  | 
| 117         element.ref = obj; |  | 
| 118         break; |  | 
| 119       case 'Context': |  | 
| 120         element = new Element.tag('context-ref'); |  | 
| 121         element.ref = obj; |  | 
| 122         break; |  | 
| 123       case 'Error': |  | 
| 124         element = new Element.tag('error-ref'); |  | 
| 125         element.ref = obj; |  | 
| 126         break; |  | 
| 127       case 'Field': |  | 
| 128         element = new Element.tag('field-ref'); |  | 
| 129         element.ref = obj; |  | 
| 130         break; |  | 
| 131       case 'Function': |  | 
| 132         element = new Element.tag('function-ref'); |  | 
| 133         element.ref = obj; |  | 
| 134         break; |  | 
| 135       case 'Instance': |  | 
| 136         element = new Element.tag('instance-ref'); |  | 
| 137         element.ref = obj; |  | 
| 138         break; |  | 
| 139       case 'Library': |  | 
| 140         if (asValue) { |  | 
| 141           element = |  | 
| 142               new Element.tag('library-ref-as-value'); |  | 
| 143           element.ref = obj; |  | 
| 144         } else { |  | 
| 145           element = |  | 
| 146               new Element.tag('library-ref'); |  | 
| 147           element.ref = obj; |  | 
| 148         } |  | 
| 149         break; |  | 
| 150       case 'Script': |  | 
| 151         element = new Element.tag('script-ref'); |  | 
| 152         element.ref = obj; |  | 
| 153         break; |  | 
| 154       default: |  | 
| 155         element = anyRef(obj.isolate, obj, |  | 
| 156             new InstanceRepository(), queue: app.queue); |  | 
| 157         break; |  | 
| 158     } |  | 
| 159     if (element == null) { |  | 
| 160       Logger.root.info('Unable to find a ref element for \'${ref.type}\''); |  | 
| 161       element = new Element.tag('span'); |  | 
| 162       element.text = "<<Unknown service ref: $ref>>"; |  | 
| 163       return; |  | 
| 164     } |  | 
| 165     children.add(element); |  | 
| 166   } |  | 
| 167 } |  | 
| OLD | NEW | 
|---|