Index: sdk/lib/js/dartium/js_dartium.dart |
diff --git a/sdk/lib/js/dartium/js_dartium.dart b/sdk/lib/js/dartium/js_dartium.dart |
index a0c48ea0d93ed32372e0262d46effebb8c054aef..2ad4bf3e5f02fd5d2f2f579a17a82f6e68bc9895 100644 |
--- a/sdk/lib/js/dartium/js_dartium.dart |
+++ b/sdk/lib/js/dartium/js_dartium.dart |
@@ -242,7 +242,8 @@ abstract class Serializable<T> { |
T toJs(); |
} |
-// A table to managed local Dart objects that are proxied in JavaScript. |
+// A table to managed local Dart objects that are proxied in JavaScript, |
+// or proxies to JavaScript objects. |
class _ProxiedObjectTable { |
// Debugging name. |
final String _name; |
@@ -283,9 +284,9 @@ class _ProxiedObjectTable { |
} |
// Adds a new object to the table and return a new ID for it. |
- String add(x) { |
+ String add(x, {String id}) { |
// TODO(vsm): Cache x and reuse id. |
- final id = '$_name-${_nextId++}'; |
+ id = (id != null) ? id : '$_name-${_nextId++}'; |
_registry[id] = x; |
return id; |
} |
@@ -347,8 +348,13 @@ _deserialize(var message) { |
// Local function. |
return _proxiedObjectTable.get(id); |
} else { |
- // Remote function. Forward to its port. |
- return new JsFunction._internal(port, id); |
+ // Remote function. |
+ var jsFunction = _proxiedObjectTable.get(id); |
+ if (jsFunction == null) { |
+ jsFunction = new JsFunction._internal(port, id); |
+ _proxiedObjectTable.add(jsFunction, id: id); |
+ } |
+ return jsFunction; |
} |
} |
@@ -360,7 +366,12 @@ _deserialize(var message) { |
return _proxiedObjectTable.get(id); |
} else { |
// Remote object. |
- return new JsObject._internal(port, id); |
+ var jsObject = _proxiedObjectTable.get(id); |
+ if (jsObject == null) { |
+ jsObject = new JsObject._internal(port, id); |
+ _proxiedObjectTable.add(jsObject, id: id); |
+ } |
+ return jsObject; |
} |
} |