fix(navcontrollerbase): fixes crash when it is destroyed

fixes #11338
This commit is contained in:
Manu Mtz.-Almeida
2017-04-24 15:19:34 +02:00
parent 53113366e2
commit cc1eb02337
2 changed files with 29 additions and 0 deletions

View File

@@ -216,6 +216,10 @@ export class NavControllerBase extends Ion implements NavController {
}
_success(result: NavResult, ti: TransitionInstruction) {
if (this._queue === null) {
this._fireError('nav controller was destroyed', ti);
return;
}
this._init = true;
this._trnsId = null;
@@ -237,6 +241,10 @@ export class NavControllerBase extends Ion implements NavController {
}
_failed(rejectReason: any, ti: TransitionInstruction) {
if (this._queue === null) {
this._fireError('nav controller was destroyed', ti);
return;
}
this._trnsId = null;
this._queue.length = 0;
@@ -245,6 +253,10 @@ export class NavControllerBase extends Ion implements NavController {
this._swipeBackCheck();
this._nextTrns();
this._fireError(rejectReason, ti);
}
_fireError(rejectReason: any, ti: TransitionInstruction) {
if (ti.done) {
ti.done(false, false, rejectReason);
}

View File

@@ -1068,6 +1068,23 @@ describe('NavController', () => {
});
describe('destroy', () => {
it('should not crash when destroyed while transitioning', (done) => {
let view1 = mockView(MockView1);
nav.push(view1).then(() => {
fail('it should not succeed');
done();
}).catch((err: any) => {
expect(err).toEqual('nav controller was destroyed');
done();
});
nav.destroy();
}, 10000);
});
let nav: NavControllerBase;
let trnsDone: jasmine.Spy;