| 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 ClassElement, Element, FieldElement, FunctionElement, MemberElement; |
| 10 import '../elements/entities.dart'; | 10 import '../elements/entities.dart'; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 /// JavaScriptInterop mechanism which is allowed for user libraries. | 124 /// JavaScriptInterop mechanism which is allowed for user libraries. |
| 125 bool isNative(Element element) { | 125 bool isNative(Element element) { |
| 126 if (isJsInterop(element)) return true; | 126 if (isJsInterop(element)) return true; |
| 127 if (element.isClass) { | 127 if (element.isClass) { |
| 128 return nativeClassTagInfo.containsKey(element.declaration); | 128 return nativeClassTagInfo.containsKey(element.declaration); |
| 129 } else { | 129 } else { |
| 130 return nativeMemberName.containsKey(element.declaration); | 130 return nativeMemberName.containsKey(element.declaration); |
| 131 } | 131 } |
| 132 } | 132 } |
| 133 | 133 |
| 134 /// Returns `true` if [element] or any of its superclasses is native. |
| 135 bool isNativeOrExtendsNative(ClassElement element) { |
| 136 if (element == null) return false; |
| 137 if (isNative(element) || isJsInterop(element)) { |
| 138 return true; |
| 139 } |
| 140 assert(element.isResolved); |
| 141 return isNativeOrExtendsNative(element.superclass); |
| 142 } |
| 143 |
| 134 /// Sets the native [name] for the member [element]. This name is used for | 144 /// Sets the native [name] for the member [element]. This name is used for |
| 135 /// [element] in the generated JavaScript. | 145 /// [element] in the generated JavaScript. |
| 136 void setNativeMemberName(MemberElement element, String name) { | 146 void setNativeMemberName(MemberElement element, String name) { |
| 137 // TODO(johnniwinther): Avoid setting this more than once. The enqueuer | 147 // TODO(johnniwinther): Avoid setting this more than once. The enqueuer |
| 138 // might enqueue [element] several times (before processing it) and computes | 148 // might enqueue [element] several times (before processing it) and computes |
| 139 // name on each call to `internalAddToWorkList`. | 149 // name on each call to `internalAddToWorkList`. |
| 140 assert(invariant( | 150 assert(invariant( |
| 141 element, | 151 element, |
| 142 nativeMemberName[element.declaration] == null || | 152 nativeMemberName[element.declaration] == null || |
| 143 nativeMemberName[element.declaration] == name, | 153 nativeMemberName[element.declaration] == name, |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 } | 236 } |
| 227 | 237 |
| 228 /// Apply JS$ escaping scheme to convert possible escaped Dart names into | 238 /// Apply JS$ escaping scheme to convert possible escaped Dart names into |
| 229 /// JS names. | 239 /// JS names. |
| 230 String getUnescapedJSInteropName(String name) { | 240 String getUnescapedJSInteropName(String name) { |
| 231 return name.startsWith(_jsInteropEscapePrefix) | 241 return name.startsWith(_jsInteropEscapePrefix) |
| 232 ? name.substring(_jsInteropEscapePrefix.length) | 242 ? name.substring(_jsInteropEscapePrefix.length) |
| 233 : name; | 243 : name; |
| 234 } | 244 } |
| 235 } | 245 } |
| OLD | NEW |