| 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 * Support for interoperating with JavaScript. | 6 * Support for interoperating with JavaScript. |
| 7 * | 7 * |
| 8 * This library provides access to JavaScript objects from Dart, allowing | 8 * This library provides access to JavaScript objects from Dart, allowing |
| 9 * Dart code to get and set properties, and call methods of JavaScript objects | 9 * Dart code to get and set properties, and call methods of JavaScript objects |
| 10 * and invoke JavaScript functions. The library takes care of converting | 10 * and invoke JavaScript functions. The library takes care of converting |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 * import 'dart:js'; | 36 * import 'dart:js'; |
| 37 * | 37 * |
| 38 * main() { | 38 * main() { |
| 39 * var object = new JsObject(context['Object']); | 39 * var object = new JsObject(context['Object']); |
| 40 * object['greeting'] = 'Hello'; | 40 * object['greeting'] = 'Hello'; |
| 41 * object['greet'] = (name) => "${object['greeting']} $name"; | 41 * object['greet'] = (name) => "${object['greeting']} $name"; |
| 42 * var message = object.callMethod('greet', ['JavaScript']); | 42 * var message = object.callMethod('greet', ['JavaScript']); |
| 43 * context['console'].callMethod('log', [message]); | 43 * context['console'].callMethod('log', [message]); |
| 44 * } | 44 * } |
| 45 * | 45 * |
| 46 * ## Proxying and Automatic Conversion | 46 * ## Proxying and automatic conversion |
| 47 * | 47 * |
| 48 * When setting properties on a JsObject or passing arguments to a Javascript | 48 * When setting properties on a JsObject or passing arguments to a Javascript |
| 49 * method or function, Dart objects are automatically converted or proxied to | 49 * method or function, Dart objects are automatically converted or proxied to |
| 50 * JavaScript objects. When accessing JavaScript properties, or when a Dart | 50 * JavaScript objects. When accessing JavaScript properties, or when a Dart |
| 51 * closure is invoked from JavaScript, the JavaScript objects are also | 51 * closure is invoked from JavaScript, the JavaScript objects are also |
| 52 * converted to Dart. | 52 * converted to Dart. |
| 53 * | 53 * |
| 54 * Functions and closures are proxied in such a way that they are callable. A | 54 * Functions and closures are proxied in such a way that they are callable. A |
| 55 * Dart closure assigned to a JavaScript property is proxied by a function in | 55 * Dart closure assigned to a JavaScript property is proxied by a function in |
| 56 * JavaScript. A JavaScript function accessed from Dart is proxied by a | 56 * JavaScript. A JavaScript function accessed from Dart is proxied by a |
| (...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 } | 528 } |
| 529 | 529 |
| 530 Object _getDartProxy(o, String propertyName, createProxy(o)) { | 530 Object _getDartProxy(o, String propertyName, createProxy(o)) { |
| 531 var dartProxy = JS('', '#[#]', o, propertyName); | 531 var dartProxy = JS('', '#[#]', o, propertyName); |
| 532 if (dartProxy == null) { | 532 if (dartProxy == null) { |
| 533 dartProxy = createProxy(o); | 533 dartProxy = createProxy(o); |
| 534 _defineProperty(o, propertyName, dartProxy); | 534 _defineProperty(o, propertyName, dartProxy); |
| 535 } | 535 } |
| 536 return dartProxy; | 536 return dartProxy; |
| 537 } | 537 } |
| OLD | NEW |