From 7b46d25db222f89b131c6ffd9c38c84046347920 Mon Sep 17 00:00:00 2001 From: ExE Boss <3889017+ExE-Boss@users.noreply.github.com> Date: Mon, 27 Aug 2018 15:50:40 +0200 Subject: [PATCH] =?UTF-8?q?refactor:=20Make=20the=C2=A0`wrapAPIs`=20functi?= =?UTF-8?q?on=20take=20the=C2=A0`chrome`=20object=20as=C2=A0a=C2=A0paramet?= =?UTF-8?q?er=20(#139)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/browser-polyfill.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/browser-polyfill.js b/src/browser-polyfill.js index ff24f34..f4b6dec 100644 --- a/src/browser-polyfill.js +++ b/src/browser-polyfill.js @@ -15,7 +15,7 @@ if (typeof browser === "undefined" || Object.getPrototypeOf(browser) !== Object. // contents of a function until the first time it's called, and since it will // never actually need to be called, this allows the polyfill to be included // in Firefox nearly for free. - const wrapAPIs = () => { + const wrapAPIs = extensionAPIs => { // NOTE: apiMetadata is associated to the content of the api-metadata.json file // at build time by replacing the following "include" with the content of the // JSON file. @@ -90,8 +90,8 @@ if (typeof browser === "undefined" || Object.getPrototypeOf(browser) !== Object. */ const makeCallback = (promise, metadata) => { return (...callbackArgs) => { - if (chrome.runtime.lastError) { - promise.reject(chrome.runtime.lastError); + if (extensionAPIs.runtime.lastError) { + promise.reject(extensionAPIs.runtime.lastError); } else if (metadata.singleCallbackArg || callbackArgs.length <= 1) { promise.resolve(callbackArgs[0]); } else { @@ -441,14 +441,14 @@ if (typeof browser === "undefined" || Object.getPrototypeOf(browser) !== Object. }); const wrappedSendMessageCallback = ({reject, resolve}, reply) => { - if (chrome.runtime.lastError) { + if (extensionAPIs.runtime.lastError) { // Detect when none of the listeners replied to the sendMessage call and resolve // the promise to undefined as in Firefox. // See https://github.com/mozilla/webextension-polyfill/issues/130 - if (chrome.runtime.lastError.message === CHROME_SEND_MESSAGE_CALLBACK_NO_RESPONSE_MESSAGE) { + if (extensionAPIs.runtime.lastError.message === CHROME_SEND_MESSAGE_CALLBACK_NO_RESPONSE_MESSAGE) { resolve(); } else { - reject(chrome.runtime.lastError); + reject(extensionAPIs.runtime.lastError); } } else if (reply && reply.__mozWebExtensionPolyfillReject__) { // Convert back the JSON representation of the error into @@ -504,12 +504,12 @@ if (typeof browser === "undefined" || Object.getPrototypeOf(browser) !== Object. }, }; - return wrapObject(chrome, staticWrappers, apiMetadata); + return wrapObject(extensionAPIs, staticWrappers, apiMetadata); }; // The build process adds a UMD wrapper around this file, which makes the // `module` variable available. - module.exports = wrapAPIs(); // eslint-disable-line no-undef + module.exports = wrapAPIs(chrome); // eslint-disable-line no-undef } else { module.exports = browser; // eslint-disable-line no-undef }