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

Unified Diff: pkg/browser/lib/interop.js

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
« no previous file with comments | « no previous file | sdk/lib/js/dart2js/js_dart2js.dart » ('j') | sdk/lib/js/dart2js/js_dart2js.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/browser/lib/interop.js
diff --git a/pkg/browser/lib/interop.js b/pkg/browser/lib/interop.js
index 8577e4f28b8c30aa67270ff78727da5789d0bea0..fd475597ab7139891b959ccfcffff10ffb8a5d06 100644
--- a/pkg/browser/lib/interop.js
+++ b/pkg/browser/lib/interop.js
@@ -14,7 +14,7 @@ function ReceivePortSync() {
}
// Type for remote proxies to Dart objects with dart2js.
-function DartProxy(o) {
+function DartObject(o) {
this.o = o;
}
@@ -250,16 +250,16 @@ function DartProxy(o) {
return Object.keys(this.map).length;
}
+ var _dartRefPropertyName = "_$dart_ref";
+
// Adds an object to the table and return an ID for serialization.
ProxiedObjectTable.prototype.add = function (obj) {
- for (var ref in this.map) {
- var o = this.map[ref];
- if (o === obj) {
- return ref;
- }
+ var ref = obj[_dartRefPropertyName];
+ if (ref == null) {
+ ref = this.name + '-' + this._nextId++;
+ this.map[ref] = obj;
+ Object.defineProperty(obj, _dartRefPropertyName, { value: ref });
}
- var ref = this.name + '-' + this._nextId++;
- this.map[ref] = obj;
return ref;
}
@@ -328,7 +328,7 @@ function DartProxy(o) {
proxiedObjectTable._initialize()
// Type for remote proxies to Dart objects.
- function DartProxy(id, sendPort) {
+ function DartObject(id, sendPort) {
this.id = id;
this.port = sendPort;
}
@@ -361,7 +361,7 @@ function DartProxy(o) {
proxiedObjectTable.add(message),
proxiedObjectTable.sendPort ];
}
- } else if (message instanceof DartProxy) {
+ } else if (message instanceof DartObject) {
// Remote object proxy.
return [ 'objref', message.id, message.port ];
} else {
@@ -417,7 +417,7 @@ function DartProxy(o) {
}
}
- // Creates a DartProxy to forwards to the remote object.
+ // Creates a DartObject to forwards to the remote object.
function deserializeObject(message) {
var id = message[1];
var port = message[2];
@@ -427,7 +427,7 @@ function DartProxy(o) {
return proxiedObjectTable.get(id);
} else {
// Remote object.
- return new DartProxy(id, port);
+ return new DartObject(id, port);
}
}
« no previous file with comments | « no previous file | sdk/lib/js/dart2js/js_dart2js.dart » ('j') | sdk/lib/js/dart2js/js_dart2js.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698