Skip to content

Commit

Permalink
Auto merge of #23545 - CYBAI:support-module-script, r=jdm,manishearth
Browse files Browse the repository at this point in the history
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 -->
  • Loading branch information
bors-servo committed Jan 6, 2020
2 parents 3b44218 + 508bfbd commit 5c7a4db
Show file tree
Hide file tree
Showing 81 changed files with 5,980 additions and 607 deletions.
9 changes: 9 additions & 0 deletions components/script/dom/bindings/trace.rs
Expand Up @@ -311,6 +311,15 @@ unsafe impl<T: JSTraceable> JSTraceable for VecDeque<T> {
}
}

unsafe impl<T: JSTraceable + Eq + Hash> JSTraceable for indexmap::IndexSet<T> {
#[inline]
unsafe fn trace(&self, trc: *mut JSTracer) {
for e in self.iter() {
e.trace(trc);
}
}
}

unsafe impl<A, B, C, D> JSTraceable for (A, B, C, D)
where
A: JSTraceable,
Expand Down
30 changes: 30 additions & 0 deletions components/script/dom/globalscope.rs
Expand Up @@ -24,6 +24,7 @@ use crate::dom::event::{Event, EventBubbles, EventCancelable, EventStatus};
use crate::dom::eventsource::EventSource;
use crate::dom::eventtarget::EventTarget;
use crate::dom::file::File;
use crate::dom::htmlscriptelement::ScriptId;
use crate::dom::messageevent::MessageEvent;
use crate::dom::messageport::MessagePort;
use crate::dom::paintworkletglobalscope::PaintWorkletGlobalScope;
Expand All @@ -32,6 +33,7 @@ use crate::dom::window::Window;
use crate::dom::workerglobalscope::WorkerGlobalScope;
use crate::dom::workletglobalscope::WorkletGlobalScope;
use crate::microtask::{Microtask, MicrotaskQueue};
use crate::script_module::ModuleTree;
use crate::script_runtime::{CommonScriptMsg, JSContext as SafeJSContext, ScriptChan, ScriptPort};
use crate::script_thread::{MainThreadScriptChan, ScriptThread};
use crate::task::TaskCanceller;
Expand Down Expand Up @@ -119,6 +121,14 @@ pub struct GlobalScope {
/// Timers used by the Console API.
console_timers: DomRefCell<HashMap<DOMString, u64>>,

/// module map is used when importing JavaScript modules
/// https://html.spec.whatwg.org/multipage/#concept-settings-object-module-map
#[ignore_malloc_size_of = "mozjs"]
module_map: DomRefCell<HashMap<ServoUrl, Rc<ModuleTree>>>,

#[ignore_malloc_size_of = "mozjs"]
inline_module_map: DomRefCell<HashMap<ScriptId, Rc<ModuleTree>>>,

/// For providing instructions to an optional devtools server.
#[ignore_malloc_size_of = "channels are hard"]
devtools_chan: Option<IpcSender<ScriptToDevtoolsControlMsg>>,
Expand Down Expand Up @@ -391,6 +401,8 @@ impl GlobalScope {
pipeline_id,
devtools_wants_updates: Default::default(),
console_timers: DomRefCell::new(Default::default()),
module_map: DomRefCell::new(Default::default()),
inline_module_map: DomRefCell::new(Default::default()),
devtools_chan,
mem_profiler_chan,
time_profiler_chan,
Expand Down Expand Up @@ -1357,6 +1369,24 @@ impl GlobalScope {
&self.consumed_rejections
}

pub fn set_module_map(&self, url: ServoUrl, module: ModuleTree) {
self.module_map.borrow_mut().insert(url, Rc::new(module));
}

pub fn get_module_map(&self) -> &DomRefCell<HashMap<ServoUrl, Rc<ModuleTree>>> {
&self.module_map
}

pub fn set_inline_module_map(&self, script_id: ScriptId, module: ModuleTree) {
self.inline_module_map
.borrow_mut()
.insert(script_id, Rc::new(module));
}

pub fn get_inline_module_map(&self) -> &DomRefCell<HashMap<ScriptId, Rc<ModuleTree>>> {
&self.inline_module_map
}

#[allow(unsafe_code)]
pub fn get_cx(&self) -> SafeJSContext {
unsafe { SafeJSContext::from_ptr(Runtime::get()) }
Expand Down

0 comments on commit 5c7a4db

Please sign in to comment.