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

Unified Diff: client/dart.js

Issue 10834426: Support general serializing of functions between JS and Dart (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments 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 dae0d2b61482a36eab12c9112a360af5b25a45c9..711aeee5702478258e964aad47a196e109154701 100644
--- a/client/dart.js
+++ b/client/dart.js
@@ -46,6 +46,33 @@ function ReceivePortSync() {
}
(function() {
+ // Track proxied functions.
+ // TODO: Fix leaks, particularly in dart2js case.
+ var functionRefMap = {};
+
+ var nextFunctionRefId = 0;
+
+ function functionRefDispatch(message) {
+ var id = message[0];
+ var args = message[1];
+ var f = functionRefMap[id];
+ // TODO: Should we capture this automatically?
+ return f.apply(null, args);
+ }
+
+ var functionRefPort = null;
+
+ function makeFunctionRef(f) {
+ if (functionRefPort == null) {
+ var port = new ReceivePortSync();
+ port.receive(functionRefDispatch);
+ functionRefPort = port.toSendPort();
+ }
+ var ref = 'func-ref-' + (nextFunctionRefId++);
+ functionRefMap[ref] = f;
+ return ref;
+ }
+
function serialize(message) {
var visited = [];
function checkedSerialization(obj, serializer) {
@@ -79,6 +106,9 @@ function ReceivePortSync() {
return [ 'sendport', 'nativejs', message.receivePort.id ];
} else if (message instanceof DartSendPortSync) {
return [ 'sendport', 'dart', message.isolateId, message.portId ];
+ } else if (message instanceof Function) {
+ return [ 'funcref', makeFunctionRef(message),
+ doSerialize(functionRefPort) ];
} else {
return checkedSerialization(message, function(id) {
var keys = Object.getOwnPropertyNames(message);
« 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