| 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 patch class ReceivePort { | 5 patch class ReceivePort { |
| 6 /* patch */ factory ReceivePort() { | 6 /* patch */ factory ReceivePort() { |
| 7 return new _ReceivePortImpl(); | 7 return new _ReceivePortImpl(); |
| 8 } | 8 } |
| 9 } | 9 } |
| 10 | 10 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 // Called from the VM to create a new ReceivePort instance. | 28 // Called from the VM to create a new ReceivePort instance. |
| 29 static _ReceivePortImpl _get_or_create(int id) { | 29 static _ReceivePortImpl _get_or_create(int id) { |
| 30 if (_portMap != null) { | 30 if (_portMap != null) { |
| 31 _ReceivePortImpl port = _portMap[id]; | 31 _ReceivePortImpl port = _portMap[id]; |
| 32 if (port != null) { | 32 if (port != null) { |
| 33 return port; | 33 return port; |
| 34 } | 34 } |
| 35 } | 35 } |
| 36 return new _ReceivePortImpl._internal(id); | 36 return new _ReceivePortImpl._internal(id); |
| 37 } | 37 } |
| 38 |
| 38 _ReceivePortImpl._internal(int id) : _id = id { | 39 _ReceivePortImpl._internal(int id) : _id = id { |
| 39 if (_portMap == null) { | 40 if (_portMap == null) { |
| 40 _portMap = new Map(); | 41 _portMap = new Map(); |
| 41 } | 42 } |
| 42 _portMap[id] = this; | 43 _portMap[id] = this; |
| 43 } | 44 } |
| 44 | 45 |
| 46 // Called from the VM to retrieve the ReceivePort for a message. |
| 47 static _ReceivePortImpl _lookupReceivePort(int id) { |
| 48 assert(_portMap != null); |
| 49 return _portMap[id]; |
| 50 } |
| 51 |
| 45 // Called from the VM to dispatch to the handler. | 52 // Called from the VM to dispatch to the handler. |
| 46 static void _handleMessage(int id, int replyId, var message) { | 53 static void _handleMessage(_ReceivePortImpl port, int replyId, var message) { |
| 47 assert(_portMap != null); | 54 assert(port != null); |
| 48 ReceivePort port = _portMap[id]; | |
| 49 SendPort replyTo = (replyId == 0) ? null : new _SendPortImpl(replyId); | 55 SendPort replyTo = (replyId == 0) ? null : new _SendPortImpl(replyId); |
| 50 (port._onMessage)(message, replyTo); | 56 (port._onMessage)(message, replyTo); |
| 51 } | 57 } |
| 52 | 58 |
| 53 // Call into the VM to close the VM maintained mappings. | 59 // Call into the VM to close the VM maintained mappings. |
| 54 static _closeInternal(int id) native "ReceivePortImpl_closeInternal"; | 60 static _closeInternal(int id) native "ReceivePortImpl_closeInternal"; |
| 55 | 61 |
| 56 final int _id; | 62 final int _id; |
| 57 var _onMessage; | 63 var _onMessage; |
| 58 | 64 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 | 162 |
| 157 class _TimerFactory { | 163 class _TimerFactory { |
| 158 static _TimerFactoryClosure _factory; | 164 static _TimerFactoryClosure _factory; |
| 159 } | 165 } |
| 160 | 166 |
| 161 // TODO(ahe): Warning: this is NOT called by Dartium. Instead, it sets | 167 // TODO(ahe): Warning: this is NOT called by Dartium. Instead, it sets |
| 162 // [_TimerFactory._factory] directly. | 168 // [_TimerFactory._factory] directly. |
| 163 void _setTimerFactoryClosure(_TimerFactoryClosure closure) { | 169 void _setTimerFactoryClosure(_TimerFactoryClosure closure) { |
| 164 _TimerFactory._factory = closure; | 170 _TimerFactory._factory = closure; |
| 165 } | 171 } |
| OLD | NEW |