Index: lib/html/dart2js/html_dart2js.dart |
diff --git a/lib/html/dart2js/html_dart2js.dart b/lib/html/dart2js/html_dart2js.dart |
index d260a5c029e2835b9fd9bfdf3ab4924b47ae9beb..dca6f89e9459a8438f85e4874192ed9c9f0a0076 100644 |
--- a/lib/html/dart2js/html_dart2js.dart |
+++ b/lib/html/dart2js/html_dart2js.dart |
@@ -37663,9 +37663,20 @@ _serialize(var message) { |
} |
class JsProxy { |
+ SendPortSync _port; |
final _id; |
- JsProxy._internal(this._id); |
+ JsProxy._internal(this._port, this._id); |
+ |
+ noSuchMethod(method, args) { |
+ var result = _port.callSync([_id, method, args]); |
+ switch (result[0]) { |
+ case 'return': return result[1]; |
+ case 'exception': throw result[1]; |
+ case 'none': throw new NoSuchMethodException(this, method, args); |
+ default: throw 'Invalid return value'; |
+ } |
+ } |
} |
class _JsSerializer extends _Serializer { |
@@ -37674,7 +37685,7 @@ class _JsSerializer extends _Serializer { |
if (x is _JsSendPortSync) return visitJsSendPortSync(x); |
if (x is _LocalSendPortSync) return visitLocalSendPortSync(x); |
if (x is _RemoteSendPortSync) return visitRemoteSendPortSync(x); |
- throw "Illegal underlying port $x"; |
+ throw "Unknown port type $x"; |
} |
visitJsSendPortSync(_JsSendPortSync x) { |
@@ -37696,17 +37707,19 @@ class _JsSerializer extends _Serializer { |
if (x is JsProxy) return visitJsProxy(x); |
// TODO: Handle DOM elements and proxy other objects. |
- var proxyId = _makeDartProxyRef(x); |
- return [ 'objref', 'dart', proxyId ]; |
+ var proxyId = _dartProxyRegistry._add(x); |
+ return [ 'objref', proxyId, |
+ visitSendPortSync(_dartProxyRegistry._sendPort) ]; |
} |
visitFunction(Function func) { |
return [ 'funcref', |
- _makeFunctionRef(func), visitSendPortSync(_sendPort()), null ]; |
+ _functionRegistry._add(func), |
+ visitSendPortSync(_functionRegistry._sendPort), null ]; |
} |
visitJsProxy(JsProxy proxy) { |
- return [ 'objref', 'nativejs', proxy._id ]; |
+ return [ 'objref', proxy._id, visitSendPortSync(proxy._port) ]; |
} |
} |
@@ -37717,8 +37730,12 @@ class _Registry<T> { |
final String _name; |
int _nextId; |
final Map<String, T> _registry; |
+ final ReceivePortSync _port; |
- _Registry(this._name) : _nextId = 0, _registry = <T>{}; |
+ _Registry(this._name) : |
+ _nextId = 0, |
+ _registry = <T>{}, |
+ _port = new ReceivePortSync(); |
String _add(T x) { |
// TODO(vsm): Cache x and reuse id. |
@@ -37730,14 +37747,12 @@ class _Registry<T> { |
T _get(String id) { |
return _registry[id]; |
} |
+ |
+ get _sendPort => _port.toSendPort(); |
} |
class _FunctionRegistry extends _Registry<Function> { |
- final ReceivePortSync _port; |
- |
- _FunctionRegistry() : |
- super('func-ref'), |
- _port = new ReceivePortSync() { |
+ _FunctionRegistry() : super('func-ref') { |
_port.receive((msg) { |
final id = msg[0]; |
final args = msg[1]; |
@@ -37752,8 +37767,6 @@ class _FunctionRegistry extends _Registry<Function> { |
} |
}); |
} |
- |
- get _sendPort => _port.toSendPort(); |
} |
_FunctionRegistry __functionRegistry; |
@@ -37761,15 +37774,21 @@ get _functionRegistry { |
if (__functionRegistry === null) __functionRegistry = new _FunctionRegistry(); |
return __functionRegistry; |
} |
- |
-_makeFunctionRef(f) => _functionRegistry._add(f); |
-_sendPort() => _functionRegistry._sendPort; |
/// End of function serialization implementation. |
/// Object proxy implementation. |
class _DartProxyRegistry extends _Registry<Object> { |
- _DartProxyRegistry() : super('dart-ref'); |
+ final ReceivePortSync _port; |
+ |
+ _DartProxyRegistry() : |
+ super('dart-ref'), |
+ _port = new ReceivePortSync() { |
+ _port.receive((msg) { |
+ // TODO(vsm): Support a mechanism to register a handler here. |
+ throw 'Invocation unsupported on Dart proxies'; |
+ }); |
+ } |
} |
_DartProxyRegistry __dartProxyRegistry; |
@@ -37780,9 +37799,6 @@ get _dartProxyRegistry { |
return __dartProxyRegistry; |
} |
-_makeDartProxyRef(f) => _dartProxyRegistry._add(f); |
-_getDartProxyObj(id) => _dartProxyRegistry._get(id); |
- |
/// End of object proxy implementation. |
_deserialize(var message) { |
@@ -37832,18 +37848,13 @@ class _JsDeserializer extends _Deserializer { |
} |
deserializeProxy(x) { |
- String tag = x[1]; |
- switch (tag) { |
- case 'nativejs': |
- var id = x[2]; |
- return new JsProxy._internal(id); |
- case 'dart': |
- var id = x[2]; |
- // TODO(vsm): Check for isolate id. If the isolate isn't the |
- // current isolate, return a DartProxy. |
- return _getDartProxyObj(id); |
- default: throw 'Illegal proxy: $x'; |
- } |
+ var id = x[1]; |
+ var port = deserializeSendPort(x[2]); |
+ if (port is _JsSendPortSync) return new JsProxy._internal(port, id); |
+ if (port is _LocalSendPortSync) return _dartProxyRegistry._get(id); |
+ // TODO(vsm): Support this case. |
+ if (port is _RemoteSendPortSync) throw 'Remote Dart proxies unsupported'; |
+ throw 'Illegal proxy: $port'; |
} |
} |