rvagg/node-leveldown — pull request #48 by rvagg (2013-07-20 11:32:01+00:00)
Title: Initial 0.11 compatibility attempt, using new project: NAN

Node 0.11.4 introduced V8 3.20.2 which has a crazy amount of breaking API changes, maintaining compatibility across versions is a tricky prospect but I've been hacking away at a solution for cross-version compatibility for a little while now; I need it for a few native addon projects.

So say hello to **NAN** ( Native Abstractions for Node.js): https://github.com/rvagg/nan, which is really just a header file that can be included in a built and provide all the necessary abstractions to get 0.8, 0.10 and 0.11/0.12 compatibility without having to do any version sniffing yourself (in theory!).

This compiles and runs for me on Linux for 0.8. 0.10 and 0.11.4, I haven't tested any other platform and I worry about Windows... Previous versions of 0.11 won't work, there are incompatibilities that can't be tested because they haven't been incrementing `NODE_MODULE_VERSION`.

Note that if you get this running in 0.11 and run the LevelUP tests against this then you'll get a couple of failures:

* a `setTimeout` problem caused by [this](https://github.com/joyent/node/issues/5796) Node bug that's impacting [slow-stream](https://github.com/rvagg/node-slow-stream) but that's only for testing and that should be fixed in 0.11.5.
* an sparse `Array` problem caused by [this](https://code.google.com/p/v8/issues/detail?id=2790) V8 bug (found thanks to LevelUP + Node 0.11!) in the tests that make big blobs of data using the `Array.apply(null, Array(1024 * 100))` trick. Just reduce that `100` to a `90` and it'll run.

Would appreciate anyone who wants to have a play and look over the code. I'm happy to answer any questions anyone has on what I've done and even happier if anyone can find problems in what I've done.

Also relevant:
* [You're going to have to rewrite it anyway](http://atxconsulting.com/2013/07/06/rewrite-it-anyway/) by @tjfontaine
* [Node Google Group thread](https://groups.google.com/forum/#!msg/nodejs/VlUJ68n6QBg/fPsuArtR0roJ) on the same topic

i.e. there may be an "official" solution to this problem, but I don't have the patience to wait for it—it's not likely to appear until much later in the 0.11 cycle because it'd be no small job, and I had this in progress anyway so I just finished it off.