dom: Implement Navigator.languages.

This commit is contained in:
Josh Matthews 2020-07-14 11:50:59 -04:00
parent 9fe92ecb4c
commit 2acd295ea6
10 changed files with 670 additions and 15 deletions

View file

@ -6,6 +6,7 @@ use crate::dom::bindings::codegen::Bindings::NavigatorBinding::NavigatorMethods;
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::root::{DomRoot, MutNullableDom};
use crate::dom::bindings::str::DOMString;
use crate::dom::bindings::utils::to_frozen_array;
use crate::dom::bluetooth::Bluetooth;
use crate::dom::gamepadlist::GamepadList;
use crate::dom::gpu::GPU;
@ -18,7 +19,9 @@ use crate::dom::pluginarray::PluginArray;
use crate::dom::serviceworkercontainer::ServiceWorkerContainer;
use crate::dom::window::Window;
use crate::dom::xrsystem::XRSystem;
use crate::script_runtime::JSContext;
use dom_struct::dom_struct;
use js::jsval::JSVal;
#[dom_struct]
pub struct Navigator {
@ -122,6 +125,12 @@ impl NavigatorMethods for Navigator {
navigatorinfo::Language()
}
// https://html.spec.whatwg.org/multipage/#dom-navigator-languages
#[allow(unsafe_code)]
fn Languages(&self, cx: JSContext) -> JSVal {
to_frozen_array(&[self.Language()], cx)
}
// https://html.spec.whatwg.org/multipage/#dom-navigator-plugins
fn Plugins(&self) -> DomRoot<PluginArray> {
self.plugins.or_init(|| PluginArray::new(&self.global()))