| 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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 var uri = library.uri; | 304 var uri = library.uri; |
| 305 // make sure the annotation is from package://js | 305 // make sure the annotation is from package://js |
| 306 if (uri.scheme == 'package' && uri.path == 'js/js.dart') { | 306 if (uri.scheme == 'package' && uri.path == 'js/js.dart') { |
| 307 return true; | 307 return true; |
| 308 } | 308 } |
| 309 } | 309 } |
| 310 } | 310 } |
| 311 return false; | 311 return false; |
| 312 } | 312 } |
| 313 | 313 |
| 314 bool _hasJsName(mirrors.DeclarationMirror mirror) => _getJsName(mirror) != null; | 314 bool _hasJsName(mirrors.DeclarationMirror mirror) { |
| 315 if (_atJsType != null) { |
| 316 for (var annotation in mirror.metadata) { |
| 317 if (annotation.type.reflectedType == _atJsType) { |
| 318 return true; |
| 319 } |
| 320 } |
| 321 } |
| 322 return false; |
| 323 } |
| 315 | 324 |
| 316 var _domNameType; | 325 var _domNameType; |
| 317 | 326 |
| 318 bool hasDomName(mirrors.DeclarationMirror mirror) { | 327 bool hasDomName(mirrors.DeclarationMirror mirror) { |
| 319 var location = mirror.location; | 328 var location = mirror.location; |
| 320 if (location == null || location.sourceUri.scheme != 'dart') return false; | 329 if (location == null || location.sourceUri.scheme != 'dart') return false; |
| 321 for (var annotation in mirror.metadata) { | 330 for (var annotation in mirror.metadata) { |
| 322 if (mirrors.MirrorSystem.getName(annotation.type.simpleName) == "DomName") { | 331 if (mirrors.MirrorSystem.getName(annotation.type.simpleName) == "DomName") { |
| 323 // We can't make sure the annotation is in dart: as Dartium believes it | 332 // We can't make sure the annotation is in dart: as Dartium believes it |
| 324 // is file://dart/sdk/lib/html/html_common/metadata.dart | 333 // is file://dart/sdk/lib/html/html_common/metadata.dart |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 627 const ${_UNDEFINED_VAR} = const Object(); | 636 const ${_UNDEFINED_VAR} = const Object(); |
| 628 | 637 |
| 629 ${sb} | 638 ${sb} |
| 630 """); | 639 """); |
| 631 } | 640 } |
| 632 } | 641 } |
| 633 | 642 |
| 634 // Remember the @JS type to compare annotation type. | 643 // Remember the @JS type to compare annotation type. |
| 635 var _atJsType = -1; | 644 var _atJsType = -1; |
| 636 | 645 |
| 637 /** | 646 void setupJsTypeCache() { |
| 638 * Generates part files defining source code for JSObjectImpl, all DOM classes | |
| 639 * classes. This codegen is needed so that type checks for all registered | |
| 640 * JavaScript interop classes pass. | |
| 641 * If genCachedPatches is true then the patch files don't exist this is a specia
l | |
| 642 * signal to generate and emit the patches to stdout to be captured and put into | |
| 643 * the file sdk/lib/js/dartium/cached_patches.dart | |
| 644 */ | |
| 645 List<String> _generateInteropPatchFiles(List<String> libraryPaths, genCachedPatc
hes) { | |
| 646 // Cache the @JS Type. | 647 // Cache the @JS Type. |
| 647 if (_atJsType == -1) { | 648 if (_atJsType == -1) { |
| 648 var uri = new Uri(scheme: "package", path: "js/js.dart"); | 649 var uri = new Uri(scheme: "package", path: "js/js.dart"); |
| 649 var jsLibrary = mirrors.currentMirrorSystem().libraries[uri]; | 650 var jsLibrary = mirrors.currentMirrorSystem().libraries[uri]; |
| 650 if (jsLibrary != null) { | 651 if (jsLibrary != null) { |
| 651 // @ JS used somewhere. | 652 // @ JS used somewhere. |
| 652 var jsDeclaration = jsLibrary.declarations[new Symbol("JS")]; | 653 var jsDeclaration = jsLibrary.declarations[new Symbol("JS")]; |
| 653 _atJsType = jsDeclaration.reflectedType; | 654 _atJsType = jsDeclaration.reflectedType; |
| 654 } else { | 655 } else { |
| 655 // @ JS not used in any library. | 656 // @ JS not used in any library. |
| 656 _atJsType = null; | 657 _atJsType = null; |
| 657 } | 658 } |
| 658 } | 659 } |
| 660 } |
| 661 |
| 662 /** |
| 663 * Generates part files defining source code for JSObjectImpl, all DOM classes |
| 664 * classes. This codegen is needed so that type checks for all registered |
| 665 * JavaScript interop classes pass. |
| 666 * If genCachedPatches is true then the patch files don't exist this is a specia
l |
| 667 * signal to generate and emit the patches to stdout to be captured and put into |
| 668 * the file sdk/lib/js/dartium/cached_patches.dart |
| 669 */ |
| 670 List<String> _generateInteropPatchFiles(List<String> libraryPaths, genCachedPatc
hes) { |
| 671 // Cache the @JS Type. |
| 672 if (_atJsType == -1) setupJsTypeCache(); |
| 659 | 673 |
| 660 var ret = _generateExternalMethods(libraryPaths, genCachedPatches ? false : tr
ue); | 674 var ret = _generateExternalMethods(libraryPaths, genCachedPatches ? false : tr
ue); |
| 661 var libraryPrefixes = new Map<mirrors.LibraryMirror, String>(); | 675 var libraryPrefixes = new Map<mirrors.LibraryMirror, String>(); |
| 662 var prefixNames = new Set<String>(); | 676 var prefixNames = new Set<String>(); |
| 663 var sb = new StringBuffer(); | 677 var sb = new StringBuffer(); |
| 664 | 678 |
| 665 var implements = <String>[]; | 679 var implements = <String>[]; |
| 666 var implementsArray = <String>[]; | 680 var implementsArray = <String>[]; |
| 667 var implementsDom = <String>[]; | 681 var implementsDom = <String>[]; |
| 668 var listMirror = mirrors.reflectType(List); | 682 var listMirror = mirrors.reflectType(List); |
| (...skipping 875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1544 if (ret == null) { | 1558 if (ret == null) { |
| 1545 // TODO(jacobr): we could optimize this. | 1559 // TODO(jacobr): we could optimize this. |
| 1546 ret = JSFunction._createWithThis(f); | 1560 ret = JSFunction._createWithThis(f); |
| 1547 _interopCaptureThisExpando[f] = ret; | 1561 _interopCaptureThisExpando[f] = ret; |
| 1548 } | 1562 } |
| 1549 return ret; | 1563 return ret; |
| 1550 } | 1564 } |
| 1551 } | 1565 } |
| 1552 | 1566 |
| 1553 debugPrint(_) {} | 1567 debugPrint(_) {} |
| OLD | NEW |