Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix console.log(globalThis) crash #3175 #3267

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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
7 changes: 7 additions & 0 deletions src/workerd/api/tests/global-scope-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import {
deepStrictEqual,
strictEqual,
throws,
doesNotThrow,
notStrictEqual,
ok,
} from 'node:assert';

import { AsyncLocalStorage } from 'node:async_hooks';
import util from 'node:util';

export const navigatorUserAgent = {
async test() {
Expand Down Expand Up @@ -744,3 +746,8 @@ export const toStringTag = {
strictEqual(new Headers()[internalFlag], internalFlag);
},
};
export const validateGlobalThis = {
test() {
util.inspect(globalThis);
},
};
Loading