| 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 10 matching lines...) Expand all Loading... |
| 21 : _result = null { | 21 : _result = null { |
| 22 _validateErrorCode(_errorCode); | 22 _validateErrorCode(_errorCode); |
| 23 if (_errorDetail is! String) { | 23 if (_errorDetail is! String) { |
| 24 throw new ArgumentError.value(_errorDetail, | 24 throw new ArgumentError.value(_errorDetail, |
| 25 "errorDetail", | 25 "errorDetail", |
| 26 "Must be a String"); | 26 "Must be a String"); |
| 27 } | 27 } |
| 28 } | 28 } |
| 29 | 29 |
| 30 /// Invalid method parameter(s) error code. | 30 /// Invalid method parameter(s) error code. |
| 31 static const kInvalidParams = -32602; | 31 @deprecated static const kInvalidParams = invalidParams; |
| 32 /// Generic extension error code. | 32 /// Generic extension error code. |
| 33 static const kExtensionError = -32000; | 33 @deprecated static const kExtensionError = extensionError; |
| 34 /// Maximum extension provided error code. | 34 /// Maximum extension provided error code. |
| 35 static const kExtensionErrorMax = -32000; | 35 @deprecated static const kExtensionErrorMax = extensionErrorMax; |
| 36 /// Minimum extension provided error code. | 36 /// Minimum extension provided error code. |
| 37 static const kExtensionErrorMin = -32016; | 37 @deprecated static const kExtensionErrorMin = extensionErrorMin; |
| 38 |
| 39 /// Invalid method parameter(s) error code. |
| 40 static const invalidParams = -32602; |
| 41 /// Generic extension error code. |
| 42 static const extensionError = -32000; |
| 43 /// Maximum extension provided error code. |
| 44 static const extensionErrorMax = -32000; |
| 45 /// Minimum extension provided error code. |
| 46 static const extensionErrorMin = -32016; |
| 47 |
| 38 | 48 |
| 39 static String _errorCodeMessage(int errorCode) { | 49 static String _errorCodeMessage(int errorCode) { |
| 40 _validateErrorCode(errorCode); | 50 _validateErrorCode(errorCode); |
| 41 if (errorCode == kInvalidParams) { | 51 if (errorCode == kInvalidParams) { |
| 42 return "Invalid params"; | 52 return "Invalid params"; |
| 43 } | 53 } |
| 44 return "Server error"; | 54 return "Server error"; |
| 45 } | 55 } |
| 46 | 56 |
| 47 static _validateErrorCode(int errorCode) { | 57 static _validateErrorCode(int errorCode) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 /// | 93 /// |
| 84 /// [method] - the method name of the service protocol request. | 94 /// [method] - the method name of the service protocol request. |
| 85 /// [parameters] - A map holding the parameters to the service protocol request. | 95 /// [parameters] - A map holding the parameters to the service protocol request. |
| 86 /// | 96 /// |
| 87 /// *NOTE*: All parameter names and values are **encoded as strings**. | 97 /// *NOTE*: All parameter names and values are **encoded as strings**. |
| 88 typedef Future<ServiceExtensionResponse> | 98 typedef Future<ServiceExtensionResponse> |
| 89 ServiceExtensionHandler(String method, Map<String, String> parameters); | 99 ServiceExtensionHandler(String method, Map<String, String> parameters); |
| 90 | 100 |
| 91 /// Register a [ServiceExtensionHandler] that will be invoked in this isolate | 101 /// Register a [ServiceExtensionHandler] that will be invoked in this isolate |
| 92 /// for [method]. *NOTE*: Service protocol extensions must be registered | 102 /// for [method]. *NOTE*: Service protocol extensions must be registered |
| 93 /// in each isolate and users of extensions must always specify a target | 103 /// in each isolate. |
| 94 /// isolate. | 104 /// |
| 105 /// *NOTE*: [method] must begin with 'ext.' and you should use the following |
| 106 /// structure to avoid conflicts with other packages: 'ext.package.command'. |
| 107 /// That is, immediately following the 'ext.' prefix, should be the registering |
| 108 /// package name followed by another period ('.') and then the command name. |
| 109 /// For example: 'ext.dart.io.getOpenFiles'. |
| 110 /// |
| 111 /// Because service extensions are isolate specific, clients using extensions |
| 112 /// must always include an 'isolateId' parameter with each RPC. |
| 95 void registerExtension(String method, ServiceExtensionHandler handler) { | 113 void registerExtension(String method, ServiceExtensionHandler handler) { |
| 96 if (method is! String) { | 114 if (method is! String) { |
| 97 throw new ArgumentError.value(method, | 115 throw new ArgumentError.value(method, |
| 98 'method', | 116 'method', |
| 99 'Must be a String'); | 117 'Must be a String'); |
| 100 } | 118 } |
| 119 if (!method.startsWith('ext.')) { |
| 120 throw new ArgumentError.value(method, |
| 121 'method', |
| 122 'Must begin with ext.'); |
| 123 } |
| 101 if (_lookupExtension(method) != null) { | 124 if (_lookupExtension(method) != null) { |
| 102 throw new ArgumentError('Extension already registered: $method'); | 125 throw new ArgumentError('Extension already registered: $method'); |
| 103 } | 126 } |
| 104 if (handler is! ServiceExtensionHandler) { | 127 if (handler is! ServiceExtensionHandler) { |
| 105 throw new ArgumentError.value(handler, | 128 throw new ArgumentError.value(handler, |
| 106 'handler', | 129 'handler', |
| 107 'Must be a ServiceExtensionHandler'); | 130 'Must be a ServiceExtensionHandler'); |
| 108 } | 131 } |
| 109 _registerExtension(method, handler); | 132 _registerExtension(method, handler); |
| 110 } | 133 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 128 | 151 |
| 129 external _postEvent(String eventKind, String eventData); | 152 external _postEvent(String eventKind, String eventData); |
| 130 | 153 |
| 131 // Both of these functions are written inside C++ to avoid updating the data | 154 // Both of these functions are written inside C++ to avoid updating the data |
| 132 // structures in Dart, getting an OOB, and observing stale state. Do not move | 155 // structures in Dart, getting an OOB, and observing stale state. Do not move |
| 133 // these into Dart code unless you can ensure that the operations will can be | 156 // these into Dart code unless you can ensure that the operations will can be |
| 134 // done atomically. Native code lives in vm/isolate.cc- | 157 // done atomically. Native code lives in vm/isolate.cc- |
| 135 // LookupServiceExtensionHandler and RegisterServiceExtensionHandler. | 158 // LookupServiceExtensionHandler and RegisterServiceExtensionHandler. |
| 136 external ServiceExtensionHandler _lookupExtension(String method); | 159 external ServiceExtensionHandler _lookupExtension(String method); |
| 137 external _registerExtension(String method, ServiceExtensionHandler handler); | 160 external _registerExtension(String method, ServiceExtensionHandler handler); |
| OLD | NEW |