| 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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 | 193 |
| 194 int id = _nextFreeRefId++; | 194 int id = _nextFreeRefId++; |
| 195 _attachInfo(map, id); | 195 _attachInfo(map, id); |
| 196 var keys = _serializeList(map.getKeys()); | 196 var keys = _serializeList(map.getKeys()); |
| 197 var values = _serializeList(map.getValues()); | 197 var values = _serializeList(map.getValues()); |
| 198 // TODO(floitsch): we are losing the generic type. | 198 // TODO(floitsch): we are losing the generic type. |
| 199 return ['map', id, keys, values]; | 199 return ['map', id, keys, values]; |
| 200 } | 200 } |
| 201 | 201 |
| 202 visitNativeJsSendPort(_NativeJsSendPort port) { | 202 visitNativeJsSendPort(_NativeJsSendPort port) { |
| 203 return ['sendport', _globalState.currentWorkerId, | 203 return ['sendport', _globalState.currentManagerId, |
| 204 port._isolateId, port._receivePort._id]; | 204 port._isolateId, port._receivePort._id]; |
| 205 } | 205 } |
| 206 | 206 |
| 207 visitWorkerSendPort(_WorkerSendPort port) { | 207 visitWorkerSendPort(_WorkerSendPort port) { |
| 208 return ['sendport', port._workerId, port._isolateId, port._receivePortId]; | 208 return ['sendport', port._workerId, port._isolateId, port._receivePortId]; |
| 209 } | 209 } |
| 210 | 210 |
| 211 visitBufferingSendPort(_BufferingSendPort port) { | 211 visitBufferingSendPort(_BufferingSendPort port) { |
| 212 if (port._port != null) { | 212 if (port._port != null) { |
| 213 return _visitNativeOrWorkerPort(port._port); | 213 return _visitNativeOrWorkerPort(port._port); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 assert(len == values.length); | 295 assert(len == values.length); |
| 296 for (int i = 0; i < len; i++) { | 296 for (int i = 0; i < len; i++) { |
| 297 var key = _deserializeHelper(keys[i]); | 297 var key = _deserializeHelper(keys[i]); |
| 298 var value = _deserializeHelper(values[i]); | 298 var value = _deserializeHelper(values[i]); |
| 299 result[key] = value; | 299 result[key] = value; |
| 300 } | 300 } |
| 301 return result; | 301 return result; |
| 302 } | 302 } |
| 303 | 303 |
| 304 SendPort _deserializeSendPort(List x) { | 304 SendPort _deserializeSendPort(List x) { |
| 305 int workerId = x[1]; | 305 int managerId = x[1]; |
| 306 int isolateId = x[2]; | 306 int isolateId = x[2]; |
| 307 int receivePortId = x[3]; | 307 int receivePortId = x[3]; |
| 308 // If two isolates are in the same worker, we use NativeJsSendPorts to | 308 // If two isolates are in the same manager, we use NativeJsSendPorts to |
| 309 // deliver messages directly without using postMessage. | 309 // deliver messages directly without using postMessage. |
| 310 if (workerId == _globalState.currentWorkerId) { | 310 if (managerId == _globalState.currentManagerId) { |
| 311 var isolate = _globalState.isolates[isolateId]; | 311 var isolate = _globalState.isolates[isolateId]; |
| 312 if (isolate == null) return null; // Isolate has been closed. | 312 if (isolate == null) return null; // Isolate has been closed. |
| 313 var receivePort = isolate.lookup(receivePortId); | 313 var receivePort = isolate.lookup(receivePortId); |
| 314 return new _NativeJsSendPort(receivePort, isolateId); | 314 return new _NativeJsSendPort(receivePort, isolateId); |
| 315 } else { | 315 } else { |
| 316 return new _WorkerSendPort(workerId, isolateId, receivePortId); | 316 return new _WorkerSendPort(managerId, isolateId, receivePortId); |
| 317 } | 317 } |
| 318 } | 318 } |
| 319 } | 319 } |
| 320 | 320 |
| 321 // only visible for testing purposes | 321 // only visible for testing purposes |
| 322 // TODO(sigmund): remove once we can disable privacy for testing (bug #1882) | 322 // TODO(sigmund): remove once we can disable privacy for testing (bug #1882) |
| 323 class TestingOnly { | 323 class TestingOnly { |
| 324 static copy(x) { | 324 static copy(x) { |
| 325 return new _Copier().traverse(x); | 325 return new _Copier().traverse(x); |
| 326 } | 326 } |
| 327 | 327 |
| 328 // only visible for testing purposes | 328 // only visible for testing purposes |
| 329 static serialize(x) { | 329 static serialize(x) { |
| 330 _Serializer serializer = new _Serializer(); | 330 _Serializer serializer = new _Serializer(); |
| 331 _Deserializer deserializer = new _Deserializer(); | 331 _Deserializer deserializer = new _Deserializer(); |
| 332 return deserializer.deserialize(serializer.traverse(x)); | 332 return deserializer.deserialize(serializer.traverse(x)); |
| 333 } | 333 } |
| 334 } | 334 } |
| OLD | NEW |