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[]) {
|
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;
|
if (events !== undefined) doError = doError && events.error === undefined;
|
||||||
else if (!doError) return false;
|
else if (!doError) return false;
|
||||||
|
|
||||||
// If there is no 'error' event listener then throw.
|
// If there is no 'error' event listener then throw.
|
||||||
if (doError) {
|
if (doError) {
|
||||||
var er;
|
let er;
|
||||||
if (args.length > 0) er = args[0];
|
if (args.length > 0) er = args[0];
|
||||||
if (er instanceof Error) {
|
if (er instanceof Error) {
|
||||||
// Note: The comments on the `throw` lines are intentional, they show
|
// 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
|
throw er; // Unhandled 'error' event
|
||||||
}
|
}
|
||||||
// At least give some kind of context to the user
|
// 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;
|
(err as any).context = er;
|
||||||
throw err; // Unhandled 'error' event
|
throw err; // Unhandled 'error' event
|
||||||
}
|
}
|
||||||
|
|
||||||
var handler = events[type];
|
let handler = events[type];
|
||||||
|
|
||||||
if (handler === undefined) return false;
|
if (handler === undefined) return false;
|
||||||
|
|
||||||
if (typeof handler === 'function') {
|
if (typeof handler === 'function') {
|
||||||
try {
|
try {
|
||||||
Reflect.apply(handler, this, args);
|
Reflect.apply(handler, this, args);
|
||||||
|
@ -97,8 +95,7 @@ export default class Memory extends EventEmitter {
|
||||||
events[type] = undefined;
|
events[type] = undefined;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// var len = handler.length;
|
let listeners = [...handler];
|
||||||
var listeners = [...handler];
|
|
||||||
|
|
||||||
listeners
|
listeners
|
||||||
.filter((e) => {
|
.filter((e) => {
|
||||||
|
@ -118,7 +115,6 @@ export default class Memory extends EventEmitter {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user