christkv/node-mongodb-native — pull request #545 by tjanczuk (2012-03-15 20:47:53+00:00)
Title: Make callback type checks agnostic to V8 context boundaries

If a node.js application that uses MongoDB is executed with NODE_MODULE_CONTEXTS=1 environment variable (which causes each userland module to be loaded in its own V8 context), several checks for the type of the callback argument in MongoDB fail even though they should semantically pass.

For detailed description of the root cause see http://tomasz.janczuk.org/2012/03/when-javascript-function-is-not.html.

This fix addresses the issue by changing

```
callback instanceof Function
```

checks to

```
typeof callback === 'function'
```

checks.

Note that I have not verified whether similar issue exists in other locations where ```instanceof``` is used. In particular, one other suspectible use case is ```err instanceof Error``` which occurs a lot in the code base. The issue would only occur if the instance tested had been created in a different node.js module that the module performing the test.