Chromium Code Reviews| 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 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 369 if (start < 0 || start > this.length) { | 369 if (start < 0 || start > this.length) { |
| 370 throw new RangeError.range(start, 0, this.length); | 370 throw new RangeError.range(start, 0, this.length); |
| 371 } | 371 } |
| 372 if (end < start || end > this.length) { | 372 if (end < start || end > this.length) { |
| 373 throw new RangeError.range(end, start, this.length); | 373 throw new RangeError.range(end, start, this.length); |
| 374 } | 374 } |
| 375 } | 375 } |
| 376 | 376 |
| 377 // Methods required by ListMixin | 377 // Methods required by ListMixin |
| 378 | 378 |
| 379 E operator [](int index) { | 379 E operator [](index) { |
| 380 _checkIndex(index); | 380 if (index is num && index == index.toInt()) { |
|
Jacob
2013/10/29 22:08:03
can you file a bug to find a better long term solu
justinfagnani
2013/10/30 02:16:36
Done.
| |
| 381 _checkIndex(index); | |
| 382 } | |
| 381 return super[index]; | 383 return super[index]; |
| 382 } | 384 } |
| 383 | 385 |
| 384 void operator []=(int index, E value) { | 386 void operator []=(index, E value) { |
| 385 _checkIndex(index); | 387 if (index is num && index == index.toInt()) { |
| 388 _checkIndex(index); | |
| 389 } | |
| 386 super[index] = value; | 390 super[index] = value; |
| 387 } | 391 } |
| 388 | 392 |
| 389 int get length => super['length']; | 393 int get length => super['length']; |
| 390 | 394 |
| 391 void set length(int length) { super['length'] = length; } | 395 void set length(int length) { super['length'] = length; } |
| 392 | 396 |
| 393 | 397 |
| 394 // Methods overriden for better performance | 398 // Methods overriden for better performance |
| 395 | 399 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 500 JS('bool', 'typeof # == "string"', o) || | 504 JS('bool', 'typeof # == "string"', o) || |
| 501 JS('bool', 'typeof # == "number"', o) || | 505 JS('bool', 'typeof # == "number"', o) || |
| 502 JS('bool', 'typeof # == "boolean"', o)) { | 506 JS('bool', 'typeof # == "boolean"', o)) { |
| 503 return o; | 507 return o; |
| 504 } else if (o is Blob || o is KeyRange || o is ImageData || o is Node | 508 } else if (o is Blob || o is KeyRange || o is ImageData || o is Node |
| 505 || o is TypedData) { | 509 || o is TypedData) { |
| 506 return JS('Blob|KeyRange|ImageData|Node|TypedData', '#', o); | 510 return JS('Blob|KeyRange|ImageData|Node|TypedData', '#', o); |
| 507 } else if (JS('bool', '# instanceof Date', o)) { | 511 } else if (JS('bool', '# instanceof Date', o)) { |
| 508 var ms = JS('num', '#.getMilliseconds()', o); | 512 var ms = JS('num', '#.getMilliseconds()', o); |
| 509 return new DateTime.fromMillisecondsSinceEpoch(ms); | 513 return new DateTime.fromMillisecondsSinceEpoch(ms); |
| 514 } else if (JS('bool', '#.constructor === DartObject', o)) { | |
| 515 return JS('', '#.o', o); | |
| 510 } else { | 516 } else { |
| 511 return _wrapToDart(o); | 517 return _wrapToDart(o); |
| 512 } | 518 } |
| 513 } | 519 } |
| 514 | 520 |
| 515 JsObject _wrapToDart(o) { | 521 JsObject _wrapToDart(o) { |
| 516 if (JS('bool', 'typeof # == "function"', o)) { | 522 if (JS('bool', 'typeof # == "function"', o)) { |
| 517 return _getDartProxy(o, _DART_CLOSURE_PROPERTY_NAME, | 523 return _getDartProxy(o, _DART_CLOSURE_PROPERTY_NAME, |
| 518 (o) => new JsFunction._fromJs(o)); | 524 (o) => new JsFunction._fromJs(o)); |
| 519 } else if (JS('bool', '# instanceof Array', o)) { | 525 } else if (JS('bool', '# instanceof Array', o)) { |
| 520 return _getDartProxy(o, _DART_OBJECT_PROPERTY_NAME, | 526 return _getDartProxy(o, _DART_OBJECT_PROPERTY_NAME, |
| 521 (o) => new JsArray._fromJs(o)); | 527 (o) => new JsArray._fromJs(o)); |
| 522 } else if (JS('bool', '#.constructor === DartObject', o)) { | |
| 523 return JS('', '#.o', o); | |
| 524 } else { | 528 } else { |
| 525 return _getDartProxy(o, _DART_OBJECT_PROPERTY_NAME, | 529 return _getDartProxy(o, _DART_OBJECT_PROPERTY_NAME, |
| 526 (o) => new JsObject._fromJs(o)); | 530 (o) => new JsObject._fromJs(o)); |
| 527 } | 531 } |
| 528 } | 532 } |
| 529 | 533 |
| 530 Object _getDartProxy(o, String propertyName, createProxy(o)) { | 534 Object _getDartProxy(o, String propertyName, createProxy(o)) { |
| 531 var dartProxy = JS('', '#[#]', o, propertyName); | 535 var dartProxy = JS('', '#[#]', o, propertyName); |
| 532 if (dartProxy == null) { | 536 if (dartProxy == null) { |
| 533 dartProxy = createProxy(o); | 537 dartProxy = createProxy(o); |
| 534 _defineProperty(o, propertyName, dartProxy); | 538 _defineProperty(o, propertyName, dartProxy); |
| 535 } | 539 } |
| 536 return dartProxy; | 540 return dartProxy; |
| 537 } | 541 } |
| OLD | NEW |