From 2b13bb694532904704c16bec4e8a47c386e681e2 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Fri, 30 Jul 2021 01:15:11 +0530 Subject: feat(runtime): implement navigator.hardwareConcurrency (#11448) This commit implements "navigator.hardwareConcurrency" API, which supersedes "Deno.systemCpuInfo()" API (which was removed in this commit). --- runtime/js/99_main.js | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'runtime/js/99_main.js') diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js index a48105559..16a444098 100644 --- a/runtime/js/99_main.js +++ b/runtime/js/99_main.js @@ -247,6 +247,8 @@ delete Object.prototype.__proto__; const navigator = webidl.createBranded(Navigator); + let numCpus; + ObjectDefineProperties(Navigator.prototype, { gpu: { configurable: true, @@ -256,6 +258,14 @@ delete Object.prototype.__proto__; return webgpu.gpu; }, }, + hardwareConcurrency: { + configurable: true, + enumerable: true, + get() { + webidl.assertBranded(this, Navigator); + return numCpus; + }, + }, }); class WorkerNavigator { @@ -279,6 +289,14 @@ delete Object.prototype.__proto__; return webgpu.gpu; }, }, + hardwareConcurrency: { + configurable: true, + enumerable: true, + get() { + webidl.assertBranded(this, Navigator); + return numCpus; + }, + }, }); // https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope @@ -491,12 +509,13 @@ delete Object.prototype.__proto__; pid, ppid, unstableFlag, + cpuCount, } = runtimeOptions; if (locationHref != null) { location.setLocationHref(locationHref); } - + numCpus = cpuCount; registerErrors(); const internalSymbol = Symbol("Deno.internal"); @@ -566,10 +585,17 @@ delete Object.prototype.__proto__; runtimeOptions, internalName ?? name, ); - const { unstableFlag, pid, noColor, args, location: locationHref } = - runtimeOptions; + const { + unstableFlag, + pid, + noColor, + args, + location: locationHref, + cpuCount, + } = runtimeOptions; location.setLocationHref(locationHref); + numCpus = cpuCount; registerErrors(); pollForMessages(); -- cgit v1.2.3