Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit ff1a657

Browse files
author
John Messerly
committed
fix mixin field init, implicit-this
also slight change to sunflower example [email protected] Review URL: https://chromereviews.googleplex.com/144247014
1 parent bcd24e3 commit ff1a657

File tree

11 files changed

+275
-265
lines changed

11 files changed

+275
-265
lines changed

lib/runtime/dart_runtime.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,26 +89,28 @@ var dart;
8989
dart.dbinary = dbinary;
9090

9191
function as(obj, type) {
92-
if (obj == null || is(obj, type)) return obj;
93-
throw new dart_core.CastError();
92+
// TODO(vsm): Implement.
93+
// if (obj == null || is(obj, type)) return obj;
94+
// throw new core.CastError();
95+
return obj;
9496
}
9597
dart.as = as;
9698

9799
function is(obj, type) {
98100
// TODO(vsm): Implement.
99-
throw new dart_core.UnimplementedError();
101+
throw new core.UnimplementedError();
100102
}
101103
dart.is = is;
102104

103105
function isGroundType(type) {
104106
// TODO(vsm): Implement.
105-
throw new dart_core.UnimplementedError();
107+
throw new core.UnimplementedError();
106108
}
107109
dart.isGroundType = isGroundType;
108110

109111
function arity(f) {
110112
// TODO(vsm): Implement.
111-
throw new dart_core.UnimplementedError();
113+
throw new core.UnimplementedError();
112114
}
113115
dart.arity = arity;
114116

