Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 477 Object _convertToDart(o) { | 477 Object _convertToDart(o) { |
| 478 if (JS('bool', '# == null', o) || | 478 if (JS('bool', '# == null', o) || |
| 479 JS('bool', 'typeof # == "string"', o) || | 479 JS('bool', 'typeof # == "string"', o) || |
| 480 JS('bool', 'typeof # == "number"', o) || | 480 JS('bool', 'typeof # == "number"', o) || |
| 481 JS('bool', 'typeof # == "boolean"', o) || | 481 JS('bool', 'typeof # == "boolean"', o) || |
| 482 _isBrowserType(o)) { | 482 _isBrowserType(o)) { |
| 483 return o; | 483 return o; |
| 484 } else if (JS('bool', '# instanceof Date', o)) { | 484 } else if (JS('bool', '# instanceof Date', o)) { |
| 485 var ms = JS('num', '#.getTime()', o); | 485 var ms = JS('num', '#.getTime()', o); |
| 486 return new DateTime.fromMillisecondsSinceEpoch(ms); | 486 return new DateTime.fromMillisecondsSinceEpoch(ms); |
| 487 } else if (o is _DartObject) { | 487 } else if (o is _DartObject && |
| 488 JS('bool', 'dart.jsobject != dart.realRuntimeType(#)', o)) { | |
|
vsm
2015/09/02 19:14:32
My earlier change had native JS objects returning
| |
| 488 return o._dartObj; | 489 return o._dartObj; |
| 489 } else { | 490 } else { |
| 490 return _putIfAbsent(_dartProxies, o, _wrapToDart); | 491 return _putIfAbsent(_dartProxies, o, _wrapToDart); |
| 491 } | 492 } |
| 492 } | 493 } |
| 493 | 494 |
| 494 _wrapToDart(o) { | 495 _wrapToDart(o) { |
| 495 if (JS('bool', 'typeof # == "function"', o)) { | 496 if (JS('bool', 'typeof # == "function"', o)) { |
| 496 return new JsFunction._fromJs(o); | 497 return new JsFunction._fromJs(o); |
| 497 } | 498 } |
| 498 if (JS('bool', '# instanceof Array', o)) { | 499 if (JS('bool', '# instanceof Array', o)) { |
| 499 return new JsArray._fromJs(o); | 500 return new JsArray._fromJs(o); |
| 500 } | 501 } |
| 501 return new JsObject._fromJs(o); | 502 return new JsObject._fromJs(o); |
| 502 } | 503 } |
| 503 | 504 |
| 504 final _dartProxies = JS('', 'new WeakMap()'); | 505 final _dartProxies = JS('', 'new WeakMap()'); |
| 505 final _jsProxies = JS('', 'new WeakMap()'); | 506 final _jsProxies = JS('', 'new WeakMap()'); |
| 506 | 507 |
| 507 Object _putIfAbsent(weakMap, o, getValue(o)) { | 508 Object _putIfAbsent(weakMap, o, getValue(o)) { |
| 508 var value = JS('', '#.get(#)', weakMap, o); | 509 var value = JS('', '#.get(#)', weakMap, o); |
| 509 if (value == null) { | 510 if (value == null) { |
| 510 value = getValue(o); | 511 value = getValue(o); |
| 511 JS('', '#.set(#, #)', weakMap, o, value); | 512 JS('', '#.set(#, #)', weakMap, o, value); |
| 512 } | 513 } |
| 513 return value; | 514 return value; |
| 514 } | 515 } |
| OLD | NEW |