Chromium Code Reviews| Index: pkg/compiler/lib/src/js_emitter/new_emitter/model_emitter.dart |
| diff --git a/pkg/compiler/lib/src/js_emitter/new_emitter/model_emitter.dart b/pkg/compiler/lib/src/js_emitter/new_emitter/model_emitter.dart |
| index 6e37f27edaf5e9bce1be9c4199c4851c21c1f9f6..9d09af4829c5215e57b5db0278b8f15fe09076b2 100644 |
| --- a/pkg/compiler/lib/src/js_emitter/new_emitter/model_emitter.dart |
| +++ b/pkg/compiler/lib/src/js_emitter/new_emitter/model_emitter.dart |
| @@ -33,7 +33,6 @@ import '../js_emitter.dart' show NativeGenerator, buildTearOffCode; |
| import '../model.dart'; |
| - |
| class ModelEmitter { |
| final Compiler compiler; |
| final Namer namer; |
| @@ -466,7 +465,8 @@ class ModelEmitter { |
| // This string should be referenced wherever JavaScript code makes assumptions |
| // on the mixin format. |
| static final String mixinFormatDescription = |
| - "Mixins have no constructor, but a reference to their mixin class."; |
| + "Mixins have a reference to their mixin class followed by a constructor" + |
|
floitsch
2015/02/06 12:41:19
"Mixins have a reference to their mixin class at t
floitsch
2015/02/06 12:41:20
You don't need the "+" if two string literals are
zarah
2015/02/06 14:27:09
Done.
zarah
2015/02/06 14:27:09
Done.
|
| + "function in the case they have been directly instatiated"; |
|
floitsch
2015/02/06 12:41:19
"instantiated.";
zarah
2015/02/06 14:27:09
Acknowledged.
|
| js.Expression emitClass(Class cls) { |
| List elements = [js.string(cls.superclassName), |
| @@ -476,6 +476,9 @@ class ModelEmitter { |
| MixinApplication mixin = cls; |
| elements.add(js.string(mixin.mixinClass.name)); |
| elements.add(js.number(mixin.mixinClass.holder.index)); |
| + if (cls.isDirectlyInstantiated) { |
| + elements.add(_generateConstructor(cls)); |
| + } |
| } else { |
| elements.add(_generateConstructor(cls)); |
| } |
| @@ -800,18 +803,28 @@ function parseFunctionDescriptor(proto, name, descriptor) { |
| descriptor = compile(name, descriptor); |
| var prototype = determinePrototype(descriptor); |
| var constructor; |
| + var functionsIndex; |
| // $mixinFormatDescription. |
| if (typeof descriptor[2] !== 'function') { |
| - constructor = compileMixinConstructor(name, prototype, descriptor); |
| - for (var i = 4; i < descriptor.length; i += 2) { |
| - parseFunctionDescriptor(prototype, descriptor[i], descriptor[i + 1]); |
| + compileMixinConstructor(name, prototype, descriptor); |
| + // The mixin application has been directly instatiated and hence it has a |
|
floitsch
2015/02/06 12:41:20
// Descriptor[4] contains the constructor if the m
zarah
2015/02/06 14:27:09
Done.
|
| + // construtor function. |
|
floitsch
2015/02/06 12:41:19
constructor
zarah
2015/02/06 14:27:09
Acknowledged.
|
| + if (typeof descriptor[4] === 'function') { |
| + constructor = descriptor[4]; |
| + functionsIndex = 5; |
| + } else { |
| + constructor = function() {}; |
| + functionsIndex = 4; |
| } |
| } else { |
| constructor = descriptor[2]; |
| - for (var i = 3; i < descriptor.length; i += 2) { |
| - parseFunctionDescriptor(prototype, descriptor[i], descriptor[i + 1]); |
| - } |
| + functionsIndex = 3; |
| } |
| + |
| + for (var i = functionsIndex; i < descriptor.length; i += 2) { |
| + parseFunctionDescriptor(prototype, descriptor[i], descriptor[i + 1]); |
| + } |
| + |
| constructor.builtin\$cls = name; // Needed for RTI. |
| constructor.prototype = prototype; |
| prototype[#operatorIsPrefix + name] = constructor; |
| @@ -832,10 +845,6 @@ function parseFunctionDescriptor(proto, name, descriptor) { |
| var p = mixinProperties[i]; |
| prototype[p] = mixinPrototype[p]; |
| } |
| - // Since this is a mixin application the constructor will actually never |
| - // be invoked. We only use its prototype for the application's subclasses. |
| - var constructor = function() {}; |
| - return constructor; |
| } |
| function determinePrototype(descriptor) { |