Skip to content

Commit c8019f4

Browse files
committed
Fix bug decoding channel token Frankenvalue.
Adds a test for this bug.
1 parent c9cff20 commit c8019f4

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

src/workerd/api/tests/stub-storage-test.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,43 @@ export let storeServiceBinding = {
6161
}
6262
},
6363
};
64+
65+
// Test that service stubs and actor classes can both be encoded into `props`, the stub with the
66+
// props can be sent over RPC, and it all still works.
67+
export class UsePropsTest extends WorkerEntrypoint {
68+
async run() {
69+
let id = this.ctx.exports.MyActor.idFromName('bar');
70+
let stub = this.ctx.exports.MyActor.get(id);
71+
72+
{
73+
await stub.put('foo', this.ctx.props.Greeter);
74+
let greeter = await stub.get('foo');
75+
assert.strictEqual(await greeter.greet('Alice'), 'Yo, Alice!');
76+
}
77+
78+
{
79+
await stub.put('bar', this.ctx.props.MyFacet);
80+
81+
assert.strictEqual(await stub.useFacet('bar'), 'Hiya, Bob?');
82+
}
83+
}
84+
}
85+
86+
export let bindingsInProps = {
87+
async test(controller, env, ctx) {
88+
let stub = ctx.exports.UsePropsTest({
89+
props: {
90+
Greeter: ctx.exports.Greeter({ props: { greeting: 'Yo' } }),
91+
MyFacet: ctx.exports.MyFacet({ props: { greeting: 'Hiya' } }),
92+
},
93+
});
94+
95+
// Send stub over RPC so the props get encoded into a channel token with nested channel
96+
// tokens.
97+
await ctx.exports.bindingsInProps.run(stub);
98+
},
99+
100+
async run(stub) {
101+
await stub.run();
102+
},
103+
};

src/workerd/server/channel-token.c++

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ kj::Own<Frankenvalue::CapTableEntry> ChannelTokenHandler::decodeChannelTokenImpl
249249
capTable.add(decodeSubrequestChannelToken(usage, cap.getSubrequestChannel()));
250250
continue;
251251
case ChannelToken::FrankenvalueCapTable::Cap::ACTOR_CLASS_CHANNEL:
252-
capTable.add(decodeSubrequestChannelToken(usage, cap.getActorClassChannel()));
252+
capTable.add(decodeActorClassChannelToken(usage, cap.getActorClassChannel()));
253253
continue;
254254
}
255255
KJ_FAIL_REQUIRE("unknown cap table type", cap.which());

0 commit comments

Comments
 (0)