| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 _serialize(var message) { | 5 _serialize(var message) { |
| 6 return new _JsSerializer().traverse(message); | 6 return new _JsSerializer().traverse(message); |
| 7 } | 7 } |
| 8 | 8 |
| 9 class JsProxy { | 9 class JsProxy { |
| 10 SendPortSync _port; | 10 SendPortSync _port; |
| 11 final _id; | 11 final _id; |
| 12 | 12 |
| 13 JsProxy._internal(this._port, this._id); | 13 JsProxy._internal(this._port, this._id); |
| 14 | 14 |
| 15 noSuchMethod(method, args) { | 15 noSuchMethod(method, args) { |
| 16 var result = _port.callSync([_id, method, args]); | 16 var result = _port.callSync([_id, method, args]); |
| 17 switch (result[0]) { | 17 switch (result[0]) { |
| 18 case 'return': return result[1]; | 18 case 'return': return result[1]; |
| 19 case 'exception': throw result[1]; | 19 case 'exception': throw result[1]; |
| 20 case 'none': throw new NoSuchMethodException(this, method, args); | 20 case 'none': throw new NoSuchMethodException(this, method, args); |
| 21 default: throw 'Invalid return value'; | 21 default: throw 'Invalid return value'; |
| 22 } | 22 } |
| 23 } | 23 } |
| 24 } | 24 } |
| 25 | 25 |
| 26 int _localNextElementId = 0; | 26 int _localNextElementId = 0; |
| 27 | 27 |
| 28 const _DART_ID = 'data-dart_id'; | 28 const _DART_ID = 'data-dart_id'; |
| 29 | 29 |
| 30 var _elementId(Element e) { | 30 _elementId(Element e) { |
| 31 if (e.attributes.containsKey(_DART_ID)) return e.attributes[_DART_ID]; | 31 if (e.attributes.containsKey(_DART_ID)) return e.attributes[_DART_ID]; |
| 32 var id = '$_isolateId-${_localNextElementId++}'; | 32 var id = '$_isolateId-${_localNextElementId++}'; |
| 33 e.attributes[_DART_ID] = id; | 33 e.attributes[_DART_ID] = id; |
| 34 return id; | 34 return id; |
| 35 } | 35 } |
| 36 | 36 |
| 37 Element _getElement(var id) { | 37 Element _getElement(var id) { |
| 38 var list = queryAll('[$_DART_ID="$id"]'); | 38 var list = queryAll('[$_DART_ID="$id"]'); |
| 39 if (list.length > 1) throw 'Non unique ID: $id'; | 39 if (list.length > 1) throw 'Non unique ID: $id'; |
| 40 if (list.length == 0) { | 40 if (list.length == 0) { |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 } | 368 } |
| 369 } | 369 } |
| 370 | 370 |
| 371 get _isolateId => ReceivePortSync._isolateId; | 371 get _isolateId => ReceivePortSync._isolateId; |
| 372 | 372 |
| 373 void _dispatchEvent(String receiver, var message) { | 373 void _dispatchEvent(String receiver, var message) { |
| 374 var event = document.$dom_createEvent('TextEvent'); | 374 var event = document.$dom_createEvent('TextEvent'); |
| 375 event.initTextEvent(receiver, false, false, window, JSON.stringify(message)); | 375 event.initTextEvent(receiver, false, false, window, JSON.stringify(message)); |
| 376 window.$dom_dispatchEvent(event); | 376 window.$dom_dispatchEvent(event); |
| 377 } | 377 } |
| OLD | NEW |