| 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 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 JS('bool', 'typeof # == "string"', o) || | 527 JS('bool', 'typeof # == "string"', o) || |
| 528 JS('bool', 'typeof # == "number"', o) || | 528 JS('bool', 'typeof # == "number"', o) || |
| 529 JS('bool', 'typeof # == "boolean"', o)) { | 529 JS('bool', 'typeof # == "boolean"', o)) { |
| 530 return o; | 530 return o; |
| 531 } else if (_isLocalObject(o) | 531 } else if (_isLocalObject(o) |
| 532 && (o is Blob || o is Event || o is KeyRange || o is ImageData | 532 && (o is Blob || o is Event || o is KeyRange || o is ImageData |
| 533 || o is Node || o is TypedData || o is Window)) { | 533 || o is Node || o is TypedData || o is Window)) { |
| 534 // long line: dart2js doesn't allow string concatenation in the JS() form | 534 // long line: dart2js doesn't allow string concatenation in the JS() form |
| 535 return JS('Blob|Event|KeyRange|ImageData|Node|TypedData|Window', '#', o); | 535 return JS('Blob|Event|KeyRange|ImageData|Node|TypedData|Window', '#', o); |
| 536 } else if (JS('bool', '# instanceof Date', o)) { | 536 } else if (JS('bool', '# instanceof Date', o)) { |
| 537 var ms = JS('num', '#.getMilliseconds()', o); | 537 var ms = JS('num', '#.getTime()', o); |
| 538 return new DateTime.fromMillisecondsSinceEpoch(ms); | 538 return new DateTime.fromMillisecondsSinceEpoch(ms); |
| 539 } else if (JS('bool', '#.constructor === #', o, _dartProxyCtor)) { | 539 } else if (JS('bool', '#.constructor === #', o, _dartProxyCtor)) { |
| 540 return JS('', '#.o', o); | 540 return JS('', '#.o', o); |
| 541 } else { | 541 } else { |
| 542 return _wrapToDart(o); | 542 return _wrapToDart(o); |
| 543 } | 543 } |
| 544 } | 544 } |
| 545 | 545 |
| 546 JsObject _wrapToDart(o) { | 546 JsObject _wrapToDart(o) { |
| 547 if (JS('bool', 'typeof # == "function"', o)) { | 547 if (JS('bool', 'typeof # == "function"', o)) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 564 // Dart in that context. The JS object will have a cached proxy | 564 // Dart in that context. The JS object will have a cached proxy |
| 565 // but it won't be a valid Dart object in this context. | 565 // but it won't be a valid Dart object in this context. |
| 566 // For now we throw away the cached proxy, but we should be able | 566 // For now we throw away the cached proxy, but we should be able |
| 567 // to cache proxies from multiple JS contexts and Dart isolates. | 567 // to cache proxies from multiple JS contexts and Dart isolates. |
| 568 if (dartProxy == null || !_isLocalObject(o)) { | 568 if (dartProxy == null || !_isLocalObject(o)) { |
| 569 dartProxy = createProxy(o); | 569 dartProxy = createProxy(o); |
| 570 _defineProperty(o, propertyName, dartProxy); | 570 _defineProperty(o, propertyName, dartProxy); |
| 571 } | 571 } |
| 572 return dartProxy; | 572 return dartProxy; |
| 573 } | 573 } |
| OLD | NEW |