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

Unified Diff: sdk/lib/js/dartium/js_dartium.dart

Issue 26092003: Maintain referential integrity of proxy instances in dart:js (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add proxy stability for Dart->JS Created 7 years, 2 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
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;
}
}

Powered by Google App Engine
This is Rietveld 408576698