OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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:isolate'; | 5 import 'dart:isolate'; |
6 import 'dart:_internal' hide Symbol; | 6 import 'dart:_internal' hide Symbol; |
7 | 7 |
8 @patch bool debugger({bool when: true, | 8 @patch |
9 String message}) native "Developer_debugger"; | 9 bool debugger({bool when: true, String message}) native "Developer_debugger"; |
10 | 10 |
11 @patch Object inspect(Object object) native "Developer_inspect"; | 11 @patch |
| 12 Object inspect(Object object) native "Developer_inspect"; |
12 | 13 |
13 @patch void log(String message, | 14 @patch |
14 {DateTime time, | 15 void log(String message, |
15 int sequenceNumber, | 16 {DateTime time, |
16 int level: 0, | 17 int sequenceNumber, |
17 String name: '', | 18 int level: 0, |
18 Zone zone, | 19 String name: '', |
19 Object error, | 20 Zone zone, |
20 StackTrace stackTrace}) { | 21 Object error, |
| 22 StackTrace stackTrace}) { |
21 if (message is! String) { | 23 if (message is! String) { |
22 throw new ArgumentError.value(message, "message", "Must be a String"); | 24 throw new ArgumentError.value(message, "message", "Must be a String"); |
23 } | 25 } |
24 if (time == null) { | 26 if (time == null) { |
25 time = new DateTime.now(); | 27 time = new DateTime.now(); |
26 } | 28 } |
27 if (time is! DateTime) { | 29 if (time is! DateTime) { |
28 throw new ArgumentError.value(time, "time", "Must be a DateTime"); | 30 throw new ArgumentError.value(time, "time", "Must be a DateTime"); |
29 } | 31 } |
30 if (sequenceNumber == null) { | 32 if (sequenceNumber == null) { |
31 sequenceNumber = _nextSequenceNumber++; | 33 sequenceNumber = _nextSequenceNumber++; |
32 } else { | 34 } else { |
33 _nextSequenceNumber = sequenceNumber + 1; | 35 _nextSequenceNumber = sequenceNumber + 1; |
34 } | 36 } |
35 _log(message, | 37 _log(message, time.millisecondsSinceEpoch, sequenceNumber, level, name, zone, |
36 time.millisecondsSinceEpoch, | 38 error, stackTrace); |
37 sequenceNumber, | |
38 level, | |
39 name, | |
40 zone, | |
41 error, | |
42 stackTrace); | |
43 } | 39 } |
44 | 40 |
45 int _nextSequenceNumber = 0; | 41 int _nextSequenceNumber = 0; |
46 | 42 |
47 _log(String message, | 43 _log(String message, int timestamp, int sequenceNumber, int level, String name, |
48 int timestamp, | 44 Zone zone, Object error, StackTrace stackTrace) native "Developer_log"; |
49 int sequenceNumber, | |
50 int level, | |
51 String name, | |
52 Zone zone, | |
53 Object error, | |
54 StackTrace stackTrace) native "Developer_log"; | |
55 | 45 |
56 @patch void _postEvent(String eventKind, String eventData) | 46 @patch |
| 47 void _postEvent(String eventKind, String eventData) |
57 native "Developer_postEvent"; | 48 native "Developer_postEvent"; |
58 | 49 |
59 @patch ServiceExtensionHandler _lookupExtension(String method) | 50 @patch |
| 51 ServiceExtensionHandler _lookupExtension(String method) |
60 native "Developer_lookupExtension"; | 52 native "Developer_lookupExtension"; |
61 | 53 |
62 @patch _registerExtension(String method, ServiceExtensionHandler handler) | 54 @patch |
| 55 _registerExtension(String method, ServiceExtensionHandler handler) |
63 native "Developer_registerExtension"; | 56 native "Developer_registerExtension"; |
64 | 57 |
65 // This code is only invoked when there is no other Dart code on the stack. | 58 // This code is only invoked when there is no other Dart code on the stack. |
66 _runExtension(ServiceExtensionHandler handler, | 59 _runExtension( |
67 String method, | 60 ServiceExtensionHandler handler, |
68 List<String> parameterKeys, | 61 String method, |
69 List<String> parameterValues, | 62 List<String> parameterKeys, |
70 SendPort replyPort, | 63 List<String> parameterValues, |
71 Object id, | 64 SendPort replyPort, |
72 bool trace_service) { | 65 Object id, |
| 66 bool trace_service) { |
73 var parameters = {}; | 67 var parameters = {}; |
74 for (var i = 0; i < parameterKeys.length; i++) { | 68 for (var i = 0; i < parameterKeys.length; i++) { |
75 parameters[parameterKeys[i]] = parameterValues[i]; | 69 parameters[parameterKeys[i]] = parameterValues[i]; |
76 } | 70 } |
77 var response; | 71 var response; |
78 try { | 72 try { |
79 response = handler(method, parameters); | 73 response = handler(method, parameters); |
80 } catch (e, st) { | 74 } catch (e, st) { |
81 var errorDetails = (st == null) ? '$e' : '$e\n$st'; | 75 var errorDetails = (st == null) ? '$e' : '$e\n$st'; |
82 response = new ServiceExtensionResponse.error( | 76 response = new ServiceExtensionResponse.error( |
83 ServiceExtensionResponse.kExtensionError, | 77 ServiceExtensionResponse.kExtensionError, errorDetails); |
84 errorDetails); | |
85 _postResponse(replyPort, id, response, trace_service); | 78 _postResponse(replyPort, id, response, trace_service); |
86 return; | 79 return; |
87 } | 80 } |
88 if (response is! Future) { | 81 if (response is! Future) { |
89 response = new ServiceExtensionResponse.error( | 82 response = new ServiceExtensionResponse.error( |
90 ServiceExtensionResponse.kExtensionError, | 83 ServiceExtensionResponse.kExtensionError, |
91 "Extension handler must return a Future"); | 84 "Extension handler must return a Future"); |
92 _postResponse(replyPort, id, response, trace_service); | 85 _postResponse(replyPort, id, response, trace_service); |
93 return; | 86 return; |
94 } | 87 } |
95 response.catchError((e, st) { | 88 response.catchError((e, st) { |
96 // Catch any errors eagerly and wrap them in a ServiceExtensionResponse. | 89 // Catch any errors eagerly and wrap them in a ServiceExtensionResponse. |
97 var errorDetails = (st == null) ? '$e' : '$e\n$st'; | 90 var errorDetails = (st == null) ? '$e' : '$e\n$st'; |
98 return new ServiceExtensionResponse.error( | 91 return new ServiceExtensionResponse.error( |
99 ServiceExtensionResponse.kExtensionError, | 92 ServiceExtensionResponse.kExtensionError, errorDetails); |
100 errorDetails); | |
101 }).then((response) { | 93 }).then((response) { |
102 // Post the valid response or the wrapped error after verifying that | 94 // Post the valid response or the wrapped error after verifying that |
103 // the response is a ServiceExtensionResponse. | 95 // the response is a ServiceExtensionResponse. |
104 if (response is! ServiceExtensionResponse) { | 96 if (response is! ServiceExtensionResponse) { |
105 response = new ServiceExtensionResponse.error( | 97 response = new ServiceExtensionResponse.error( |
106 ServiceExtensionResponse.kExtensionError, | 98 ServiceExtensionResponse.kExtensionError, |
107 "Extension handler must complete to a ServiceExtensionResponse"); | 99 "Extension handler must complete to a ServiceExtensionResponse"); |
108 } | 100 } |
109 _postResponse(replyPort, id, response, trace_service); | 101 _postResponse(replyPort, id, response, trace_service); |
110 }).catchError((e, st) { | 102 }).catchError((e, st) { |
111 // We do not expect any errors to occur in the .then or .catchError blocks | 103 // We do not expect any errors to occur in the .then or .catchError blocks |
112 // but, suppress them just in case. | 104 // but, suppress them just in case. |
113 }); | 105 }); |
114 } | 106 } |
115 | 107 |
116 // This code is only invoked by _runExtension. | 108 // This code is only invoked by _runExtension. |
117 _postResponse(SendPort replyPort, | 109 _postResponse(SendPort replyPort, Object id, ServiceExtensionResponse response, |
118 Object id, | 110 bool trace_service) { |
119 ServiceExtensionResponse response, | |
120 bool trace_service) { | |
121 assert(replyPort != null); | 111 assert(replyPort != null); |
122 if (id == null) { | 112 if (id == null) { |
123 if (trace_service) { | 113 if (trace_service) { |
124 print("vm-service: posting no response for request"); | 114 print("vm-service: posting no response for request"); |
125 } | 115 } |
126 // No id -> no response. | 116 // No id -> no response. |
127 replyPort.send(null); | 117 replyPort.send(null); |
128 return; | 118 return; |
129 } | 119 } |
130 assert(id != null); | 120 assert(id != null); |
(...skipping 12 matching lines...) Expand all Loading... |
143 } | 133 } |
144 sb.write('${response._toString()},'); | 134 sb.write('${response._toString()},'); |
145 if (id is String) { | 135 if (id is String) { |
146 sb.write('"id":"$id"}'); | 136 sb.write('"id":"$id"}'); |
147 } else { | 137 } else { |
148 sb.write('"id":$id}'); | 138 sb.write('"id":$id}'); |
149 } | 139 } |
150 replyPort.send(sb.toString()); | 140 replyPort.send(sb.toString()); |
151 } | 141 } |
152 | 142 |
153 @patch int _getServiceMajorVersion() native "Developer_getServiceMajorVersion"; | 143 @patch |
| 144 int _getServiceMajorVersion() native "Developer_getServiceMajorVersion"; |
154 | 145 |
155 @patch int _getServiceMinorVersion() native "Developer_getServiceMinorVersion"; | 146 @patch |
| 147 int _getServiceMinorVersion() native "Developer_getServiceMinorVersion"; |
156 | 148 |
157 @patch void _getServerInfo(SendPort sendPort) native "Developer_getServerInfo"; | 149 @patch |
| 150 void _getServerInfo(SendPort sendPort) native "Developer_getServerInfo"; |
158 | 151 |
159 @patch void _webServerControl(SendPort sendPort, bool enable) | 152 @patch |
| 153 void _webServerControl(SendPort sendPort, bool enable) |
160 native "Developer_webServerControl"; | 154 native "Developer_webServerControl"; |
161 | 155 |
162 @patch String _getIsolateIDFromSendPort(SendPort sendPort) | 156 @patch |
| 157 String _getIsolateIDFromSendPort(SendPort sendPort) |
163 native "Developer_getIsolateIDFromSendPort"; | 158 native "Developer_getIsolateIDFromSendPort"; |
OLD | NEW |