unionfs
unionfs copied to clipboard
Union methods are not bound
Union methods frequently use this in their implementations. Calling them with a different context breaks them:
const fs = require('fs');
const ufs = new (require('unionfs').Union);
[].find(fs.existsSync); // undefined
[].find(ufs.existsSync); // TypeError: Cannot read property 'fss' of undefined
fs.existsSync.call(null, 'foo') // false
ufs.existsSync.call(null, 'foo') // TypeError: Cannot read property 'fss' of null
While this might be a questionable approach, this behaviour breaks unionfs compatibility with native fs. In my case this error originated from a different package in test environment where unionfs was mocking real fs.
Yes, they should be bound. It is my mistake, in recent PR review I let it slip through.