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

Unified Diff: lib/html/src/Isolates.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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/html/dartium/html_dartium.dart ('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 88989491f3ba980a183781f6d5c75e8ed8162761..ea025abe571c56f81315e9ccef77e39e92e4b565 100644
--- a/lib/html/src/Isolates.dart
+++ b/lib/html/src/Isolates.dart
@@ -29,6 +29,12 @@ class _JsSerializer extends _Serializer {
x._receivePort._isolateId, x._receivePort._portId ];
}
+ visitObject(Object x) {
+ if (x is Function) return visitFunction(x);
+ // TODO: Handle DOM elements and proxy other objects.
+ throw "Unserializable object $x";
+ }
+
visitFunction(Function func) {
return [ 'funcref',
_makeFunctionRef(func), visitSendPortSync(_sendPort()), null ];
@@ -87,6 +93,8 @@ _deserialize(var message) {
class _JsDeserializer extends _Deserializer {
+ static final _UNSPECIFIED = const Object();
+
deserializeSendPort(List x) {
String tag = x[1];
switch (tag) {
@@ -102,6 +110,27 @@ class _JsDeserializer extends _Deserializer {
}
}
+ deserializeObject(List x) {
+ String tag = x[0];
+ switch (tag) {
+ case 'funcref': return deserializeFunction(x);
+ default: throw 'Illegal object type: $x';
+ }
+ }
+
+ deserializeFunction(List x) {
+ var id = x[1];
+ SendPortSync port = deserializeSendPort(x[2]);
+ // TODO: Support varargs when there is support in the language.
+ return ([arg0 = _UNSPECIFIED, arg1 = _UNSPECIFIED,
+ arg2 = _UNSPECIFIED, arg3 = _UNSPECIFIED]) {
+ var args = [arg0, arg1, arg2, arg3];
+ var last = args.indexOf(_UNSPECIFIED);
+ if (last >= 0) args = args.getRange(0, last);
+ var message = [id, args];
+ return port.callSync(message);
+ };
+ }
}
// The receiver is JS.
« no previous file with comments | « lib/html/dartium/html_dartium.dart ('k') | lib/isolate/serialization.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698