| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2016, 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 import 'dart:html'; |
| 6 import 'dart:async'; |
| 7 import 'package:observatory/models.dart' as M; |
| 8 import 'package:observatory/src/elements/function_ref.dart'; |
| 9 import 'package:observatory/src/elements/helpers/rendering_scheduler.dart'; |
| 10 import 'package:observatory/src/elements/helpers/tag.dart'; |
| 11 import 'package:observatory/src/elements/source_link.dart'; |
| 12 |
| 13 class IsolateLocationElement extends HtmlElement implements Renderable { |
| 14 static const tag = const Tag<IsolateLocationElement>('isolate-location', |
| 15 dependencies: const [ |
| 16 FunctionRefElement.tag, |
| 17 SourceLinkElement.tag |
| 18 ]); |
| 19 |
| 20 RenderingScheduler<IsolateLocationElement> _r; |
| 21 |
| 22 Stream<RenderedEvent<IsolateLocationElement>> get onRendered => |
| 23 _r.onRendered; |
| 24 |
| 25 M.Isolate _isolate; |
| 26 M.EventRepository _events; |
| 27 M.ScriptRepository _scripts; |
| 28 StreamSubscription _debugSubscription; |
| 29 StreamSubscription _isolateSubscription; |
| 30 |
| 31 factory IsolateLocationElement(M.Isolate isolate, |
| 32 M.EventRepository events, |
| 33 M.ScriptRepository scripts, |
| 34 {RenderingQueue queue}) { |
| 35 assert(isolate != null); |
| 36 assert(events != null); |
| 37 assert(scripts != null); |
| 38 IsolateLocationElement e = document.createElement(tag.name); |
| 39 e._r = new RenderingScheduler(e, queue: queue); |
| 40 e._isolate = isolate; |
| 41 e._events = events; |
| 42 e._scripts = scripts; |
| 43 return e; |
| 44 } |
| 45 |
| 46 IsolateLocationElement.created() : super.created(); |
| 47 |
| 48 @override |
| 49 void attached() { |
| 50 super.attached(); |
| 51 _r.enable(); |
| 52 _debugSubscription = _events.onDebugEvent.listen(_eventListener); |
| 53 _isolateSubscription = _events.onIsolateEvent.listen(_eventListener); |
| 54 } |
| 55 |
| 56 @override |
| 57 void detached() { |
| 58 super.detached(); |
| 59 children = []; |
| 60 _r.disable(notify: true); |
| 61 _debugSubscription.cancel(); |
| 62 _isolateSubscription.cancel(); |
| 63 } |
| 64 |
| 65 void render() { |
| 66 switch (_isolate.status) { |
| 67 case M.IsolateStatus.loading: |
| 68 children = [new SpanElement()..text = 'not yet runnable']; |
| 69 break; |
| 70 case M.IsolateStatus.running: |
| 71 children = [ |
| 72 new SpanElement()..text = 'at ', |
| 73 new FunctionRefElement(_isolate, |
| 74 M.topFrame(_isolate.pauseEvent).function, |
| 75 queue: _r.queue), |
| 76 new SpanElement()..text = ' (', |
| 77 new SourceLinkElement(_isolate, |
| 78 M.topFrame(_isolate.pauseEvent).location, |
| 79 _scripts, |
| 80 queue: _r.queue), |
| 81 new SpanElement()..text = ') ' |
| 82 ]; |
| 83 break; |
| 84 case M.IsolateStatus.paused: |
| 85 if (_isolate.pauseEvent is M.PauseStartEvent) { |
| 86 children = [new SpanElement()..text = 'at isolate start']; |
| 87 } else if (_isolate.pauseEvent is M.PauseExitEvent) { |
| 88 children = [new SpanElement()..text = 'at isolate exit']; |
| 89 } else if (_isolate.pauseEvent is M.NoneEvent) { |
| 90 children = [new SpanElement()..text = 'not yet runnable']; |
| 91 } else { |
| 92 final content = <Element>[]; |
| 93 if (_isolate.pauseEvent is M.PauseBreakpointEvent) { |
| 94 content.add(new SpanElement()..text = 'by breakpoint'); |
| 95 } else if (_isolate.pauseEvent is M.PauseExceptionEvent) { |
| 96 content.add(new SpanElement()..text = 'by exception'); |
| 97 } |
| 98 if (M.topFrame(_isolate.pauseEvent) != null) { |
| 99 content.addAll([ |
| 100 new SpanElement()..text = ' at ', |
| 101 new FunctionRefElement(_isolate, |
| 102 M.topFrame(_isolate.pauseEvent).function, |
| 103 queue: _r.queue), |
| 104 new SpanElement()..text = ' (', |
| 105 new SourceLinkElement(_isolate, |
| 106 M.topFrame(_isolate.pauseEvent).location, |
| 107 _scripts, |
| 108 queue: _r.queue), |
| 109 new SpanElement()..text = ') ' |
| 110 ]); |
| 111 } |
| 112 children = content; |
| 113 } |
| 114 break; |
| 115 default: |
| 116 children = const []; |
| 117 } |
| 118 } |
| 119 |
| 120 void _eventListener(e) { |
| 121 if (e.isolate.id == _isolate.id) { |
| 122 _r.dirty(); |
| 123 } |
| 124 } |
| 125 } |
| OLD | NEW |