Skip to content

Commit 35daaf7

Browse files
authored
fix: resolve run-time errors when using deprecated sync error handling (#6272)
Fixes a should-be-obvious issue where we were making sure `dest` was `undefined`, then trying to set a property on it. fixes #6271
1 parent 7be67fa commit 35daaf7

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

spec/Observable-spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,17 @@ describe('Observable', () => {
799799
expect(results).to.deep.equal([1, 2]);
800800
});
801801

802+
// https://github.com/ReactiveX/rxjs/issues/6271
803+
it('should not have a run-time error if no errors are thrown and there are operators', () => {
804+
expect(() => {
805+
of(1, 2, 3).pipe(
806+
map(x => x + x),
807+
map(x => Math.log(x))
808+
)
809+
.subscribe();
810+
}).not.to.throw();
811+
});
812+
802813
afterEach(() => {
803814
config.useDeprecatedSynchronousErrorHandling = false;
804815
});

src/internal/Observable.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@ export class Observable<T> implements Subscribable<T> {
241241
* REMOVE THIS ENTIRE METHOD IN VERSION 8.
242242
*/
243243
private _deprecatedSyncErrorSubscribe(subscriber: Subscriber<unknown>) {
244-
let dest: any = subscriber;
245-
dest._syncErrorHack_isSubscribing = true;
244+
const localSubscriber: any = subscriber;
245+
localSubscriber._syncErrorHack_isSubscribing = true;
246246
const { operator } = this;
247247
if (operator) {
248248
// We don't need to try/catch on operators, as they
@@ -253,7 +253,7 @@ export class Observable<T> implements Subscribable<T> {
253253
try {
254254
this._subscribe(subscriber);
255255
} catch (err) {
256-
dest.__syncError = err;
256+
localSubscriber.__syncError = err;
257257
}
258258
}
259259

@@ -262,6 +262,7 @@ export class Observable<T> implements Subscribable<T> {
262262
// look to see if there's any synchronously thrown errors.
263263
// Does this suck for perf? Yes. So stop using the deprecated sync
264264
// error handling already. We're removing this in v8.
265+
let dest = localSubscriber;
265266
while (dest) {
266267
// Technically, someone could throw something falsy, like 0, or "",
267268
// so we need to check to see if anything was thrown, and we know
@@ -275,7 +276,8 @@ export class Observable<T> implements Subscribable<T> {
275276
}
276277
dest = dest.destination;
277278
}
278-
dest._syncErrorHack_isSubscribing = false;
279+
280+
localSubscriber._syncErrorHack_isSubscribing = false;
279281
}
280282

281283
/** @internal */

0 commit comments

Comments
 (0)