| Index: lib/html/src/Isolates.dart
|
| diff --git a/lib/html/src/Isolates.dart b/lib/html/src/Isolates.dart
|
| index 690600548c160d75249713aa2b414cfc9c6579a1..e3e89c708e8335441c770d02345dfd8000b38d9b 100644
|
| --- a/lib/html/src/Isolates.dart
|
| +++ b/lib/html/src/Isolates.dart
|
| @@ -6,43 +6,6 @@ _serialize(var message) {
|
| return new _JsSerializer().traverse(message);
|
| }
|
|
|
| -class JsProxy {
|
| - SendPortSync _port;
|
| - final _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';
|
| - }
|
| - }
|
| -}
|
| -
|
| -int _localNextElementId = 0;
|
| -
|
| -const _DART_ID = 'data-dart_id';
|
| -
|
| -_elementId(Element e) {
|
| - if (e.attributes.containsKey(_DART_ID)) return e.attributes[_DART_ID];
|
| - var id = '$_isolateId-${_localNextElementId++}';
|
| - e.attributes[_DART_ID] = id;
|
| - return id;
|
| -}
|
| -
|
| -Element _getElement(var id) {
|
| - var list = queryAll('[$_DART_ID="$id"]');
|
| - if (list.length > 1) throw 'Non unique ID: $id';
|
| - if (list.length == 0) {
|
| - throw 'Only elements attached to document can be serialized: $id';
|
| - }
|
| - return list[0];
|
| -}
|
| -
|
| class _JsSerializer extends _Serializer {
|
|
|
| visitSendPortSync(SendPortSync x) {
|
| @@ -65,147 +28,12 @@ class _JsSerializer extends _Serializer {
|
| return [ 'sendport', 'dart',
|
| x._receivePort._isolateId, x._receivePort._portId ];
|
| }
|
| -
|
| - visitObject(Object x) {
|
| - if (x is Function) return visitFunction(x);
|
| - if (x is JsProxy) return visitJsProxy(x);
|
| - if (x is Element) return visitElement(x);
|
| -
|
| - // TODO: Handle DOM elements and proxy other objects.
|
| - var proxyId = _dartProxyRegistry._add(x);
|
| - return [ 'objref', proxyId,
|
| - visitSendPortSync(_dartProxyRegistry._sendPort) ];
|
| - }
|
| -
|
| - visitFunction(Function func) {
|
| - // Look for a cached serialization first. The cached version
|
| - // should point to the original port.
|
| - var serialized = _deserializedFunctionTable.find(func);
|
| - if (serialized != null) return serialized;
|
| - // Create a new serialization forwarding to this port.
|
| - return [ 'funcref',
|
| - _functionRegistry._add(func),
|
| - visitSendPortSync(_functionRegistry._sendPort), null ];
|
| - }
|
| -
|
| - visitJsProxy(JsProxy proxy) {
|
| - return [ 'objref', proxy._id, visitSendPortSync(proxy._port) ];
|
| - }
|
| -
|
| - visitElement(Element element) {
|
| - var id = _elementId(element);
|
| - // Verify that the element is connected to the document.
|
| - // Otherwise, we will not be able to find it on the other side.
|
| - _getElement(id);
|
| - return [ 'element', id ];
|
| - }
|
| -}
|
| -
|
| -// Leaking implementation. Later will be backend specific and hopefully
|
| -// not leaking (at least in most of the cases.)
|
| -// TODO: provide better, backend specific implementation.
|
| -class _Registry<T> {
|
| - final String _name;
|
| - int _nextId;
|
| - final Map<String, T> _registry;
|
| - final ReceivePortSync _port;
|
| -
|
| - _Registry(this._name) :
|
| - _nextId = 0,
|
| - _registry = <T>{},
|
| - _port = new ReceivePortSync();
|
| -
|
| - String _add(T x) {
|
| - // TODO(vsm): Cache x and reuse id.
|
| - final id = '$_name-${_nextId++}';
|
| - _registry[id] = x;
|
| - return id;
|
| - }
|
| -
|
| - T _get(String id) {
|
| - return _registry[id];
|
| - }
|
| -
|
| - get _sendPort => _port.toSendPort();
|
| -}
|
| -
|
| -class _FunctionRegistry extends _Registry<Function> {
|
| - _FunctionRegistry() : super('func-ref') {
|
| - _port.receive((msg) {
|
| - final id = msg[0];
|
| - final args = msg[1];
|
| - final f = _registry[id];
|
| - switch (args.length) {
|
| - case 0: return f();
|
| - case 1: return f(args[0]);
|
| - case 2: return f(args[0], args[1]);
|
| - case 3: return f(args[0], args[1], args[2]);
|
| - case 4: return f(args[0], args[1], args[2], args[3]);
|
| - default: throw 'Unsupported number of arguments.';
|
| - }
|
| - });
|
| - }
|
| -}
|
| -
|
| -_FunctionRegistry __functionRegistry;
|
| -get _functionRegistry {
|
| - if (__functionRegistry === null) __functionRegistry = new _FunctionRegistry();
|
| - return __functionRegistry;
|
| -}
|
| -/// End of function serialization implementation.
|
| -
|
| -/// Object proxy implementation.
|
| -
|
| -class _DartProxyRegistry extends _Registry<Object> {
|
| - _DartProxyRegistry() : super('dart-ref') {
|
| - _port.receive((msg) {
|
| - // TODO(vsm): Support a mechanism to register a handler here.
|
| - throw 'Invocation unsupported on Dart proxies';
|
| - });
|
| - }
|
| -}
|
| -
|
| -_DartProxyRegistry __dartProxyRegistry;
|
| -get _dartProxyRegistry {
|
| - if (__dartProxyRegistry === null) {
|
| - __dartProxyRegistry = new _DartProxyRegistry();
|
| - }
|
| - return __dartProxyRegistry;
|
| }
|
|
|
| -/// End of object proxy implementation.
|
| -
|
| _deserialize(var message) {
|
| return new _JsDeserializer().deserialize(message);
|
| }
|
|
|
| -// TODO(vsm): Replace this with a hash map once functions are
|
| -// hashable.
|
| -class _DeserializedFunctionTable {
|
| - List data;
|
| - _DeserializedFunctionTable() {
|
| - data = [];
|
| - }
|
| -
|
| - find(Function f) {
|
| - for (var item in data) {
|
| - if (f == item[0]) return item[1];
|
| - }
|
| - return null;
|
| - }
|
| -
|
| - add(Function f, x) {
|
| - data.add([f, x]);
|
| - }
|
| -}
|
| -
|
| -_DeserializedFunctionTable __deserializedFunctionTable = null;
|
| -get _deserializedFunctionTable {
|
| - if (__deserializedFunctionTable == null) {
|
| - __deserializedFunctionTable = new _DeserializedFunctionTable();
|
| - }
|
| - return __deserializedFunctionTable;
|
| -}
|
|
|
| class _JsDeserializer extends _Deserializer {
|
|
|
| @@ -225,53 +53,6 @@ class _JsDeserializer extends _Deserializer {
|
| throw 'Illegal SendPortSync type: $tag';
|
| }
|
| }
|
| -
|
| - deserializeObject(List x) {
|
| - String tag = x[0];
|
| - switch (tag) {
|
| - case 'funcref': return deserializeFunction(x);
|
| - case 'objref': return deserializeProxy(x);
|
| - case 'element': return deserializeElement(x);
|
| - default: throw 'Illegal object type: $x';
|
| - }
|
| - }
|
| -
|
| - deserializeFunction(List x) {
|
| - var id = x[1];
|
| - // If the sendPort is local, just return the underlying function.
|
| - // Otherwise, create a new function that forwards to the remote
|
| - // port.
|
| - SendPortSync port = deserializeSendPort(x[2]);
|
| - if (port is _LocalSendPortSync) {
|
| - return _functionRegistry._get(id);
|
| - }
|
| - // TODO: Support varargs when there is support in the language.
|
| - var f = ([arg0 = _UNSPECIFIED, arg1 = _UNSPECIFIED,
|
| - arg2 = _UNSPECIFIED, arg3 = _UNSPECIFIED]) {
|
| - var args = [arg0, arg1, arg2, arg3];
|
| - var last = args.indexOf(_UNSPECIFIED);
|
| - if (last >= 0) args = args.getRange(0, last);
|
| - var message = [id, args];
|
| - return port.callSync(message);
|
| - };
|
| - _deserializedFunctionTable.add(f, x);
|
| - return f;
|
| - }
|
| -
|
| - deserializeProxy(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';
|
| - }
|
| -
|
| - deserializeElement(x) {
|
| - var id = x[1];
|
| - return _getElement(id);
|
| - }
|
| }
|
|
|
| // The receiver is JS.
|
|
|