| 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 // TODO(floitsch): the native-emitter should not know about ClassBuilders. | 8 // TODO(floitsch): the native-emitter should not know about ClassBuilders. |
| 9 final Map<Element, full_js_emitter.ClassBuilder> cachedBuilders; | 9 final Map<Element, full_js_emitter.ClassBuilder> cachedBuilders; |
| 10 | 10 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 } | 89 } |
| 90 if (cls.element == helpers.jsInterceptorClass) { | 90 if (cls.element == helpers.jsInterceptorClass) { |
| 91 jsInterceptorClass = cls; | 91 jsInterceptorClass = cls; |
| 92 return; | 92 return; |
| 93 } | 93 } |
| 94 if (seen.contains(cls)) return; | 94 if (seen.contains(cls)) return; |
| 95 seen.add(cls); | 95 seen.add(cls); |
| 96 walk(cls.superclass); | 96 walk(cls.superclass); |
| 97 preOrder.add(cls); | 97 preOrder.add(cls); |
| 98 } | 98 } |
| 99 |
| 99 classes.forEach(walk); | 100 classes.forEach(walk); |
| 100 | 101 |
| 101 // Find which classes are needed and which are non-leaf classes. Any class | 102 // Find which classes are needed and which are non-leaf classes. Any class |
| 102 // that is not needed can be treated as a leaf class equivalent to some | 103 // that is not needed can be treated as a leaf class equivalent to some |
| 103 // needed class. | 104 // needed class. |
| 104 | 105 |
| 105 Set<Class> neededClasses = new Set<Class>(); | 106 Set<Class> neededClasses = new Set<Class>(); |
| 106 Set<Class> nonLeafClasses = new Set<Class>(); | 107 Set<Class> nonLeafClasses = new Set<Class>(); |
| 107 | 108 |
| 108 Map<Class, List<Class>> extensionPoints = computeExtensionPoints(preOrder); | 109 Map<Class, List<Class>> extensionPoints = computeExtensionPoints(preOrder); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 cls.nativeNonLeafTags == null && | 181 cls.nativeNonLeafTags == null && |
| 181 cls.nativeExtensions == null); | 182 cls.nativeExtensions == null); |
| 182 if (leafTags[cls] != null) { | 183 if (leafTags[cls] != null) { |
| 183 cls.nativeLeafTags = leafTags[cls].toList(growable: false); | 184 cls.nativeLeafTags = leafTags[cls].toList(growable: false); |
| 184 } | 185 } |
| 185 if (nonleafTags[cls] != null) { | 186 if (nonleafTags[cls] != null) { |
| 186 cls.nativeNonLeafTags = nonleafTags[cls].toList(growable: false); | 187 cls.nativeNonLeafTags = nonleafTags[cls].toList(growable: false); |
| 187 } | 188 } |
| 188 cls.nativeExtensions = extensionPoints[cls]; | 189 cls.nativeExtensions = extensionPoints[cls]; |
| 189 } | 190 } |
| 191 |
| 190 // Add properties containing the information needed to construct maps used | 192 // Add properties containing the information needed to construct maps used |
| 191 // by getNativeInterceptor and custom elements. | 193 // by getNativeInterceptor and custom elements. |
| 192 if (compiler.enqueuer.codegen.nativeEnqueuer | 194 if (compiler.enqueuer.codegen.nativeEnqueuer |
| 193 .hasInstantiatedNativeClasses()) { | 195 .hasInstantiatedNativeClasses()) { |
| 194 fillNativeInfo(jsInterceptorClass); | 196 fillNativeInfo(jsInterceptorClass); |
| 195 for (Class cls in classes) { | 197 for (Class cls in classes) { |
| 196 if (!cls.isNative || neededClasses.contains(cls)) { | 198 if (!cls.isNative || neededClasses.contains(cls)) { |
| 197 fillNativeInfo(cls); | 199 fillNativeInfo(cls); |
| 198 } | 200 } |
| 199 } | 201 } |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 // used. We should also use an interceptor if the check can't be satisfied | 351 // used. We should also use an interceptor if the check can't be satisfied |
| 350 // by a native class in case we get a native instance that tries to spoof | 352 // by a native class in case we get a native instance that tries to spoof |
| 351 // the type info. i.e the criteria for whether or not to use an interceptor | 353 // the type info. i.e the criteria for whether or not to use an interceptor |
| 352 // is whether the receiver can be native, not the type of the test. | 354 // is whether the receiver can be native, not the type of the test. |
| 353 if (element == null || !element.isClass) return false; | 355 if (element == null || !element.isClass) return false; |
| 354 ClassElement cls = element; | 356 ClassElement cls = element; |
| 355 if (backend.isNativeOrExtendsNative(cls)) return true; | 357 if (backend.isNativeOrExtendsNative(cls)) return true; |
| 356 return isSupertypeOfNativeClass(element); | 358 return isSupertypeOfNativeClass(element); |
| 357 } | 359 } |
| 358 } | 360 } |
| OLD | NEW |