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