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 16 matching lines...) Expand all Loading... |
27 : this.emitterTask = emitterTask, | 27 : this.emitterTask = emitterTask, |
28 subtypes = new Map<ClassElement, List<ClassElement>>(), | 28 subtypes = new Map<ClassElement, List<ClassElement>>(), |
29 directSubtypes = new Map<ClassElement, List<ClassElement>>(), | 29 directSubtypes = new Map<ClassElement, List<ClassElement>>(), |
30 nativeMethods = new Set<FunctionElement>(), | 30 nativeMethods = new Set<FunctionElement>(), |
31 cachedBuilders = emitterTask.compiler.cacheStrategy.newMap(); | 31 cachedBuilders = emitterTask.compiler.cacheStrategy.newMap(); |
32 | 32 |
33 Compiler get compiler => emitterTask.compiler; | 33 Compiler get compiler => emitterTask.compiler; |
34 | 34 |
35 JavaScriptBackend get backend => compiler.backend; | 35 JavaScriptBackend get backend => compiler.backend; |
36 | 36 |
| 37 BackendHelpers get helpers => backend.helpers; |
| 38 |
37 jsAst.Expression get defPropFunction { | 39 jsAst.Expression get defPropFunction { |
38 Element element = backend.findHelper('defineProperty'); | 40 Element element = helpers.defineProperty; |
39 return emitterTask.staticFunctionAccess(element); | 41 return emitterTask.staticFunctionAccess(element); |
40 } | 42 } |
41 | 43 |
42 /** | 44 /** |
43 * Prepares native classes for emission. Returns the unneeded classes. | 45 * Prepares native classes for emission. Returns the unneeded classes. |
44 * | 46 * |
45 * Removes trivial classes (that can be represented by a super type) and | 47 * Removes trivial classes (that can be represented by a super type) and |
46 * generates properties that have to be added to classes (native or not). | 48 * generates properties that have to be added to classes (native or not). |
47 * | 49 * |
48 * Updates the `nativeLeafTags`, `nativeNonLeafTags` and `nativeExtensions` | 50 * Updates the `nativeLeafTags`, `nativeNonLeafTags` and `nativeExtensions` |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 Set<Class> seen = new Set<Class>(); | 85 Set<Class> seen = new Set<Class>(); |
84 | 86 |
85 Class objectClass = null; | 87 Class objectClass = null; |
86 Class jsInterceptorClass = null; | 88 Class jsInterceptorClass = null; |
87 | 89 |
88 void walk(Class cls) { | 90 void walk(Class cls) { |
89 if (cls.element == compiler.coreClasses.objectClass) { | 91 if (cls.element == compiler.coreClasses.objectClass) { |
90 objectClass = cls; | 92 objectClass = cls; |
91 return; | 93 return; |
92 } | 94 } |
93 if (cls.element == backend.jsInterceptorClass) { | 95 if (cls.element == helpers.jsInterceptorClass) { |
94 jsInterceptorClass = cls; | 96 jsInterceptorClass = cls; |
95 return; | 97 return; |
96 } | 98 } |
97 if (seen.contains(cls)) return; | 99 if (seen.contains(cls)) return; |
98 seen.add(cls); | 100 seen.add(cls); |
99 walk(cls.superclass); | 101 walk(cls.superclass); |
100 preOrder.add(cls); | 102 preOrder.add(cls); |
101 } | 103 } |
102 classes.forEach(walk); | 104 classes.forEach(walk); |
103 | 105 |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 cls.callStubs.isEmpty && | 257 cls.callStubs.isEmpty && |
256 !cls.superclass.isMixinApplication && | 258 !cls.superclass.isMixinApplication && |
257 !cls.fields.any(needsAccessor); | 259 !cls.fields.any(needsAccessor); |
258 } | 260 } |
259 | 261 |
260 void potentiallyConvertDartClosuresToJs( | 262 void potentiallyConvertDartClosuresToJs( |
261 List<jsAst.Statement> statements, | 263 List<jsAst.Statement> statements, |
262 FunctionElement member, | 264 FunctionElement member, |
263 List<jsAst.Parameter> stubParameters) { | 265 List<jsAst.Parameter> stubParameters) { |
264 FunctionSignature parameters = member.functionSignature; | 266 FunctionSignature parameters = member.functionSignature; |
265 Element converter = backend.findHelper('convertDartClosureToJS'); | 267 Element converter = helpers.closureConverter; |
266 jsAst.Expression closureConverter = | 268 jsAst.Expression closureConverter = |
267 emitterTask.staticFunctionAccess(converter); | 269 emitterTask.staticFunctionAccess(converter); |
268 parameters.forEachParameter((ParameterElement parameter) { | 270 parameters.forEachParameter((ParameterElement parameter) { |
269 String name = parameter.name; | 271 String name = parameter.name; |
270 // If [name] is not in [stubParameters], then the parameter is an optional | 272 // If [name] is not in [stubParameters], then the parameter is an optional |
271 // parameter that was not provided for this stub. | 273 // parameter that was not provided for this stub. |
272 for (jsAst.Parameter stubParameter in stubParameters) { | 274 for (jsAst.Parameter stubParameter in stubParameters) { |
273 if (stubParameter.name == name) { | 275 if (stubParameter.name == name) { |
274 DartType type = parameter.type.unaliased; | 276 DartType type = parameter.type.unaliased; |
275 if (type is FunctionType) { | 277 if (type is FunctionType) { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 // used. We should also use an interceptor if the check can't be satisfied | 359 // used. We should also use an interceptor if the check can't be satisfied |
358 // by a native class in case we get a native instance that tries to spoof | 360 // by a native class in case we get a native instance that tries to spoof |
359 // the type info. i.e the criteria for whether or not to use an interceptor | 361 // the type info. i.e the criteria for whether or not to use an interceptor |
360 // is whether the receiver can be native, not the type of the test. | 362 // is whether the receiver can be native, not the type of the test. |
361 if (element == null || !element.isClass) return false; | 363 if (element == null || !element.isClass) return false; |
362 ClassElement cls = element; | 364 ClassElement cls = element; |
363 if (backend.isNativeOrExtendsNative(cls)) return true; | 365 if (backend.isNativeOrExtendsNative(cls)) return true; |
364 return isSupertypeOfNativeClass(element); | 366 return isSupertypeOfNativeClass(element); |
365 } | 367 } |
366 } | 368 } |
OLD | NEW |