import upgradeFunction from 'upgrade-function'

export default function (obj, methods) {
  const ret = Object.create(Object.getPrototypeOf(obj))

  Object.getOwnPropertyNames(obj).forEach((propName) => {
    const propDesc = Object.getOwnPropertyDescriptor(obj, propName)

    if ('value' in propDesc) {
      if(typeof propDesc.value === 'function') {
        propDesc.value = propDesc.value.bind(obj)
      }
    } else if('get' in propDesc) {
      const originalGet = propDesc.get

      propDesc.get = function() {
        const val = originalGet.call(this)

        if (typeof val === 'function') {
          return val.bind(obj)
        }
        return val
      }
    }

    if (methods.indexOf(propName) !== -1) {
      if ('value' in propDesc) {
        if(typeof propDesc.value !== 'function') {
          throw new TypeError(`Property ${propName} is not a function`)
        }

        propDesc.value = upgradeFunction(propDesc.value)
      } else if('get' in propDesc) {
        const originalGet = propDesc.get

        propDesc.get = function() {
          const val = originalGet.call(this)

          if (typeof val !== 'function') {
            throw new TypeError(`Property ${propName} is not a function`)
          }
          return upgradeFunction(val)
        }
      }
    }
    Object.defineProperty(ret, propName, propDesc)
  })

  return ret
}

@@ -297,32 +297,33 @@
 Desc) %7B%0A      if
+ 
 (typeof propDesc
@@ -339,32 +339,32 @@
 = 'function') %7B%0A
-
         propDesc
@@ -410,32 +410,33 @@
  %7D%0A    %7D else if
+ 
 ('get' in propDe
@@ -502,32 +502,33 @@
 c.get = function
+ 
 () %7B%0A        con
@@ -763,16 +763,17 @@
       if
+ 
 (typeof 
@@ -960,16 +960,17 @@
  else if
+ 
 ('get' i
@@ -1021,24 +1021,24 @@
 opDesc.get%0A%0A
-
         prop
@@ -1056,16 +1056,17 @@
 function
+ 
 () %7B%0A   

Fix style errors