Index: lib/html/dart2js/html_dart2js.dart |
diff --git a/lib/html/dart2js/html_dart2js.dart b/lib/html/dart2js/html_dart2js.dart |
index dca6f89e9459a8438f85e4874192ed9c9f0a0076..1168df2418a370bfa440fa7adad9fa3223eb79b6 100644 |
--- a/lib/html/dart2js/html_dart2js.dart |
+++ b/lib/html/dart2js/html_dart2js.dart |
@@ -37679,6 +37679,26 @@ class JsProxy { |
} |
} |
+int _localNextElementId = 0; |
+ |
+const _DART_ID = 'data-dart_id'; |
+ |
+var _elementId(Element e) { |
+ if (e.attributes.containsKey(_DART_ID)) return e.attributes[_DART_ID]; |
+ var id = '$_isolateId-${_localNextElementId++}'; |
+ e.attributes[_DART_ID] = id; |
+ return id; |
+} |
+ |
+Element _getElement(var id) { |
+ var list = queryAll('[$_DART_ID="$id"]'); |
+ if (list.length > 1) throw 'Non unique ID: $id'; |
+ if (list.length == 0) { |
+ throw 'Only elements attached to document can be serialized: $id'; |
+ } |
+ return list[0]; |
+} |
+ |
class _JsSerializer extends _Serializer { |
visitSendPortSync(SendPortSync x) { |
@@ -37705,6 +37725,7 @@ class _JsSerializer extends _Serializer { |
visitObject(Object x) { |
if (x is Function) return visitFunction(x); |
if (x is JsProxy) return visitJsProxy(x); |
+ if (x is Element) return visitElement(x); |
// TODO: Handle DOM elements and proxy other objects. |
var proxyId = _dartProxyRegistry._add(x); |
@@ -37721,6 +37742,14 @@ class _JsSerializer extends _Serializer { |
visitJsProxy(JsProxy proxy) { |
return [ 'objref', proxy._id, visitSendPortSync(proxy._port) ]; |
} |
+ |
+ visitElement(Element element) { |
+ var id = _elementId(element); |
+ // Verify that the element is connected to the document. |
+ // Otherwise, we will not be able to find it on the other side. |
+ _getElement(id); |
+ return [ 'element', id ]; |
+ } |
} |
// Leaking implementation. Later will be backend specific and hopefully |
@@ -37779,11 +37808,7 @@ get _functionRegistry { |
/// Object proxy implementation. |
class _DartProxyRegistry extends _Registry<Object> { |
- final ReceivePortSync _port; |
- |
- _DartProxyRegistry() : |
- super('dart-ref'), |
- _port = new ReceivePortSync() { |
+ _DartProxyRegistry() : super('dart-ref') { |
_port.receive((msg) { |
// TODO(vsm): Support a mechanism to register a handler here. |
throw 'Invocation unsupported on Dart proxies'; |
@@ -37829,6 +37854,7 @@ class _JsDeserializer extends _Deserializer { |
switch (tag) { |
case 'funcref': return deserializeFunction(x); |
case 'objref': return deserializeProxy(x); |
+ case 'element': return deserializeElement(x); |
default: throw 'Illegal object type: $x'; |
} |
} |
@@ -37856,6 +37882,11 @@ class _JsDeserializer extends _Deserializer { |
if (port is _RemoteSendPortSync) throw 'Remote Dart proxies unsupported'; |
throw 'Illegal proxy: $port'; |
} |
+ |
+ deserializeElement(x) { |
+ var id = x[1]; |
+ return _getElement(id); |
+ } |
} |
// The receiver is JS. |
@@ -37993,6 +38024,8 @@ class ReceivePortSync { |
} |
} |
+get _isolateId => ReceivePortSync._isolateId; |
+ |
void _dispatchEvent(String receiver, var message) { |
var event = document.$dom_createEvent('TextEvent'); |
event.initTextEvent(receiver, false, false, window, JSON.stringify(message)); |