Commit e1f1737a authored by Kenton Varda's avatar Kenton Varda

Fix build breakage when using a JsonCodec::Handler for a capability type.

Problem discovered and initial test case contributed by Harris Hancock.
parent 0675ae4e
......@@ -868,6 +868,13 @@ kj::Promise<kj::Maybe<typename T::Server&>> CapabilityServerSet<T>::getLocalServ
});
}
template <typename T>
struct Orphanage::GetInnerReader<T, Kind::INTERFACE> {
static inline kj::Own<ClientHook> apply(typename T::Client t) {
return ClientHook::from(kj::mv(t));
}
};
} // namespace capnp
#endif // CAPNP_CAPABILITY_H_
......@@ -669,6 +669,28 @@ KJ_TEST("register field handler") {
KJ_EXPECT(json.encode(root) == "{\"corge\":Frob(123,\"efg\"),\"baz\":\"abcd\"}");
}
class TestCapabilityHandler: public JsonCodec::Handler<test::TestInterface> {
public:
void encode(const JsonCodec& codec, test::TestInterface::Client input,
JsonValue::Builder output) const override {
KJ_UNIMPLEMENTED("TestCapabilityHandler::encode");
}
test::TestInterface::Client decode(
const JsonCodec& codec, JsonValue::Reader input) const override {
return nullptr;
}
};
KJ_TEST("register capability handler") {
// This test currently only checks that this compiles, which at one point wasn't the caes.
// TODO(test): Actually run some code here.
TestCapabilityHandler handler;
JsonCodec json;
json.addTypeHandler(handler);
}
} // namespace
} // namespace _ (private)
} // namespace capnp
......@@ -376,7 +376,7 @@ private:
}
Orphan<DynamicValue> decodeBase(const JsonCodec& codec, JsonValue::Reader input,
Orphanage orphanage) const override final {
return decode(codec, input);
return orphanage.newOrphanCopy(decode(codec, input));
}
friend class JsonCodec;
};
......
......@@ -2082,7 +2082,7 @@ Orphan<DynamicList> Orphan<DynamicValue>::releaseAs<DynamicList>() {
template <>
Orphan<DynamicValue> Orphanage::newOrphanCopy<DynamicValue::Reader>(
const DynamicValue::Reader& copyFrom) const {
DynamicValue::Reader copyFrom) const {
switch (copyFrom.getType()) {
case DynamicValue::UNKNOWN: return nullptr;
case DynamicValue::VOID: return copyFrom.voidValue;
......
......@@ -1048,28 +1048,28 @@ struct Orphanage::GetInnerBuilder<DynamicList, Kind::OTHER> {
template <>
inline Orphan<DynamicStruct> Orphanage::newOrphanCopy<DynamicStruct::Reader>(
const DynamicStruct::Reader& copyFrom) const {
DynamicStruct::Reader copyFrom) const {
return Orphan<DynamicStruct>(
copyFrom.getSchema(), _::OrphanBuilder::copy(arena, capTable, copyFrom.reader));
}
template <>
inline Orphan<DynamicList> Orphanage::newOrphanCopy<DynamicList::Reader>(
const DynamicList::Reader& copyFrom) const {
DynamicList::Reader copyFrom) const {
return Orphan<DynamicList>(copyFrom.getSchema(),
_::OrphanBuilder::copy(arena, capTable, copyFrom.reader));
}
template <>
inline Orphan<DynamicCapability> Orphanage::newOrphanCopy<DynamicCapability::Client>(
DynamicCapability::Client& copyFrom) const {
DynamicCapability::Client copyFrom) const {
return Orphan<DynamicCapability>(
copyFrom.getSchema(), _::OrphanBuilder::copy(arena, capTable, copyFrom.hook->addRef()));
}
template <>
Orphan<DynamicValue> Orphanage::newOrphanCopy<DynamicValue::Reader>(
const DynamicValue::Reader& copyFrom) const;
DynamicValue::Reader copyFrom) const;
namespace _ { // private
......@@ -1397,7 +1397,7 @@ struct DynamicValue::Builder::AsImpl<T, Kind::LIST> {
template <typename T>
struct DynamicValue::Reader::AsImpl<T, Kind::INTERFACE> {
static typename T::Reader apply(const Reader& reader) {
static typename T::Client apply(const Reader& reader) {
return reader.as<DynamicCapability>().as<T>();
}
};
......
......@@ -136,9 +136,7 @@ public:
// to use this.
template <typename Reader>
Orphan<FromReader<Reader>> newOrphanCopy(const Reader& copyFrom) const;
template <typename Reader>
Orphan<FromReader<Reader>> newOrphanCopy(Reader& copyFrom) const;
Orphan<FromReader<Reader>> newOrphanCopy(Reader copyFrom) const;
// Allocate a new orphaned object (struct, list, or blob) and initialize it as a copy of the
// given object.
......@@ -408,14 +406,10 @@ struct Orphanage::GetInnerReader<T, Kind::BLOB> {
};
template <typename Reader>
inline Orphan<FromReader<Reader>> Orphanage::newOrphanCopy(const Reader& copyFrom) const {
inline Orphan<FromReader<Reader>> Orphanage::newOrphanCopy(Reader copyFrom) const {
return Orphan<FromReader<Reader>>(_::OrphanBuilder::copy(
arena, capTable, GetInnerReader<FromReader<Reader>>::apply(copyFrom)));
}
template <typename Reader>
inline Orphan<FromReader<Reader>> Orphanage::newOrphanCopy(Reader& copyFrom) const {
return newOrphanCopy(kj::implicitCast<const Reader&>(copyFrom));
}
template <typename T>
inline Orphan<List<ListElementType<FromReader<T>>>>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment