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

Unified Diff: lib/html/dartium/html_dartium.dart

Side-by-side diff isn't available for this file because of its large size.
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, 3 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:
Download patch
« no previous file with comments | « lib/html/dart2js/html_dart2js.dart ('k') | lib/html/src/Isolates.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/html/dartium/html_dartium.dart
diff --git a/lib/html/dartium/html_dartium.dart b/lib/html/dartium/html_dartium.dart
index d7043ce0d118f06152f0e31f47e7dd8d846662a1..59923f0ea5e483d34ad7478e130f86485d739f5f 100644
--- a/lib/html/dartium/html_dartium.dart
+++ b/lib/html/dartium/html_dartium.dart
@@ -40787,6 +40787,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) {
@@ -40813,6 +40833,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);
@@ -40829,6 +40850,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
@@ -40933,6 +40962,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';
}
}
@@ -40960,6 +40990,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.
@@ -41097,6 +41132,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/dart2js/html_dart2js.dart ('k') | lib/html/src/Isolates.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698