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

Unified Diff: lib/html/dart2js/html_dart2js.dart

Side-by-side diff isn't available for this file because of its large size.
Issue 10828338: Re-enable function serialization test (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:
Download patch
« no previous file with comments | « no previous file | lib/html/dartium/html_dartium.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/html/dart2js/html_dart2js.dart
diff --git a/lib/html/dart2js/html_dart2js.dart b/lib/html/dart2js/html_dart2js.dart
index f8c391bb244bc335baa53581d25fa27331568f08..99a92fcd1bfb0908862369726636d97828c76081 100644
--- a/lib/html/dart2js/html_dart2js.dart
+++ b/lib/html/dart2js/html_dart2js.dart
@@ -37043,8 +37043,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);
}
@@ -37966,6 +38017,7 @@ class _MessageTraverser {
if (x is Map) return visitMap(x);
if (x is SendPort) return visitSendPort(x);
if (x is SendPortSync) return visitSendPortSync(x);
+ if (x is Function) return visitFunction(x);
// TODO(floitsch): make this a real exception. (which one)?
throw "Message serialization: Illegal value $x passed";
@@ -37977,6 +38029,10 @@ class _MessageTraverser {
abstract visitSendPort(SendPort x);
abstract visitSendPortSync(SendPortSync x);
+ visitFunction(Function func) {
+ throw "Serialization of functions is not allowed.";
+ }
+
static bool isPrimitive(x) {
return (x === null) || (x is String) || (x is num) || (x is bool);
}
« no previous file with comments | « no previous file | lib/html/dartium/html_dartium.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698