| 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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 | 181 |
| 182 int id = _nextFreeRefId++; | 182 int id = _nextFreeRefId++; |
| 183 _attachInfo(map, id); | 183 _attachInfo(map, id); |
| 184 var keys = _serializeList(map.getKeys()); | 184 var keys = _serializeList(map.getKeys()); |
| 185 var values = _serializeList(map.getValues()); | 185 var values = _serializeList(map.getValues()); |
| 186 // TODO(floitsch): we are losing the generic type. | 186 // TODO(floitsch): we are losing the generic type. |
| 187 return ['map', id, keys, values]; | 187 return ['map', id, keys, values]; |
| 188 } | 188 } |
| 189 | 189 |
| 190 visitNativeJsSendPort(_NativeJsSendPort port) { | 190 visitNativeJsSendPort(_NativeJsSendPort port) { |
| 191 return ['sendport', _globalState.currentWorkerId, | 191 return ['sendport', _globalState.currentManagerId, |
| 192 port._isolateId, port._receivePort._id]; | 192 port._isolateId, port._receivePort._id]; |
| 193 } | 193 } |
| 194 | 194 |
| 195 visitWorkerSendPort(_WorkerSendPort port) { | 195 visitWorkerSendPort(_WorkerSendPort port) { |
| 196 return ['sendport', port._workerId, port._isolateId, port._receivePortId]; | 196 return ['sendport', port._workerId, port._isolateId, port._receivePortId]; |
| 197 } | 197 } |
| 198 | 198 |
| 199 visitBufferingSendPort(_BufferingSendPort port) { | 199 visitBufferingSendPort(_BufferingSendPort port) { |
| 200 if (port._port != null) { | 200 if (port._port != null) { |
| 201 return _visitNativeOrWorkerPort(port._port); | 201 return _visitNativeOrWorkerPort(port._port); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 assert(len == values.length); | 275 assert(len == values.length); |
| 276 for (int i = 0; i < len; i++) { | 276 for (int i = 0; i < len; i++) { |
| 277 var key = _deserializeHelper(keys[i]); | 277 var key = _deserializeHelper(keys[i]); |
| 278 var value = _deserializeHelper(values[i]); | 278 var value = _deserializeHelper(values[i]); |
| 279 result[key] = value; | 279 result[key] = value; |
| 280 } | 280 } |
| 281 return result; | 281 return result; |
| 282 } | 282 } |
| 283 | 283 |
| 284 SendPort _deserializeSendPort(List x) { | 284 SendPort _deserializeSendPort(List x) { |
| 285 int workerId = x[1]; | 285 int managerId = x[1]; |
| 286 int isolateId = x[2]; | 286 int isolateId = x[2]; |
| 287 int receivePortId = x[3]; | 287 int receivePortId = x[3]; |
| 288 // If two isolates are in the same worker, we use NativeJsSendPorts to | 288 // If two isolates are in the same manager, we use NativeJsSendPorts to |
| 289 // deliver messages directly without using postMessage. | 289 // deliver messages directly without using postMessage. |
| 290 if (workerId == _globalState.currentWorkerId) { | 290 if (managerId == _globalState.currentManagerId) { |
| 291 var isolate = _globalState.isolates[isolateId]; | 291 var isolate = _globalState.isolates[isolateId]; |
| 292 if (isolate == null) return null; // Isolate has been closed. | 292 if (isolate == null) return null; // Isolate has been closed. |
| 293 var receivePort = isolate.lookup(receivePortId); | 293 var receivePort = isolate.lookup(receivePortId); |
| 294 return new _NativeJsSendPort(receivePort, isolateId); | 294 return new _NativeJsSendPort(receivePort, isolateId); |
| 295 } else { | 295 } else { |
| 296 return new _WorkerSendPort(workerId, isolateId, receivePortId); | 296 return new _WorkerSendPort(managerId, isolateId, receivePortId); |
| 297 } | 297 } |
| 298 } | 298 } |
| 299 } | 299 } |
| 300 | 300 |
| 301 // only visible for testing purposes | 301 // only visible for testing purposes |
| 302 // TODO(sigmund): remove once we can disable privacy for testing (bug #1882) | 302 // TODO(sigmund): remove once we can disable privacy for testing (bug #1882) |
| 303 class TestingOnly { | 303 class TestingOnly { |
| 304 static copy(x) { | 304 static copy(x) { |
| 305 return new _Copier().traverse(x); | 305 return new _Copier().traverse(x); |
| 306 } | 306 } |
| 307 | 307 |
| 308 // only visible for testing purposes | 308 // only visible for testing purposes |
| 309 static serialize(x) { | 309 static serialize(x) { |
| 310 _Serializer serializer = new _Serializer(); | 310 _Serializer serializer = new _Serializer(); |
| 311 _Deserializer deserializer = new _Deserializer(); | 311 _Deserializer deserializer = new _Deserializer(); |
| 312 return deserializer.deserialize(serializer.traverse(x)); | 312 return deserializer.deserialize(serializer.traverse(x)); |
| 313 } | 313 } |
| 314 } | 314 } |
| OLD | NEW |