Skip to content

Commit 061df76

Browse files
author
bors-servo
authored
Auto merge of #23545 - CYBAI:support-module-script, r=<try>
[WIP] 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 - [ ] Support internal module script - [ ] Compile cyclic modules --- - [ ] `./mach build -d` does not report any errors - [ ] `./mach test-tidy` does not report any errors - [ ] These changes fix #23370 (GitHub issue number if applicable) - [ ] There are tests for these changes OR - [ ] These changes do not require tests because ___ <!-- 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 b3eed5b + 7371b4f commit 061df76

File tree

5 files changed

+786
-123
lines changed

5 files changed

+786
-123
lines changed

components/script/dom/globalscope.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use crate::dom::window::Window;
2626
use crate::dom::workerglobalscope::WorkerGlobalScope;
2727
use crate::dom::workletglobalscope::WorkletGlobalScope;
2828
use crate::microtask::{Microtask, MicrotaskQueue};
29+
use crate::script_module::ModuleObject;
2930
use crate::script_runtime::{CommonScriptMsg, ScriptChan, ScriptPort};
3031
use crate::script_thread::{MainThreadScriptChan, ScriptThread};
3132
use crate::task::TaskCanceller;
@@ -92,6 +93,11 @@ pub struct GlobalScope {
9293
/// Timers used by the Console API.
9394
console_timers: DomRefCell<HashMap<DOMString, u64>>,
9495

96+
/// module map is used when importing JavaScript modules
97+
/// https://html.spec.whatwg.org/multipage/#concept-settings-object-module-map
98+
#[ignore_malloc_size_of = "mozjs"]
99+
module_map: DomRefCell<HashMap<ServoUrl, ModuleObject>>,
100+
95101
/// For providing instructions to an optional devtools server.
96102
#[ignore_malloc_size_of = "channels are hard"]
97103
devtools_chan: Option<IpcSender<ScriptToDevtoolsControlMsg>>,
@@ -179,6 +185,7 @@ impl GlobalScope {
179185
pipeline_id,
180186
devtools_wants_updates: Default::default(),
181187
console_timers: DomRefCell::new(Default::default()),
188+
module_map: DomRefCell::new(Default::default()),
182189
devtools_chan,
183190
mem_profiler_chan,
184191
time_profiler_chan,
@@ -296,6 +303,14 @@ impl GlobalScope {
296303
&self.consumed_rejections
297304
}
298305

306+
pub fn set_module_map(&self, url: ServoUrl, module: ModuleObject) {
307+
self.module_map.borrow_mut().insert(url, module);
308+
}
309+
310+
pub fn get_module_map(&self) -> &DomRefCell<HashMap<ServoUrl, ModuleObject>> {
311+
&self.module_map
312+
}
313+
299314
#[allow(unsafe_code)]
300315
pub fn get_cx(&self) -> *mut JSContext {
301316
Runtime::get()

0 commit comments

Comments
 (0)