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'; |
11 import 'package:observatory/src/elements/helpers/rendering_scheduler.dart'; | 11 import 'package:observatory/src/elements/helpers/rendering_scheduler.dart'; |
12 import 'package:observatory/src/elements/helpers/tag.dart'; | 12 import 'package:observatory/src/elements/helpers/tag.dart'; |
13 import 'package:observatory/src/elements/helpers/uris.dart'; | 13 import 'package:observatory/src/elements/helpers/uris.dart'; |
14 import 'package:observatory/utils.dart'; | 14 import 'package:observatory/utils.dart'; |
15 | 15 |
16 class InstanceRefElement extends HtmlElement implements Renderable { | 16 class InstanceRefElement extends HtmlElement implements Renderable { |
17 static const tag = const Tag<InstanceRefElement>('instance-ref'); | 17 static const tag = const Tag<InstanceRefElement>('instance-ref', |
| 18 dependencies: const [CurlyBlockElement.tag]); |
18 | 19 |
19 RenderingScheduler<InstanceRefElement> _r; | 20 RenderingScheduler<InstanceRefElement> _r; |
20 | 21 |
21 Stream<RenderedEvent<InstanceRefElement>> get onRendered => _r.onRendered; | 22 Stream<RenderedEvent<InstanceRefElement>> get onRendered => _r.onRendered; |
22 | 23 |
23 M.IsolateRef _isolate; | 24 M.IsolateRef _isolate; |
24 M.InstanceRef _instance; | 25 M.InstanceRef _instance; |
25 M.InstanceRepository _instances; | 26 M.ObjectRepository _objects; |
26 M.Instance _loadedInstance; | 27 M.Instance _loadedInstance; |
27 bool _expanded = false; | 28 bool _expanded = false; |
28 | 29 |
29 M.IsolateRef get isolate => _isolate; | 30 M.IsolateRef get isolate => _isolate; |
30 M.InstanceRef get instance => _instance; | 31 M.InstanceRef get instance => _instance; |
31 | 32 |
32 factory InstanceRefElement(M.IsolateRef isolate, M.InstanceRef instance, | 33 factory InstanceRefElement( |
33 M.InstanceRepository instances, | 34 M.IsolateRef isolate, M.InstanceRef instance, M.ObjectRepository objects, |
34 {RenderingQueue queue}) { | 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(objects != 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._objects = objects; |
43 return e; | 44 return e; |
44 } | 45 } |
45 | 46 |
46 InstanceRefElement.created() : super.created(); | 47 InstanceRefElement.created() : super.created(); |
47 | 48 |
48 @override | 49 @override |
49 void attached() { | 50 void attached() { |
50 super.attached(); | 51 super.attached(); |
51 _r.enable(); | 52 _r.enable(); |
52 } | 53 } |
(...skipping 25 matching lines...) Expand all Loading... |
78 e.control.disabled = false; | 79 e.control.disabled = false; |
79 } | 80 } |
80 }) | 81 }) |
81 ]); | 82 ]); |
82 } | 83 } |
83 | 84 |
84 children = content; | 85 children = content; |
85 } | 86 } |
86 | 87 |
87 Future _refresh() async { | 88 Future _refresh() async { |
88 _loadedInstance = await _instances.get(_isolate, _instance.id); | 89 _loadedInstance = await _objects.get(_isolate, _instance.id); |
89 _r.dirty(); | 90 _r.dirty(); |
90 } | 91 } |
91 | 92 |
92 List<Element> _createShowMoreButton() { | 93 List<Element> _createShowMoreButton() { |
93 if (_loadedInstance.count == null) { | 94 if (_loadedInstance.count == null) { |
94 return []; | 95 return []; |
95 } | 96 } |
96 final count = _loadedInstance.count; | 97 final count = _loadedInstance.count; |
97 final button = new ButtonElement()..text = 'show next ${count}'; | 98 final button = new ButtonElement()..text = 'show next ${count}'; |
98 button.onClick.listen((_) async { | 99 button.onClick.listen((_) async { |
99 button.disabled = true; | 100 button.disabled = true; |
100 _loadedInstance = | 101 _loadedInstance = |
101 await _instances.get(_isolate, _instance.id, count: count * 2); | 102 await _objects.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: |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 new AnchorElement(href: Uris.inspect(_isolate, object: _instance)) | 203 new AnchorElement(href: Uris.inspect(_isolate, object: _instance)) |
203 ..classes = ['emphasize'] | 204 ..classes = ['emphasize'] |
204 ..text = _instance.clazz.name | 205 ..text = _instance.clazz.name |
205 ]; | 206 ]; |
206 } | 207 } |
207 throw new Exception('Unknown InstanceKind: ${_instance.kind}'); | 208 throw new Exception('Unknown InstanceKind: ${_instance.kind}'); |
208 } | 209 } |
209 | 210 |
210 bool _hasValue() { | 211 bool _hasValue() { |
211 switch (_instance.kind) { | 212 switch (_instance.kind) { |
| 213 case M.InstanceKind.closure: |
212 case M.InstanceKind.plainInstance: | 214 case M.InstanceKind.plainInstance: |
213 case M.InstanceKind.mirrorReference: | 215 case M.InstanceKind.mirrorReference: |
214 case M.InstanceKind.stackTrace: | 216 case M.InstanceKind.stackTrace: |
215 case M.InstanceKind.weakProperty: | 217 case M.InstanceKind.weakProperty: |
216 return true; | 218 return true; |
217 case M.InstanceKind.list: | 219 case M.InstanceKind.list: |
218 case M.InstanceKind.map: | 220 case M.InstanceKind.map: |
219 case M.InstanceKind.uint8ClampedList: | 221 case M.InstanceKind.uint8ClampedList: |
220 case M.InstanceKind.uint8List: | 222 case M.InstanceKind.uint8List: |
221 case M.InstanceKind.uint16List: | 223 case M.InstanceKind.uint16List: |
(...skipping 12 matching lines...) Expand all Loading... |
234 default: | 236 default: |
235 return false; | 237 return false; |
236 } | 238 } |
237 } | 239 } |
238 | 240 |
239 List<Element> _createValue() { | 241 List<Element> _createValue() { |
240 if (_loadedInstance == null) { | 242 if (_loadedInstance == null) { |
241 return [new SpanElement()..text = 'Loading...']; | 243 return [new SpanElement()..text = 'Loading...']; |
242 } | 244 } |
243 switch (_instance.kind) { | 245 switch (_instance.kind) { |
| 246 case M.InstanceKind.closure: |
| 247 return [ |
| 248 new DivElement() |
| 249 ..children = [ |
| 250 new SpanElement()..text = 'function = ', |
| 251 anyRef(_isolate, _loadedInstance.closureFunction, _objects, |
| 252 queue: _r.queue) |
| 253 ], |
| 254 new DivElement() |
| 255 ..children = [ |
| 256 new SpanElement()..text = 'context = ', |
| 257 anyRef(_isolate, _loadedInstance.closureContext, _objects, |
| 258 queue: _r.queue) |
| 259 ], |
| 260 ]; |
244 case M.InstanceKind.plainInstance: | 261 case M.InstanceKind.plainInstance: |
245 return _loadedInstance.fields | 262 return _loadedInstance.fields |
246 .map((f) => new DivElement() | 263 .map((f) => new DivElement() |
247 ..children = [ | 264 ..children = [ |
248 new FieldRefElement(_isolate, f.decl, _instances, | 265 new FieldRefElement(_isolate, f.decl, _objects, |
249 queue: _r.queue), | 266 queue: _r.queue), |
250 new SpanElement()..text = ' = ', | 267 new SpanElement()..text = ' = ', |
251 anyRef(_isolate, f.value, _instances, queue: _r.queue) | 268 anyRef(_isolate, f.value, _objects, queue: _r.queue) |
252 ]) | 269 ]) |
253 .toList(); | 270 .toList(); |
254 case M.InstanceKind.list: | 271 case M.InstanceKind.list: |
255 var index = 0; | 272 var index = 0; |
256 return _loadedInstance.elements | 273 return _loadedInstance.elements |
257 .map((element) => new DivElement() | 274 .map((element) => new DivElement() |
258 ..children = [ | 275 ..children = [ |
259 new SpanElement()..text = '[ ${index++} ] : ', | 276 new SpanElement()..text = '[ ${index++} ] : ', |
260 anyRef(_isolate, element, _instances, queue: _r.queue) | 277 anyRef(_isolate, element, _objects, queue: _r.queue) |
261 ]) | 278 ]) |
262 .toList() | 279 .toList() |
263 ..addAll(_createShowMoreButton()); | 280 ..addAll(_createShowMoreButton()); |
264 case M.InstanceKind.map: | 281 case M.InstanceKind.map: |
265 return _loadedInstance.associations | 282 return _loadedInstance.associations |
266 .map((association) => new DivElement() | 283 .map((association) => new DivElement() |
267 ..children = [ | 284 ..children = [ |
268 new SpanElement()..text = '[ ', | 285 new SpanElement()..text = '[ ', |
269 anyRef(_isolate, association.key, _instances, queue: _r.queue), | 286 anyRef(_isolate, association.key, _objects, queue: _r.queue), |
270 new SpanElement()..text = ' ] : ', | 287 new SpanElement()..text = ' ] : ', |
271 anyRef(_isolate, association.value, _instances, queue: _r.queue) | 288 anyRef(_isolate, association.value, _objects, queue: _r.queue) |
272 ]) | 289 ]) |
273 .toList() | 290 .toList() |
274 ..addAll(_createShowMoreButton()); | 291 ..addAll(_createShowMoreButton()); |
275 case M.InstanceKind.uint8ClampedList: | 292 case M.InstanceKind.uint8ClampedList: |
276 case M.InstanceKind.uint8List: | 293 case M.InstanceKind.uint8List: |
277 case M.InstanceKind.uint16List: | 294 case M.InstanceKind.uint16List: |
278 case M.InstanceKind.uint32List: | 295 case M.InstanceKind.uint32List: |
279 case M.InstanceKind.uint64List: | 296 case M.InstanceKind.uint64List: |
280 case M.InstanceKind.int8List: | 297 case M.InstanceKind.int8List: |
281 case M.InstanceKind.int16List: | 298 case M.InstanceKind.int16List: |
282 case M.InstanceKind.int32List: | 299 case M.InstanceKind.int32List: |
283 case M.InstanceKind.int64List: | 300 case M.InstanceKind.int64List: |
284 case M.InstanceKind.float32List: | 301 case M.InstanceKind.float32List: |
285 case M.InstanceKind.float64List: | 302 case M.InstanceKind.float64List: |
286 case M.InstanceKind.int32x4List: | 303 case M.InstanceKind.int32x4List: |
287 case M.InstanceKind.float32x4List: | 304 case M.InstanceKind.float32x4List: |
288 case M.InstanceKind.float64x2List: | 305 case M.InstanceKind.float64x2List: |
289 var index = 0; | 306 var index = 0; |
290 return _loadedInstance.typedElements | 307 return _loadedInstance.typedElements |
291 .map((e) => new DivElement()..text = '[ ${index++} ] : $e') | 308 .map((e) => new DivElement()..text = '[ ${index++} ] : $e') |
292 .toList() | 309 .toList() |
293 ..addAll(_createShowMoreButton()); | 310 ..addAll(_createShowMoreButton()); |
294 case M.InstanceKind.mirrorReference: | 311 case M.InstanceKind.mirrorReference: |
295 return [ | 312 return [ |
296 new SpanElement()..text = '<referent> : ', | 313 new SpanElement()..text = '<referent> : ', |
297 new InstanceRefElement(_isolate, _loadedInstance.referent, _instances, | 314 anyRef(_isolate, _loadedInstance.referent, _objects, queue: _r.queue) |
298 queue: _r.queue) | |
299 ]; | 315 ]; |
300 case M.InstanceKind.stackTrace: | 316 case M.InstanceKind.stackTrace: |
301 return [ | 317 return [ |
302 new DivElement() | 318 new DivElement() |
303 ..classes = ['stackTraceBox'] | 319 ..classes = ['stackTraceBox'] |
304 ..text = _instance.valueAsString | 320 ..text = _instance.valueAsString |
305 ]; | 321 ]; |
306 case M.InstanceKind.weakProperty: | 322 case M.InstanceKind.weakProperty: |
307 return [ | 323 return [ |
308 new SpanElement()..text = '<key> : ', | 324 new SpanElement()..text = '<key> : ', |
309 new InstanceRefElement(_isolate, _loadedInstance.key, _instances, | 325 new InstanceRefElement(_isolate, _loadedInstance.key, _objects, |
310 queue: _r.queue), | 326 queue: _r.queue), |
311 new BRElement(), | 327 new BRElement(), |
312 new SpanElement()..text = '<value> : ', | 328 new SpanElement()..text = '<value> : ', |
313 new InstanceRefElement(_isolate, _loadedInstance.value, _instances, | 329 new InstanceRefElement(_isolate, _loadedInstance.value, _objects, |
314 queue: _r.queue), | 330 queue: _r.queue), |
315 ]; | 331 ]; |
316 default: | 332 default: |
317 return []; | 333 return []; |
318 } | 334 } |
319 } | 335 } |
320 } | 336 } |
OLD | NEW |