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 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 return false; | 499 return false; |
500 } | 500 } |
501 | 501 |
502 List<String> _generateExternalMethods(List<String> libraryPaths) { | 502 List<String> _generateExternalMethods(List<String> libraryPaths) { |
503 var staticCodegen = <String>[]; | 503 var staticCodegen = <String>[]; |
504 | 504 |
505 if (libraryPaths.length == 0) { | 505 if (libraryPaths.length == 0) { |
506 mirrors.currentMirrorSystem().libraries.forEach((uri, library) { | 506 mirrors.currentMirrorSystem().libraries.forEach((uri, library) { |
507 var library_name = "${uri.scheme}:${uri.path}"; | 507 var library_name = "${uri.scheme}:${uri.path}"; |
508 if (cached_patches.containsKey(library_name)) { | 508 if (cached_patches.containsKey(library_name)) { |
| 509 // Use the pre-generated patch files for DOM dart:nnnn libraries. |
509 var patch = cached_patches[library_name]; | 510 var patch = cached_patches[library_name]; |
510 staticCodegen.addAll(patch); | 511 staticCodegen.addAll(patch); |
511 } else { | 512 } else if (_hasJsName(library)) { |
| 513 // Library marked with @JS |
512 _generateLibraryCodegen(uri, library, staticCodegen); | 514 _generateLibraryCodegen(uri, library, staticCodegen); |
513 } | 515 } |
514 }); // End of library foreach | 516 }); // End of library foreach |
515 } else { | 517 } else { |
516 // Used to generate cached_patches.dart file for all IDL generated dart: | 518 // Used to generate cached_patches.dart file for all IDL generated dart: |
517 // files to the WebKit DOM. | 519 // files to the WebKit DOM. |
518 for (var library_name in libraryPaths) { | 520 for (var library_name in libraryPaths) { |
519 var parts = library_name.split(':'); | 521 var parts = library_name.split(':'); |
520 var uri = new Uri(scheme: parts[0], path: parts[1]); | 522 var uri = new Uri(scheme: parts[0], path: parts[1]); |
521 var library = mirrors.currentMirrorSystem().libraries[uri]; | 523 var library = mirrors.currentMirrorSystem().libraries[uri]; |
522 _generateLibraryCodegen(uri, library, staticCodegen); | 524 _generateLibraryCodegen(uri, library, staticCodegen); |
523 } | 525 } |
524 } | 526 } |
525 | 527 |
526 return staticCodegen; | 528 return staticCodegen; |
527 } | 529 } |
528 | 530 |
529 _generateLibraryCodegen(uri, library, staticCodegen) { | 531 _generateLibraryCodegen(uri, library, staticCodegen) { |
530 // Is it a dart generated library? | 532 // Is it a dart generated library? |
531 var dartLibrary = uri.scheme == 'dart'; | 533 var dartLibrary = uri.scheme == 'dart'; |
532 | 534 |
533 var sb = new StringBuffer(); | 535 var sb = new StringBuffer(); |
534 String jsLibraryName = _getJsName(library); | 536 String jsLibraryName = _getJsName(library); |
535 library.declarations.forEach((name, declaration) { | 537 |
| 538 // Sort by patch file by its declaration name. |
| 539 var sortedDeclKeys = library.declarations.keys.toList(); |
| 540 sortedDeclKeys.sort((a, b) => mirrors.MirrorSystem.getName(a).compareTo(mirr
ors.MirrorSystem.getName(b))); |
| 541 |
| 542 sortedDeclKeys.forEach((name) { |
| 543 var declaration = library.declarations[name]; |
536 if (declaration is mirrors.MethodMirror) { | 544 if (declaration is mirrors.MethodMirror) { |
537 if ((_hasJsName(declaration) || jsLibraryName != null) && | 545 if ((_hasJsName(declaration) || jsLibraryName != null) && |
538 _isExternal(declaration)) { | 546 _isExternal(declaration)) { |
539 addMemberHelper(declaration, jsLibraryName, sb); | 547 addMemberHelper(declaration, jsLibraryName, sb); |
540 } | 548 } |
541 } else if (declaration is mirrors.ClassMirror) { | 549 } else if (declaration is mirrors.ClassMirror) { |
542 mirrors.ClassMirror clazz = declaration; | 550 mirrors.ClassMirror clazz = declaration; |
543 var isDom = dartLibrary ? hasDomName(clazz) : false; | 551 var isDom = dartLibrary ? hasDomName(clazz) : false; |
544 var isJsInterop = _hasJsName(clazz); | 552 var isJsInterop = _hasJsName(clazz); |
545 if (isDom || isJsInterop) { | 553 if (isDom || isJsInterop) { |
(...skipping 1025 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1571 if (ret == null) { | 1579 if (ret == null) { |
1572 // TODO(jacobr): we could optimize this. | 1580 // TODO(jacobr): we could optimize this. |
1573 ret = JSFunction._createWithThis(f); | 1581 ret = JSFunction._createWithThis(f); |
1574 _interopCaptureThisExpando[f] = ret; | 1582 _interopCaptureThisExpando[f] = ret; |
1575 } | 1583 } |
1576 return ret; | 1584 return ret; |
1577 } | 1585 } |
1578 } | 1586 } |
1579 | 1587 |
1580 debugPrint(_) {} | 1588 debugPrint(_) {} |
OLD | NEW |