Per discussion in #62, this allows importing modules to use "normal"
imports, which is important for typescript since it doesn't understand
`capnp.importSystem()` and friends.
We could also merge in the type declarations themselves, but that isn't
strictly necessary, since typescript is built around being able to
supply your own stubs for other libraries. I may do something in that
vein in a follow-on pr, but I want to think a bit about how this
will all fit together.
This covers most of the API that is documented in the README, though I
see that there are some things exposed in `capnp.js` but not documented
-- the declaration file does not currently cover those.
This is designed to work with the output of:
https://github.com/zenhack/capnpc-node-typescript
...which is nearing completion.
I found this by running clang-analyzer. With the previous version of the
code, if `handler` is null, then we assign `self = nullptr` and then
immediately call a method on it.
I'm pretty sure this can't actually happen -- I don't think
`uv_timer_start` will ever pass nullptr to the callback -- but the logic
is obviously bogus so let's replace it with something defensive.
I just published this to the npm registry, we should probably update the
version in the git repo too.
It seems to work on node 12, though node 10 is still failing. I actually
*can* reproduce the failures locally if:
- I start a fresh npm project and do `npm install
`/path/to/node-canpnp/src`
- The working directory for `node-capnp` is clean.
I may try to troubleshoot this more later. Perhaps we should unpublish,
but having a version that works on node 12 is possibly an improvement,
so maybe not...
Npm insisted that 0.4.0 already existed and was refusing to re-publish
it (I assume there was a deleted failed attempt), so I had to bump the
version to get it to work.
I guess it never cauased a problem because the result was 1 which just happened to map to TAKE_OWNERSHIP and the other flags are safe to skip (just inefficient)...
- You can't just call SetWeak() on a handle and then let the handle go out-of-scope. You have to Reset() it when the weak callback is called. Honestly unsure why this doesn't crash.
- The weak handle should have MarkIndependent() called on it, otherwise v8 is less aggressive about GCing it.
- OwnHandle's move semantics were broken. They created a copy (which actually creates a new v8 persistent handle), but then zero'd the original (which means it would never be cleaned up by v8). V8 provides a nice `Global` type which has the semantics we always wanted, so use that.
After deploying this change, the frequency of production problems seems to have increased rather than decreased. I don't know if this change is the reason for the increase, but since it did not accomplish its sole goal of decreasing the problem rate, I'm reverting it.
This reverts commit 8497d70320.