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

Side by Side Diff: tools/dom/src/Isolates.dart

Issue 11824053: Implement port equality on SendPortSync (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 80 char fix Created 7 years, 11 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
« no previous file with comments | « tests/html/js_interop_2_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 part of html; 5 part of html;
6 6
7 _serialize(var message) { 7 _serialize(var message) {
8 return new _JsSerializer().traverse(message); 8 return new _JsSerializer().traverse(message);
9 } 9 }
10 10
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 65
66 num _id; 66 num _id;
67 _JsSendPortSync(this._id); 67 _JsSendPortSync(this._id);
68 68
69 callSync(var message) { 69 callSync(var message) {
70 var serialized = _serialize(message); 70 var serialized = _serialize(message);
71 var result = _callPortSync(_id, serialized); 71 var result = _callPortSync(_id, serialized);
72 return _deserialize(result); 72 return _deserialize(result);
73 } 73 }
74 74
75 bool operator==(var other) {
76 return (other is _JsSendPortSync) && (_id == other._id);
77 }
78
79 int get hashCode => _id;
75 } 80 }
76 81
77 // TODO(vsm): Differentiate between Dart2Js and Dartium isolates. 82 // TODO(vsm): Differentiate between Dart2Js and Dartium isolates.
78 // The receiver is a different Dart isolate, compiled to JS. 83 // The receiver is a different Dart isolate, compiled to JS.
79 class _RemoteSendPortSync implements SendPortSync { 84 class _RemoteSendPortSync implements SendPortSync {
80 85
81 int _isolateId; 86 int _isolateId;
82 int _portId; 87 int _portId;
83 _RemoteSendPortSync(this._isolateId, this._portId); 88 _RemoteSendPortSync(this._isolateId, this._portId);
84 89
(...skipping 10 matching lines...) Expand all
95 var source = '$target-result'; 100 var source = '$target-result';
96 var result = null; 101 var result = null;
97 var listener = (Event e) { 102 var listener = (Event e) {
98 result = json.parse(_getPortSyncEventData(e)); 103 result = json.parse(_getPortSyncEventData(e));
99 }; 104 };
100 window.on[source].add(listener); 105 window.on[source].add(listener);
101 _dispatchEvent(target, [source, message]); 106 _dispatchEvent(target, [source, message]);
102 window.on[source].remove(listener); 107 window.on[source].remove(listener);
103 return result; 108 return result;
104 } 109 }
110
111 bool operator==(var other) {
112 return (other is _RemoteSendPortSync) && (_isolateId == other._isolateId)
113 && (_portId == other._portId);
114 }
115
116 int get hashCode => _isolateId >> 16 + _portId;
105 } 117 }
106 118
107 // The receiver is in the same Dart isolate, compiled to JS. 119 // The receiver is in the same Dart isolate, compiled to JS.
108 class _LocalSendPortSync implements SendPortSync { 120 class _LocalSendPortSync implements SendPortSync {
109 121
110 ReceivePortSync _receivePort; 122 ReceivePortSync _receivePort;
111 123
112 _LocalSendPortSync._internal(this._receivePort); 124 _LocalSendPortSync._internal(this._receivePort);
113 125
114 callSync(var message) { 126 callSync(var message) {
115 // TODO(vsm): Do a more efficient deep copy. 127 // TODO(vsm): Do a more efficient deep copy.
116 var copy = _deserialize(_serialize(message)); 128 var copy = _deserialize(_serialize(message));
117 var result = _receivePort._callback(copy); 129 var result = _receivePort._callback(copy);
118 return _deserialize(_serialize(result)); 130 return _deserialize(_serialize(result));
119 } 131 }
132
133 bool operator==(var other) {
134 return (other is _LocalSendPortSync)
135 && (_receivePort == other._receivePort);
136 }
137
138 int get hashCode => _receivePort.hashCode;
120 } 139 }
121 140
122 // TODO(vsm): Move this to dart:isolate. This will take some 141 // TODO(vsm): Move this to dart:isolate. This will take some
123 // refactoring as there are dependences here on the DOM. Users 142 // refactoring as there are dependences here on the DOM. Users
124 // interact with this class (or interface if we change it) directly - 143 // interact with this class (or interface if we change it) directly -
125 // new ReceivePortSync. I think most of the DOM logic could be 144 // new ReceivePortSync. I think most of the DOM logic could be
126 // delayed until the corresponding SendPort is registered on the 145 // delayed until the corresponding SendPort is registered on the
127 // window. 146 // window.
128 147
129 // A Dart ReceivePortSync (tagged 'dart' when serialized) is 148 // A Dart ReceivePortSync (tagged 'dart' when serialized) is
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 } 215 }
197 216
198 get _isolateId => ReceivePortSync._isolateId; 217 get _isolateId => ReceivePortSync._isolateId;
199 218
200 void _dispatchEvent(String receiver, var message) { 219 void _dispatchEvent(String receiver, var message) {
201 var event = new CustomEvent(receiver, false, false, json.stringify(message)); 220 var event = new CustomEvent(receiver, false, false, json.stringify(message));
202 window.$dom_dispatchEvent(event); 221 window.$dom_dispatchEvent(event);
203 } 222 }
204 223
205 String _getPortSyncEventData(CustomEvent event) => event.detail; 224 String _getPortSyncEventData(CustomEvent event) => event.detail;
OLDNEW
« no previous file with comments | « tests/html/js_interop_2_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698