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