Skip to content

Commit

Permalink
Remove Object.create and promisifyAll. Fix #1297.
Browse files Browse the repository at this point in the history
  • Loading branch information
FelisCatus committed Nov 27, 2017
1 parent 05e9f3a commit 374d47a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
9 changes: 3 additions & 6 deletions omega-target-chromium-extension/src/module/chrome_api.coffee
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)
9 changes: 6 additions & 3 deletions omega-target-chromium-extension/src/module/options.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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 = {}
Expand Down
11 changes: 5 additions & 6 deletions omega-target-chromium-extension/src/module/storage.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
chromeApiPromisifyAll = require('./chrome_api')
chromeApiPromisify = require('./chrome_api').chromeApiPromisify
OmegaTarget = require('omega-target')
Promise = OmegaTarget.Promise

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 374d47a

Please sign in to comment.