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

Unified Diff: lib/html/dart2js/html_dart2js.dart

Side-by-side diff isn't available for this file because of its large size.
Issue 10914129: Remove proxying support from dart:html (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Regen dart:html Created 8 years, 3 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:
Download patch
« no previous file with comments | « client/dart.js ('k') | lib/html/dartium/html_dartium.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/html/dart2js/html_dart2js.dart
diff --git a/lib/html/dart2js/html_dart2js.dart b/lib/html/dart2js/html_dart2js.dart
index a98bb1e5bf25d44f513d19f2ff92036ab9917f93..3648b54a2d1fa5401f4f629d2b43a009fd2fd039 100644
--- a/lib/html/dart2js/html_dart2js.dart
+++ b/lib/html/dart2js/html_dart2js.dart
@@ -37910,43 +37910,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) {
@@ -37969,147 +37932,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 {
@@ -38129,53 +37957,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.
« no previous file with comments | « client/dart.js ('k') | lib/html/dartium/html_dartium.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698