modules/
lib.rs

1/*
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 */
6
7#![allow(clippy::module_inception)]
8#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
9
10use ion::{Context, Object};
11use runtime::module::{StandardModules, init_global_module, init_module};
12
13pub use crate::assert::Assert;
14pub use crate::fs::{FileSystem, FileSystemSync};
15pub use crate::path::PathM;
16pub use crate::url::UrlM;
17
18mod assert;
19mod fs;
20mod path;
21mod url;
22
23macro_rules! inner_init {
24	($cx:ident, $global:ident, $init:ident) => {{
25		fn inner(cx: &Context, global: &Object) -> Option<()> {
26			$init(cx, global, &Assert)?;
27			let fs_sync = $init(cx, global, &FileSystemSync)?;
28			$init(cx, global, &FileSystem { sync: &fs_sync })?;
29			$init(cx, global, &PathM)?;
30			$init(cx, global, &UrlM)?;
31			Some(())
32		}
33		inner($cx, $global).is_some()
34	}};
35}
36
37pub struct Modules;
38
39impl StandardModules for Modules {
40	fn init(self, cx: &Context, global: &Object) -> bool {
41		inner_init!(cx, global, init_module)
42	}
43
44	fn init_globals(self, cx: &Context, global: &Object) -> bool {
45		inner_init!(cx, global, init_global_module)
46	}
47}