Skip to content

Commit 79bddab

Browse files
author
bors-servo
authored
Auto merge of #23545 - CYBAI:support-module-script, r=<try>
Support type=module script element This is still WIP but hope can be reviewed first to see if I'm on the right track. Thanks! 🙇‍♂️ - [x] Support external module script - [x] Support internal module script - [x] Compile cyclic modules --- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #23370 (GitHub issue number if applicable) - [x] There are tests for these changes <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23545) <!-- Reviewable:end -->
2 parents 3b44218 + 508bfbd commit 79bddab

File tree

81 files changed

+5980
-607
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+5980
-607
lines changed

components/script/dom/bindings/trace.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,15 @@ unsafe impl<T: JSTraceable> JSTraceable for VecDeque<T> {
311311
}
312312
}
313313

314+
unsafe impl<T: JSTraceable + Eq + Hash> JSTraceable for indexmap::IndexSet<T> {
315+
#[inline]
316+
unsafe fn trace(&self, trc: *mut JSTracer) {
317+
for e in self.iter() {
318+
e.trace(trc);
319+
}
320+
}
321+
}
322+
314323
unsafe impl<A, B, C, D> JSTraceable for (A, B, C, D)
315324
where
316325
A: JSTraceable,

components/script/dom/globalscope.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use crate::dom::event::{Event, EventBubbles, EventCancelable, EventStatus};
2424
use crate::dom::eventsource::EventSource;
2525
use crate::dom::eventtarget::EventTarget;
2626
use crate::dom::file::File;
27+
use crate::dom::htmlscriptelement::ScriptId;
2728
use crate::dom::messageevent::MessageEvent;
2829
use crate::dom::messageport::MessagePort;
2930
use crate::dom::paintworkletglobalscope::PaintWorkletGlobalScope;
@@ -32,6 +33,7 @@ use crate::dom::window::Window;
3233
use crate::dom::workerglobalscope::WorkerGlobalScope;
3334
use crate::dom::workletglobalscope::WorkletGlobalScope;
3435
use crate::microtask::{Microtask, MicrotaskQueue};
36+
use crate::script_module::ModuleTree;
3537
use crate::script_runtime::{CommonScriptMsg, JSContext as SafeJSContext, ScriptChan, ScriptPort};
3638
use crate::script_thread::{MainThreadScriptChan, ScriptThread};
3739
use crate::task::TaskCanceller;
@@ -119,6 +121,14 @@ pub struct GlobalScope {
119121
/// Timers used by the Console API.
120122
console_timers: DomRefCell<HashMap<DOMString, u64>>,
121123

124+
/// module map is used when importing JavaScript modules
125+
/// https://html.spec.whatwg.org/multipage/#concept-settings-object-module-map
126+
#[ignore_malloc_size_of = "mozjs"]
127+
module_map: DomRefCell<HashMap<ServoUrl, Rc<ModuleTree>>>,
128+
129+
#[ignore_malloc_size_of = "mozjs"]
130+
inline_module_map: DomRefCell<HashMap<ScriptId, Rc<ModuleTree>>>,
131+
122132
/// For providing instructions to an optional devtools server.
123133
#[ignore_malloc_size_of = "channels are hard"]
124134
devtools_chan: Option<IpcSender<ScriptToDevtoolsControlMsg>>,
@@ -391,6 +401,8 @@ impl GlobalScope {
391401
pipeline_id,
392402
devtools_wants_updates: Default::default(),
393403
console_timers: DomRefCell::new(Default::default()),
404+
module_map: DomRefCell::new(Default::default()),
405+
inline_module_map: DomRefCell::new(Default::default()),
394406
devtools_chan,
395407
mem_profiler_chan,
396408
time_profiler_chan,
@@ -1357,6 +1369,24 @@ impl GlobalScope {
13571369
&self.consumed_rejections
13581370
}
13591371

1372+
pub fn set_module_map(&self, url: ServoUrl, module: ModuleTree) {
1373+
self.module_map.borrow_mut().insert(url, Rc::new(module));
1374+
}
1375+
1376+
pub fn get_module_map(&self) -> &DomRefCell<HashMap<ServoUrl, Rc<ModuleTree>>> {
1377+
&self.module_map
1378+
}
1379+
1380+
pub fn set_inline_module_map(&self, script_id: ScriptId, module: ModuleTree) {
1381+
self.inline_module_map
1382+
.borrow_mut()
1383+
.insert(script_id, Rc::new(module));
1384+
}
1385+
1386+
pub fn get_inline_module_map(&self) -> &DomRefCell<HashMap<ScriptId, Rc<ModuleTree>>> {
1387+
&self.inline_module_map
1388+
}
1389+
13601390
#[allow(unsafe_code)]
13611391
pub fn get_cx(&self) -> SafeJSContext {
13621392
unsafe { SafeJSContext::from_ptr(Runtime::get()) }

0 commit comments

Comments
 (0)