1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

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. // 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) { export { loadWebGPU };
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 };

View file

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

View file

@ -2,10 +2,7 @@
import { primordials } from "ext:core/mod.js"; import { primordials } from "ext:core/mod.js";
import { op_bootstrap_log_level } from "ext:core/ops"; import { op_bootstrap_log_level } from "ext:core/ops";
const { const { SafeArrayIterator } = primordials;
Promise,
SafeArrayIterator,
} = primordials;
// WARNING: Keep this in sync with Rust (search for LogLevel) // WARNING: Keep this in sync with Rust (search for LogLevel)
const LogLevel = { const LogLevel = {
@ -36,52 +33,4 @@ function log(...args) {
} }
} }
function createResolvable() { export { log };
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 };

View file

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

View file

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

View file

@ -1,6 +1,6 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. // 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 { import {
op_bootstrap_language, op_bootstrap_language,
op_bootstrap_numcpus, op_bootstrap_numcpus,
@ -12,12 +12,11 @@ const {
SymbolFor, SymbolFor,
} = primordials; } = primordials;
import * as util from "ext:runtime/06_util.js";
import * as location from "ext:deno_web/12_location.js"; import * as location from "ext:deno_web/12_location.js";
import * as console from "ext:deno_console/01_console.js"; import * as console from "ext:deno_console/01_console.js";
import * as webidl from "ext:deno_webidl/00_webidl.js"; import * as webidl from "ext:deno_webidl/00_webidl.js";
import * as globalInterfaces from "ext:deno_web/04_global_interfaces.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) { function memoizeLazy(f) {
let v_ = null; let v_ = null;
@ -63,7 +62,7 @@ ObjectDefineProperties(WorkerNavigator.prototype, {
enumerable: true, enumerable: true,
get() { get() {
webidl.assertBranded(this, WorkerNavigatorPrototype); webidl.assertBranded(this, WorkerNavigatorPrototype);
loadWebGPU(); const webgpu = loadWebGPU();
return webgpu.gpu; return webgpu.gpu;
}, },
}, },
@ -108,9 +107,9 @@ const workerRuntimeGlobalProperties = {
WorkerGlobalScope: globalInterfaces.workerGlobalScopeConstructorDescriptor, WorkerGlobalScope: globalInterfaces.workerGlobalScopeConstructorDescriptor,
DedicatedWorkerGlobalScope: DedicatedWorkerGlobalScope:
globalInterfaces.dedicatedWorkerGlobalScopeConstructorDescriptor, globalInterfaces.dedicatedWorkerGlobalScopeConstructorDescriptor,
WorkerNavigator: util.nonEnumerable(WorkerNavigator), WorkerNavigator: core.propNonEnumerable(WorkerNavigator),
navigator: util.getterOnly(() => workerNavigator), navigator: core.propGetterOnly(() => workerNavigator),
self: util.getterOnly(() => globalThis), self: core.propGetterOnly(() => globalThis),
}; };
export { workerRuntimeGlobalProperties }; export { workerRuntimeGlobalProperties };

View file

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