mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
script: implement navigator.hardwareConcurrency (#31268)
Signed-off-by: syvb <me@iter.ca>
This commit is contained in:
parent
044b94d5eb
commit
20404a72c0
14 changed files with 32 additions and 40 deletions
|
@ -2,8 +2,11 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use std::convert::TryInto;
|
||||
|
||||
use dom_struct::dom_struct;
|
||||
use js::jsval::JSVal;
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
use crate::dom::bindings::codegen::Bindings::NavigatorBinding::NavigatorMethods;
|
||||
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
|
||||
|
@ -24,6 +27,13 @@ use crate::dom::window::Window;
|
|||
use crate::dom::xrsystem::XRSystem;
|
||||
use crate::script_runtime::JSContext;
|
||||
|
||||
pub(super) fn hardware_concurrency() -> u64 {
|
||||
lazy_static! {
|
||||
static ref CPUS: u64 = num_cpus::get().try_into().unwrap_or(1);
|
||||
}
|
||||
*CPUS
|
||||
}
|
||||
|
||||
#[dom_struct]
|
||||
pub struct Navigator {
|
||||
reflector_: Reflector,
|
||||
|
@ -206,4 +216,9 @@ impl NavigatorMethods for Navigator {
|
|||
fn Gpu(&self) -> DomRoot<GPU> {
|
||||
self.gpu.or_init(|| GPU::new(&self.global()))
|
||||
}
|
||||
|
||||
/// <https://html.spec.whatwg.org/multipage/#dom-navigator-hardwareconcurrency>
|
||||
fn HardwareConcurrency(&self) -> u64 {
|
||||
hardware_concurrency()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue