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 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 var wrapper = JS('', 'function(/*...arguments*/) {' | 468 var wrapper = JS('', 'function(/*...arguments*/) {' |
469 ' let args = Array.prototype.map.call(arguments, #);' | 469 ' let args = Array.prototype.map.call(arguments, #);' |
470 ' return #(#(...args));' | 470 ' return #(#(...args));' |
471 '}', _convertToDart, _convertToJS, f); | 471 '}', _convertToDart, _convertToJS, f); |
472 _dartProxies[wrapper] = f; | 472 _dartProxies[wrapper] = f; |
473 return wrapper; | 473 return wrapper; |
474 } | 474 } |
475 | 475 |
476 // converts a Dart object to a reference to a native JS object | 476 // converts a Dart object to a reference to a native JS object |
477 // which might be a DartObject JS->Dart proxy | 477 // which might be a DartObject JS->Dart proxy |
478 Object _convertToDart(o, [bool isBrowserType(x)]) { | 478 Object _convertToDart(o) { |
479 if (isBrowserType == null) isBrowserType = _isBrowserType; | |
480 if (JS('bool', '# == null', o) || | 479 if (JS('bool', '# == null', o) || |
481 JS('bool', 'typeof # == "string"', o) || | 480 JS('bool', 'typeof # == "string"', o) || |
482 JS('bool', 'typeof # == "number"', o) || | 481 JS('bool', 'typeof # == "number"', o) || |
483 JS('bool', 'typeof # == "boolean"', o) || | 482 JS('bool', 'typeof # == "boolean"', o) || |
484 isBrowserType(o)) { | 483 _isBrowserType(o)) { |
485 return o; | 484 return o; |
486 } else if (JS('bool', '# instanceof Date', o)) { | 485 } else if (JS('bool', '# instanceof Date', o)) { |
487 var ms = JS('num', '#.getTime()', o); | 486 var ms = JS('num', '#.getTime()', o); |
488 return new DateTime.fromMillisecondsSinceEpoch(ms); | 487 return new DateTime.fromMillisecondsSinceEpoch(ms); |
489 } else if (o is _DartObject && | 488 } else if (o is _DartObject && |
490 JS('bool', 'dart.jsobject != dart.realRuntimeType(#)', o)) { | 489 JS('bool', 'dart.jsobject != dart.realRuntimeType(#)', o)) { |
491 return o._dartObj; | 490 return o._dartObj; |
492 } else { | 491 } else { |
493 return _putIfAbsent(_dartProxies, o, _wrapToDart); | 492 return _putIfAbsent(_dartProxies, o, _wrapToDart); |
494 } | 493 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 ' for (let arg of arguments) {' | 549 ' for (let arg of arguments) {' |
551 ' args.push(arg);' | 550 ' args.push(arg);' |
552 ' }' | 551 ' }' |
553 ' return #(...args);' | 552 ' return #(...args);' |
554 '}', | 553 '}', |
555 f); | 554 f); |
556 _interopCaptureThisExpando[f] = ret; | 555 _interopCaptureThisExpando[f] = ret; |
557 } | 556 } |
558 return ret; | 557 return ret; |
559 } | 558 } |
OLD | NEW |