-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(IE10): Remove dependency on Object.setPrototypeOf (#3967)
This reimplements all Error types as ES5 classes, and types them with TypeScript such that we no longer need to rely on Object.setPrototypeOf, which was causing issues for users who had not polyfilled it properly in IE10. fixes #3966
- Loading branch information
Showing
6 changed files
with
129 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,24 @@ | ||
/** | ||
* An error thrown when duetime elapses. | ||
* | ||
* @see {@link timeout} | ||
* | ||
* @class TimeoutError | ||
*/ | ||
export class TimeoutError extends Error { | ||
|
||
public readonly name = 'TimeoutError'; | ||
|
||
constructor() { | ||
super('Timeout has occurred'); | ||
(Object as any).setPrototypeOf(this, TimeoutError.prototype); | ||
} | ||
} | ||
export interface TimeoutError extends Error { | ||
} | ||
|
||
export interface TimeoutErrorCtor { | ||
new(): TimeoutError; | ||
} | ||
|
||
function TimeoutErrorImpl(this: any) { | ||
Error.call(this); | ||
this.message = 'Timeout has occurred'; | ||
this.name = 'TimeoutError'; | ||
return this; | ||
} | ||
|
||
TimeoutErrorImpl.prototype = Object.create(Error.prototype); | ||
|
||
/** | ||
* An error thrown when duetime elapses. | ||
* | ||
* @see {@link timeout} | ||
* | ||
* @class TimeoutError | ||
*/ | ||
export const TimeoutError: TimeoutErrorCtor = TimeoutErrorImpl as any; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,25 @@ | ||
export interface UnsubscriptionError extends Error { | ||
readonly errors: any[]; | ||
} | ||
|
||
export interface UnsubscriptionErrorCtor { | ||
new(errors: any[]): UnsubscriptionError; | ||
} | ||
|
||
function UnsubscriptionErrorImpl(this: any, errors: any[]) { | ||
Error.call(this); | ||
this.message = errors ? | ||
`${errors.length} errors occurred during unsubscription: | ||
${errors.map((err, i) => `${i + 1}) ${err.toString()}`).join('\n ')}` : ''; | ||
this.name = 'UnsubscriptionError'; | ||
this.errors = errors; | ||
return this; | ||
} | ||
|
||
UnsubscriptionErrorImpl.prototype = Object.create(Error.prototype); | ||
|
||
/** | ||
* An error thrown when one or more errors have occurred during the | ||
* `unsubscribe` of a {@link Subscription}. | ||
*/ | ||
export class UnsubscriptionError extends Error { | ||
|
||
public readonly name = 'UnsubscriptionError'; | ||
|
||
constructor(public errors: any[]) { | ||
super(errors ? | ||
`${errors.length} errors occurred during unsubscription: | ||
${errors.map((err, i) => `${i + 1}) ${err.toString()}`).join('\n ')}` : ''); | ||
(Object as any).setPrototypeOf(this, UnsubscriptionError.prototype); | ||
} | ||
} | ||
export const UnsubscriptionError: UnsubscriptionErrorCtor = UnsubscriptionErrorImpl as any; |