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

Unified Diff: lib/html/src/Isolates.dart

Issue 10883037: Serialize Elements through PortSync (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix line length 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') | tests/html/js_interop_element_test.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 ee3626d65394ea991435945d2fba2459258a9f87..bedb8b49bbadec2211a3ad246bfd4e6ec28b3313 100644
--- a/lib/html/src/Isolates.dart
+++ b/lib/html/src/Isolates.dart
@@ -23,6 +23,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) {
@@ -49,6 +69,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);
@@ -65,6 +86,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
@@ -169,6 +198,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';
}
}
@@ -196,6 +226,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.
@@ -333,6 +368,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));
« no previous file with comments | « lib/html/dartium/html_dartium.dart ('k') | tests/html/js_interop_element_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698