| 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 /// Analysis to determine how to generate code for typed JavaScript interop. | 5 /// Analysis to determine how to generate code for typed JavaScript interop. |
| 6 library compiler.src.js_backend.js_interop_analysis; | 6 library compiler.src.js_backend.js_interop_analysis; |
| 7 | 7 |
| 8 import '../common.dart'; | |
| 9 import '../constants/values.dart' | 8 import '../constants/values.dart' |
| 10 show ConstantValue, ConstructedConstantValue, StringConstantValue; | 9 show ConstantValue, ConstructedConstantValue, StringConstantValue; |
| 11 import '../diagnostics/messages.dart' show MessageKind; | 10 import '../diagnostics/messages.dart' show MessageKind; |
| 12 import '../elements/elements.dart' | 11 import '../elements/elements.dart' |
| 13 show | 12 show |
| 14 ClassElement, | 13 ClassElement, |
| 15 Element, | 14 Element, |
| 16 FieldElement, | 15 FieldElement, |
| 17 FunctionElement, | 16 FunctionElement, |
| 18 LibraryElement, | 17 LibraryElement, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 48 .forEach(processJsInteropAnnotationsInLibrary); | 47 .forEach(processJsInteropAnnotationsInLibrary); |
| 49 } | 48 } |
| 50 } | 49 } |
| 51 | 50 |
| 52 void onCodegenStart() { | 51 void onCodegenStart() { |
| 53 _inCodegen = true; | 52 _inCodegen = true; |
| 54 } | 53 } |
| 55 | 54 |
| 56 void processJsInteropAnnotation(Element e) { | 55 void processJsInteropAnnotation(Element e) { |
| 57 for (MetadataAnnotation annotation in e.implementation.metadata) { | 56 for (MetadataAnnotation annotation in e.implementation.metadata) { |
| 58 // TODO(johnniwinther): Avoid processing unresolved elements. | |
| 59 if (annotation.constant == null) continue; | |
| 60 ConstantValue constant = | 57 ConstantValue constant = |
| 61 backend.compiler.constants.getConstantValue(annotation.constant); | 58 backend.compiler.constants.getConstantValue(annotation.constant); |
| 62 if (constant == null || constant is! ConstructedConstantValue) continue; | 59 if (constant == null || constant is! ConstructedConstantValue) continue; |
| 63 ConstructedConstantValue constructedConstant = constant; | 60 ConstructedConstantValue constructedConstant = constant; |
| 64 if (constructedConstant.type.element == helpers.jsAnnotationClass) { | 61 if (constructedConstant.type.element == helpers.jsAnnotationClass) { |
| 65 ConstantValue value = constructedConstant.fields[nameField]; | 62 ConstantValue value = constructedConstant.fields[nameField]; |
| 66 if (value.isString) { | 63 if (value.isString) { |
| 67 StringConstantValue stringValue = value; | 64 StringConstantValue stringValue = value; |
| 68 backend.nativeData | 65 backend.nativeData |
| 69 .setJsInteropName(e, stringValue.primitiveValue.slowToString()); | 66 .setJsInteropName(e, stringValue.primitiveValue.slowToString()); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 var name = backend.namer.invocationName(selector); | 176 var name = backend.namer.invocationName(selector); |
| 180 statements.add(js.statement( | 177 statements.add(js.statement( |
| 181 'Function.prototype.# = function(#) { return this(#) }', | 178 'Function.prototype.# = function(#) { return this(#) }', |
| 182 [name, parameters, parameters])); | 179 [name, parameters, parameters])); |
| 183 } | 180 } |
| 184 }); | 181 }); |
| 185 }); | 182 }); |
| 186 return new jsAst.Block(statements); | 183 return new jsAst.Block(statements); |
| 187 } | 184 } |
| 188 } | 185 } |
| OLD | NEW |