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 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 if (!declaration.isConstructor) { | 507 if (!declaration.isConstructor) { |
508 var jsName = _getJsMemberName(declaration); | 508 var jsName = _getJsMemberName(declaration); |
509 path = (path != null && path.isNotEmpty) ? "${path}.${jsName}" : jsName; | 509 path = (path != null && path.isNotEmpty) ? "${path}.${jsName}" : jsName; |
510 } | 510 } |
511 var name = memberName != null ? memberName : _getDeclarationName(declaration); | 511 var name = memberName != null ? memberName : _getDeclarationName(declaration); |
512 if (declaration.isConstructor) { | 512 if (declaration.isConstructor) { |
513 sb.write("factory"); | 513 sb.write("factory"); |
514 } else if (isStatic) { | 514 } else if (isStatic) { |
515 sb.write("static"); | 515 sb.write("static"); |
516 } else { | 516 } else { |
517 sb.write("patch"); | 517 sb.write("@patch"); |
518 } | 518 } |
519 sb.write(" "); | 519 sb.write(" "); |
520 if (declaration.isGetter) { | 520 if (declaration.isGetter) { |
521 sb.write("get $name => ${_accessJsPath(path)};"); | 521 sb.write("get $name => ${_accessJsPath(path)};"); |
522 } else if (declaration.isSetter) { | 522 } else if (declaration.isSetter) { |
523 sb.write("set $name(v) {\n" | 523 sb.write("set $name(v) {\n" |
524 " ${_JS_LIBRARY_PREFIX}.safeForTypedInterop(v);\n" | 524 " ${_JS_LIBRARY_PREFIX}.safeForTypedInterop(v);\n" |
525 " return ${_accessJsPathSetter(path)};\n" | 525 " return ${_accessJsPathSetter(path)};\n" |
526 "}\n"); | 526 "}\n"); |
527 } else { | 527 } else { |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
722 """); | 722 """); |
723 } | 723 } |
724 | 724 |
725 if (sbPatch.isNotEmpty) { | 725 if (sbPatch.isNotEmpty) { |
726 var typeVariablesClause = ''; | 726 var typeVariablesClause = ''; |
727 if (!clazz.typeVariables.isEmpty) { | 727 if (!clazz.typeVariables.isEmpty) { |
728 typeVariablesClause = | 728 typeVariablesClause = |
729 '<${clazz.typeVariables.map((m) => mirrors.MirrorSystem.getName(
m.simpleName)).join(',')}>'; | 729 '<${clazz.typeVariables.map((m) => mirrors.MirrorSystem.getName(
m.simpleName)).join(',')}>'; |
730 } | 730 } |
731 sb.write(""" | 731 sb.write(""" |
732 patch class $className$typeVariablesClause { | 732 @patch class $className$typeVariablesClause { |
733 $sbPatch | 733 $sbPatch |
734 } | 734 } |
735 """); | 735 """); |
736 if (isDom) { | 736 if (isDom) { |
737 sb.write(""" | 737 sb.write(""" |
738 class $classNameImpl$typeVariablesClause extends $className implements ${_JS_LIB
RARY_PREFIX}.JSObjectInterfacesDom { | 738 class $classNameImpl$typeVariablesClause extends $className implements ${_JS_LIB
RARY_PREFIX}.JSObjectInterfacesDom { |
739 ${classNameImpl}.internal_() : super.internal_(); | 739 ${classNameImpl}.internal_() : super.internal_(); |
740 get runtimeType => $className; | 740 get runtimeType => $className; |
741 toString() => super.toString(); | 741 toString() => super.toString(); |
742 } | 742 } |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
877 class JSArrayImpl extends JSArray ${buildImplementsClause(implementsArray)} { | 877 class JSArrayImpl extends JSArray ${buildImplementsClause(implementsArray)} { |
878 JSArrayImpl.internal() : super.internal(); | 878 JSArrayImpl.internal() : super.internal(); |
879 } | 879 } |
880 | 880 |
881 // Interfaces that are safe to slam on all DOM classes. | 881 // Interfaces that are safe to slam on all DOM classes. |
882 // Adding implementsClause would be risky as it could contain Function which | 882 // Adding implementsClause would be risky as it could contain Function which |
883 // is likely to break a lot of instanceof checks. | 883 // is likely to break a lot of instanceof checks. |
884 abstract class JSObjectInterfacesDom $implementsClauseDom { | 884 abstract class JSObjectInterfacesDom $implementsClauseDom { |
885 } | 885 } |
886 | 886 |
887 patch class JSObject { | 887 @patch class JSObject { |
888 static Type get instanceRuntimeType => JSObjectImpl; | 888 static Type get instanceRuntimeType => JSObjectImpl; |
889 } | 889 } |
890 | 890 |
891 patch class JSFunction { | 891 @patch class JSFunction { |
892 static Type get instanceRuntimeType => JSFunctionImpl; | 892 static Type get instanceRuntimeType => JSFunctionImpl; |
893 } | 893 } |
894 | 894 |
895 patch class JSArray { | 895 @patch class JSArray { |
896 static Type get instanceRuntimeType => JSArrayImpl; | 896 static Type get instanceRuntimeType => JSArrayImpl; |
897 } | 897 } |
898 | 898 |
899 _registerAllJsInterfaces() { | 899 _registerAllJsInterfaces() { |
900 _registerJsInterfaces([${allTypes.join(", ")}]); | 900 _registerJsInterfaces([${allTypes.join(", ")}]); |
901 } | 901 } |
902 | 902 |
903 '''); | 903 '''); |
904 ret..addAll(["dart:js", "JSInteropImpl.dart", sb.toString()]); | 904 ret..addAll(["dart:js", "JSInteropImpl.dart", sb.toString()]); |
905 return ret; | 905 return ret; |
(...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1694 } else { | 1694 } else { |
1695 var ret = _interopCaptureThisExpando[f]; | 1695 var ret = _interopCaptureThisExpando[f]; |
1696 if (ret == null) { | 1696 if (ret == null) { |
1697 // TODO(jacobr): we could optimize this. | 1697 // TODO(jacobr): we could optimize this. |
1698 ret = JSFunction._createWithThis(f); | 1698 ret = JSFunction._createWithThis(f); |
1699 _interopCaptureThisExpando[f] = ret; | 1699 _interopCaptureThisExpando[f] = ret; |
1700 } | 1700 } |
1701 return ret; | 1701 return ret; |
1702 } | 1702 } |
1703 } | 1703 } |
OLD | NEW |