Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 // Defines message visitors, serialization, and deserialization. | 5 // Defines message visitors, serialization, and deserialization. |
| 6 | 6 |
| 7 /** Serialize [message] (or simulate serialization). */ | 7 /** Serialize [message] (or simulate serialization). */ |
| 8 _serializeMessage(message) { | 8 _serializeMessage(message) { |
| 9 if (_globalState.needSerialization) { | 9 if (_globalState.needSerialization) { |
| 10 return new _Serializer().traverse(message); | 10 return new _Serializer().traverse(message); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 SendPort visitWorkerSendPort(_WorkerSendPort port) { | 143 SendPort visitWorkerSendPort(_WorkerSendPort port) { |
| 144 return new _WorkerSendPort( | 144 return new _WorkerSendPort( |
| 145 port._workerId, port._isolateId, port._receivePortId); | 145 port._workerId, port._isolateId, port._receivePortId); |
| 146 } | 146 } |
| 147 | 147 |
| 148 SendPort visitBufferingSendPort(_BufferingSendPort port) { | 148 SendPort visitBufferingSendPort(_BufferingSendPort port) { |
| 149 if (port._port != null) { | 149 if (port._port != null) { |
| 150 return _visitNativeOrWorkerPort(port._port); | 150 return _visitNativeOrWorkerPort(port._port); |
| 151 } else { | 151 } else { |
| 152 // TODO(floitsch): Use real exception (which one?). | 152 // TODO(floitsch): Use real exception (which one?). |
| 153 throw "internal error: must call _waitForPendingPorts to ensure all" | 153 throw |
|
Lasse Reichstein Nielsen
2012/06/18 09:25:32
I liked the original indentation better. Just remo
ahe
2012/06/18 10:39:16
I don't follow the logic of your argument.
| |
| 154 + " ports are resolved at this point."; | 154 "internal error: must call _waitForPendingPorts to ensure all" |
| 155 " ports are resolved at this point."; | |
| 155 } | 156 } |
| 156 } | 157 } |
| 157 } | 158 } |
| 158 | 159 |
| 159 /** Visitor that serializes a message as a JSON array. */ | 160 /** Visitor that serializes a message as a JSON array. */ |
| 160 class _Serializer extends _MessageTraverser { | 161 class _Serializer extends _MessageTraverser { |
| 161 int _nextFreeRefId = 0; | 162 int _nextFreeRefId = 0; |
| 162 | 163 |
| 163 _Serializer() : super(); | 164 _Serializer() : super(); |
| 164 | 165 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 194 | 195 |
| 195 visitWorkerSendPort(_WorkerSendPort port) { | 196 visitWorkerSendPort(_WorkerSendPort port) { |
| 196 return ['sendport', port._workerId, port._isolateId, port._receivePortId]; | 197 return ['sendport', port._workerId, port._isolateId, port._receivePortId]; |
| 197 } | 198 } |
| 198 | 199 |
| 199 visitBufferingSendPort(_BufferingSendPort port) { | 200 visitBufferingSendPort(_BufferingSendPort port) { |
| 200 if (port._port != null) { | 201 if (port._port != null) { |
| 201 return _visitNativeOrWorkerPort(port._port); | 202 return _visitNativeOrWorkerPort(port._port); |
| 202 } else { | 203 } else { |
| 203 // TODO(floitsch): Use real exception (which one?). | 204 // TODO(floitsch): Use real exception (which one?). |
| 204 throw "internal error: must call _waitForPendingPorts to ensure all" | 205 throw |
| 205 + " ports are resolved at this point."; | 206 "internal error: must call _waitForPendingPorts to ensure all" |
| 207 " ports are resolved at this point."; | |
|
Lasse Reichstein Nielsen
2012/06/18 09:25:32
Ditto.
ahe
2012/06/18 10:39:16
Ditto.
| |
| 206 } | 208 } |
| 207 } | 209 } |
| 208 | 210 |
| 209 _serializeList(List list) { | 211 _serializeList(List list) { |
| 210 int len = list.length; | 212 int len = list.length; |
| 211 var result = new List(len); | 213 var result = new List(len); |
| 212 for (int i = 0; i < len; i++) { | 214 for (int i = 0; i < len; i++) { |
| 213 result[i] = _dispatch(list[i]); | 215 result[i] = _dispatch(list[i]); |
| 214 } | 216 } |
| 215 return result; | 217 return result; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 305 return new _Copier().traverse(x); | 307 return new _Copier().traverse(x); |
| 306 } | 308 } |
| 307 | 309 |
| 308 // only visible for testing purposes | 310 // only visible for testing purposes |
| 309 static serialize(x) { | 311 static serialize(x) { |
| 310 _Serializer serializer = new _Serializer(); | 312 _Serializer serializer = new _Serializer(); |
| 311 _Deserializer deserializer = new _Deserializer(); | 313 _Deserializer deserializer = new _Deserializer(); |
| 312 return deserializer.deserialize(serializer.traverse(x)); | 314 return deserializer.deserialize(serializer.traverse(x)); |
| 313 } | 315 } |
| 314 } | 316 } |
| OLD | NEW |