| Index: lib/html/dartium/html_dartium.dart
|
| diff --git a/lib/html/dartium/html_dartium.dart b/lib/html/dartium/html_dartium.dart
|
| index 193777a97bd1343ad9347db35d68ad69374790c6..f270742488e88bb4de8fdc90485fea3e3a3c5cd4 100644
|
| --- a/lib/html/dartium/html_dartium.dart
|
| +++ b/lib/html/dartium/html_dartium.dart
|
| @@ -40771,9 +40771,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 {
|
| @@ -40782,7 +40793,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) {
|
| @@ -40804,17 +40815,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) ];
|
| }
|
| }
|
|
|
| @@ -40825,8 +40838,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.
|
| @@ -40838,14 +40855,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];
|
| @@ -40860,8 +40875,6 @@ class _FunctionRegistry extends _Registry<Function> {
|
| }
|
| });
|
| }
|
| -
|
| - get _sendPort => _port.toSendPort();
|
| }
|
|
|
| _FunctionRegistry __functionRegistry;
|
| @@ -40869,15 +40882,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;
|
| @@ -40888,9 +40907,6 @@ get _dartProxyRegistry {
|
| return __dartProxyRegistry;
|
| }
|
|
|
| -_makeDartProxyRef(f) => _dartProxyRegistry._add(f);
|
| -_getDartProxyObj(id) => _dartProxyRegistry._get(id);
|
| -
|
| /// End of object proxy implementation.
|
|
|
| _deserialize(var message) {
|
| @@ -40940,18 +40956,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';
|
| }
|
| }
|
|
|
|
|