Skip to content

Conversation

@tjanczuk
Copy link
Contributor

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.

@christkv christkv merged commit cbbd426 into mongodb:master Mar 16, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants