use duck typing for event listener

This commit is contained in:
siikamiika 2020-04-04 16:59:17 +03:00
parent 067c26982e
commit 123e725049

View File

@ -325,7 +325,13 @@ const yomichan = (() => {
reject = _reject; reject = _reject;
}); });
if (eventHandler === chrome.runtime.onMessage) { if (
typeof eventHandler.addListener === 'undefined' ||
typeof eventHandler.removeListener === 'undefined'
) {
throw new Error('Event handler type not supported');
}
const runtimeMessageCallback = ({action, params}, sender, sendResponse) => { const runtimeMessageCallback = ({action, params}, sender, sendResponse) => {
let timeoutId = null; let timeoutId = null;
if (timeout !== null) { if (timeout !== null) {
@ -350,9 +356,6 @@ const yomichan = (() => {
}; };
eventHandler.addListener(runtimeMessageCallback); eventHandler.addListener(runtimeMessageCallback);
} else {
throw new Error('Event handler type not supported');
}
return listenerPromise; return listenerPromise;
} }