| 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 part of dart.developer; | 5 part of dart.developer; |
| 6 | 6 |
| 7 class ServiceExtensionResponse { | 7 class ServiceExtensionResponse { |
| 8 final String _result; | 8 final String _result; |
| 9 final int _errorCode; | 9 final int _errorCode; |
| 10 final String _errorDetail; | 10 final String _errorDetail; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 throw new ArgumentError('Extension already registered: $method'); | 102 throw new ArgumentError('Extension already registered: $method'); |
| 103 } | 103 } |
| 104 if (handler is! ServiceExtensionHandler) { | 104 if (handler is! ServiceExtensionHandler) { |
| 105 throw new ArgumentError.value(handler, | 105 throw new ArgumentError.value(handler, |
| 106 'handler', | 106 'handler', |
| 107 'Must be a ServiceExtensionHandler'); | 107 'Must be a ServiceExtensionHandler'); |
| 108 } | 108 } |
| 109 _registerExtension(method, handler); | 109 _registerExtension(method, handler); |
| 110 } | 110 } |
| 111 | 111 |
| 112 /// Post an event of [eventKind] with payload of [eventData] to the `Extension` |
| 113 /// event stream. |
| 114 void postEvent(String eventKind, Map eventData) { |
| 115 if (eventKind is! String) { |
| 116 throw new ArgumentError.value(eventKind, |
| 117 'eventKind', |
| 118 'Must be a String'); |
| 119 } |
| 120 if (eventData is! Map) { |
| 121 throw new ArgumentError.value(eventData, |
| 122 'eventData', |
| 123 'Must be a Map'); |
| 124 } |
| 125 String eventDataAsString = JSON.encode(eventData); |
| 126 _postEvent(eventKind, eventDataAsString); |
| 127 } |
| 128 |
| 129 external _postEvent(String eventKind, String eventData); |
| 130 |
| 112 // Both of these functions are written inside C++ to avoid updating the data | 131 // Both of these functions are written inside C++ to avoid updating the data |
| 113 // structures in Dart, getting an OOB, and observing stale state. Do not move | 132 // structures in Dart, getting an OOB, and observing stale state. Do not move |
| 114 // these into Dart code unless you can ensure that the operations will can be | 133 // these into Dart code unless you can ensure that the operations will can be |
| 115 // done atomically. Native code lives in vm/isolate.cc- | 134 // done atomically. Native code lives in vm/isolate.cc- |
| 116 // LookupServiceExtensionHandler and RegisterServiceExtensionHandler. | 135 // LookupServiceExtensionHandler and RegisterServiceExtensionHandler. |
| 117 external ServiceExtensionHandler _lookupExtension(String method); | 136 external ServiceExtensionHandler _lookupExtension(String method); |
| 118 external _registerExtension(String method, ServiceExtensionHandler handler); | 137 external _registerExtension(String method, ServiceExtensionHandler handler); |
| OLD | NEW |