refactor: use web utils and lazy load utils from core (#22289)

This commit is contained in:
Leo Kettmeir 2024-02-06 22:28:32 +01:00 committed by GitHub
parent c6def993e0
commit c8b2af8ed1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 164 additions and 301 deletions

View file

@ -1,6 +1,6 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { primordials } from "ext:core/mod.js";
import { core, primordials } from "ext:core/mod.js";
import {
op_bootstrap_language,
op_bootstrap_numcpus,
@ -12,14 +12,13 @@ const {
SymbolFor,
} = primordials;
import * as util from "ext:runtime/06_util.js";
import * as location from "ext:deno_web/12_location.js";
import * as console from "ext:deno_console/01_console.js";
import * as webidl from "ext:deno_webidl/00_webidl.js";
import * as globalInterfaces from "ext:deno_web/04_global_interfaces.js";
import * as webStorage from "ext:deno_webstorage/01_webstorage.js";
import * as prompt from "ext:runtime/41_prompt.js";
import { loadWebGPU, webgpu } from "ext:deno_webgpu/00_init.js";
import { loadWebGPU } from "ext:deno_webgpu/00_init.js";
class Navigator {
constructor() {
@ -65,7 +64,7 @@ ObjectDefineProperties(Navigator.prototype, {
enumerable: true,
get() {
webidl.assertBranded(this, NavigatorPrototype);
loadWebGPU();
const webgpu = loadWebGPU();
return webgpu.gpu;
},
},
@ -108,16 +107,16 @@ const mainRuntimeGlobalProperties = {
Location: location.locationConstructorDescriptor,
location: location.locationDescriptor,
Window: globalInterfaces.windowConstructorDescriptor,
window: util.getterOnly(() => globalThis),
self: util.getterOnly(() => globalThis),
Navigator: util.nonEnumerable(Navigator),
navigator: util.getterOnly(() => navigator),
alert: util.writable(prompt.alert),
confirm: util.writable(prompt.confirm),
prompt: util.writable(prompt.prompt),
localStorage: util.getterOnly(webStorage.localStorage),
sessionStorage: util.getterOnly(webStorage.sessionStorage),
Storage: util.nonEnumerable(webStorage.Storage),
window: core.propGetterOnly(() => globalThis),
self: core.propGetterOnly(() => globalThis),
Navigator: core.propNonEnumerable(Navigator),
navigator: core.propGetterOnly(() => navigator),
alert: core.propWritable(prompt.alert),
confirm: core.propWritable(prompt.confirm),
prompt: core.propWritable(prompt.prompt),
localStorage: core.propGetterOnly(webStorage.localStorage),
sessionStorage: core.propGetterOnly(webStorage.sessionStorage),
Storage: core.propNonEnumerable(webStorage.Storage),
};
export { mainRuntimeGlobalProperties, memoizeLazy };