Skip to content

Commit

Permalink
fix(navcontrollerbase): fixes crash when it is destroyed
Browse files Browse the repository at this point in the history
fixes #11338
  • Loading branch information
manucorporat committed Apr 24, 2017
1 parent 5311336 commit cc1eb02
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/navigation/nav-controller-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -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);
}
Expand Down
17 changes: 17 additions & 0 deletions src/navigation/test/nav-controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit cc1eb02

Please sign in to comment.