| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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 import 'dart:html'; | 5 import 'dart:html'; |
| 6 import 'dart:async'; | 6 import 'dart:async'; |
| 7 import 'package:observatory/models.dart' as M; | 7 import 'package:observatory/models.dart' as M; |
| 8 import 'package:observatory/src/elements/curly_block.dart'; | 8 import 'package:observatory/src/elements/curly_block.dart'; |
| 9 import 'package:observatory/src/elements/field_ref.dart'; | 9 import 'package:observatory/src/elements/field_ref.dart'; |
| 10 import 'package:observatory/src/elements/helpers/any_ref.dart'; | 10 import 'package:observatory/src/elements/helpers/any_ref.dart'; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 M.IsolateRef _isolate; | 24 M.IsolateRef _isolate; |
| 25 M.InstanceRef _instance; | 25 M.InstanceRef _instance; |
| 26 M.InstanceRepository _instances; | 26 M.InstanceRepository _instances; |
| 27 M.Instance _loadedInstance; | 27 M.Instance _loadedInstance; |
| 28 bool _expanded = false; | 28 bool _expanded = false; |
| 29 | 29 |
| 30 M.IsolateRef get isolate => _isolate; | 30 M.IsolateRef get isolate => _isolate; |
| 31 M.InstanceRef get instance => _instance; | 31 M.InstanceRef get instance => _instance; |
| 32 | 32 |
| 33 factory InstanceRefElement(M.IsolateRef isolate, M.InstanceRef instance, | 33 factory InstanceRefElement(M.IsolateRef isolate, M.InstanceRef instance, |
| 34 M.InstanceRepository instances, {RenderingQueue queue}) { | 34 M.InstanceRepository instances, |
| 35 {RenderingQueue queue}) { |
| 35 assert(isolate != null); | 36 assert(isolate != null); |
| 36 assert(instance != null); | 37 assert(instance != null); |
| 37 assert(instances != null); | 38 assert(instances != null); |
| 38 InstanceRefElement e = document.createElement(tag.name); | 39 InstanceRefElement e = document.createElement(tag.name); |
| 39 e._r = new RenderingScheduler(e, queue: queue); | 40 e._r = new RenderingScheduler(e, queue: queue); |
| 40 e._isolate = isolate; | 41 e._isolate = isolate; |
| 41 e._instance = instance; | 42 e._instance = instance; |
| 42 e._instances = instances; | 43 e._instances = instances; |
| 43 return e; | 44 return e; |
| 44 } | 45 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 59 } | 60 } |
| 60 | 61 |
| 61 void render() { | 62 void render() { |
| 62 final content = _createLink(); | 63 final content = _createLink(); |
| 63 | 64 |
| 64 if (_hasValue()) { | 65 if (_hasValue()) { |
| 65 content.addAll([ | 66 content.addAll([ |
| 66 new SpanElement()..text = ' ', | 67 new SpanElement()..text = ' ', |
| 67 new CurlyBlockElement(expanded: _expanded, queue: _r.queue) | 68 new CurlyBlockElement(expanded: _expanded, queue: _r.queue) |
| 68 ..content = [ | 69 ..content = [ |
| 69 new DivElement()..classes = ['indent'] | 70 new DivElement() |
| 71 ..classes = ['indent'] |
| 70 ..children = _createValue() | 72 ..children = _createValue() |
| 71 ] | 73 ] |
| 72 ..onToggle.listen((e) async { | 74 ..onToggle.listen((e) async { |
| 73 _expanded = e.control.expanded; | 75 _expanded = e.control.expanded; |
| 74 if (_expanded) { | 76 if (_expanded) { |
| 75 e.control.disabled = true; | 77 e.control.disabled = true; |
| 76 await _refresh(); | 78 await _refresh(); |
| 77 e.control.disabled = false; | 79 e.control.disabled = false; |
| 78 } | 80 } |
| 79 }) | 81 }) |
| 80 ]); | 82 ]); |
| 81 } | 83 } |
| 82 | 84 |
| 83 children = content; | 85 children = content; |
| 84 } | 86 } |
| 85 | 87 |
| 86 Future _refresh() async { | 88 Future _refresh() async { |
| 87 _loadedInstance = await _instances.get(_isolate, _instance.id); | 89 _loadedInstance = await _instances.get(_isolate, _instance.id); |
| 88 _r.dirty(); | 90 _r.dirty(); |
| 89 } | 91 } |
| 90 | 92 |
| 91 List<Element> _createShowMoreButton() { | 93 List<Element> _createShowMoreButton() { |
| 92 if (_loadedInstance.count == null) { | 94 if (_loadedInstance.count == null) { |
| 93 return []; | 95 return []; |
| 94 } | 96 } |
| 95 final count = _loadedInstance.count; | 97 final count = _loadedInstance.count; |
| 96 final button = new ButtonElement() | 98 final button = new ButtonElement()..text = 'show next ${count}'; |
| 97 ..text = 'show next ${count}'; | |
| 98 button.onClick.listen((_) async { | 99 button.onClick.listen((_) async { |
| 99 button.disabled = true; | 100 button.disabled = true; |
| 100 _loadedInstance = await _instances.get(_isolate, _instance.id, | 101 _loadedInstance = |
| 101 count: count * 2); | 102 await _instances.get(_isolate, _instance.id, count: count * 2); |
| 102 _r.dirty(); | 103 _r.dirty(); |
| 103 }); | 104 }); |
| 104 return [button]; | 105 return [button]; |
| 105 } | 106 } |
| 106 | 107 |
| 107 List<Element> _createLink() { | 108 List<Element> _createLink() { |
| 108 switch (_instance.kind) { | 109 switch (_instance.kind) { |
| 109 case M.InstanceKind.vNull: | 110 case M.InstanceKind.vNull: |
| 110 case M.InstanceKind.bool: | 111 case M.InstanceKind.bool: |
| 111 case M.InstanceKind.int: | 112 case M.InstanceKind.int: |
| 112 case M.InstanceKind.double: | 113 case M.InstanceKind.double: |
| 113 case M.InstanceKind.float32x4: | 114 case M.InstanceKind.float32x4: |
| 114 case M.InstanceKind.float64x2: | 115 case M.InstanceKind.float64x2: |
| 115 case M.InstanceKind.int32x4: | 116 case M.InstanceKind.int32x4: |
| 116 return [ | 117 return [ |
| 117 new AnchorElement(href: Uris.inspect(_isolate, object: _instance)) | 118 new AnchorElement(href: Uris.inspect(_isolate, object: _instance)) |
| 118 ..text = _instance.valueAsString | 119 ..text = _instance.valueAsString |
| 119 ]; | 120 ]; |
| 120 case M.InstanceKind.string: | 121 case M.InstanceKind.string: |
| 121 return [ | 122 return [ |
| 122 new AnchorElement(href: Uris.inspect(_isolate, object: _instance)) | 123 new AnchorElement(href: Uris.inspect(_isolate, object: _instance)) |
| 123 ..text = Utils.formatStringAsLiteral(_instance.valueAsString, | 124 ..text = Utils.formatStringAsLiteral( |
| 124 _instance.valueAsStringIsTruncated) | 125 _instance.valueAsString, _instance.valueAsStringIsTruncated) |
| 125 ]; | 126 ]; |
| 126 case M.InstanceKind.type: | 127 case M.InstanceKind.type: |
| 127 case M.InstanceKind.typeRef: | 128 case M.InstanceKind.typeRef: |
| 128 case M.InstanceKind.typeParameter: | 129 case M.InstanceKind.typeParameter: |
| 129 case M.InstanceKind.boundedType: | 130 case M.InstanceKind.boundedType: |
| 130 return [ | 131 return [ |
| 131 new AnchorElement(href: Uris.inspect(_isolate, object: _instance)) | 132 new AnchorElement(href: Uris.inspect(_isolate, object: _instance)) |
| 132 ..text = _instance.name | 133 ..text = _instance.name |
| 133 ]; | 134 ]; |
| 134 case M.InstanceKind.closure: | 135 case M.InstanceKind.closure: |
| 135 return [ | 136 return [ |
| 136 new AnchorElement(href: Uris.inspect(_isolate, object: _instance)) | 137 new AnchorElement(href: Uris.inspect(_isolate, object: _instance)) |
| 137 ..children = [ | 138 ..children = [ |
| 138 new SpanElement()..classes = ['emphasize'] | 139 new SpanElement() |
| 140 ..classes = ['emphasize'] |
| 139 ..text = 'Closure', | 141 ..text = 'Closure', |
| 140 new SpanElement()..text = _instance.closureFunction.name | 142 new SpanElement()..text = _instance.closureFunction.name |
| 141 ] | 143 ] |
| 142 ]; | 144 ]; |
| 143 case M.InstanceKind.regExp: | 145 case M.InstanceKind.regExp: |
| 144 return [ | 146 return [ |
| 145 new AnchorElement(href: Uris.inspect(_isolate, object: _instance)) | 147 new AnchorElement(href: Uris.inspect(_isolate, object: _instance)) |
| 146 ..children = [ | 148 ..children = [ |
| 147 new SpanElement()..classes = ['emphasize'] | 149 new SpanElement() |
| 150 ..classes = ['emphasize'] |
| 148 ..text = _instance.clazz.name, | 151 ..text = _instance.clazz.name, |
| 149 new SpanElement()..text = _instance.pattern.name | 152 new SpanElement()..text = _instance.pattern.name |
| 150 ] | 153 ] |
| 151 ]; | 154 ]; |
| 152 case M.InstanceKind.stackTrace: | 155 case M.InstanceKind.stackTrace: |
| 153 return [ | 156 return [ |
| 154 new AnchorElement(href: Uris.inspect(_isolate, object: _instance)) | 157 new AnchorElement(href: Uris.inspect(_isolate, object: _instance)) |
| 155 ..text = _instance.clazz.name, | 158 ..text = _instance.clazz.name, |
| 156 new CurlyBlockElement(queue: _r.queue) | 159 new CurlyBlockElement(queue: _r.queue) |
| 157 ..content = [ | 160 ..content = [ |
| 158 new DivElement()..classes = ['stackTraceBox'] | 161 new DivElement() |
| 162 ..classes = ['stackTraceBox'] |
| 159 ..text = _instance.valueAsString | 163 ..text = _instance.valueAsString |
| 160 ] | 164 ] |
| 161 ]; | 165 ]; |
| 162 case M.InstanceKind.plainInstance: | 166 case M.InstanceKind.plainInstance: |
| 163 return [ | 167 return [ |
| 164 new AnchorElement(href: Uris.inspect(_isolate, object: _instance)) | 168 new AnchorElement(href: Uris.inspect(_isolate, object: _instance)) |
| 165 ..classes = ['emphasize'] | 169 ..classes = ['emphasize'] |
| 166 ..text = _instance.clazz.name | 170 ..text = _instance.clazz.name |
| 167 ]; | 171 ]; |
| 168 case M.InstanceKind.list: | 172 case M.InstanceKind.list: |
| 169 case M.InstanceKind.map: | 173 case M.InstanceKind.map: |
| 170 case M.InstanceKind.uint8ClampedList: | 174 case M.InstanceKind.uint8ClampedList: |
| 171 case M.InstanceKind.uint8List: | 175 case M.InstanceKind.uint8List: |
| 172 case M.InstanceKind.uint16List: | 176 case M.InstanceKind.uint16List: |
| 173 case M.InstanceKind.uint32List: | 177 case M.InstanceKind.uint32List: |
| 174 case M.InstanceKind.uint64List: | 178 case M.InstanceKind.uint64List: |
| 175 case M.InstanceKind.int8List: | 179 case M.InstanceKind.int8List: |
| 176 case M.InstanceKind.int16List: | 180 case M.InstanceKind.int16List: |
| 177 case M.InstanceKind.int32List: | 181 case M.InstanceKind.int32List: |
| 178 case M.InstanceKind.int64List: | 182 case M.InstanceKind.int64List: |
| 179 case M.InstanceKind.float32List: | 183 case M.InstanceKind.float32List: |
| 180 case M.InstanceKind.float64List: | 184 case M.InstanceKind.float64List: |
| 181 case M.InstanceKind.int32x4List: | 185 case M.InstanceKind.int32x4List: |
| 182 case M.InstanceKind.float32x4List: | 186 case M.InstanceKind.float32x4List: |
| 183 case M.InstanceKind.float64x2List: | 187 case M.InstanceKind.float64x2List: |
| 184 return [ | 188 return [ |
| 185 new AnchorElement(href: Uris.inspect(_isolate, object: _instance)) | 189 new AnchorElement(href: Uris.inspect(_isolate, object: _instance)) |
| 186 ..children = [ | 190 ..children = [ |
| 187 new SpanElement()..classes = ['emphasize'] | 191 new SpanElement() |
| 192 ..classes = ['emphasize'] |
| 188 ..text = _instance.clazz.name, | 193 ..text = _instance.clazz.name, |
| 189 new SpanElement()..text = ' (${_instance.length})' | 194 new SpanElement()..text = ' (${_instance.length})' |
| 190 ] | 195 ] |
| 191 ]; | 196 ]; |
| 192 case M.InstanceKind.mirrorReference: | 197 case M.InstanceKind.mirrorReference: |
| 193 return [ | 198 return [ |
| 194 new AnchorElement(href: Uris.inspect(_isolate, object: _instance)) | 199 new AnchorElement(href: Uris.inspect(_isolate, object: _instance)) |
| 195 ..classes = ['emphasize'] | 200 ..classes = ['emphasize'] |
| 196 ..text = _instance.clazz.name | 201 ..text = _instance.clazz.name |
| 197 ]; | 202 ]; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 225 case M.InstanceKind.float32List: | 230 case M.InstanceKind.float32List: |
| 226 case M.InstanceKind.float64List: | 231 case M.InstanceKind.float64List: |
| 227 case M.InstanceKind.int32x4List: | 232 case M.InstanceKind.int32x4List: |
| 228 case M.InstanceKind.float32x4List: | 233 case M.InstanceKind.float32x4List: |
| 229 case M.InstanceKind.float64x2List: | 234 case M.InstanceKind.float64x2List: |
| 230 return _instance.length > 0; | 235 return _instance.length > 0; |
| 231 default: | 236 default: |
| 232 return false; | 237 return false; |
| 233 } | 238 } |
| 234 } | 239 } |
| 240 |
| 235 List<Element> _createValue() { | 241 List<Element> _createValue() { |
| 236 if (_loadedInstance == null) { | 242 if (_loadedInstance == null) { |
| 237 return [new SpanElement()..text = 'Loading...']; | 243 return [new SpanElement()..text = 'Loading...']; |
| 238 } | 244 } |
| 239 switch (_instance.kind) { | 245 switch (_instance.kind) { |
| 240 case M.InstanceKind.plainInstance: | 246 case M.InstanceKind.plainInstance: |
| 241 return _loadedInstance.fields.map((f) => | 247 return _loadedInstance.fields |
| 242 new DivElement() | 248 .map((f) => new DivElement() |
| 243 ..children = [ | 249 ..children = [ |
| 244 new FieldRefElement(_isolate, f.decl, _instances, | 250 new FieldRefElement(_isolate, f.decl, _instances, |
| 245 queue: _r.queue), | 251 queue: _r.queue), |
| 246 new SpanElement()..text = ' = ', | 252 new SpanElement()..text = ' = ', |
| 247 anyRef(_isolate, f.value, _instances, queue: _r.queue) | 253 anyRef(_isolate, f.value, _instances, queue: _r.queue) |
| 248 ]).toList(); | 254 ]) |
| 255 .toList(); |
| 249 case M.InstanceKind.list: | 256 case M.InstanceKind.list: |
| 250 var index = 0; | 257 var index = 0; |
| 251 return _loadedInstance.elements.map((element) => | 258 return _loadedInstance.elements |
| 252 new DivElement() | 259 .map((element) => new DivElement() |
| 253 ..children = [ | 260 ..children = [ |
| 254 new SpanElement()..text = '[ ${index++} ] : ', | 261 new SpanElement()..text = '[ ${index++} ] : ', |
| 255 anyRef(_isolate, element, _instances, queue: _r.queue) | 262 anyRef(_isolate, element, _instances, queue: _r.queue) |
| 256 ]).toList()..addAll(_createShowMoreButton()); | 263 ]) |
| 264 .toList()..addAll(_createShowMoreButton()); |
| 257 case M.InstanceKind.map: | 265 case M.InstanceKind.map: |
| 258 return _loadedInstance.associations.map((association) => | 266 return _loadedInstance.associations |
| 259 new DivElement() | 267 .map((association) => new DivElement() |
| 260 ..children = [ | 268 ..children = [ |
| 261 new SpanElement()..text = '[ ', | 269 new SpanElement()..text = '[ ', |
| 262 anyRef(_isolate, association.key, _instances, queue: _r.queue), | 270 anyRef(_isolate, association.key, _instances, queue: _r.queue), |
| 263 new SpanElement()..text = ' ] : ', | 271 new SpanElement()..text = ' ] : ', |
| 264 anyRef(_isolate, association.value, _instances, queue: _r.queue) | 272 anyRef(_isolate, association.value, _instances, queue: _r.queue) |
| 265 ]).toList()..addAll(_createShowMoreButton()); | 273 ]) |
| 274 .toList()..addAll(_createShowMoreButton()); |
| 266 case M.InstanceKind.uint8ClampedList: | 275 case M.InstanceKind.uint8ClampedList: |
| 267 case M.InstanceKind.uint8List: | 276 case M.InstanceKind.uint8List: |
| 268 case M.InstanceKind.uint16List: | 277 case M.InstanceKind.uint16List: |
| 269 case M.InstanceKind.uint32List: | 278 case M.InstanceKind.uint32List: |
| 270 case M.InstanceKind.uint64List: | 279 case M.InstanceKind.uint64List: |
| 271 case M.InstanceKind.int8List: | 280 case M.InstanceKind.int8List: |
| 272 case M.InstanceKind.int16List: | 281 case M.InstanceKind.int16List: |
| 273 case M.InstanceKind.int32List: | 282 case M.InstanceKind.int32List: |
| 274 case M.InstanceKind.int64List: | 283 case M.InstanceKind.int64List: |
| 275 case M.InstanceKind.float32List: | 284 case M.InstanceKind.float32List: |
| 276 case M.InstanceKind.float64List: | 285 case M.InstanceKind.float64List: |
| 277 case M.InstanceKind.int32x4List: | 286 case M.InstanceKind.int32x4List: |
| 278 case M.InstanceKind.float32x4List: | 287 case M.InstanceKind.float32x4List: |
| 279 case M.InstanceKind.float64x2List: | 288 case M.InstanceKind.float64x2List: |
| 280 var index = 0; | 289 var index = 0; |
| 281 return _loadedInstance.typedElements | 290 return _loadedInstance.typedElements |
| 282 .map((e) => new DivElement()..text = '[ ${index++} ] : $e') | 291 .map((e) => new DivElement()..text = '[ ${index++} ] : $e') |
| 283 .toList()..addAll(_createShowMoreButton()); | 292 .toList()..addAll(_createShowMoreButton()); |
| 284 case M.InstanceKind.mirrorReference: | 293 case M.InstanceKind.mirrorReference: |
| 285 return [ | 294 return [ |
| 286 new SpanElement()..text = '<referent> : ', | 295 new SpanElement()..text = '<referent> : ', |
| 287 new InstanceRefElement(_isolate, _loadedInstance.referent, _instances, | 296 new InstanceRefElement(_isolate, _loadedInstance.referent, _instances, |
| 288 queue: _r.queue) | 297 queue: _r.queue) |
| 289 ]; | 298 ]; |
| 290 case M.InstanceKind.weakProperty: | 299 case M.InstanceKind.weakProperty: |
| 291 return [ | 300 return [ |
| 292 new SpanElement()..text = '<key> : ', | 301 new SpanElement()..text = '<key> : ', |
| 293 new InstanceRefElement(_isolate, _loadedInstance.key, _instances, | 302 new InstanceRefElement(_isolate, _loadedInstance.key, _instances, |
| 294 queue: _r.queue), | 303 queue: _r.queue), |
| 295 new BRElement(), | 304 new BRElement(), |
| 296 new SpanElement()..text = '<value> : ', | 305 new SpanElement()..text = '<value> : ', |
| 297 new InstanceRefElement(_isolate, _loadedInstance.value, _instances, | 306 new InstanceRefElement(_isolate, _loadedInstance.value, _instances, |
| 298 queue: _r.queue), | 307 queue: _r.queue), |
| 299 ]; | 308 ]; |
| 300 default: | 309 default: |
| 301 return []; | 310 return []; |
| 302 } | 311 } |
| 303 } | 312 } |
| 304 } | 313 } |
| OLD | NEW |