Skip to main content

script/dom/filesystem/
filesystem.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use dom_struct::dom_struct;
6use js::context::JSContext;
7use script_bindings::reflector::{Reflector, reflect_dom_object_with_cx};
8
9use crate::dom::bindings::codegen::Bindings::FileSystemBinding::FileSystemMethods;
10use crate::dom::bindings::root::{Dom, DomRoot};
11use crate::dom::bindings::str::USVString;
12use crate::dom::filesystemdirectoryentry::FileSystemDirectoryEntry;
13use crate::dom::globalscope::GlobalScope;
14
15#[dom_struct]
16pub(crate) struct FileSystem {
17    reflector_: Reflector,
18    name: USVString,
19    root: Dom<FileSystemDirectoryEntry>,
20}
21
22impl FileSystem {
23    fn new_inherited(name: USVString, root: &FileSystemDirectoryEntry) -> FileSystem {
24        FileSystem {
25            reflector_: Reflector::new(),
26            name,
27            root: Dom::from_ref(root),
28        }
29    }
30
31    pub(crate) fn new(
32        cx: &mut JSContext,
33        global: &GlobalScope,
34        name: USVString,
35        root: &FileSystemDirectoryEntry,
36    ) -> DomRoot<FileSystem> {
37        reflect_dom_object_with_cx(Box::new(FileSystem::new_inherited(name, root)), global, cx)
38    }
39}
40
41impl FileSystemMethods<crate::DomTypeHolder> for FileSystem {
42    /// <https://wicg.github.io/entries-api/#dom-filesystem-name>
43    fn Name(&self) -> USVString {
44        self.name.clone()
45    }
46
47    /// <https://wicg.github.io/entries-api/#dom-filesystem-root>
48    fn Root(&self) -> DomRoot<FileSystemDirectoryEntry> {
49        DomRoot::from_ref(&self.root)
50    }
51}