mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Introduce DynamicModuleOwner dom struct
This commit is contained in:
parent
f221b00007
commit
0c7f08f743
4 changed files with 72 additions and 0 deletions
|
@ -47,6 +47,10 @@ DOMInterfaces = {
|
||||||
'inRealms': ['PromiseAttribute', 'PromiseNativeHandler'],
|
'inRealms': ['PromiseAttribute', 'PromiseNativeHandler'],
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'DynamicModuleOwner': {
|
||||||
|
'inRealms': ['PromiseAttribute'],
|
||||||
|
},
|
||||||
|
|
||||||
'URL': {
|
'URL': {
|
||||||
'weakReferenceable': True,
|
'weakReferenceable': True,
|
||||||
},
|
},
|
||||||
|
|
54
components/script/dom/dynamicmoduleowner.rs
Normal file
54
components/script/dom/dynamicmoduleowner.rs
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* 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 crate::dom::bindings::codegen::Bindings::DynamicModuleOwnerBinding::DynamicModuleOwnerMethods;
|
||||||
|
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
|
||||||
|
use crate::dom::bindings::root::DomRoot;
|
||||||
|
use crate::dom::globalscope::GlobalScope;
|
||||||
|
use crate::dom::promise::Promise;
|
||||||
|
use dom_struct::dom_struct;
|
||||||
|
use std::rc::Rc;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
/// An unique id for dynamic module
|
||||||
|
#[derive(Clone, Copy, Debug, Eq, Hash, JSTraceable, PartialEq)]
|
||||||
|
pub struct DynamicModuleId(pub Uuid);
|
||||||
|
|
||||||
|
#[dom_struct]
|
||||||
|
pub struct DynamicModuleOwner {
|
||||||
|
reflector_: Reflector,
|
||||||
|
|
||||||
|
#[ignore_malloc_size_of = "Rc"]
|
||||||
|
promise: Rc<Promise>,
|
||||||
|
|
||||||
|
/// Unique id for each dynamic module
|
||||||
|
#[ignore_malloc_size_of = "Defined in uuid"]
|
||||||
|
id: DynamicModuleId,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DynamicModuleOwner {
|
||||||
|
#[allow(unrooted_must_root)]
|
||||||
|
fn new_inherited(promise: Rc<Promise>, id: DynamicModuleId) -> Self {
|
||||||
|
DynamicModuleOwner {
|
||||||
|
reflector_: Reflector::new(),
|
||||||
|
promise,
|
||||||
|
id,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(unrooted_must_root)]
|
||||||
|
pub fn new(global: &GlobalScope, promise: Rc<Promise>, id: DynamicModuleId) -> DomRoot<Self> {
|
||||||
|
reflect_dom_object(
|
||||||
|
Box::new(DynamicModuleOwner::new_inherited(promise, id)),
|
||||||
|
global,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DynamicModuleOwnerMethods for DynamicModuleOwner {
|
||||||
|
// https://html.spec.whatwg.org/multipage/#integration-with-the-javascript-module-system:import()
|
||||||
|
fn Promise(&self) -> Rc<Promise> {
|
||||||
|
self.promise.clone()
|
||||||
|
}
|
||||||
|
}
|
|
@ -295,6 +295,7 @@ pub mod domrectreadonly;
|
||||||
pub mod domstringlist;
|
pub mod domstringlist;
|
||||||
pub mod domstringmap;
|
pub mod domstringmap;
|
||||||
pub mod domtokenlist;
|
pub mod domtokenlist;
|
||||||
|
pub mod dynamicmoduleowner;
|
||||||
pub mod element;
|
pub mod element;
|
||||||
pub mod errorevent;
|
pub mod errorevent;
|
||||||
pub mod event;
|
pub mod event;
|
||||||
|
|
13
components/script/dom/webidls/DynamicModuleOwner.webidl
Normal file
13
components/script/dom/webidls/DynamicModuleOwner.webidl
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* 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/. */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is defined for [`Dynamic Module`](https://html.spec.whatwg.org/multipage/#fetch-an-import()-module-script-graph)
|
||||||
|
* so that we can hold a traceable owner for those dynamic modules which don't hold a owner.
|
||||||
|
*/
|
||||||
|
|
||||||
|
[NoInterfaceObject, Exposed=Window]
|
||||||
|
interface DynamicModuleOwner {
|
||||||
|
readonly attribute Promise<any> promise;
|
||||||
|
};
|
Loading…
Add table
Add a link
Reference in a new issue