| 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 dart2js.js_emitter; | 5 part of dart2js.js_emitter; |
| 6 | 6 |
| 7 class NativeEmitter { | 7 class NativeEmitter { |
| 8 | 8 |
| 9 // TODO(floitsch): the native-emitter should not know about ClassBuilders. | 9 // TODO(floitsch): the native-emitter should not know about ClassBuilders. |
| 10 final Map<Element, full_js_emitter.ClassBuilder> cachedBuilders; | 10 final Map<Element, full_js_emitter.ClassBuilder> cachedBuilders; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 needed = true; | 127 needed = true; |
| 128 } else if (interceptorClassesNeededByConstants.contains(classElement)) { | 128 } else if (interceptorClassesNeededByConstants.contains(classElement)) { |
| 129 needed = true; | 129 needed = true; |
| 130 } else if (classesModifiedByEmitRTISupport.contains(classElement)) { | 130 } else if (classesModifiedByEmitRTISupport.contains(classElement)) { |
| 131 // TODO(9556): Remove this test when [emitRuntimeTypeSupport] no longer | 131 // TODO(9556): Remove this test when [emitRuntimeTypeSupport] no longer |
| 132 // adds information to a class prototype or constructor. | 132 // adds information to a class prototype or constructor. |
| 133 needed = true; | 133 needed = true; |
| 134 } else if (extensionPoints.containsKey(cls)) { | 134 } else if (extensionPoints.containsKey(cls)) { |
| 135 needed = true; | 135 needed = true; |
| 136 } | 136 } |
| 137 if (cls.isNative && | 137 if (classElement.isJsInterop) { |
| 138 native.nativeTagsForcedNonLeaf(classElement)) { | 138 needed = false; |
| 139 } else if (cls.isNative && native.nativeTagsForcedNonLeaf(classElement)) { |
| 139 needed = true; | 140 needed = true; |
| 140 nonLeafClasses.add(cls); | 141 nonLeafClasses.add(cls); |
| 141 } | 142 } |
| 142 | 143 |
| 143 if (needed || neededClasses.contains(cls)) { | 144 if (needed || neededClasses.contains(cls)) { |
| 144 neededClasses.add(cls); | 145 neededClasses.add(cls); |
| 145 neededClasses.add(cls.superclass); | 146 neededClasses.add(cls.superclass); |
| 146 nonLeafClasses.add(cls.superclass); | 147 nonLeafClasses.add(cls.superclass); |
| 147 } | 148 } |
| 148 } | 149 } |
| 149 | 150 |
| 150 // Collect all the tags that map to each native class. | 151 // Collect all the tags that map to each native class. |
| 151 | 152 |
| 152 Map<Class, Set<String>> leafTags = new Map<Class, Set<String>>(); | 153 Map<Class, Set<String>> leafTags = new Map<Class, Set<String>>(); |
| 153 Map<Class, Set<String>> nonleafTags = new Map<Class, Set<String>>(); | 154 Map<Class, Set<String>> nonleafTags = new Map<Class, Set<String>>(); |
| 154 | 155 |
| 155 for (Class cls in classes) { | 156 for (Class cls in classes) { |
| 156 if (!cls.isNative) continue; | 157 if (!cls.isNative) continue; |
| 158 if (cls.element.isJsInterop) continue; |
| 157 List<String> nativeTags = native.nativeTagsOfClass(cls.element); | 159 List<String> nativeTags = native.nativeTagsOfClass(cls.element); |
| 158 | 160 |
| 159 if (nonLeafClasses.contains(cls) || | 161 if (nonLeafClasses.contains(cls) || |
| 160 extensionPoints.containsKey(cls)) { | 162 extensionPoints.containsKey(cls)) { |
| 161 nonleafTags | 163 nonleafTags |
| 162 .putIfAbsent(cls, () => new Set<String>()) | 164 .putIfAbsent(cls, () => new Set<String>()) |
| 163 .addAll(nativeTags); | 165 .addAll(nativeTags); |
| 164 } else { | 166 } else { |
| 165 Class sufficingInterceptor = cls; | 167 Class sufficingInterceptor = cls; |
| 166 while (!neededClasses.contains(sufficingInterceptor)) { | 168 while (!neededClasses.contains(sufficingInterceptor)) { |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 // used. We should also use an interceptor if the check can't be satisfied | 345 // used. We should also use an interceptor if the check can't be satisfied |
| 344 // by a native class in case we get a native instance that tries to spoof | 346 // by a native class in case we get a native instance that tries to spoof |
| 345 // the type info. i.e the criteria for whether or not to use an interceptor | 347 // the type info. i.e the criteria for whether or not to use an interceptor |
| 346 // is whether the receiver can be native, not the type of the test. | 348 // is whether the receiver can be native, not the type of the test. |
| 347 if (element == null || !element.isClass) return false; | 349 if (element == null || !element.isClass) return false; |
| 348 ClassElement cls = element; | 350 ClassElement cls = element; |
| 349 if (Elements.isNativeOrExtendsNative(cls)) return true; | 351 if (Elements.isNativeOrExtendsNative(cls)) return true; |
| 350 return isSupertypeOfNativeClass(element); | 352 return isSupertypeOfNativeClass(element); |
| 351 } | 353 } |
| 352 } | 354 } |
| OLD | NEW |