| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 part of js_backend; | 5 part of js_backend; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * A function element that represents a closure call. The signature is copied | 8 * A function element that represents a closure call. The signature is copied |
| 9 * from the given element. | 9 * from the given element. |
| 10 */ | 10 */ |
| (...skipping 962 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 973 emitInstanceMembers(classElement, buffer, true); | 973 emitInstanceMembers(classElement, buffer, true); |
| 974 buffer.add('\n};\n\n'); | 974 buffer.add('\n};\n\n'); |
| 975 } | 975 } |
| 976 | 976 |
| 977 void emitInterceptorMethods( | 977 void emitInterceptorMethods( |
| 978 void defineInstanceMember(String name, StringBuffer memberBuffer)) { | 978 void defineInstanceMember(String name, StringBuffer memberBuffer)) { |
| 979 JavaScriptBackend backend = compiler.backend; | 979 JavaScriptBackend backend = compiler.backend; |
| 980 // Emit forwarders for the ObjectInterceptor class. We need to | 980 // Emit forwarders for the ObjectInterceptor class. We need to |
| 981 // emit all possible sends on intercepted methods. | 981 // emit all possible sends on intercepted methods. |
| 982 for (Selector selector in backend.usedInterceptors) { | 982 for (Selector selector in backend.usedInterceptors) { |
| 983 |
| 984 List<js.Parameter> parameters = <js.Parameter>[]; |
| 985 List<js.Expression> arguments = <js.Expression>[]; |
| 986 parameters.add(new js.Parameter('receiver')); |
| 987 |
| 983 String name; | 988 String name; |
| 984 String comma = ''; | |
| 985 String parameters = ''; | |
| 986 if (selector.isGetter()) { | 989 if (selector.isGetter()) { |
| 987 name = backend.namer.getterName(selector.library, selector.name); | 990 name = backend.namer.getterName(selector.library, selector.name); |
| 988 } else if (selector.isSetter()) { | 991 } else if (selector.isSetter()) { |
| 989 name = backend.namer.setterName(selector.library, selector.name); | 992 name = backend.namer.setterName(selector.library, selector.name); |
| 993 parameters.add(new js.Parameter('value')); |
| 994 arguments.add(new js.VariableUse('value')); |
| 990 } else { | 995 } else { |
| 991 assert(selector.isCall() || selector.isOperator()); | 996 assert(selector.isCall() || selector.isOperator()); |
| 992 name = backend.namer.instanceMethodInvocationName( | 997 name = backend.namer.instanceMethodInvocationName( |
| 993 selector.library, selector.name, selector); | 998 selector.library, selector.name, selector); |
| 994 if (selector.argumentCount > 0) { | 999 for (int i = 0; i < selector.argumentCount; i++) { |
| 995 comma = ', '; | 1000 String argName = 'a$i'; |
| 996 int i = 0; | 1001 parameters.add(new js.Parameter(argName)); |
| 997 for (; i < selector.argumentCount - 1; i++) { | 1002 arguments.add(new js.VariableUse(argName)); |
| 998 parameters = '${parameters}a$i, '; | |
| 999 } | |
| 1000 parameters = '${parameters}a$i'; | |
| 1001 } | 1003 } |
| 1002 } | 1004 } |
| 1003 StringBuffer body = new StringBuffer( | 1005 js.Fun function = |
| 1004 "function(receiver$comma$parameters) {" | 1006 new js.Fun(parameters, |
| 1005 " return receiver.$name($parameters); }"); | 1007 new js.Block( |
| 1006 defineInstanceMember(name, body); | 1008 <js.Statement>[ |
| 1009 new js.Return( |
| 1010 new js.VariableUse('receiver') |
| 1011 .dot(name) |
| 1012 .callWith(arguments))])); |
| 1013 |
| 1014 CodeBuffer code = new CodeBuffer(); |
| 1015 code.add(js.prettyPrint(function, compiler)); |
| 1016 defineInstanceMember(name, code); |
| 1007 } | 1017 } |
| 1008 } | 1018 } |
| 1009 | 1019 |
| 1010 /** | 1020 /** |
| 1011 * Generate "is tests" for [cls]: itself, and the "is tests" for the | 1021 * Generate "is tests" for [cls]: itself, and the "is tests" for the |
| 1012 * classes it implements. We don't need to add the "is tests" of the | 1022 * classes it implements. We don't need to add the "is tests" of the |
| 1013 * super class because they will be inherited at runtime. | 1023 * super class because they will be inherited at runtime. |
| 1014 */ | 1024 */ |
| 1015 void generateIsTestsOn(ClassElement cls, | 1025 void generateIsTestsOn(ClassElement cls, |
| 1016 void emitIsTest(ClassElement element)) { | 1026 void emitIsTest(ClassElement element)) { |
| (...skipping 830 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1847 const String HOOKS_API_USAGE = """ | 1857 const String HOOKS_API_USAGE = """ |
| 1848 // Generated by dart2js, the Dart to JavaScript compiler. | 1858 // Generated by dart2js, the Dart to JavaScript compiler. |
| 1849 // The code supports the following hooks: | 1859 // The code supports the following hooks: |
| 1850 // dartPrint(message) - if this function is defined it is called | 1860 // dartPrint(message) - if this function is defined it is called |
| 1851 // instead of the Dart [print] method. | 1861 // instead of the Dart [print] method. |
| 1852 // dartMainRunner(main) - if this function is defined, the Dart [main] | 1862 // dartMainRunner(main) - if this function is defined, the Dart [main] |
| 1853 // method will not be invoked directly. | 1863 // method will not be invoked directly. |
| 1854 // Instead, a closure that will invoke [main] is | 1864 // Instead, a closure that will invoke [main] is |
| 1855 // passed to [dartMainRunner]. | 1865 // passed to [dartMainRunner]. |
| 1856 """; | 1866 """; |
| OLD | NEW |