From 3d63de2a836053904dcbcdd06e82bf13a8936014 Mon Sep 17 00:00:00 2001 From: OJ Kwon Date: Tue, 9 May 2017 13:22:16 -0700 Subject: [PATCH] fix(Subscriber): do not call complete with undefined value param (#2559) --- spec/Subscriber-spec.ts | 17 ++++++++++++++++- src/Subscriber.ts | 6 ++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/spec/Subscriber-spec.ts b/spec/Subscriber-spec.ts index bafe6cc6a6..02c4afbc2d 100644 --- a/spec/Subscriber-spec.ts +++ b/spec/Subscriber-spec.ts @@ -85,7 +85,7 @@ describe('Subscriber', () => { }); it('should not be closed when other subscriber with same observer instance completes', () => { - let observer = { + const observer = { next: function () { /*noop*/ } }; @@ -97,4 +97,19 @@ describe('Subscriber', () => { expect(sub1.closed).to.be.false; expect(sub2.closed).to.be.true; }); + + it('should call complete observer without any arguments', () => { + let argument: Array = null; + + const observer = { + complete: (...args: Array) => { + argument = args; + } + }; + + const sub1 = new Subscriber(observer); + sub1.complete(); + + expect(argument).to.have.lengthOf(0); + }); }); diff --git a/src/Subscriber.ts b/src/Subscriber.ts index bcbd38b458..36d8459191 100644 --- a/src/Subscriber.ts +++ b/src/Subscriber.ts @@ -234,11 +234,13 @@ class SafeSubscriber extends Subscriber { if (!this.isStopped) { const { _parentSubscriber } = this; if (this._complete) { + const wrappedComplete = () => this._complete.call(this._context); + if (!_parentSubscriber.syncErrorThrowable) { - this.__tryOrUnsub(this._complete); + this.__tryOrUnsub(wrappedComplete); this.unsubscribe(); } else { - this.__tryOrSetError(_parentSubscriber, this._complete); + this.__tryOrSetError(_parentSubscriber, wrappedComplete); this.unsubscribe(); } } else {