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

Side by Side Diff: lib/isolate/serialization.dart

Issue 10834426: Support general serializing of functions between JS and Dart (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments Created 8 years, 4 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 | « lib/html/src/Isolates.dart ('k') | tests/html/js_interop_func_passing_test.dart » ('j') | 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 class _MessageTraverserVisitedMap { 5 class _MessageTraverserVisitedMap {
6 6
7 operator[](var object) => null; 7 operator[](var object) => null;
8 void operator[]=(var object, var info) { } 8 void operator[]=(var object, var info) { }
9 9
10 void reset() { } 10 void reset() { }
(...skipping 19 matching lines...) Expand all
30 } 30 }
31 return result; 31 return result;
32 } 32 }
33 33
34 _dispatch(var x) { 34 _dispatch(var x) {
35 if (isPrimitive(x)) return visitPrimitive(x); 35 if (isPrimitive(x)) return visitPrimitive(x);
36 if (x is List) return visitList(x); 36 if (x is List) return visitList(x);
37 if (x is Map) return visitMap(x); 37 if (x is Map) return visitMap(x);
38 if (x is SendPort) return visitSendPort(x); 38 if (x is SendPort) return visitSendPort(x);
39 if (x is SendPortSync) return visitSendPortSync(x); 39 if (x is SendPortSync) return visitSendPortSync(x);
40 if (x is Function) return visitFunction(x);
41 40
42 // TODO(floitsch): make this a real exception. (which one)? 41 // Overridable fallback.
43 throw "Message serialization: Illegal value $x passed"; 42 return visitObject(x);
44 } 43 }
45 44
46 abstract visitPrimitive(x); 45 abstract visitPrimitive(x);
47 abstract visitList(List x); 46 abstract visitList(List x);
48 abstract visitMap(Map x); 47 abstract visitMap(Map x);
49 abstract visitSendPort(SendPort x); 48 abstract visitSendPort(SendPort x);
50 abstract visitSendPortSync(SendPortSync x); 49 abstract visitSendPortSync(SendPortSync x);
51 50
52 visitFunction(Function func) { 51 visitObject(Object x) {
53 throw "Serialization of functions is not allowed."; 52 // TODO(floitsch): make this a real exception. (which one)?
53 throw "Message serialization: Illegal value $x passed";
54 } 54 }
55 55
56 static bool isPrimitive(x) { 56 static bool isPrimitive(x) {
57 return (x === null) || (x is String) || (x is num) || (x is bool); 57 return (x === null) || (x is String) || (x is num) || (x is bool);
58 } 58 }
59 } 59 }
60 60
61 61
62 /** A visitor that recursively copies a message. */ 62 /** A visitor that recursively copies a message. */
63 class _Copier extends _MessageTraverser { 63 class _Copier extends _MessageTraverser {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 } 151 }
152 152
153 _deserializeHelper(x) { 153 _deserializeHelper(x) {
154 if (isPrimitive(x)) return x; 154 if (isPrimitive(x)) return x;
155 assert(x is List); 155 assert(x is List);
156 switch (x[0]) { 156 switch (x[0]) {
157 case 'ref': return _deserializeRef(x); 157 case 'ref': return _deserializeRef(x);
158 case 'list': return _deserializeList(x); 158 case 'list': return _deserializeList(x);
159 case 'map': return _deserializeMap(x); 159 case 'map': return _deserializeMap(x);
160 case 'sendport': return deserializeSendPort(x); 160 case 'sendport': return deserializeSendPort(x);
161 // TODO(floitsch): Use real exception (which one?). 161 default: return deserializeObject(x);
162 default: throw "Unexpected serialized object";
163 } 162 }
164 } 163 }
165 164
166 _deserializeRef(List x) { 165 _deserializeRef(List x) {
167 int id = x[1]; 166 int id = x[1];
168 var result = _deserialized[id]; 167 var result = _deserialized[id];
169 assert(result !== null); 168 assert(result !== null);
170 return result; 169 return result;
171 } 170 }
172 171
(...skipping 20 matching lines...) Expand all
193 for (int i = 0; i < len; i++) { 192 for (int i = 0; i < len; i++) {
194 var key = _deserializeHelper(keys[i]); 193 var key = _deserializeHelper(keys[i]);
195 var value = _deserializeHelper(values[i]); 194 var value = _deserializeHelper(values[i]);
196 result[key] = value; 195 result[key] = value;
197 } 196 }
198 return result; 197 return result;
199 } 198 }
200 199
201 abstract deserializeSendPort(List x); 200 abstract deserializeSendPort(List x);
202 201
202 deserializeObject(List x) {
203 // TODO(floitsch): Use real exception (which one?).
204 throw "Unexpected serialized object";
205 }
203 } 206 }
OLDNEW
« no previous file with comments | « lib/html/src/Isolates.dart ('k') | tests/html/js_interop_func_passing_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698