@@ -189,17 +191,21 @@ var dart;
189191
* superclass (prototype).
190192
*/
191193
function mixin(base/*, ...mixins*/) {
192-
// Inherit statics from Base to simulate ES6 class inheritance
193-
// Conceptually this is: `class Mixin extends base {}`
194+
// Build the mixin constructor. This runs the superclass as well as each
195+
// of the mixins' constructors.
196+
var mixins = Array.prototype.slice.call(arguments, 1);
194197
function Mixin() {
195198
base.apply(this, arguments);
199+
// Run mixin constructors. They cannot have arguments.
200+
for (var i = 0; i< mixins.length; i++) mixins[i].call(this);
196201
}
202+
// Inherit statics from Base to simulate ES6 class inheritance
203+
// Conceptually this is: `class Mixin extends base {}`
197204
Mixin.__proto__ = base;
198205
Mixin.prototype = Object.create(base.prototype);
199206
// Copy each mixin, with later ones overwriting earlier entries.
200-
for (var i = 1; i < arguments.length; i++) {
201-
var from = arguments[i];
202-
copyProperties(Mixin.prototype, from.prototype);
207+
for (var i = 0; i< mixins.length; i++) {
208+
copyProperties(Mixin.prototype, mixins[i].prototype);
203209
}
204210
return Mixin;
205211
}
@@ -258,7 +264,7 @@ var dart;
258264
dart.defineNamedConstructor = defineNamedConstructor;
259265

260266
function stackTrace(exception) {
261-
throw new dart_core.UnimplementedError();
267+
throw new core.UnimplementedError();
262268
}
263269
dart.stackTrace = stackTrace;
264270

lib/src/codegen/js_codegen.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,8 +645,7 @@ $name.prototype[Symbol.iterator] = function() {
645645
if (e.enclosingElement is CompilationUnitElement &&
646646
(e.library != libraryInfo.library || _needsModuleGetter(e))) {
647647
out.write('${_jsLibraryName(e.library)}.');
648-
} else if (currentClass != null &&
649-
e.enclosingElement == currentClass.element) {
648+
} else if (currentClass != null) {
650649
if (e is PropertyAccessorElement && !e.variable.isStatic ||
651650
e is ClassMemberElement && !e.isStatic && e is! ConstructorElement) {
652651
out.write('this.');

test/codegen/expect/DeltaBlue/DeltaBlue.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -80,23 +80,23 @@ var DeltaBlue;
8080
this.myOutput = myOutput;
8181
this.satisfied = false;
8282
super(strength);
83-
addConstraint();
83+
this.addConstraint();
8484
}
8585
addToGraph() {
8686
this.myOutput.addConstraint(this);
8787
this.satisfied = false;
8888
}
8989
chooseMethod(mark) {
90-
this.satisfied = (this.myOutput.mark !== mark) && Strength.stronger(strength, this.myOutput.walkStrength);
90+
this.satisfied = (this.myOutput.mark !== mark) && Strength.stronger(this.strength, this.myOutput.walkStrength);
9191
}
9292
isSatisfied() { return this.satisfied; }
9393
markInputs(mark) {
9494
}
9595
output() { return this.myOutput; }
9696
recalculate() {
97-
this.myOutput.walkStrength = strength;
98-
this.myOutput.stay = !isInput();
99-
if (this.myOutput.stay) execute();
97+
this.myOutput.walkStrength = this.strength;
98+
this.myOutput.stay = !this.isInput();
99+
if (this.myOutput.stay) this.execute();
100100
}
101101
markUnsatisfied() {
102102
this.satisfied = false;
@@ -134,19 +134,19 @@ var DeltaBlue;
134134
this.v2 = v2;
135135
this.direction = NONE;
136136
super(strength);
137-
addConstraint();
137+
this.addConstraint();
138138
}
139139
chooseMethod(mark) {
140140
if (this.v1.mark === mark) {
141-
this.direction = (this.v2.mark !== mark && Strength.stronger(strength, this.v2.walkStrength)) ? FORWARD : NONE;
141+
this.direction = (this.v2.mark !== mark && Strength.stronger(this.strength, this.v2.walkStrength)) ? FORWARD : NONE;
142142
}
143143
if (this.v2.mark === mark) {
144-
this.direction = (this.v1.mark !== mark && Strength.stronger(strength, this.v1.walkStrength)) ? BACKWARD : NONE;
144+
this.direction = (this.v1.mark !== mark && Strength.stronger(this.strength, this.v1.walkStrength)) ? BACKWARD : NONE;
145145
}
146146
if (Strength.weaker(this.v1.walkStrength, this.v2.walkStrength)) {
147-
this.direction = Strength.stronger(strength, this.v1.walkStrength) ? BACKWARD : NONE;
147+
this.direction = Strength.stronger(this.strength, this.v1.walkStrength) ? BACKWARD : NONE;
148148
} else {
149-
this.direction = Strength.stronger(strength, this.v2.walkStrength) ? FORWARD : BACKWARD;
149+
this.direction = Strength.stronger(this.strength, this.v2.walkStrength) ? FORWARD : BACKWARD;
150150
}
151151
}
152152
addToGraph() {
@@ -162,9 +162,9 @@ var DeltaBlue;
162162
output() { return this.direction === FORWARD ? this.v2 : this.v1; }
163163
recalculate() {
164164
let ihn = this.input(), out = this.output();
165-
out.walkStrength = Strength.weakest(strength, ihn.walkStrength);
165+
out.walkStrength = Strength.weakest(this.strength, ihn.walkStrength);
166166
out.stay = ihn.stay;
167-
if (out.stay) execute();
167+
if (out.stay) this.execute();
168168
}
169169
markUnsatisfied() {
170170
this.direction = NONE;
@@ -201,15 +201,15 @@ var DeltaBlue;
201201
this.scale.mark = this.offset.mark = mark;
202202
}
203203
execute() {
204-
if (direction === FORWARD) {
205-
v2.value = v1.value * this.scale.value + this.offset.value;
204+
if (this.direction === FORWARD) {
205+
this.v2.value = this.v1.value * this.scale.value + this.offset.value;
206206
} else {
207-
v1.value = ((v2.value - this.offset.value) / this.scale.value).truncate();
207+
this.v1.value = ((this.v2.value - this.offset.value) / this.scale.value).truncate();
208208
}
209209
}
210210
recalculate() {
211-
let ihn = input(), out = output();
212-
out.walkStrength = Strength.weakest(strength, ihn.walkStrength);
211+
let ihn = this.input(), out = this.output();
212+
out.walkStrength = Strength.weakest(this.strength, ihn.walkStrength);
213213
out.stay = ihn.stay && this.scale.stay && this.offset.stay;
214214
if (out.stay) this.execute();
215215
}
@@ -220,7 +220,7 @@ var DeltaBlue;
220220
super(v1, v2, strength);
221221
}
222222
execute() {
223-
output().value = input().value;
223+
this.output().value = this.input().value;
224224
}
225225
}
226226

test/codegen/expect/_internal/_internal.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,8 @@ var _internal;
434434
super._(iterable, takeCount);
435435
}
436436
get length() {
437-
let iterableLength = _iterable.length;
438-
if (iterableLength > _takeCount) return _takeCount;
437+
let iterableLength = this._iterable.length;
438+
if (iterableLength > this._takeCount) return this._takeCount;
439439
return iterableLength;
440440
}
441441
}
@@ -527,7 +527,7 @@ var _internal;
527527
super._(iterable, skipCount);
528528
}
529529
get length() {
530-
let length = _iterable.length - _skipCount;
530+
let length = this._iterable.length - this._skipCount;
531531
if (length >= 0) return length;
532532
return 0;
533533
}

0 commit comments

Comments
 (0)