From 374d47ab6512fee01c9f87f2833f29b236ca0212 Mon Sep 17 00:00:00 2001 From: FelisCatus Date: Mon, 27 Nov 2017 00:43:38 -0800 Subject: [PATCH] Remove Object.create and promisifyAll. Fix #1297. --- .../src/module/chrome_api.coffee | 9 +++------ .../src/module/options.coffee | 9 ++++++--- .../src/module/storage.coffee | 11 +++++------ 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/omega-target-chromium-extension/src/module/chrome_api.coffee b/omega-target-chromium-extension/src/module/chrome_api.coffee index 9fe35f5d..68e819f2 100644 --- a/omega-target-chromium-extension/src/module/chrome_api.coffee +++ b/omega-target-chromium-extension/src/module/chrome_api.coffee @@ -1,9 +1,9 @@ OmegaTarget = require('omega-target') Promise = OmegaTarget.Promise -chromeApiPromisifer = (originalMethod) -> +exports.chromeApiPromisify = (target, method) -> return (args...) -> - new Promise (resolve, reject) => + new Promise (resolve, reject) -> callback = (callbackArgs...) -> if chrome.runtime.lastError? error = new Error(chrome.runtime.lastError.message) @@ -15,7 +15,4 @@ chromeApiPromisifer = (originalMethod) -> resolve(callbackArgs) args.push(callback) - originalMethod.apply(this, args) - -module.exports = (obj) -> - Promise.promisifyAll(Object.create(obj), {promisifier: chromeApiPromisifer}) + target[method].apply(target, args) diff --git a/omega-target-chromium-extension/src/module/options.coffee b/omega-target-chromium-extension/src/module/options.coffee index 23d652e7..ba3dd4d7 100644 --- a/omega-target-chromium-extension/src/module/options.coffee +++ b/omega-target-chromium-extension/src/module/options.coffee @@ -2,9 +2,12 @@ OcontextMenu_inspectElementmegaTarget = require('omega-target') OmegaPac = OmegaTarget.OmegaPac Promise = OmegaTarget.Promise querystring = require('querystring') -chromeApiPromisifyAll = require('./chrome_api') +chromeApiPromisify = require('./chrome_api').chromeApiPromisify if chrome?.proxy?.settings - proxySettings = chromeApiPromisifyAll(chrome.proxy.settings) + proxySettings = + clearAsync: chromeApiPromisify(chrome.proxy.settings, 'clear') + setAsync: chromeApiPromisify(chrome.proxy.settings, 'set') + get: chrome.proxy.settings.get.bind(chrome.proxy.settings) else proxySettings = setAsync: -> Promise.resolve() @@ -139,7 +142,7 @@ class ChromeOptions extends OmegaTarget.Options meta ?= profile if profile.profileType == 'SystemProfile' # Clear proxy settings, returning proxy control to Chromium. - return proxySettings.clearAsync({}).then => + return chromeApiPromisify(chrome.proxy.settings, 'clear')({}).then => proxySettings.get {}, @_proxyChangeListener return config = {} diff --git a/omega-target-chromium-extension/src/module/storage.coffee b/omega-target-chromium-extension/src/module/storage.coffee index 08384912..381e415c 100644 --- a/omega-target-chromium-extension/src/module/storage.coffee +++ b/omega-target-chromium-extension/src/module/storage.coffee @@ -1,4 +1,4 @@ -chromeApiPromisifyAll = require('./chrome_api') +chromeApiPromisify = require('./chrome_api').chromeApiPromisify OmegaTarget = require('omega-target') Promise = OmegaTarget.Promise @@ -39,12 +39,11 @@ class ChromeStorage extends OmegaTarget.Storage if browser?.storage?[@areaName] @storage = browser.storage[@areaName] else - wrapper = chromeApiPromisifyAll(chrome.storage[@areaName]) @storage = - get: wrapper.getAsync.bind(wrapper), - set: wrapper.setAsync.bind(wrapper), - remove: wrapper.removeAsync.bind(wrapper), - clear: wrapper.clearAsync.bind(wrapper), + get: chromeApiPromisify(chrome.storage[@areaName], 'get') + set: chromeApiPromisify(chrome.storage[@areaName], 'set') + remove: chromeApiPromisify(chrome.storage[@areaName], 'remove') + clear: chromeApiPromisify(chrome.storage[@areaName], 'clear') get: (keys) -> keys ?= null