| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 /** | 5 /** |
| 6 * The js.dart library provides simple JavaScript invocation from Dart that | 6 * The js.dart library provides simple JavaScript invocation from Dart that |
| 7 * works on both Dartium and on other modern browsers via Dart2JS. | 7 * works on both Dartium and on other modern browsers via Dart2JS. |
| 8 * | 8 * |
| 9 * It provides a model based on scoped [JsObject] objects. Proxies give Dart | 9 * It provides a model based on scoped [JsObject] objects. Proxies give Dart |
| 10 * code access to JavaScript objects, fields, and functions as well as the | 10 * code access to JavaScript objects, fields, and functions as well as the |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 return _forward(this, name, 'method', args != null ? args : []); | 204 return _forward(this, name, 'method', args != null ? args : []); |
| 205 } | 205 } |
| 206 | 206 |
| 207 // Forward member accesses to the backing JavaScript object. | 207 // Forward member accesses to the backing JavaScript object. |
| 208 static _forward(JsObject receiver, String member, String kind, List args) { | 208 static _forward(JsObject receiver, String member, String kind, List args) { |
| 209 var result = receiver._port.callSync([receiver._id, member, kind, | 209 var result = receiver._port.callSync([receiver._id, member, kind, |
| 210 args.map(_serialize).toList()]); | 210 args.map(_serialize).toList()]); |
| 211 switch (result[0]) { | 211 switch (result[0]) { |
| 212 case 'return': return _deserialize(result[1]); | 212 case 'return': return _deserialize(result[1]); |
| 213 case 'throws': throw _deserialize(result[1]); | 213 case 'throws': throw _deserialize(result[1]); |
| 214 case 'none': throw new NoSuchMethodError(receiver, member, args, {}); | 214 case 'none': |
| 215 throw new NoSuchMethodError(receiver, new Symbol(member), args, {}); |
| 215 default: throw 'Invalid return value'; | 216 default: throw 'Invalid return value'; |
| 216 } | 217 } |
| 217 } | 218 } |
| 218 } | 219 } |
| 219 | 220 |
| 220 /// A [JsObject] subtype to JavaScript functions. | 221 /// A [JsObject] subtype to JavaScript functions. |
| 221 class JsFunction extends JsObject implements Serializable<JsFunction> { | 222 class JsFunction extends JsObject implements Serializable<JsFunction> { |
| 222 JsFunction._internal(SendPortSync port, String id) | 223 JsFunction._internal(SendPortSync port, String id) |
| 223 : super._internal(port, id); | 224 : super._internal(port, id); |
| 224 | 225 |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 // Serialized type. | 369 // Serialized type. |
| 369 return message; | 370 return message; |
| 370 } | 371 } |
| 371 var tag = message[0]; | 372 var tag = message[0]; |
| 372 switch (tag) { | 373 switch (tag) { |
| 373 case 'funcref': return deserializeFunction(message); | 374 case 'funcref': return deserializeFunction(message); |
| 374 case 'objref': return deserializeObject(message); | 375 case 'objref': return deserializeObject(message); |
| 375 } | 376 } |
| 376 throw 'Unsupported serialized data: $message'; | 377 throw 'Unsupported serialized data: $message'; |
| 377 } | 378 } |
| OLD | NEW |