Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/workerd/api/tests/js-rpc-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1731,3 +1731,19 @@ export let proxiedRpcTarget = {
}
},
};

// Test that we can construct a WorkerEntrypoint
export class MyEntrypoint extends WorkerEntrypoint {
rpcFunc() {
return 'hello from entrypoint';
}
}
function constructEntrypoint(cls, env) {
return new cls({ waitUntil: () => {} }, env);
}
export let testConstructEntrypoint = {
async test(controller, env, ctx) {
const constructed = constructEntrypoint(MyEntrypoint, env);
assert.strictEqual(await constructed.rpcFunc(), 'hello from entrypoint');
},
};
4 changes: 1 addition & 3 deletions src/workerd/api/worker-rpc.c++
Original file line number Diff line number Diff line change
Expand Up @@ -1967,9 +1967,7 @@ kj::Promise<WorkerInterface::CustomEvent::Result> JsRpcSessionCustomEventImpl::s
// =======================================================================================

jsg::Ref<WorkerEntrypoint> WorkerEntrypoint::constructor(
const v8::FunctionCallbackInfo<v8::Value>& args,
jsg::Ref<ExecutionContext> ctx,
jsg::JsObject env) {
const v8::FunctionCallbackInfo<v8::Value>& args, jsg::JsObject ctx, jsg::JsObject env) {
// HACK: We take `FunctionCallbackInfo` mostly so that we can set properties directly on
// `This()`. There ought to be a better way to get access to `this` in a constructor.
// We *also* declare `ctx` and `env` params more explicitly just for the sake of type checking.
Expand Down
5 changes: 2 additions & 3 deletions src/workerd/api/worker-rpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -492,9 +492,8 @@ class JsRpcSessionCustomEventImpl final: public WorkerInterface::CustomEvent {
// define a constructor.
class WorkerEntrypoint: public jsg::Object {
public:
static jsg::Ref<WorkerEntrypoint> constructor(const v8::FunctionCallbackInfo<v8::Value>& args,
jsg::Ref<ExecutionContext> ctx,
jsg::JsObject env);
static jsg::Ref<WorkerEntrypoint> constructor(
const v8::FunctionCallbackInfo<v8::Value>& args, jsg::JsObject ctx, jsg::JsObject env);

JSG_RESOURCE_TYPE(WorkerEntrypoint) {}
};
Expand Down
Loading