Index: lib/html/dart2js/html_dart2js.dart |
diff --git a/lib/html/dart2js/html_dart2js.dart b/lib/html/dart2js/html_dart2js.dart |
index d8792a240506a5267f05e947a7d5e36f2cb37915..1557cb4bf081dd140ac004978021507a6ee0ab6e 100644 |
--- a/lib/html/dart2js/html_dart2js.dart |
+++ b/lib/html/dart2js/html_dart2js.dart |
@@ -37682,6 +37682,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) { |
@@ -37708,6 +37728,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); |
@@ -37724,6 +37745,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 |
@@ -37828,6 +37857,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'; |
} |
} |
@@ -37855,6 +37885,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. |
@@ -37992,6 +38027,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)); |