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/src/elements/sentinel_value.dart'; | 14 import 'package:observatory/src/elements/sentinel_value.dart'; |
| 15 import 'package:observatory/utils.dart'; |
15 | 16 |
16 class InstanceRefElement extends HtmlElement implements Renderable { | 17 class InstanceRefElement extends HtmlElement implements Renderable { |
17 static const tag = const Tag<InstanceRefElement>('instance-ref-wrapped'); | 18 static const tag = const Tag<InstanceRefElement>('instance-ref-wrapped'); |
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; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 } | 59 } |
59 | 60 |
60 void render() { | 61 void render() { |
61 final content = _createLink(); | 62 final content = _createLink(); |
62 | 63 |
63 if (_hasValue()) { | 64 if (_hasValue()) { |
64 content.addAll([ | 65 content.addAll([ |
65 new SpanElement()..text = ' ', | 66 new SpanElement()..text = ' ', |
66 new CurlyBlockElement(expanded: _expanded, queue: _r.queue) | 67 new CurlyBlockElement(expanded: _expanded, queue: _r.queue) |
67 ..children = [ | 68 ..children = [ |
68 new DivElement()..classes = ['indent'] | 69 new DivElement()..classes = const ['indent'] |
69 ..children = _createValue() | 70 ..children = _createValue() |
70 ] | 71 ] |
71 ..onToggle.listen((e) async { | 72 ..onToggle.listen((e) async { |
72 _expanded = e.control.expanded; | 73 _expanded = e.control.expanded; |
73 if (_expanded) { | 74 if (_expanded) { |
74 e.control.disabled = true; | 75 e.control.disabled = true; |
75 await _refresh(); | 76 await _refresh(); |
76 e.control.disabled = false; | 77 e.control.disabled = false; |
77 } | 78 } |
78 }) | 79 }) |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 case M.InstanceKind.float32x4: | 113 case M.InstanceKind.float32x4: |
113 case M.InstanceKind.float64x2: | 114 case M.InstanceKind.float64x2: |
114 case M.InstanceKind.int32x4: | 115 case M.InstanceKind.int32x4: |
115 return [ | 116 return [ |
116 new AnchorElement(href: Uris.inspect(_isolate, object: _instance)) | 117 new AnchorElement(href: Uris.inspect(_isolate, object: _instance)) |
117 ..text = _instance.valueAsString | 118 ..text = _instance.valueAsString |
118 ]; | 119 ]; |
119 case M.InstanceKind.string: | 120 case M.InstanceKind.string: |
120 return [ | 121 return [ |
121 new AnchorElement(href: Uris.inspect(_isolate, object: _instance)) | 122 new AnchorElement(href: Uris.inspect(_isolate, object: _instance)) |
122 ..text = asStringLiteral(_instance.valueAsString, | 123 ..text = Utils.formatStringAsLiteral(_instance.valueAsString, |
123 _instance.valueAsStringIsTruncated) | 124 _instance.valueAsStringIsTruncated) |
124 ]; | 125 ]; |
125 case M.InstanceKind.type: | 126 case M.InstanceKind.type: |
126 case M.InstanceKind.typeRef: | 127 case M.InstanceKind.typeRef: |
127 case M.InstanceKind.typeParameter: | 128 case M.InstanceKind.typeParameter: |
128 case M.InstanceKind.boundedType: | 129 case M.InstanceKind.boundedType: |
129 return [ | 130 return [ |
130 new AnchorElement(href: Uris.inspect(_isolate, object: _instance)) | 131 new AnchorElement(href: Uris.inspect(_isolate, object: _instance)) |
131 ..text = _instance.name | 132 ..text = _instance.name |
132 ]; | 133 ]; |
133 case M.InstanceKind.closure: | 134 case M.InstanceKind.closure: |
134 return [ | 135 return [ |
135 new AnchorElement(href: Uris.inspect(_isolate, object: _instance)) | 136 new AnchorElement(href: Uris.inspect(_isolate, object: _instance)) |
136 ..children = [ | 137 ..children = [ |
137 new SpanElement()..classes = ['empathize']..text = 'Closure', | 138 new SpanElement()..classes = const ['emphasize'] |
| 139 ..text = 'Closure', |
138 new SpanElement()..text = _instance.closureFunction.name | 140 new SpanElement()..text = _instance.closureFunction.name |
139 ] | 141 ] |
140 ]; | 142 ]; |
141 case M.InstanceKind.regExp: | 143 case M.InstanceKind.regExp: |
142 return [ | 144 return [ |
143 new AnchorElement(href: Uris.inspect(_isolate, object: _instance)) | 145 new AnchorElement(href: Uris.inspect(_isolate, object: _instance)) |
144 ..children = [ | 146 ..children = [ |
145 new SpanElement()..classes = ['empathize'] | 147 new SpanElement()..classes = const ['emphasize'] |
146 ..text = _instance.clazz.name, | 148 ..text = _instance.clazz.name, |
147 new SpanElement()..text = _instance.pattern.name | 149 new SpanElement()..text = _instance.pattern.name |
148 ] | 150 ] |
149 ]; | 151 ]; |
150 case M.InstanceKind.stackTrace: | 152 case M.InstanceKind.stackTrace: |
151 return [ | 153 return [ |
152 new AnchorElement(href: Uris.inspect(_isolate, object: _instance)) | 154 new AnchorElement(href: Uris.inspect(_isolate, object: _instance)) |
153 ..text = _instance.clazz.name, | 155 ..text = _instance.clazz.name, |
154 new CurlyBlockElement(queue: _r.queue) | 156 new CurlyBlockElement(queue: _r.queue) |
155 ..children = [ | 157 ..children = [ |
156 new DivElement()..classes = ['stackTraceBox'] | 158 new DivElement()..classes = const ['stackTraceBox'] |
157 ..text = _instance.valueAsString | 159 ..text = _instance.valueAsString |
158 ] | 160 ] |
159 ]; | 161 ]; |
160 case M.InstanceKind.plainInstance: | 162 case M.InstanceKind.plainInstance: |
161 return [ | 163 return [ |
162 new AnchorElement(href: Uris.inspect(_isolate, object: _instance)) | 164 new AnchorElement(href: Uris.inspect(_isolate, object: _instance)) |
163 ..classes = ['empathize'] | 165 ..classes = ['emphasize'] |
164 ..text = _instance.clazz.name | 166 ..text = _instance.clazz.name |
165 ]; | 167 ]; |
166 case M.InstanceKind.list: | 168 case M.InstanceKind.list: |
167 case M.InstanceKind.map: | 169 case M.InstanceKind.map: |
168 case M.InstanceKind.uint8ClampedList: | 170 case M.InstanceKind.uint8ClampedList: |
169 case M.InstanceKind.uint8List: | 171 case M.InstanceKind.uint8List: |
170 case M.InstanceKind.uint16List: | 172 case M.InstanceKind.uint16List: |
171 case M.InstanceKind.uint32List: | 173 case M.InstanceKind.uint32List: |
172 case M.InstanceKind.uint64List: | 174 case M.InstanceKind.uint64List: |
173 case M.InstanceKind.int8List: | 175 case M.InstanceKind.int8List: |
174 case M.InstanceKind.int16List: | 176 case M.InstanceKind.int16List: |
175 case M.InstanceKind.int32List: | 177 case M.InstanceKind.int32List: |
176 case M.InstanceKind.int64List: | 178 case M.InstanceKind.int64List: |
177 case M.InstanceKind.float32List: | 179 case M.InstanceKind.float32List: |
178 case M.InstanceKind.float64List: | 180 case M.InstanceKind.float64List: |
179 case M.InstanceKind.int32x4List: | 181 case M.InstanceKind.int32x4List: |
180 case M.InstanceKind.float32x4List: | 182 case M.InstanceKind.float32x4List: |
181 case M.InstanceKind.float64x2List: | 183 case M.InstanceKind.float64x2List: |
182 return [ | 184 return [ |
183 new AnchorElement(href: Uris.inspect(_isolate, object: _instance)) | 185 new AnchorElement(href: Uris.inspect(_isolate, object: _instance)) |
184 ..children = [ | 186 ..children = [ |
185 new SpanElement()..classes = ['empathize'] | 187 new SpanElement()..classes = const ['emphasize'] |
186 ..text = _instance.clazz.name, | 188 ..text = _instance.clazz.name, |
187 new SpanElement()..text = ' (${_instance.length})' | 189 new SpanElement()..text = ' (${_instance.length})' |
188 ] | 190 ] |
189 ]; | 191 ]; |
190 case M.InstanceKind.mirrorReference: | 192 case M.InstanceKind.mirrorReference: |
191 return [ | 193 return [ |
192 new AnchorElement(href: Uris.inspect(_isolate, object: _instance)) | 194 new AnchorElement(href: Uris.inspect(_isolate, object: _instance)) |
193 ..classes = ['empathize'] | 195 ..classes = const ['emphasize'] |
194 ..text = _instance.clazz.name | 196 ..text = _instance.clazz.name |
195 ]; | 197 ]; |
196 case M.InstanceKind.weakProperty: | 198 case M.InstanceKind.weakProperty: |
197 return [ | 199 return [ |
198 new AnchorElement(href: Uris.inspect(_isolate, object: _instance)) | 200 new AnchorElement(href: Uris.inspect(_isolate, object: _instance)) |
199 ..classes = ['empathize'] | 201 ..classes = const ['emphasize'] |
200 ..text = _instance.clazz.name | 202 ..text = _instance.clazz.name |
201 ]; | 203 ]; |
202 } | 204 } |
203 throw new Exception('Unkown InstanceKind: ${_instance.kind}'); | 205 throw new Exception('Unkown InstanceKind: ${_instance.kind}'); |
204 } | 206 } |
205 | 207 |
206 bool _hasValue() { | 208 bool _hasValue() { |
207 switch (_instance.kind) { | 209 switch (_instance.kind) { |
208 case M.InstanceKind.plainInstance: | 210 case M.InstanceKind.plainInstance: |
209 case M.InstanceKind.mirrorReference: | 211 case M.InstanceKind.mirrorReference: |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 queue: _r.queue), | 309 queue: _r.queue), |
308 new BRElement(), | 310 new BRElement(), |
309 new SpanElement()..text = '<value> : ', | 311 new SpanElement()..text = '<value> : ', |
310 new InstanceRefElement(_isolate, _loadedInstance.value, _instances, | 312 new InstanceRefElement(_isolate, _loadedInstance.value, _instances, |
311 queue: _r.queue), | 313 queue: _r.queue), |
312 ]; | 314 ]; |
313 default: | 315 default: |
314 return []; | 316 return []; |
315 } | 317 } |
316 } | 318 } |
317 | |
318 static String asStringLiteral(String value, [bool wasTruncated=false]) { | |
319 var result = new List(); | |
320 result.add("'".codeUnitAt(0)); | |
321 for (int codeUnit in value.codeUnits) { | |
322 if (codeUnit == '\n'.codeUnitAt(0)) result.addAll('\\n'.codeUnits); | |
323 else if (codeUnit == '\r'.codeUnitAt(0)) result.addAll('\\r'.codeUnits); | |
324 else if (codeUnit == '\f'.codeUnitAt(0)) result.addAll('\\f'.codeUnits); | |
325 else if (codeUnit == '\b'.codeUnitAt(0)) result.addAll('\\b'.codeUnits); | |
326 else if (codeUnit == '\t'.codeUnitAt(0)) result.addAll('\\t'.codeUnits); | |
327 else if (codeUnit == '\v'.codeUnitAt(0)) result.addAll('\\v'.codeUnits); | |
328 else if (codeUnit == '\$'.codeUnitAt(0)) result.addAll('\\\$'.codeUnits); | |
329 else if (codeUnit == '\\'.codeUnitAt(0)) result.addAll('\\\\'.codeUnits); | |
330 else if (codeUnit == "'".codeUnitAt(0)) result.addAll("'".codeUnits); | |
331 else if (codeUnit < 32) { | |
332 var escapeSequence = "\\u" + codeUnit.toRadixString(16).padLeft(4, "0")
; | |
333 result.addAll(escapeSequence.codeUnits); | |
334 } else result.add(codeUnit); | |
335 } | |
336 if (wasTruncated) { | |
337 result.addAll("...".codeUnits); | |
338 } else { | |
339 result.add("'".codeUnitAt(0)); | |
340 } | |
341 return new String.fromCharCodes(result); | |
342 } | |
343 } | 319 } |
OLD | NEW |