| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 library js_backend.native_data; | 5 library js_backend.native_data; |
| 6 | 6 |
| 7 import '../common.dart'; | 7 import '../common.dart'; |
| 8 import '../elements/elements.dart' | 8 import '../elements/elements.dart' |
| 9 show ClassElement, Element, FieldElement, FunctionElement, MemberElement; | 9 show |
| 10 ClassElement, |
| 11 Element, |
| 12 Entity, |
| 13 FieldElement, |
| 14 FunctionElement, |
| 15 MemberElement; |
| 10 import '../native/behavior.dart' show NativeBehavior; | 16 import '../native/behavior.dart' show NativeBehavior; |
| 11 | 17 |
| 12 /// Additional element information for native classes and methods and js-interop | 18 /// Additional element information for native classes and methods and js-interop |
| 13 /// methods. | 19 /// methods. |
| 14 class NativeData { | 20 class NativeData { |
| 15 /// The JavaScript names for elements implemented via typed JavaScript | 21 /// The JavaScript names for elements implemented via typed JavaScript |
| 16 /// interop. | 22 /// interop. |
| 17 Map<Element, String> jsInteropNames = <Element, String>{}; | 23 Map<Element, String> jsInteropNames = <Element, String>{}; |
| 18 | 24 |
| 19 /// The JavaScript names for native JavaScript elements implemented. | 25 /// The JavaScript names for native JavaScript elements implemented. |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 'Element $element is js interop but js interop name has not yet ' | 101 'Element $element is js interop but js interop name has not yet ' |
| 96 'been computed.')); | 102 'been computed.')); |
| 97 if (jsInteropName != null && jsInteropName.isNotEmpty) { | 103 if (jsInteropName != null && jsInteropName.isNotEmpty) { |
| 98 return jsInteropName; | 104 return jsInteropName; |
| 99 } | 105 } |
| 100 return element.isLibrary ? 'self' : getUnescapedJSInteropName(element.name); | 106 return element.isLibrary ? 'self' : getUnescapedJSInteropName(element.name); |
| 101 } | 107 } |
| 102 | 108 |
| 103 /// Computes the name for [element] to use in the generated JavaScript. This | 109 /// Computes the name for [element] to use in the generated JavaScript. This |
| 104 /// is either given through a native annotation or a js interop annotation. | 110 /// is either given through a native annotation or a js interop annotation. |
| 105 String getFixedBackendName(Element element) { | 111 String getFixedBackendName(Entity entity) { |
| 112 // TODO(johnniwinther): Remove this assignment from [Entity] to [Element] |
| 113 // when `.declaration` is no longer needed. |
| 114 Element element = entity; |
| 106 String name = nativeMemberName[element.declaration]; | 115 String name = nativeMemberName[element.declaration]; |
| 107 if (name == null && isJsInterop(element)) { | 116 if (name == null && isJsInterop(element)) { |
| 108 // If an element isJsInterop but _isJsInterop is false that means it is | 117 // If an element isJsInterop but _isJsInterop is false that means it is |
| 109 // considered interop as the parent class is interop. | 118 // considered interop as the parent class is interop. |
| 110 name = _jsNameHelper( | 119 name = _jsNameHelper( |
| 111 element.isConstructor ? element.enclosingClass : element); | 120 element.isConstructor ? element.enclosingClass : element); |
| 112 nativeMemberName[element.declaration] = name; | 121 nativeMemberName[element.declaration] = name; |
| 113 } | 122 } |
| 114 return name; | 123 return name; |
| 115 } | 124 } |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 } | 231 } |
| 223 | 232 |
| 224 /// Apply JS$ escaping scheme to convert possible escaped Dart names into | 233 /// Apply JS$ escaping scheme to convert possible escaped Dart names into |
| 225 /// JS names. | 234 /// JS names. |
| 226 String getUnescapedJSInteropName(String name) { | 235 String getUnescapedJSInteropName(String name) { |
| 227 return name.startsWith(_jsInteropEscapePrefix) | 236 return name.startsWith(_jsInteropEscapePrefix) |
| 228 ? name.substring(_jsInteropEscapePrefix.length) | 237 ? name.substring(_jsInteropEscapePrefix.length) |
| 229 : name; | 238 : name; |
| 230 } | 239 } |
| 231 } | 240 } |
| OLD | NEW |