Index: pkg/browser/lib/interop.js |
diff --git a/pkg/browser/lib/interop.js b/pkg/browser/lib/interop.js |
index 99556fa864252c8a1abca879d9ca9ed853d82d99..8577e4f28b8c30aa67270ff78727da5789d0bea0 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 DartObject(o) { |
+function DartProxy(o) { |
this.o = o; |
} |
@@ -250,27 +250,17 @@ function DartObject(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, id) { |
- if (id != null) { |
- this.map[id] = obj; |
- return id; |
- } else { |
- var ref = obj[_dartRefPropertyName]; |
- if (ref == null) { |
- ref = this.name + '-' + this._nextId++; |
- this.map[ref] = obj; |
- Object.defineProperty(obj, _dartRefPropertyName, { value: ref }); |
+ ProxiedObjectTable.prototype.add = function (obj) { |
+ for (var ref in this.map) { |
+ var o = this.map[ref]; |
+ if (o === obj) { |
+ return ref; |
} |
- return ref; |
} |
- } |
- |
- // Gets the object or function corresponding to this ID. |
- ProxiedObjectTable.prototype.contains = function (id) { |
- return this.map.hasOwnProperty(id); |
+ var ref = this.name + '-' + this._nextId++; |
+ this.map[ref] = obj; |
+ return ref; |
} |
// Gets the object or function corresponding to this ID. |
@@ -338,7 +328,7 @@ function DartObject(o) { |
proxiedObjectTable._initialize() |
// Type for remote proxies to Dart objects. |
- function DartObject(id, sendPort) { |
+ function DartProxy(id, sendPort) { |
this.id = id; |
this.port = sendPort; |
} |
@@ -371,7 +361,7 @@ function DartObject(o) { |
proxiedObjectTable.add(message), |
proxiedObjectTable.sendPort ]; |
} |
- } else if (message instanceof DartObject) { |
+ } else if (message instanceof DartProxy) { |
// Remote object proxy. |
return [ 'objref', message.id, message.port ]; |
} else { |
@@ -412,9 +402,6 @@ function DartObject(o) { |
return proxiedObjectTable.get(id); |
} else { |
// Remote function. Forward to its port. |
- if (proxiedObjectTable.contains(id)) { |
- return proxiedObjectTable.get(id); |
- } |
var f = function () { |
var args = Array.prototype.slice.apply(arguments); |
args.splice(0, 0, this); |
@@ -426,12 +413,11 @@ function DartObject(o) { |
// Cache the remote id and port. |
f._dart_id = id; |
f._dart_port = port; |
- proxiedObjectTable.add(f, id); |
return f; |
} |
} |
- // Creates a DartObject to forwards to the remote object. |
+ // Creates a DartProxy to forwards to the remote object. |
function deserializeObject(message) { |
var id = message[1]; |
var port = message[2]; |
@@ -441,12 +427,7 @@ function DartObject(o) { |
return proxiedObjectTable.get(id); |
} else { |
// Remote object. |
- if (proxiedObjectTable.contains(id)) { |
- return proxiedObjectTable.get(id); |
- } |
- proxy = new DartObject(id, port); |
- proxiedObjectTable.add(proxy, id); |
- return proxy; |
+ return new DartProxy(id, port); |
} |
} |