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

Unified Diff: lib/html/src/Isolates.dart

Issue 10690142: Move function serialization to sync ports. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « client/dart.js ('k') | lib/isolate/serialization.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/html/src/Isolates.dart
diff --git a/lib/html/src/Isolates.dart b/lib/html/src/Isolates.dart
index 70026a07015baa9cf874ac58641d442e4c0516c3..88989491f3ba980a183781f6d5c75e8ed8162761 100644
--- a/lib/html/src/Isolates.dart
+++ b/lib/html/src/Isolates.dart
@@ -28,8 +28,59 @@ class _JsSerializer extends _Serializer {
return [ 'sendport', 'dart',
x._receivePort._isolateId, x._receivePort._portId ];
}
+
+ visitFunction(Function func) {
+ return [ 'funcref',
+ _makeFunctionRef(func), visitSendPortSync(_sendPort()), null ];
+ }
}
+// Leaking implementation. Later will be backend specific and hopefully
+// not leaking (at least in most of the cases.)
+// TODO: provide better, backend specific implementation.
+class _FunctionRegistry {
+ final ReceivePortSync _port;
+ int _nextId;
+ final Map<String, Function> _registry;
+
+ _FunctionRegistry() :
+ _port = new ReceivePortSync(),
+ _nextId = 0,
+ _registry = <Function>{} {
+ _port.receive((msg) {
+ final id = msg[0];
+ final args = msg[1];
+ final f = _registry[id];
+ switch (args.length) {
+ case 0: return f();
+ case 1: return f(args[0]);
+ case 2: return f(args[0], args[1]);
+ case 3: return f(args[0], args[1], args[2]);
+ case 4: return f(args[0], args[1], args[2], args[3]);
+ default: throw 'Unsupported number of arguments.';
+ }
+ });
+ }
+
+ String _add(Function f) {
+ final id = 'func-ref-${_nextId++}';
+ _registry[id] = f;
+ return id;
+ }
+
+ get _sendPort() => _port.toSendPort();
+}
+
+_FunctionRegistry __functionRegistry;
+get _functionRegistry() {
+ if (__functionRegistry === null) __functionRegistry = new _FunctionRegistry();
+ return __functionRegistry;
+}
+
+_makeFunctionRef(f) => _functionRegistry._add(f);
+_sendPort() => _functionRegistry._sendPort;
+/// End of function serialization implementation.
+
_deserialize(var message) {
return new _JsDeserializer().deserialize(message);
}
« no previous file with comments | « client/dart.js ('k') | lib/isolate/serialization.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698