Skip to content

Commit d1393b0

Browse files
committed
fix(di): injecting null causes a cyclic dependency
1 parent 46bb4e3 commit d1393b0

File tree

2 files changed

+244
-188
lines changed

2 files changed

+244
-188
lines changed

modules/angular2/src/di/injector.ts

Lines changed: 54 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -197,16 +197,16 @@ export interface InjectorStrategy {
197197
}
198198

199199
export class InjectorInlineStrategy implements InjectorStrategy {
200-
obj0: any = null;
201-
obj1: any = null;
202-
obj2: any = null;
203-
obj3: any = null;
204-
obj4: any = null;
205-
obj5: any = null;
206-
obj6: any = null;
207-
obj7: any = null;
208-
obj8: any = null;
209-
obj9: any = null;
200+
obj0: any = undefinedValue;
201+
obj1: any = undefinedValue;
202+
obj2: any = undefinedValue;
203+
obj3: any = undefinedValue;
204+
obj4: any = undefinedValue;
205+
obj5: any = undefinedValue;
206+
obj6: any = undefinedValue;
207+
obj7: any = undefinedValue;
208+
obj8: any = undefinedValue;
209+
obj9: any = undefinedValue;
210210

211211
constructor(public injector: Injector, public protoStrategy: ProtoInjectorInlineStrategy) {}
212212

@@ -217,16 +217,26 @@ export class InjectorInlineStrategy implements InjectorStrategy {
217217
inj._constructionCounter = 0;
218218

219219

220-
if (isPresent(p.keyId0) && isBlank(this.obj0)) this.obj0 = inj._new(p.binding0, p.visibility0);
221-
if (isPresent(p.keyId1) && isBlank(this.obj1)) this.obj1 = inj._new(p.binding1, p.visibility1);
222-
if (isPresent(p.keyId2) && isBlank(this.obj2)) this.obj2 = inj._new(p.binding2, p.visibility2);
223-
if (isPresent(p.keyId3) && isBlank(this.obj3)) this.obj3 = inj._new(p.binding3, p.visibility3);
224-
if (isPresent(p.keyId4) && isBlank(this.obj4)) this.obj4 = inj._new(p.binding4, p.visibility4);
225-
if (isPresent(p.keyId5) && isBlank(this.obj5)) this.obj5 = inj._new(p.binding5, p.visibility5);
226-
if (isPresent(p.keyId6) && isBlank(this.obj6)) this.obj6 = inj._new(p.binding6, p.visibility6);
227-
if (isPresent(p.keyId7) && isBlank(this.obj7)) this.obj7 = inj._new(p.binding7, p.visibility7);
228-
if (isPresent(p.keyId8) && isBlank(this.obj8)) this.obj8 = inj._new(p.binding8, p.visibility8);
229-
if (isPresent(p.keyId9) && isBlank(this.obj9)) this.obj9 = inj._new(p.binding9, p.visibility9);
220+
if (isPresent(p.keyId0) && this.obj0 === undefinedValue)
221+
this.obj0 = inj._new(p.binding0, p.visibility0);
222+
if (isPresent(p.keyId1) && this.obj1 === undefinedValue)
223+
this.obj1 = inj._new(p.binding1, p.visibility1);
224+
if (isPresent(p.keyId2) && this.obj2 === undefinedValue)
225+
this.obj2 = inj._new(p.binding2, p.visibility2);
226+
if (isPresent(p.keyId3) && this.obj3 === undefinedValue)
227+
this.obj3 = inj._new(p.binding3, p.visibility3);
228+
if (isPresent(p.keyId4) && this.obj4 === undefinedValue)
229+
this.obj4 = inj._new(p.binding4, p.visibility4);
230+
if (isPresent(p.keyId5) && this.obj5 === undefinedValue)
231+
this.obj5 = inj._new(p.binding5, p.visibility5);
232+
if (isPresent(p.keyId6) && this.obj6 === undefinedValue)
233+
this.obj6 = inj._new(p.binding6, p.visibility6);
234+
if (isPresent(p.keyId7) && this.obj7 === undefinedValue)
235+
this.obj7 = inj._new(p.binding7, p.visibility7);
236+
if (isPresent(p.keyId8) && this.obj8 === undefinedValue)
237+
this.obj8 = inj._new(p.binding8, p.visibility8);
238+
if (isPresent(p.keyId9) && this.obj9 === undefinedValue)
239+
this.obj9 = inj._new(p.binding9, p.visibility9);
230240
}
231241

232242
attach(parent: Injector, isBoundary: boolean): void {
@@ -236,78 +246,78 @@ export class InjectorInlineStrategy implements InjectorStrategy {
236246
}
237247

238248
dehydrate() {
239-
this.obj0 = null;
240-
this.obj1 = null;
241-
this.obj2 = null;
242-
this.obj3 = null;
243-
this.obj4 = null;
244-
this.obj5 = null;
245-
this.obj6 = null;
246-
this.obj7 = null;
247-
this.obj8 = null;
248-
this.obj9 = null;
249+
this.obj0 = undefinedValue;
250+
this.obj1 = undefinedValue;
251+
this.obj2 = undefinedValue;
252+
this.obj3 = undefinedValue;
253+
this.obj4 = undefinedValue;
254+
this.obj5 = undefinedValue;
255+
this.obj6 = undefinedValue;
256+
this.obj7 = undefinedValue;
257+
this.obj8 = undefinedValue;
258+
this.obj9 = undefinedValue;
249259
}
250260

251261
getObjByKeyId(keyId: number, visibility: number): any {
252262
var p = this.protoStrategy;
253263
var inj = this.injector;
254264

255265
if (p.keyId0 === keyId && (p.visibility0 & visibility) > 0) {
256-
if (isBlank(this.obj0)) {
266+
if (this.obj0 === undefinedValue) {
257267
this.obj0 = inj._new(p.binding0, p.visibility0);
258268
}
259269
return this.obj0;
260270
}
261271
if (p.keyId1 === keyId && (p.visibility1 & visibility) > 0) {
262-
if (isBlank(this.obj1)) {
272+
if (this.obj1 === undefinedValue) {
263273
this.obj1 = inj._new(p.binding1, p.visibility1);
264274
}
265275
return this.obj1;
266276
}
267277
if (p.keyId2 === keyId && (p.visibility2 & visibility) > 0) {
268-
if (isBlank(this.obj2)) {
278+
if (this.obj2 === undefinedValue) {
269279
this.obj2 = inj._new(p.binding2, p.visibility2);
270280
}
271281
return this.obj2;
272282
}
273283
if (p.keyId3 === keyId && (p.visibility3 & visibility) > 0) {
274-
if (isBlank(this.obj3)) {
284+
if (this.obj3 === undefinedValue) {
275285
this.obj3 = inj._new(p.binding3, p.visibility3);
276286
}
277287
return this.obj3;
278288
}
279289
if (p.keyId4 === keyId && (p.visibility4 & visibility) > 0) {
280-
if (isBlank(this.obj4)) {
290+
if (this.obj4 === undefinedValue) {
281291
this.obj4 = inj._new(p.binding4, p.visibility4);
282292
}
283293
return this.obj4;
284294
}
285295
if (p.keyId5 === keyId && (p.visibility5 & visibility) > 0) {
286-
if (isBlank(this.obj5)) {
296+
if (this.obj5 === undefinedValue) {
287297
this.obj5 = inj._new(p.binding5, p.visibility5);
288298
}
289299
return this.obj5;
290300
}
291301
if (p.keyId6 === keyId && (p.visibility6 & visibility) > 0) {
292-
if (isBlank(this.obj6)) {
302+
if (this.obj6 === undefinedValue) {
293303
this.obj6 = inj._new(p.binding6, p.visibility6);
294304
}
295305
return this.obj6;
296306
}
297307
if (p.keyId7 === keyId && (p.visibility7 & visibility) > 0) {
298-
if (isBlank(this.obj7)) {
308+
if (this.obj7 === undefinedValue) {
299309
this.obj7 = inj._new(p.binding7, p.visibility7);
300310
}
301311
return this.obj7;
302312
}
303313
if (p.keyId8 === keyId && (p.visibility8 & visibility) > 0) {
304-
if (isBlank(this.obj8)) {
314+
if (this.obj8 === undefinedValue) {
305315
this.obj8 = inj._new(p.binding8, p.visibility8);
306316
}
307317
return this.obj8;
308318
}
309319
if (p.keyId9 === keyId && (p.visibility9 & visibility) > 0) {
310-
if (isBlank(this.obj9)) {
320+
if (this.obj9 === undefinedValue) {
311321
this.obj9 = inj._new(p.binding9, p.visibility9);
312322
}
313323
return this.obj9;
@@ -339,12 +349,13 @@ export class InjectorDynamicStrategy implements InjectorStrategy {
339349

340350
constructor(public protoStrategy: ProtoInjectorDynamicStrategy, public injector: Injector) {
341351
this.objs = ListWrapper.createFixedSize(protoStrategy.bindings.length);
352+
ListWrapper.fill(this.objs, undefinedValue);
342353
}
343354

344355
hydrate(): void {
345356
var p = this.protoStrategy;
346357
for (var i = 0; i < p.keyIds.length; i++) {
347-
if (isPresent(p.keyIds[i]) && isBlank(this.objs[i])) {
358+
if (isPresent(p.keyIds[i]) && this.objs[i] === undefinedValue) {
348359
this.objs[i] = this.injector._new(p.bindings[i], p.visibilities[i]);
349360
}
350361
}
@@ -356,14 +367,14 @@ export class InjectorDynamicStrategy implements InjectorStrategy {
356367
inj._isBoundary = isBoundary;
357368
}
358369

359-
dehydrate(): void { ListWrapper.fill(this.objs, null); }
370+
dehydrate(): void { ListWrapper.fill(this.objs, undefinedValue); }
360371

361372
getObjByKeyId(keyId: number, visibility: number): any {
362373
var p = this.protoStrategy;
363374

364375
for (var i = 0; i < p.keyIds.length; i++) {
365376
if (p.keyIds[i] === keyId && (p.visibilities[i] & visibility) > 0) {
366-
if (isBlank(this.objs[i])) {
377+
if (this.objs[i] === undefinedValue) {
367378
this.objs[i] = this.injector._new(p.bindings[i], p.visibilities[i]);
368379
}
369380

0 commit comments

Comments
 (0)