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

Unified Diff: client/dart.js

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 | « no previous file | lib/html/dart2js/html_dart2js.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: client/dart.js
diff --git a/client/dart.js b/client/dart.js
index 6d80aa4fc3a24617d63c0daa383369f31538278e..15ac8a40b4848ef47f14351a86be369769d833dc 100644
--- a/client/dart.js
+++ b/client/dart.js
@@ -88,6 +88,12 @@ function ReceivePortSync() {
} else if (message instanceof Function) {
return [ 'funcref', functionRefTable.makeRef(message),
doSerialize(functionRefTable.sendPort) ];
+ } else if (message instanceof HTMLElement) {
+ var id = elementId(message);
+ // 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 ];
} else if (message instanceof DartProxy) {
return [ 'objref', message._id, doSerialize(message._port) ];
} else if (message.__proto__ != {}.__proto__) {
@@ -126,6 +132,7 @@ function ReceivePortSync() {
case 'list': return deserializeList(message);
case 'funcref': return deserializeFunction(message);
case 'objref': return deserializeProxy(message);
+ case 'element': return deserializeElement(message);
default: throw 'unimplemented';
}
}
@@ -187,6 +194,11 @@ function ReceivePortSync() {
throw 'Illegal proxy object: ' + message;
}
+ function deserializeElement(message) {
+ var id = message[1];
+ return getElement(id);
+ }
+
window.registerPort = function(name, port) {
var stringified = JSON.stringify(serialize(port));
window.localStorage['dart-port:' + name] = stringified;
@@ -376,4 +388,24 @@ function ReceivePortSync() {
return sendPort.callSync([ref, Array.prototype.slice.call(arguments)]);
}
}
+
+ var localNextElementId = 0;
+ var _DART_ID = 'data-dart_id';
+
+ function elementId(e) {
+ if (e.hasAttribute(_DART_ID)) return e.getAttribute(_DART_ID);
+ var id = (localNextElementId++).toString();
+ e.setAttribute(_DART_ID, id);
+ return id;
+ }
+
+ function getElement(id) {
+ var list = document.querySelectorAll('[' + _DART_ID + '="' + id + '"]');
+
+ if (list.length > 1) throw 'Non unique ID: ' + id;
+ if (list.length == 0) {
+ throw 'Element must be attached to the document: ' + id;
+ }
+ return list[0];
+ }
})();
« no previous file with comments | « no previous file | lib/html/dart2js/html_dart2js.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698