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 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 int get length { | 442 int get length { |
443 // Check the length honours the List contract. | 443 // Check the length honours the List contract. |
444 var len = JS('', '#.length', _jsObject); | 444 var len = JS('', '#.length', _jsObject); |
445 // JavaScript arrays have lengths which are unsigned 32-bit integers. | 445 // JavaScript arrays have lengths which are unsigned 32-bit integers. |
446 if (JS('bool', 'typeof # === "number" && (# >>> 0) === #', len, len, len)) { | 446 if (JS('bool', 'typeof # === "number" && (# >>> 0) === #', len, len, len)) { |
447 return JS('int', '#', len); | 447 return JS('int', '#', len); |
448 } | 448 } |
449 throw new StateError('Bad JsArray length'); | 449 throw new StateError('Bad JsArray length'); |
450 } | 450 } |
451 | 451 |
452 void set length(int length) { super['length'] = length; } | 452 set length(int length) { super['length'] = length; } |
453 | 453 |
454 | 454 |
455 // Methods overriden for better performance | 455 // Methods overriden for better performance |
456 | 456 |
457 void add(E value) { | 457 void add(E value) { |
458 callMethod('push', [value]); | 458 callMethod('push', [value]); |
459 } | 459 } |
460 | 460 |
461 void addAll(Iterable<E> iterable) { | 461 void addAll(Iterable<E> iterable) { |
462 var list = (JS('bool', '# instanceof Array', iterable)) | 462 var list = (JS('bool', '# instanceof Array', iterable)) |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 // Dart in that context. The JS object will have a cached proxy | 627 // Dart in that context. The JS object will have a cached proxy |
628 // but it won't be a valid Dart object in this context. | 628 // but it won't be a valid Dart object in this context. |
629 // For now we throw away the cached proxy, but we should be able | 629 // For now we throw away the cached proxy, but we should be able |
630 // to cache proxies from multiple JS contexts and Dart isolates. | 630 // to cache proxies from multiple JS contexts and Dart isolates. |
631 if (dartProxy == null || !_isLocalObject(o)) { | 631 if (dartProxy == null || !_isLocalObject(o)) { |
632 dartProxy = createProxy(o); | 632 dartProxy = createProxy(o); |
633 _defineProperty(o, propertyName, dartProxy); | 633 _defineProperty(o, propertyName, dartProxy); |
634 } | 634 } |
635 return dartProxy; | 635 return dartProxy; |
636 } | 636 } |
OLD | NEW |