Promise capabilities take ownership of the capability to which they resolve.

Make sure that the node-level capability is replaced with one that will throw an exception from calls, rather than segfault on null pointer.
This commit is contained in:
Kenton Varda committed 2016-06-20 14:28:00 -07:00
1 parent 27ef02fac9
commit 65edaa8a57
1 file changed
+9
+9
View File
@@ -2348,7 +2348,16 @@ v8::Handle<v8::Value> fulfillPromisedCap(const v8::Arguments& args) {
KJV8_UNWRAP(capnp::DynamicCapability::Client, cap, args[1]);
return liftKj([&]() -> v8::Handle<v8::Value> {
auto schema = cap.getSchema();
fulfiller->fulfill(kj::mv(cap));
// Avoid segfault if capability is called again.
cap = capnp::Capability::Client(
capnp::newBrokenCap(KJ_EXCEPTION(DISCONNECTED,
"Capability was used to resolve a promise capability and so has been closed.")))
.castAs<capnp::DynamicCapability>(schema);
return v8::Undefined();
});
}