unionfs icon indicating copy to clipboard operation
unionfs copied to clipboard

Union methods are not bound

Open l1bbcsg opened this issue 7 years ago • 1 comments

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.

l1bbcsg avatar Feb 08 '19 13:02 l1bbcsg

Yes, they should be bound. It is my mistake, in recent PR review I let it slip through.

streamich avatar Feb 08 '19 13:02 streamich