Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(556)

Side by Side Diff: dart/lib/isolate/frog/ports.dart

Issue 10575033: Implement override checks. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 /** Common functionality to all send ports. */ 5 /** Common functionality to all send ports. */
6 class _BaseSendPort implements SendPort { 6 class _BaseSendPort implements SendPort {
7 /** Id for the destination isolate. */ 7 /** Id for the destination isolate. */
8 final int _isolateId; 8 final int _isolateId;
9 9
10 const _BaseSendPort(this._isolateId); 10 const _BaseSendPort(this._isolateId);
11 11
12 static void checkReplyTo(SendPort replyTo) { 12 void _checkReplyTo(SendPort replyTo) {
13 if (replyTo !== null 13 if (replyTo !== null
14 && replyTo is! _NativeJsSendPort 14 && replyTo is! _NativeJsSendPort
15 && replyTo is! _WorkerSendPort 15 && replyTo is! _WorkerSendPort
16 && replyTo is! _BufferingSendPort) { 16 && replyTo is! _BufferingSendPort) {
17 throw new Exception("SendPort.send: Illegal replyTo port type"); 17 throw new Exception("SendPort.send: Illegal replyTo port type");
18 } 18 }
19 } 19 }
20 20
21 Future call(var message) { 21 Future call(var message) {
22 final completer = new Completer(); 22 final completer = new Completer();
(...skipping 16 matching lines...) Expand all
39 } 39 }
40 40
41 /** A send port that delivers messages in-memory via native JavaScript calls. */ 41 /** A send port that delivers messages in-memory via native JavaScript calls. */
42 class _NativeJsSendPort extends _BaseSendPort implements SendPort { 42 class _NativeJsSendPort extends _BaseSendPort implements SendPort {
43 final _ReceivePortImpl _receivePort; 43 final _ReceivePortImpl _receivePort;
44 44
45 const _NativeJsSendPort(this._receivePort, int isolateId) : super(isolateId); 45 const _NativeJsSendPort(this._receivePort, int isolateId) : super(isolateId);
46 46
47 void send(var message, [SendPort replyTo = null]) { 47 void send(var message, [SendPort replyTo = null]) {
48 _waitForPendingPorts([message, replyTo], () { 48 _waitForPendingPorts([message, replyTo], () {
49 checkReplyTo(replyTo); 49 _checkReplyTo(replyTo);
50 // Check that the isolate still runs and the port is still open 50 // Check that the isolate still runs and the port is still open
51 final isolate = _globalState.isolates[_isolateId]; 51 final isolate = _globalState.isolates[_isolateId];
52 if (isolate == null) return; 52 if (isolate == null) return;
53 if (_receivePort._callback == null) return; 53 if (_receivePort._callback == null) return;
54 54
55 // We force serialization/deserialization as a simple way to ensure 55 // We force serialization/deserialization as a simple way to ensure
56 // isolate communication restrictions are respected between isolates that 56 // isolate communication restrictions are respected between isolates that
57 // live in the same worker. [_NativeJsSendPort] delivers both messages 57 // live in the same worker. [_NativeJsSendPort] delivers both messages
58 // from the same worker and messages from other workers. In particular, 58 // from the same worker and messages from other workers. In particular,
59 // messages sent from a worker via a [_WorkerSendPort] are received at 59 // messages sent from a worker via a [_WorkerSendPort] are received at
(...skipping 29 matching lines...) Expand all
89 // TODO(eub): abstract this for iframes. 89 // TODO(eub): abstract this for iframes.
90 class _WorkerSendPort extends _BaseSendPort implements SendPort { 90 class _WorkerSendPort extends _BaseSendPort implements SendPort {
91 final int _workerId; 91 final int _workerId;
92 final int _receivePortId; 92 final int _receivePortId;
93 93
94 const _WorkerSendPort(this._workerId, int isolateId, this._receivePortId) 94 const _WorkerSendPort(this._workerId, int isolateId, this._receivePortId)
95 : super(isolateId); 95 : super(isolateId);
96 96
97 void send(var message, [SendPort replyTo = null]) { 97 void send(var message, [SendPort replyTo = null]) {
98 _waitForPendingPorts([message, replyTo], () { 98 _waitForPendingPorts([message, replyTo], () {
99 checkReplyTo(replyTo); 99 _checkReplyTo(replyTo);
100 final workerMessage = _serializeMessage({ 100 final workerMessage = _serializeMessage({
101 'command': 'message', 101 'command': 'message',
102 'port': this, 102 'port': this,
103 'msg': message, 103 'msg': message,
104 'replyTo': replyTo}); 104 'replyTo': replyTo});
105 105
106 if (_globalState.isWorker) { 106 if (_globalState.isWorker) {
107 // communication from one worker to another go through the main worker: 107 // communication from one worker to another go through the main worker:
108 _globalState.mainManager.postMessage(workerMessage); 108 _globalState.mainManager.postMessage(workerMessage);
109 } else { 109 } else {
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 // map.getValues().forEach(_dispatch); 244 // map.getValues().forEach(_dispatch);
245 map.getValues().forEach((e) => _dispatch(e)); 245 map.getValues().forEach((e) => _dispatch(e));
246 } 246 }
247 247
248 visitBufferingSendPort(_BufferingSendPort port) { 248 visitBufferingSendPort(_BufferingSendPort port) {
249 if (port._port == null) { 249 if (port._port == null) {
250 ports.add(port._futurePort); 250 ports.add(port._futurePort);
251 } 251 }
252 } 252 }
253 } 253 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698