| 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 final Map<Element, ClassBuilder> cachedBuilders; | 9 final Map<Element, ClassBuilder> cachedBuilders; |
| 10 | 10 |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 generateClassInfo(jsInterceptorClass); | 232 generateClassInfo(jsInterceptorClass); |
| 233 for (Class cls in classes) { | 233 for (Class cls in classes) { |
| 234 if (!cls.isNative || neededClasses.contains(cls)) { | 234 if (!cls.isNative || neededClasses.contains(cls)) { |
| 235 generateClassInfo(cls); | 235 generateClassInfo(cls); |
| 236 } | 236 } |
| 237 } | 237 } |
| 238 } | 238 } |
| 239 | 239 |
| 240 // Emit the native class interceptors that were actually used. | 240 // Emit the native class interceptors that were actually used. |
| 241 for (Class cls in classes) { | 241 for (Class cls in classes) { |
| 242 assert(!cls.onlyForRti); |
| 242 ClassElement classElement = cls.element; | 243 ClassElement classElement = cls.element; |
| 243 if (!cls.isNative) continue; | 244 if (!cls.isNative) continue; |
| 244 if (neededClasses.contains(cls)) { | 245 if (neededClasses.contains(cls)) { |
| 245 ClassBuilder builder = builders[classElement]; | 246 ClassBuilder builder = builders[classElement]; |
| 246 | 247 |
| 247 // In CSP mode [emitClassConstructor] and [emitClassGettersSetters] have | 248 // In CSP mode [emitClassConstructor] and [emitClassGettersSetters] have |
| 248 // a side-effect on "precompiled" functions in [OldEmitter]. For this | 249 // a side-effect on "precompiled" functions in [OldEmitter]. For this |
| 249 // reason, it is important that we don't call these methods before we | 250 // reason, it is important that we don't call these methods before we |
| 250 // are certain that a class is needed. | 251 // are certain that a class is needed. |
| 251 | 252 |
| 252 emitterTask.oldEmitter.classEmitter | 253 emitterTask.oldEmitter.classEmitter.emitConstructorsForCSP(cls); |
| 253 .emitConstructorsForCSP(classElement); | |
| 254 | 254 |
| 255 // [emitClassGettersSettersForCSP] does not affect whether or not a | 255 // [emitClassGettersSettersForCSP] does not affect whether or not a |
| 256 // class is needed. If getters/setters are emitted, the class has fields | 256 // class is needed. If getters/setters are emitted, the class has fields |
| 257 // and is therefore non-trivial. | 257 // and is therefore non-trivial. |
| 258 emitterTask.oldEmitter.classEmitter.emitClassGettersSettersForCSP( | 258 emitterTask.oldEmitter.classEmitter.emitClassGettersSettersForCSP( |
| 259 classElement, builder); | 259 cls, builder); |
| 260 | 260 |
| 261 // Define interceptor class for [classElement]. | 261 // Define interceptor class for [classElement]. |
| 262 emitterTask.oldEmitter.classEmitter.emitClassBuilderWithReflectionData( | 262 emitterTask.oldEmitter.classEmitter.emitClassBuilderWithReflectionData( |
| 263 cls.name, | 263 cls, |
| 264 classElement, builders[cls], | 264 builders[cls], |
| 265 emitterTask.oldEmitter.getElementDescriptor(classElement)); | 265 emitterTask.oldEmitter.getElementDescriptor(classElement)); |
| 266 emitterTask.oldEmitter.needsClassSupport = true; | 266 emitterTask.oldEmitter.needsClassSupport = true; |
| 267 } | 267 } |
| 268 } | 268 } |
| 269 } | 269 } |
| 270 | 270 |
| 271 /** | 271 /** |
| 272 * Computes the native classes that are extended (subclassed) by non-native | 272 * Computes the native classes that are extended (subclassed) by non-native |
| 273 * classes and the set non-mative classes that extend them. (A List is used | 273 * classes and the set non-mative classes that extend them. (A List is used |
| 274 * instead of a Set for out stability). | 274 * instead of a Set for out stability). |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 builder = cachedBuilders[classElement]; | 315 builder = cachedBuilders[classElement]; |
| 316 if (builder != null) return builder; | 316 if (builder != null) return builder; |
| 317 builder = new ClassBuilder(classElement, backend.namer); | 317 builder = new ClassBuilder(classElement, backend.namer); |
| 318 cachedBuilders[classElement] = builder; | 318 cachedBuilders[classElement] = builder; |
| 319 } else { | 319 } else { |
| 320 builder = new ClassBuilder(classElement, backend.namer); | 320 builder = new ClassBuilder(classElement, backend.namer); |
| 321 } | 321 } |
| 322 builder.superName = superclass.name; | 322 builder.superName = superclass.name; |
| 323 | 323 |
| 324 bool hasFields = emitterTask.oldEmitter.classEmitter.emitFields( | 324 bool hasFields = emitterTask.oldEmitter.classEmitter.emitFields( |
| 325 classElement, builder, classIsNative: true); | 325 cls, builder, classIsNative: true); |
| 326 int propertyCount = builder.properties.length; | 326 int propertyCount = builder.properties.length; |
| 327 emitterTask.oldEmitter.classEmitter.emitCheckedClassSetters( | 327 emitterTask.oldEmitter.classEmitter.emitCheckedClassSetters(cls, builder); |
| 328 classElement, builder); | |
| 329 emitterTask.oldEmitter.classEmitter.emitInstanceMembers( | 328 emitterTask.oldEmitter.classEmitter.emitInstanceMembers( |
| 330 classElement, builder); | 329 classElement, builder); |
| 331 emitterTask.oldEmitter.classEmitter | 330 emitterTask.oldEmitter.classEmitter |
| 332 .emitRuntimeTypeInformation(cls, builder); | 331 .emitRuntimeTypeInformation(cls, builder); |
| 333 | 332 |
| 334 if (!hasFields && | 333 if (!hasFields && |
| 335 builder.properties.length == propertyCount && | 334 builder.properties.length == propertyCount && |
| 336 superclass is! MixinApplicationElement) { | 335 superclass is! MixinApplicationElement) { |
| 337 builder.isTrivial = true; | 336 builder.isTrivial = true; |
| 338 } | 337 } |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 targetOutput.add(';'); | 488 targetOutput.add(';'); |
| 490 } | 489 } |
| 491 targetOutput.addBuffer(jsAst.prettyPrint( | 490 targetOutput.addBuffer(jsAst.prettyPrint( |
| 492 new jsAst.ExpressionStatement(init), compiler)); | 491 new jsAst.ExpressionStatement(init), compiler)); |
| 493 targetOutput.add('\n'); | 492 targetOutput.add('\n'); |
| 494 } | 493 } |
| 495 | 494 |
| 496 targetOutput.add('\n'); | 495 targetOutput.add('\n'); |
| 497 } | 496 } |
| 498 } | 497 } |
| OLD | NEW |