2024-01-06 08:40:26 -05:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
|
|
|
2024-02-06 16:28:32 -05:00
|
|
|
import { core, primordials } from "ext:core/mod.js";
|
2024-01-29 16:02:26 -05:00
|
|
|
import {
|
2024-01-10 17:37:25 -05:00
|
|
|
op_bootstrap_language,
|
|
|
|
op_bootstrap_numcpus,
|
|
|
|
op_bootstrap_user_agent,
|
2024-01-29 16:02:26 -05:00
|
|
|
} from "ext:core/ops";
|
2024-01-06 08:40:26 -05:00
|
|
|
const {
|
|
|
|
ObjectDefineProperties,
|
|
|
|
SymbolFor,
|
|
|
|
} = primordials;
|
|
|
|
|
|
|
|
import * as location from "ext:deno_web/12_location.js";
|
2024-08-16 07:34:09 -04:00
|
|
|
import { privateInspect } from "ext:deno_console/01_console.js";
|
2024-01-06 08:40:26 -05:00
|
|
|
import * as webidl from "ext:deno_webidl/00_webidl.js";
|
|
|
|
import * as globalInterfaces from "ext:deno_web/04_global_interfaces.js";
|
2024-02-06 16:28:32 -05:00
|
|
|
import { loadWebGPU } from "ext:deno_webgpu/00_init.js";
|
2024-01-06 08:40:26 -05:00
|
|
|
|
|
|
|
function memoizeLazy(f) {
|
|
|
|
let v_ = null;
|
|
|
|
return () => {
|
|
|
|
if (v_ === null) {
|
|
|
|
v_ = f();
|
|
|
|
}
|
|
|
|
return v_;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-01-10 17:37:25 -05:00
|
|
|
const numCpus = memoizeLazy(() => op_bootstrap_numcpus());
|
|
|
|
const userAgent = memoizeLazy(() => op_bootstrap_user_agent());
|
|
|
|
const language = memoizeLazy(() => op_bootstrap_language());
|
2024-01-06 08:40:26 -05:00
|
|
|
|
|
|
|
class WorkerNavigator {
|
|
|
|
constructor() {
|
|
|
|
webidl.illegalConstructor();
|
|
|
|
}
|
|
|
|
|
|
|
|
[SymbolFor("Deno.privateCustomInspect")](inspect, inspectOptions) {
|
2024-08-16 07:34:09 -04:00
|
|
|
return privateInspect(
|
|
|
|
this,
|
|
|
|
["hardwareConcurrency", "userAgent", "language", "languages"],
|
|
|
|
inspect,
|
2024-01-06 08:40:26 -05:00
|
|
|
inspectOptions,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const workerNavigator = webidl.createBranded(WorkerNavigator);
|
|
|
|
|
|
|
|
ObjectDefineProperties(WorkerNavigator.prototype, {
|
|
|
|
gpu: {
|
|
|
|
configurable: true,
|
|
|
|
enumerable: true,
|
|
|
|
get() {
|
|
|
|
webidl.assertBranded(this, WorkerNavigatorPrototype);
|
2024-02-06 16:28:32 -05:00
|
|
|
const webgpu = loadWebGPU();
|
2024-01-06 08:40:26 -05:00
|
|
|
return webgpu.gpu;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
hardwareConcurrency: {
|
|
|
|
configurable: true,
|
|
|
|
enumerable: true,
|
|
|
|
get() {
|
|
|
|
webidl.assertBranded(this, WorkerNavigatorPrototype);
|
|
|
|
return numCpus();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
userAgent: {
|
|
|
|
configurable: true,
|
|
|
|
enumerable: true,
|
|
|
|
get() {
|
|
|
|
webidl.assertBranded(this, WorkerNavigatorPrototype);
|
|
|
|
return userAgent();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
language: {
|
|
|
|
configurable: true,
|
|
|
|
enumerable: true,
|
|
|
|
get() {
|
|
|
|
webidl.assertBranded(this, WorkerNavigatorPrototype);
|
|
|
|
return language();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
languages: {
|
|
|
|
configurable: true,
|
|
|
|
enumerable: true,
|
|
|
|
get() {
|
|
|
|
webidl.assertBranded(this, WorkerNavigatorPrototype);
|
|
|
|
return [language()];
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
const WorkerNavigatorPrototype = WorkerNavigator.prototype;
|
|
|
|
|
|
|
|
const workerRuntimeGlobalProperties = {
|
|
|
|
WorkerLocation: location.workerLocationConstructorDescriptor,
|
|
|
|
location: location.workerLocationDescriptor,
|
|
|
|
WorkerGlobalScope: globalInterfaces.workerGlobalScopeConstructorDescriptor,
|
|
|
|
DedicatedWorkerGlobalScope:
|
|
|
|
globalInterfaces.dedicatedWorkerGlobalScopeConstructorDescriptor,
|
2024-02-06 16:28:32 -05:00
|
|
|
WorkerNavigator: core.propNonEnumerable(WorkerNavigator),
|
|
|
|
navigator: core.propGetterOnly(() => workerNavigator),
|
|
|
|
self: core.propGetterOnly(() => globalThis),
|
2024-01-06 08:40:26 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
export { workerRuntimeGlobalProperties };
|