rse / aggregation

Aggregation of Base Class and Mixin Classes
59 stars 8 forks source link

Symbol props not supported #7

Open dkebler opened 4 years ago

dkebler commented 4 years ago

I am using the nodejs event emitter as a mixin and the in the latest version of nodejs 12.16 they haved added a Symbol property which breaks aggregation.

https://github.com/nodejs/node/pull/31788

if I add add a console.log(prop) to the forEach loop the output is below. You can see it throws an error when encountering a Symbol which is does have a match method because it is not a string.

I have no idea if these this new Symbol must be mixed in order for the Emitter class to work correctly but if so I have no idea of how to the do that properly.

constructor
_events
_eventsCount
_maxListeners
setMaxListeners
getMaxListeners
emit
addListener
on
prependListener
once
prependOnceListener
removeListener
off
removeAllListeners
listeners
rawListeners
listenerCount
eventNames
Symbol(kCapture)
/mnt/AllData/hacking/active-dev-repos/uci/lib/uci-utils/sync/node_modules/aggregation/src/aggregation-es6.js:1
TypeError: prop.match is not a function
    at /mnt/AllData/hacking/active-dev-repos/uci/lib/uci-utils/sync/node_modules/aggregation/src/aggregation-es6.js:50:18
    at Array.forEach (<anonymous>)
    at copyProps (/mnt/AllData/hacking/active-dev-repos/uci/lib/uci-utils/sync/node_modules/aggregation/src/aggregation-es6.js:48:8)
    at /mnt/AllData/hacking/active-dev-repos/uci/lib/uci-utils/sync/node_modules/aggregation/src/aggregation-es6.js:58:5
    at Array.forEach (<anonymous>)
    at aggregation (/mnt/AllData/hacking/active-dev-repos/uci/lib/uci-utils/sync/node_modules/aggregation/src/aggregation-es6.js:57:10)
    at Object.<anonymous> (/mnt/AllData/hacking/active-dev-repos/uci/lib/uci-utils/sync/src/sync.js:19:20)
    at Generator.next (<anonymous>)
dkebler commented 4 years ago

just assuming one should pass all symbols through I did this.

  let copyProps = (target, source) => {
    Object.getOwnPropertyNames(source)
      .concat(Object.getOwnPropertySymbols(source))
      .forEach((prop) => {
        if (typeof prop.match ==='function') {
          if (prop.match(/^(?:initializer|constructor|prototype|arguments|caller|name|bind|call|apply|toString|length)$/))
            return
        }
        Object.defineProperty(target, prop, Object.getOwnPropertyDescriptor(source, prop))
      })
  }