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.
Algorithm documented here: https://github.com/sandstorm-io/sandstorm/blob/master/src/sandstorm/powerbox.capnp#L115
Although this is Sandstorm-specific, I'm putting it into node-capnp for convenience: this needs to be implemented in C++, and it would be surprisingly difficult to create a second Node module that shares the Cap'n Proto library with capnp.node.
GetAlignedPoniterFromInternalField() can crash if the internal field is not a pointer, so we can't use this trick of checking if the field contains a pointer to the type's type_info.
The correct thing to do is use FunctionTemplate::HasInstance() to type-check the value. To do that, we of course have to have a reference to the FunctionTemplate already. To make this lookup fast, I used template-static-singletons.
This switches from the (apparently deprecated) WeakCallbackData-based SetWeak() to the newer WeakCallbackInfo-based one.
I have no fucking idea what the difference is, or what the WeakCallbackType enum is supposed to mean, or why it didn't work before. There is no documentation. There are various pages around the internet that make reference to this API but no comprehensive explanation anywhere as to the details. You're supposed to just know, or something.
This seems correct, and works around a bug in Sandstorm where a capability shared between multiple components is sometimes closed by one of them. This isn't the best way to fix the bug, but the real fix will require some refactoring.