diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2021-07-30 01:15:11 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-29 21:45:11 +0200 |
commit | 2b13bb694532904704c16bec4e8a47c386e681e2 (patch) | |
tree | 0021131ce86873a5aa965d79b99185b3ca5c5aff /runtime/js | |
parent | eece46f0d85faa90c97841a4f409be39272e809b (diff) |
feat(runtime): implement navigator.hardwareConcurrency (#11448)
This commit implements "navigator.hardwareConcurrency" API, which
supersedes "Deno.systemCpuInfo()" API (which was removed in this commit).
Diffstat (limited to 'runtime/js')
-rw-r--r-- | runtime/js/30_os.js | 10 | ||||
-rw-r--r-- | runtime/js/90_deno_ns.js | 1 | ||||
-rw-r--r-- | runtime/js/99_main.js | 32 |
3 files changed, 29 insertions, 14 deletions
diff --git a/runtime/js/30_os.js b/runtime/js/30_os.js index afb5aa4e0..f026940ca 100644 --- a/runtime/js/30_os.js +++ b/runtime/js/30_os.js @@ -24,15 +24,6 @@ return core.opSync("op_system_memory_info"); } - function systemCpuInfo() { - const { cores, speed } = core.opSync("op_system_cpu_info"); - // Map nulls to undefined for compatibility - return { - cores: cores ?? undefined, - speed: speed ?? undefined, - }; - } - // This is an internal only method used by the test harness to override the // behavior of exit when the exit sanitizer is enabled. let exitHandler = null; @@ -89,7 +80,6 @@ exit, osRelease, systemMemoryInfo, - systemCpuInfo, hostname, loadavg, }; diff --git a/runtime/js/90_deno_ns.js b/runtime/js/90_deno_ns.js index e4d0b00f2..27900431f 100644 --- a/runtime/js/90_deno_ns.js +++ b/runtime/js/90_deno_ns.js @@ -118,7 +118,6 @@ hostname: __bootstrap.os.hostname, osRelease: __bootstrap.os.osRelease, systemMemoryInfo: __bootstrap.os.systemMemoryInfo, - systemCpuInfo: __bootstrap.os.systemCpuInfo, applySourceMap: __bootstrap.errorStack.opApplySourceMap, formatDiagnostics: __bootstrap.errorStack.opFormatDiagnostics, sleepSync: __bootstrap.timers.sleepSync, 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(); |