Cleanup
This commit is contained in:
parent
28ac0201b9
commit
6faa078095
16
memory.ts
16
memory.ts
|
@ -65,15 +65,15 @@ export default class Memory extends EventEmitter {
|
|||
}
|
||||
|
||||
private originalEmit(type: string, ...args: unknown[]) {
|
||||
var doError = type === 'error';
|
||||
let doError = type === 'error';
|
||||
|
||||
var events = (this as any)._events;
|
||||
let events = (this as any)._events;
|
||||
if (events !== undefined) doError = doError && events.error === undefined;
|
||||
else if (!doError) return false;
|
||||
|
||||
// If there is no 'error' event listener then throw.
|
||||
if (doError) {
|
||||
var er;
|
||||
let er;
|
||||
if (args.length > 0) er = args[0];
|
||||
if (er instanceof Error) {
|
||||
// Note: The comments on the `throw` lines are intentional, they show
|
||||
|
@ -81,15 +81,13 @@ export default class Memory extends EventEmitter {
|
|||
throw er; // Unhandled 'error' event
|
||||
}
|
||||
// At least give some kind of context to the user
|
||||
var err = new Error('Unhandled error.' + (er ? ' (' + (er as any).message + ')' : ''));
|
||||
let err = new Error('Unhandled error.' + (er ? ' (' + (er as any).message + ')' : ''));
|
||||
(err as any).context = er;
|
||||
throw err; // Unhandled 'error' event
|
||||
}
|
||||
|
||||
var handler = events[type];
|
||||
|
||||
let handler = events[type];
|
||||
if (handler === undefined) return false;
|
||||
|
||||
if (typeof handler === 'function') {
|
||||
try {
|
||||
Reflect.apply(handler, this, args);
|
||||
|
@ -97,8 +95,7 @@ export default class Memory extends EventEmitter {
|
|||
events[type] = undefined;
|
||||
}
|
||||
} else {
|
||||
// var len = handler.length;
|
||||
var listeners = [...handler];
|
||||
let listeners = [...handler];
|
||||
|
||||
listeners
|
||||
.filter((e) => {
|
||||
|
@ -118,7 +115,6 @@ export default class Memory extends EventEmitter {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user