Index: lib/html/dart2js/html_dart2js.dart |
diff --git a/lib/html/dart2js/html_dart2js.dart b/lib/html/dart2js/html_dart2js.dart |
index 61538d6394e5e55b72ab089fdd6f9ca04b1d8266..3ecfbce2d97de9ca6029f850e00fa875a60ca382 100644 |
--- a/lib/html/dart2js/html_dart2js.dart |
+++ b/lib/html/dart2js/html_dart2js.dart |
@@ -37121,6 +37121,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 ]; |
@@ -37179,6 +37185,8 @@ _deserialize(var message) { |
class _JsDeserializer extends _Deserializer { |
+ static final _UNSPECIFIED = const Object(); |
+ |
deserializeSendPort(List x) { |
String tag = x[1]; |
switch (tag) { |
@@ -37194,6 +37202,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. |
@@ -38067,10 +38096,9 @@ 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"; |
+ // Overridable fallback. |
+ return visitObject(x); |
} |
abstract visitPrimitive(x); |
@@ -38079,8 +38107,9 @@ class _MessageTraverser { |
abstract visitSendPort(SendPort x); |
abstract visitSendPortSync(SendPortSync x); |
- visitFunction(Function func) { |
- throw "Serialization of functions is not allowed."; |
+ visitObject(Object x) { |
+ // TODO(floitsch): make this a real exception. (which one)? |
+ throw "Message serialization: Illegal value $x passed"; |
} |
static bool isPrimitive(x) { |
@@ -38188,8 +38217,7 @@ class _Deserializer { |
case 'list': return _deserializeList(x); |
case 'map': return _deserializeMap(x); |
case 'sendport': return deserializeSendPort(x); |
- // TODO(floitsch): Use real exception (which one?). |
- default: throw "Unexpected serialized object"; |
+ default: return deserializeObject(x); |
} |
} |
@@ -38230,4 +38258,8 @@ class _Deserializer { |
abstract deserializeSendPort(List x); |
+ deserializeObject(List x) { |
+ // TODO(floitsch): Use real exception (which one?). |
+ throw "Unexpected serialized object"; |
+ } |
} |