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,38 +1,7 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { op_lazy_load_esm } from "ext:core/ops";
import { core } from "ext:core/mod.js";
let webgpu;
const loadWebGPU = core.createLazyLoader("ext:deno_webgpu/01_webgpu.js");
function webGPUNonEnumerable(getter) {
let valueIsSet = false;
let value;
return {
get() {
loadWebGPU();
if (valueIsSet) {
return value;
} else {
return getter();
}
},
set(v) {
loadWebGPU();
valueIsSet = true;
value = v;
},
enumerable: false,
configurable: true,
};
}
function loadWebGPU() {
if (!webgpu) {
webgpu = op_lazy_load_esm("ext:deno_webgpu/01_webgpu.js");
}
}
export { loadWebGPU, webgpu, webGPUNonEnumerable };
export { loadWebGPU };

View File

@ -22,7 +22,7 @@ const {
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { createFilteredInspectProxy } from "ext:deno_console/01_console.js";
import { loadWebGPU, webgpu } from "ext:deno_webgpu/00_init.js";
import { loadWebGPU } from "ext:deno_webgpu/00_init.js";
const _surfaceRid = Symbol("[[surfaceRid]]");
const _configuration = Symbol("[[configuration]]");
@ -55,7 +55,7 @@ class GPUCanvasContext {
context: "Argument 1",
});
const { _device, assertDevice } = webgpu;
const { _device, assertDevice } = loadWebGPU();
this[_device] = configuration.device[_device];
this[_configuration] = configuration;
const device = assertDevice(this, {
@ -78,7 +78,7 @@ class GPUCanvasContext {
}
unconfigure() {
const { _device } = webgpu;
const { _device } = loadWebGPU();
webidl.assertBranded(this, GPUCanvasContextPrototype);
@ -94,7 +94,7 @@ class GPUCanvasContext {
if (this[_configuration] === null) {
throw new DOMException("context is not configured.", "InvalidStateError");
}
const { createGPUTexture, assertDevice } = webgpu;
const { createGPUTexture, assertDevice } = loadWebGPU();
const device = assertDevice(this, { prefix, context: "this" });
@ -130,7 +130,7 @@ class GPUCanvasContext {
// Required to present the texture; browser don't need this.
[_present]() {
const { assertDevice } = webgpu;
const { assertDevice } = loadWebGPU();
webidl.assertBranded(this, GPUCanvasContextPrototype);
const prefix = "Failed to execute 'present' on 'GPUCanvasContext'";
@ -160,8 +160,6 @@ const GPUCanvasContextPrototype = GPUCanvasContext.prototype;
function createCanvasContext(options) {
// lazy load webgpu if needed
loadWebGPU();
const canvasContext = webidl.createBranded(GPUCanvasContext);
canvasContext[_surfaceRid] = options.surfaceRid;
canvasContext[_canvas] = options.canvas;

View File

@ -2,10 +2,7 @@
import { primordials } from "ext:core/mod.js";
import { op_bootstrap_log_level } from "ext:core/ops";
const {
Promise,
SafeArrayIterator,
} = primordials;
const { SafeArrayIterator } = primordials;
// WARNING: Keep this in sync with Rust (search for LogLevel)
const LogLevel = {
@ -36,52 +33,4 @@ function log(...args) {
}
}
function createResolvable() {
let resolve;
let reject;
const promise = new Promise((res, rej) => {
resolve = res;
reject = rej;
});
promise.resolve = resolve;
promise.reject = reject;
return promise;
}
function writable(value) {
return {
value,
writable: true,
enumerable: true,
configurable: true,
};
}
function nonEnumerable(value) {
return {
value,
writable: true,
enumerable: false,
configurable: true,
};
}
function readOnly(value) {
return {
value,
enumerable: true,
writable: false,
configurable: true,
};
}
function getterOnly(getter) {
return {
get: getter,
set() {},
enumerable: true,
configurable: true,
};
}
export { createResolvable, getterOnly, log, nonEnumerable, readOnly, writable };
export { log };

View File

@ -1,9 +1,7 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { core } from "ext:core/mod.js";
import { op_lazy_load_esm } from "ext:core/ops";
import * as util from "ext:runtime/06_util.js";
import * as event from "ext:deno_web/02_event.js";
import * as timers from "ext:deno_web/02_timers.js";
import * as base64 from "ext:deno_web/05_base64.js";
@ -32,214 +30,166 @@ import * as messagePort from "ext:deno_web/13_message_port.js";
import * as webidl from "ext:deno_webidl/00_webidl.js";
import { DOMException } from "ext:deno_web/01_dom_exception.js";
import * as abortSignal from "ext:deno_web/03_abort_signal.js";
import { webgpu, webGPUNonEnumerable } from "ext:deno_webgpu/00_init.js";
import { loadWebGPU } from "ext:deno_webgpu/00_init.js";
import * as webgpuSurface from "ext:deno_webgpu/02_surface.js";
import { unstableIds } from "ext:runtime/90_deno_ns.js";
let image;
function ImageNonEnumerable(getter) {
let valueIsSet = false;
let value;
return {
get() {
loadImage();
if (valueIsSet) {
return value;
} else {
return getter();
}
},
set(v) {
loadImage();
valueIsSet = true;
value = v;
},
enumerable: false,
configurable: true,
};
}
function ImageWritable(getter) {
let valueIsSet = false;
let value;
return {
get() {
loadImage();
if (valueIsSet) {
return value;
} else {
return getter();
}
},
set(v) {
loadImage();
valueIsSet = true;
value = v;
},
enumerable: true,
configurable: true,
};
}
function loadImage() {
if (!image) {
image = op_lazy_load_esm("ext:deno_canvas/01_image.js");
}
}
const loadImage = core.createLazyLoader("ext:deno_canvas/01_image.js");
// https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope
const windowOrWorkerGlobalScope = {
AbortController: util.nonEnumerable(abortSignal.AbortController),
AbortSignal: util.nonEnumerable(abortSignal.AbortSignal),
Blob: util.nonEnumerable(file.Blob),
ByteLengthQueuingStrategy: util.nonEnumerable(
AbortController: core.propNonEnumerable(abortSignal.AbortController),
AbortSignal: core.propNonEnumerable(abortSignal.AbortSignal),
Blob: core.propNonEnumerable(file.Blob),
ByteLengthQueuingStrategy: core.propNonEnumerable(
streams.ByteLengthQueuingStrategy,
),
CloseEvent: util.nonEnumerable(event.CloseEvent),
CompressionStream: util.nonEnumerable(compression.CompressionStream),
CountQueuingStrategy: util.nonEnumerable(
CloseEvent: core.propNonEnumerable(event.CloseEvent),
CompressionStream: core.propNonEnumerable(compression.CompressionStream),
CountQueuingStrategy: core.propNonEnumerable(
streams.CountQueuingStrategy,
),
CryptoKey: util.nonEnumerable(crypto.CryptoKey),
CustomEvent: util.nonEnumerable(event.CustomEvent),
DecompressionStream: util.nonEnumerable(compression.DecompressionStream),
DOMException: util.nonEnumerable(DOMException),
ErrorEvent: util.nonEnumerable(event.ErrorEvent),
Event: util.nonEnumerable(event.Event),
EventTarget: util.nonEnumerable(event.EventTarget),
File: util.nonEnumerable(file.File),
FileReader: util.nonEnumerable(fileReader.FileReader),
FormData: util.nonEnumerable(formData.FormData),
Headers: util.nonEnumerable(headers.Headers),
ImageData: ImageNonEnumerable(() => image.ImageData),
ImageBitmap: ImageNonEnumerable(() => image.ImageBitmap),
MessageEvent: util.nonEnumerable(event.MessageEvent),
Performance: util.nonEnumerable(performance.Performance),
PerformanceEntry: util.nonEnumerable(performance.PerformanceEntry),
PerformanceMark: util.nonEnumerable(performance.PerformanceMark),
PerformanceMeasure: util.nonEnumerable(performance.PerformanceMeasure),
PromiseRejectionEvent: util.nonEnumerable(event.PromiseRejectionEvent),
ProgressEvent: util.nonEnumerable(event.ProgressEvent),
ReadableStream: util.nonEnumerable(streams.ReadableStream),
ReadableStreamDefaultReader: util.nonEnumerable(
CryptoKey: core.propNonEnumerable(crypto.CryptoKey),
CustomEvent: core.propNonEnumerable(event.CustomEvent),
DecompressionStream: core.propNonEnumerable(compression.DecompressionStream),
DOMException: core.propNonEnumerable(DOMException),
ErrorEvent: core.propNonEnumerable(event.ErrorEvent),
Event: core.propNonEnumerable(event.Event),
EventTarget: core.propNonEnumerable(event.EventTarget),
File: core.propNonEnumerable(file.File),
FileReader: core.propNonEnumerable(fileReader.FileReader),
FormData: core.propNonEnumerable(formData.FormData),
Headers: core.propNonEnumerable(headers.Headers),
ImageData: core.propNonEnumerableLazyLoaded(
(image) => image.ImageData,
loadImage,
),
ImageBitmap: core.propNonEnumerableLazyLoaded(
(image) => image.ImageBitmap,
loadImage,
),
MessageEvent: core.propNonEnumerable(event.MessageEvent),
Performance: core.propNonEnumerable(performance.Performance),
PerformanceEntry: core.propNonEnumerable(performance.PerformanceEntry),
PerformanceMark: core.propNonEnumerable(performance.PerformanceMark),
PerformanceMeasure: core.propNonEnumerable(performance.PerformanceMeasure),
PromiseRejectionEvent: core.propNonEnumerable(event.PromiseRejectionEvent),
ProgressEvent: core.propNonEnumerable(event.ProgressEvent),
ReadableStream: core.propNonEnumerable(streams.ReadableStream),
ReadableStreamDefaultReader: core.propNonEnumerable(
streams.ReadableStreamDefaultReader,
),
Request: util.nonEnumerable(request.Request),
Response: util.nonEnumerable(response.Response),
TextDecoder: util.nonEnumerable(encoding.TextDecoder),
TextEncoder: util.nonEnumerable(encoding.TextEncoder),
TextDecoderStream: util.nonEnumerable(encoding.TextDecoderStream),
TextEncoderStream: util.nonEnumerable(encoding.TextEncoderStream),
TransformStream: util.nonEnumerable(streams.TransformStream),
URL: util.nonEnumerable(url.URL),
URLPattern: util.nonEnumerable(urlPattern.URLPattern),
URLSearchParams: util.nonEnumerable(url.URLSearchParams),
WebSocket: util.nonEnumerable(webSocket.WebSocket),
MessageChannel: util.nonEnumerable(messagePort.MessageChannel),
MessagePort: util.nonEnumerable(messagePort.MessagePort),
Worker: util.nonEnumerable(worker.Worker),
WritableStream: util.nonEnumerable(streams.WritableStream),
WritableStreamDefaultWriter: util.nonEnumerable(
Request: core.propNonEnumerable(request.Request),
Response: core.propNonEnumerable(response.Response),
TextDecoder: core.propNonEnumerable(encoding.TextDecoder),
TextEncoder: core.propNonEnumerable(encoding.TextEncoder),
TextDecoderStream: core.propNonEnumerable(encoding.TextDecoderStream),
TextEncoderStream: core.propNonEnumerable(encoding.TextEncoderStream),
TransformStream: core.propNonEnumerable(streams.TransformStream),
URL: core.propNonEnumerable(url.URL),
URLPattern: core.propNonEnumerable(urlPattern.URLPattern),
URLSearchParams: core.propNonEnumerable(url.URLSearchParams),
WebSocket: core.propNonEnumerable(webSocket.WebSocket),
MessageChannel: core.propNonEnumerable(messagePort.MessageChannel),
MessagePort: core.propNonEnumerable(messagePort.MessagePort),
Worker: core.propNonEnumerable(worker.Worker),
WritableStream: core.propNonEnumerable(streams.WritableStream),
WritableStreamDefaultWriter: core.propNonEnumerable(
streams.WritableStreamDefaultWriter,
),
WritableStreamDefaultController: util.nonEnumerable(
WritableStreamDefaultController: core.propNonEnumerable(
streams.WritableStreamDefaultController,
),
ReadableByteStreamController: util.nonEnumerable(
ReadableByteStreamController: core.propNonEnumerable(
streams.ReadableByteStreamController,
),
ReadableStreamBYOBReader: util.nonEnumerable(
ReadableStreamBYOBReader: core.propNonEnumerable(
streams.ReadableStreamBYOBReader,
),
ReadableStreamBYOBRequest: util.nonEnumerable(
ReadableStreamBYOBRequest: core.propNonEnumerable(
streams.ReadableStreamBYOBRequest,
),
ReadableStreamDefaultController: util.nonEnumerable(
ReadableStreamDefaultController: core.propNonEnumerable(
streams.ReadableStreamDefaultController,
),
TransformStreamDefaultController: util.nonEnumerable(
TransformStreamDefaultController: core.propNonEnumerable(
streams.TransformStreamDefaultController,
),
atob: util.writable(base64.atob),
btoa: util.writable(base64.btoa),
createImageBitmap: ImageWritable(() => image.createImageBitmap),
clearInterval: util.writable(timers.clearInterval),
clearTimeout: util.writable(timers.clearTimeout),
atob: core.propWritable(base64.atob),
btoa: core.propWritable(base64.btoa),
createImageBitmap: core.propWritableLazyLoaded(
(image) => image.createImageBitmap,
loadImage,
),
clearInterval: core.propWritable(timers.clearInterval),
clearTimeout: core.propWritable(timers.clearTimeout),
caches: {
enumerable: true,
configurable: true,
get: caches.cacheStorage,
},
CacheStorage: util.nonEnumerable(caches.CacheStorage),
Cache: util.nonEnumerable(caches.Cache),
console: util.nonEnumerable(
CacheStorage: core.propNonEnumerable(caches.CacheStorage),
Cache: core.propNonEnumerable(caches.Cache),
console: core.propNonEnumerable(
new console.Console((msg, level) => core.print(msg, level > 1)),
),
crypto: util.readOnly(crypto.crypto),
Crypto: util.nonEnumerable(crypto.Crypto),
SubtleCrypto: util.nonEnumerable(crypto.SubtleCrypto),
fetch: util.writable(fetch.fetch),
EventSource: util.writable(eventSource.EventSource),
performance: util.writable(performance.performance),
reportError: util.writable(event.reportError),
setInterval: util.writable(timers.setInterval),
setTimeout: util.writable(timers.setTimeout),
structuredClone: util.writable(messagePort.structuredClone),
crypto: core.propReadOnly(crypto.crypto),
Crypto: core.propNonEnumerable(crypto.Crypto),
SubtleCrypto: core.propNonEnumerable(crypto.SubtleCrypto),
fetch: core.propWritable(fetch.fetch),
EventSource: core.propWritable(eventSource.EventSource),
performance: core.propWritable(performance.performance),
reportError: core.propWritable(event.reportError),
setInterval: core.propWritable(timers.setInterval),
setTimeout: core.propWritable(timers.setTimeout),
structuredClone: core.propWritable(messagePort.structuredClone),
// Branding as a WebIDL object
[webidl.brand]: util.nonEnumerable(webidl.brand),
[webidl.brand]: core.propNonEnumerable(webidl.brand),
};
const unstableForWindowOrWorkerGlobalScope = {};
unstableForWindowOrWorkerGlobalScope[unstableIds.broadcastChannel] = {
BroadcastChannel: util.nonEnumerable(broadcastChannel.BroadcastChannel),
BroadcastChannel: core.propNonEnumerable(broadcastChannel.BroadcastChannel),
};
unstableForWindowOrWorkerGlobalScope[unstableIds.net] = {
WebSocketStream: util.nonEnumerable(webSocketStream.WebSocketStream),
WebSocketStream: core.propNonEnumerable(webSocketStream.WebSocketStream),
};
// deno-fmt-ignore
unstableForWindowOrWorkerGlobalScope[unstableIds.webgpu] = {
GPU: webGPUNonEnumerable(() => webgpu.GPU),
GPUAdapter: webGPUNonEnumerable(() => webgpu.GPUAdapter),
GPUAdapterInfo: webGPUNonEnumerable(() => webgpu.GPUAdapterInfo),
GPUSupportedLimits: webGPUNonEnumerable(() => webgpu.GPUSupportedLimits),
GPUSupportedFeatures: webGPUNonEnumerable(() => webgpu.GPUSupportedFeatures),
GPUDeviceLostInfo: webGPUNonEnumerable(() => webgpu.GPUDeviceLostInfo),
GPUDevice: webGPUNonEnumerable(() => webgpu.GPUDevice),
GPUQueue: webGPUNonEnumerable(() => webgpu.GPUQueue),
GPUBuffer: webGPUNonEnumerable(() => webgpu.GPUBuffer),
GPUBufferUsage: webGPUNonEnumerable(() => webgpu.GPUBufferUsage),
GPUMapMode: webGPUNonEnumerable(() => webgpu.GPUMapMode),
GPUTextureUsage: webGPUNonEnumerable(() => webgpu.GPUTextureUsage),
GPUTexture: webGPUNonEnumerable(() => webgpu.GPUTexture),
GPUTextureView: webGPUNonEnumerable(() => webgpu.GPUTextureView),
GPUSampler: webGPUNonEnumerable(() => webgpu.GPUSampler),
GPUBindGroupLayout: webGPUNonEnumerable(() => webgpu.GPUBindGroupLayout),
GPUPipelineLayout: webGPUNonEnumerable(() => webgpu.GPUPipelineLayout),
GPUBindGroup: webGPUNonEnumerable(() => webgpu.GPUBindGroup),
GPUShaderModule: webGPUNonEnumerable(() => webgpu.GPUShaderModule),
GPUShaderStage: webGPUNonEnumerable(() => webgpu.GPUShaderStage),
GPUComputePipeline: webGPUNonEnumerable(() => webgpu.GPUComputePipeline),
GPURenderPipeline: webGPUNonEnumerable(() => webgpu.GPURenderPipeline),
GPUColorWrite: webGPUNonEnumerable(() => webgpu.GPUColorWrite),
GPUCommandEncoder: webGPUNonEnumerable(() => webgpu.GPUCommandEncoder),
GPURenderPassEncoder: webGPUNonEnumerable(() => webgpu.GPURenderPassEncoder),
GPUComputePassEncoder: webGPUNonEnumerable(() =>
webgpu.GPUComputePassEncoder
),
GPUCommandBuffer: webGPUNonEnumerable(() => webgpu.GPUCommandBuffer),
GPURenderBundleEncoder: webGPUNonEnumerable(() =>
webgpu.GPURenderBundleEncoder
),
GPURenderBundle: webGPUNonEnumerable(() => webgpu.GPURenderBundle),
GPUQuerySet: webGPUNonEnumerable(() => webgpu.GPUQuerySet),
GPUError: webGPUNonEnumerable(() => webgpu.GPUError),
GPUValidationError: webGPUNonEnumerable(() => webgpu.GPUValidationError),
GPUOutOfMemoryError: webGPUNonEnumerable(() => webgpu.GPUOutOfMemoryError),
GPUCanvasContext: webGPUNonEnumerable(() => webgpuSurface.GPUCanvasContext),
GPU: core.propNonEnumerableLazyLoaded((webgpu) => webgpu.GPU, loadWebGPU),
GPUAdapter: core.propNonEnumerableLazyLoaded((webgpu) => webgpu.GPUAdapter, loadWebGPU),
GPUAdapterInfo: core.propNonEnumerableLazyLoaded((webgpu) => webgpu.GPUAdapterInfo, loadWebGPU),
GPUSupportedLimits: core.propNonEnumerableLazyLoaded((webgpu) => webgpu.GPUSupportedLimits, loadWebGPU),
GPUSupportedFeatures: core.propNonEnumerableLazyLoaded((webgpu) => webgpu.GPUSupportedFeatures, loadWebGPU),
GPUDeviceLostInfo: core.propNonEnumerableLazyLoaded((webgpu) => webgpu.GPUDeviceLostInfo, loadWebGPU),
GPUDevice: core.propNonEnumerableLazyLoaded((webgpu) => webgpu.GPUDevice, loadWebGPU),
GPUQueue: core.propNonEnumerableLazyLoaded((webgpu) => webgpu.GPUQueue, loadWebGPU),
GPUBuffer: core.propNonEnumerableLazyLoaded((webgpu) => webgpu.GPUBuffer, loadWebGPU),
GPUBufferUsage: core.propNonEnumerableLazyLoaded((webgpu) => webgpu.GPUBufferUsage, loadWebGPU),
GPUMapMode: core.propNonEnumerableLazyLoaded((webgpu) => webgpu.GPUMapMode, loadWebGPU),
GPUTextureUsage: core.propNonEnumerableLazyLoaded((webgpu) => webgpu.GPUTextureUsage, loadWebGPU),
GPUTexture: core.propNonEnumerableLazyLoaded((webgpu) => webgpu.GPUTexture, loadWebGPU),
GPUTextureView: core.propNonEnumerableLazyLoaded((webgpu) => webgpu.GPUTextureView, loadWebGPU),
GPUSampler: core.propNonEnumerableLazyLoaded((webgpu) => webgpu.GPUSampler, loadWebGPU),
GPUBindGroupLayout: core.propNonEnumerableLazyLoaded((webgpu) => webgpu.GPUBindGroupLayout, loadWebGPU),
GPUPipelineLayout: core.propNonEnumerableLazyLoaded((webgpu) => webgpu.GPUPipelineLayout, loadWebGPU),
GPUBindGroup: core.propNonEnumerableLazyLoaded((webgpu) => webgpu.GPUBindGroup, loadWebGPU),
GPUShaderModule: core.propNonEnumerableLazyLoaded((webgpu) => webgpu.GPUShaderModule, loadWebGPU),
GPUShaderStage: core.propNonEnumerableLazyLoaded((webgpu) => webgpu.GPUShaderStage, loadWebGPU),
GPUComputePipeline: core.propNonEnumerableLazyLoaded((webgpu) => webgpu.GPUComputePipeline, loadWebGPU),
GPURenderPipeline: core.propNonEnumerableLazyLoaded((webgpu) => webgpu.GPURenderPipeline, loadWebGPU),
GPUColorWrite: core.propNonEnumerableLazyLoaded((webgpu) => webgpu.GPUColorWrite, loadWebGPU),
GPUCommandEncoder: core.propNonEnumerableLazyLoaded((webgpu) => webgpu.GPUCommandEncoder, loadWebGPU),
GPURenderPassEncoder: core.propNonEnumerableLazyLoaded((webgpu) => webgpu.GPURenderPassEncoder, loadWebGPU),
GPUComputePassEncoder: core.propNonEnumerableLazyLoaded((webgpu) => webgpu.GPUComputePassEncoder, loadWebGPU),
GPUCommandBuffer: core.propNonEnumerableLazyLoaded((webgpu) => webgpu.GPUCommandBuffer, loadWebGPU),
GPURenderBundleEncoder: core.propNonEnumerableLazyLoaded((webgpu) => webgpu.GPURenderBundleEncoder, loadWebGPU),
GPURenderBundle: core.propNonEnumerableLazyLoaded((webgpu) => webgpu.GPURenderBundle, loadWebGPU),
GPUQuerySet: core.propNonEnumerableLazyLoaded((webgpu) => webgpu.GPUQuerySet, loadWebGPU),
GPUError: core.propNonEnumerableLazyLoaded((webgpu) => webgpu.GPUError, loadWebGPU),
GPUValidationError: core.propNonEnumerableLazyLoaded((webgpu) => webgpu.GPUValidationError, loadWebGPU),
GPUOutOfMemoryError: core.propNonEnumerableLazyLoaded((webgpu) => webgpu.GPUOutOfMemoryError, loadWebGPU),
GPUCanvasContext: core.propNonEnumerable(webgpuSurface.GPUCanvasContext),
};
export { unstableForWindowOrWorkerGlobalScope, windowOrWorkerGlobalScope };

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 };

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,12 +12,11 @@ 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 { loadWebGPU, webgpu } from "ext:deno_webgpu/00_init.js";
import { loadWebGPU } from "ext:deno_webgpu/00_init.js";
function memoizeLazy(f) {
let v_ = null;
@ -63,7 +62,7 @@ ObjectDefineProperties(WorkerNavigator.prototype, {
enumerable: true,
get() {
webidl.assertBranded(this, WorkerNavigatorPrototype);
loadWebGPU();
const webgpu = loadWebGPU();
return webgpu.gpu;
},
},
@ -108,9 +107,9 @@ const workerRuntimeGlobalProperties = {
WorkerGlobalScope: globalInterfaces.workerGlobalScopeConstructorDescriptor,
DedicatedWorkerGlobalScope:
globalInterfaces.dedicatedWorkerGlobalScopeConstructorDescriptor,
WorkerNavigator: util.nonEnumerable(WorkerNavigator),
navigator: util.getterOnly(() => workerNavigator),
self: util.getterOnly(() => globalThis),
WorkerNavigator: core.propNonEnumerable(WorkerNavigator),
navigator: core.propGetterOnly(() => workerNavigator),
self: core.propGetterOnly(() => globalThis),
};
export { workerRuntimeGlobalProperties };

View File

@ -51,7 +51,6 @@ const {
const {
isNativeError,
} = core;
import * as util from "ext:runtime/06_util.js";
import * as event from "ext:deno_web/02_event.js";
import * as location from "ext:deno_web/12_location.js";
import * as version from "ext:runtime/01_version.ts";
@ -729,9 +728,9 @@ function bootstrapMainRuntime(runtimeOptions) {
// TODO(bartlomieju): in the future we might want to change the
// behavior of setting `name` to actually update the process name.
// Empty string matches what browsers do.
name: util.writable(""),
close: util.writable(windowClose),
closed: util.getterOnly(() => windowIsClosing),
name: core.propWritable(""),
close: core.propWritable(windowClose),
closed: core.propGetterOnly(() => windowIsClosing),
});
ObjectSetPrototypeOf(globalThis, Window.prototype);
@ -757,11 +756,11 @@ function bootstrapMainRuntime(runtimeOptions) {
);
ObjectDefineProperties(finalDenoNs, {
pid: util.getterOnly(opPid),
ppid: util.getterOnly(opPpid),
noColor: util.getterOnly(() => op_bootstrap_no_color()),
args: util.getterOnly(opArgs),
mainModule: util.getterOnly(() => op_main_module()),
pid: core.propGetterOnly(opPid),
ppid: core.propGetterOnly(opPpid),
noColor: core.propGetterOnly(() => op_bootstrap_no_color()),
args: core.propGetterOnly(opArgs),
mainModule: core.propGetterOnly(() => op_main_module()),
// TODO(kt3k): Remove this export at v2
// See https://github.com/denoland/deno/issues/9294
customInspect: {
@ -811,7 +810,7 @@ function bootstrapMainRuntime(runtimeOptions) {
// Setup `Deno` global - we're actually overriding already existing global
// `Deno` with `Deno` namespace from "./deno.ts".
ObjectDefineProperty(globalThis, "Deno", util.readOnly(finalDenoNs));
ObjectDefineProperty(globalThis, "Deno", core.propReadOnly(finalDenoNs));
if (nodeBootstrap) {
nodeBootstrap(hasNodeModulesDir, maybeBinaryNpmCommandName);
@ -859,16 +858,16 @@ function bootstrapWorkerRuntime(
});
ObjectDefineProperties(globalThis, workerRuntimeGlobalProperties);
ObjectDefineProperties(globalThis, {
name: util.writable(name),
name: core.propWritable(name),
// TODO(bartlomieju): should be readonly?
close: util.nonEnumerable(workerClose),
postMessage: util.writable(postMessage),
close: core.propNonEnumerable(workerClose),
postMessage: core.propWritable(postMessage),
});
if (enableTestingFeaturesFlag) {
ObjectDefineProperty(
globalThis,
"importScripts",
util.writable(importScripts),
core.propWritable(importScripts),
);
}
ObjectSetPrototypeOf(globalThis, DedicatedWorkerGlobalScope.prototype);
@ -918,9 +917,9 @@ function bootstrapWorkerRuntime(
}
ObjectDefineProperties(finalDenoNs, {
pid: util.getterOnly(opPid),
noColor: util.getterOnly(() => op_bootstrap_no_color()),
args: util.getterOnly(opArgs),
pid: core.propGetterOnly(opPid),
noColor: core.propGetterOnly(() => op_bootstrap_no_color()),
args: core.propGetterOnly(opArgs),
// TODO(kt3k): Remove this export at v2
// See https://github.com/denoland/deno/issues/9294
customInspect: {
@ -936,7 +935,7 @@ function bootstrapWorkerRuntime(
});
// Setup `Deno` global - we're actually overriding already
// existing global `Deno` with `Deno` namespace from "./deno.ts".
ObjectDefineProperty(globalThis, "Deno", util.readOnly(finalDenoNs));
ObjectDefineProperty(globalThis, "Deno", core.propReadOnly(finalDenoNs));
if (nodeBootstrap) {
nodeBootstrap(hasNodeModulesDir, maybeBinaryNpmCommandName);