Skip to content

Commit

Permalink
Fixed issue
Browse files Browse the repository at this point in the history
  • Loading branch information
EngoDev committed Dec 24, 2024
1 parent 8620d14 commit 79c839b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions src/workerd/api/global-scope.c++
Original file line number Diff line number Diff line change
Expand Up @@ -884,16 +884,19 @@ double Performance::now() {
}

#ifdef WORKERD_EXPERIMENTAL_ENABLE_WEBGPU
jsg::Ref<api::gpu::GPU> Navigator::getGPU(CompatibilityFlags::Reader flags) {
jsg::Optional<jsg::Ref<api::gpu::GPU>> Navigator::getGPU(CompatibilityFlags::Reader flags) {
// is this a durable object?
KJ_IF_SOME(actor, IoContext::current().getActor()) {
JSG_REQUIRE(actor.getPersistent() != kj::none, TypeError,
"webgpu api is only available in Durable Objects (no storage)");
if (actor.getPersistent() == kj::none) {
return kj::none;
}
} else {
JSG_FAIL_REQUIRE(TypeError, "webgpu api is only available in Durable Objects");
return kj::none;
};

JSG_REQUIRE(flags.getWebgpu(), TypeError, "webgpu needs the webgpu compatibility flag set");
if (!flags.getWebgpu()) {
return kj::none;
}

return jsg::alloc<api::gpu::GPU>();
}
Expand Down
2 changes: 1 addition & 1 deletion src/workerd/api/global-scope.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class Navigator: public jsg::Object {
return "Cloudflare-Workers"_kj;
}
#ifdef WORKERD_EXPERIMENTAL_ENABLE_WEBGPU
jsg::Ref<api::gpu::GPU> getGPU(CompatibilityFlags::Reader flags);
jsg::Optional<jsg::Ref<api::gpu::GPU>> getGPU(CompatibilityFlags::Reader flags);
#endif

bool sendBeacon(jsg::Lock& js, kj::String url, jsg::Optional<Body::Initializer> body);
Expand Down

0 comments on commit 79c839b

Please sign in to comment.