Make CanGc derive Copy and Clone (#33407)

Signed-off-by: Taym <haddadi.taym@gmail.com>
This commit is contained in:
Taym Haddadi 2024-09-12 12:24:44 +02:00 committed by GitHub
parent 637770600f
commit 747e562ff0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 61 additions and 72 deletions

View file

@ -101,7 +101,7 @@ pub trait WorkerEventLoopMethods {
pub fn run_worker_event_loop<T, WorkerMsg, Event>(
worker_scope: &T,
worker: Option<&TrustedWorkerAddress>,
_can_gc: CanGc,
can_gc: CanGc,
) where
WorkerMsg: QueuedTaskConversion + Send,
T: WorkerEventLoopMethods<WorkerMsg = WorkerMsg, Event = Event>
@ -156,7 +156,7 @@ pub fn run_worker_event_loop<T, WorkerMsg, Event>(
};
worker_scope
.upcast::<GlobalScope>()
.perform_a_microtask_checkpoint(CanGc::note());
.perform_a_microtask_checkpoint(can_gc);
}
worker_scope
.upcast::<GlobalScope>()

View file

@ -1239,10 +1239,10 @@ impl ElementQueue {
}
/// <https://html.spec.whatwg.org/multipage/#invoke-custom-element-reactions>
fn invoke_reactions(&self, _can_gc: CanGc) {
fn invoke_reactions(&self, can_gc: CanGc) {
// Steps 1-2
while let Some(element) = self.next_element() {
element.invoke_reactions(CanGc::note())
element.invoke_reactions(can_gc)
}
self.queue.borrow_mut().clear();
}

View file

@ -333,7 +333,7 @@ impl DedicatedWorkerGlobalScope {
gpu_id_hub: Arc<Identities>,
control_receiver: Receiver<DedicatedWorkerControlMsg>,
context_sender: Sender<ContextForRequestInterrupt>,
_can_gc: CanGc,
can_gc: CanGc,
) -> JoinHandle<()> {
let serialized_worker_url = worker_url.to_string();
let top_level_browsing_context_id = TopLevelBrowsingContextId::installed();
@ -479,7 +479,7 @@ impl DedicatedWorkerGlobalScope {
// until the event loop is destroyed,
// which happens after the closing flag is set to true.
while !scope.is_closing() {
run_worker_event_loop(&*global, Some(&worker), CanGc::note());
run_worker_event_loop(&*global, Some(&worker), can_gc);
}
},
reporter_name,

View file

@ -399,7 +399,7 @@ impl Element {
}
}
pub fn invoke_reactions(&self, _can_gc: CanGc) {
pub fn invoke_reactions(&self, can_gc: CanGc) {
loop {
rooted_vec!(let mut reactions);
match *self.rare_data_mut() {
@ -414,7 +414,7 @@ impl Element {
}
for reaction in reactions.iter() {
reaction.invoke(self, CanGc::note());
reaction.invoke(self, can_gc);
}
reactions.clear();

View file

@ -450,13 +450,13 @@ impl HTMLImageElement {
(ImageResponse::Loaded(image, url), ImageRequestPhase::Pending) => {
self.abort_request(State::Unavailable, ImageRequestPhase::Pending, can_gc);
self.image_request.set(ImageRequestPhase::Current);
self.handle_loaded_image(image, url, CanGc::note());
self.handle_loaded_image(image, url, can_gc);
(true, false)
},
(ImageResponse::PlaceholderLoaded(image, url), ImageRequestPhase::Pending) => {
self.abort_request(State::Unavailable, ImageRequestPhase::Pending, can_gc);
self.image_request.set(ImageRequestPhase::Current);
self.handle_loaded_image(image, url, CanGc::note());
self.handle_loaded_image(image, url, can_gc);
(false, true)
},
(ImageResponse::MetadataLoaded(meta), ImageRequestPhase::Current) => {
@ -474,7 +474,7 @@ impl HTMLImageElement {
},
(ImageResponse::None, ImageRequestPhase::Pending) => {
self.abort_request(State::Broken, ImageRequestPhase::Current, can_gc);
self.abort_request(State::Broken, ImageRequestPhase::Pending, CanGc::note());
self.abort_request(State::Broken, ImageRequestPhase::Pending, can_gc);
self.image_request.set(ImageRequestPhase::Current);
(false, true)
},
@ -874,7 +874,7 @@ impl HTMLImageElement {
}
},
}
self.fetch_image(url, CanGc::note());
self.fetch_image(url, can_gc);
}
/// Step 8-12 of html.spec.whatwg.org/multipage/#update-the-image-data
@ -888,7 +888,7 @@ impl HTMLImageElement {
Some(data) => data,
None => {
self.abort_request(State::Broken, ImageRequestPhase::Current, can_gc);
self.abort_request(State::Broken, ImageRequestPhase::Pending, CanGc::note());
self.abort_request(State::Broken, ImageRequestPhase::Pending, can_gc);
// Step 9.
// FIXME(nox): Why are errors silenced here?
let _ = task_source.queue(
@ -923,7 +923,7 @@ impl HTMLImageElement {
},
Err(_) => {
self.abort_request(State::Broken, ImageRequestPhase::Current, can_gc);
self.abort_request(State::Broken, ImageRequestPhase::Pending, CanGc::note());
self.abort_request(State::Broken, ImageRequestPhase::Pending, can_gc);
// Step 12.1-12.5.
let src = src.0;
// FIXME(nox): Why are errors silenced here?
@ -1011,11 +1011,7 @@ impl HTMLImageElement {
ImageRequestPhase::Current,
can_gc,
);
self.abort_request(
State::Unavailable,
ImageRequestPhase::Pending,
CanGc::note(),
);
self.abort_request(State::Unavailable, ImageRequestPhase::Pending, can_gc);
let mut current_request = self.current_request.borrow_mut();
current_request.final_url = Some(img_url.clone());
current_request.image = Some(image.clone());
@ -1069,7 +1065,7 @@ impl HTMLImageElement {
elem: &HTMLImageElement,
selected_source: String,
selected_pixel_density: f64,
_can_gc: CanGc,
can_gc: CanGc,
) -> IpcSender<PendingImageResponse> {
let trusted_node = Trusted::new(elem);
let (responder_sender, responder_receiver) = ipc::channel().unwrap();
@ -1095,7 +1091,7 @@ impl HTMLImageElement {
if generation == element.generation.get() {
element.process_image_response_for_environment_change(image,
USVString::from(selected_source_clone), generation,
selected_pixel_density, CanGc::note());
selected_pixel_density, can_gc);
}
}),
&canceller,
@ -1150,7 +1146,7 @@ impl HTMLImageElement {
&mut self.pending_request.borrow_mut(),
&img_url,
&selected_source,
CanGc::note(),
can_gc,
);
let window = window_from_node(self);
@ -1161,7 +1157,7 @@ impl HTMLImageElement {
self,
selected_source.0.clone(),
selected_pixel_density,
CanGc::note(),
can_gc,
);
let cache_result = image_cache.track_image(
img_url.clone(),
@ -1382,7 +1378,7 @@ impl HTMLImageElement {
// run update_the_image_data when the element is created.
// https://html.spec.whatwg.org/multipage/#when-to-obtain-images
image.update_the_image_data(CanGc::note());
image.update_the_image_data(can_gc);
Ok(image)
}

View file

@ -1352,7 +1352,7 @@ impl HTMLMediaElement {
}
}
fn setup_media_player(&self, resource: &Resource, _can_gc: CanGc) -> Result<(), ()> {
fn setup_media_player(&self, resource: &Resource, can_gc: CanGc) -> Result<(), ()> {
let stream_type = match *resource {
Resource::Object => {
if let Some(ref src_object) = *self.src_object.borrow() {
@ -1403,7 +1403,7 @@ impl HTMLMediaElement {
let this = trusted_node.clone();
if let Err(err) = task_source.queue_with_canceller(
task!(handle_player_event: move || {
this.root().handle_player_event(&event, CanGc::note());
this.root().handle_player_event(&event, can_gc);
}),
&canceller,
) {

View file

@ -55,11 +55,11 @@ impl HTMLSourceElement {
fn iterate_next_html_image_element_siblings(
next_siblings_iterator: impl Iterator<Item = Root<Dom<Node>>>,
_can_gc: CanGc,
can_gc: CanGc,
) {
for next_sibling in next_siblings_iterator {
if let Some(html_image_element_sibling) = next_sibling.downcast::<HTMLImageElement>() {
html_image_element_sibling.update_the_image_data(CanGc::note());
html_image_element_sibling.update_the_image_data(can_gc);
}
}
}

View file

@ -75,7 +75,7 @@ impl MediaElementAudioSourceNode {
Box::new(node),
window,
proto,
CanGc::note(),
can_gc,
))
}

View file

@ -295,7 +295,7 @@ impl ServiceWorkerGlobalScope {
control_receiver: Receiver<ServiceWorkerControlMsg>,
context_sender: Sender<ContextForRequestInterrupt>,
closing: Arc<AtomicBool>,
_can_gc: CanGc,
can_gc: CanGc,
) -> JoinHandle<()> {
let ScopeThings {
script_url,
@ -399,7 +399,7 @@ impl ServiceWorkerGlobalScope {
// which happens after the closing flag is set to true,
// or until the worker has run beyond its allocated time.
while !scope.is_closing() && !global.has_timed_out() {
run_worker_event_loop(&*global, None, CanGc::note());
run_worker_event_loop(&*global, None, can_gc);
}
},
reporter_name,

View file

@ -287,7 +287,7 @@ impl Tokenizer {
pub fn feed(
&self,
input: &BufferQueue,
_can_gc: CanGc,
can_gc: CanGc,
) -> TokenizerResult<DomRoot<HTMLScriptElement>> {
let mut send_tendrils = VecDeque::new();
while let Some(str) = input.pop_front() {
@ -309,7 +309,7 @@ impl Tokenizer {
.expect("Unexpected channel panic in main thread.")
{
ToTokenizerMsg::ProcessOperation(parse_op) => {
self.process_operation(parse_op, CanGc::note())
self.process_operation(parse_op, can_gc)
},
ToTokenizerMsg::TokenizerResultDone { updated_input } => {
let buffer_queue = create_buffer_queue(updated_input);
@ -330,7 +330,7 @@ impl Tokenizer {
}
}
pub fn end(&self, _can_gc: CanGc) {
pub fn end(&self, can_gc: CanGc) {
self.html_tokenizer_sender
.send(ToHtmlTokenizerMsg::End)
.unwrap();
@ -341,7 +341,7 @@ impl Tokenizer {
.expect("Unexpected channel panic in main thread.")
{
ToTokenizerMsg::ProcessOperation(parse_op) => {
self.process_operation(parse_op, CanGc::note())
self.process_operation(parse_op, can_gc)
},
ToTokenizerMsg::TokenizerResultDone { updated_input: _ } |
ToTokenizerMsg::TokenizerResultScript {

View file

@ -338,7 +338,7 @@ impl ServoParser {
}
/// Steps 6-8 of <https://html.spec.whatwg.org/multipage/#document.write()>
pub fn write(&self, text: Vec<DOMString>, _can_gc: CanGc) {
pub fn write(&self, text: Vec<DOMString>, can_gc: CanGc) {
assert!(self.can_write());
if self.document.has_pending_parsing_blocking_script() {
@ -361,7 +361,7 @@ impl ServoParser {
input.push_back(String::from(chunk).into());
}
self.tokenize(|tokenizer| tokenizer.feed(&input, CanGc::note()));
self.tokenize(|tokenizer| tokenizer.feed(&input, can_gc));
if self.suspended.get() {
// Parser got suspended, insert remaining input at end of
@ -532,7 +532,7 @@ impl ServoParser {
)
}
fn do_parse_sync(&self, _can_gc: CanGc) {
fn do_parse_sync(&self, can_gc: CanGc) {
assert!(self.script_input.is_empty());
// This parser will continue to parse while there is either pending input or
@ -546,7 +546,7 @@ impl ServoParser {
}
}
}
self.tokenize(|tokenizer| tokenizer.feed(&self.network_input, CanGc::note()));
self.tokenize(|tokenizer| tokenizer.feed(&self.network_input, can_gc));
if self.suspended.get() {
return;
@ -555,7 +555,7 @@ impl ServoParser {
assert!(self.network_input.is_empty());
if self.last_chunk_received.get() {
self.finish(CanGc::note());
self.finish(can_gc);
}
}
@ -1353,15 +1353,7 @@ fn create_element_for_token(
CustomElementCreationMode::Asynchronous
};
let element = Element::create(
name,
is,
document,
creator,
creation_mode,
None,
CanGc::note(),
);
let element = Element::create(name, is, document, creator, creation_mode, None, can_gc);
// https://html.spec.whatwg.org/multipage#the-input-element:value-sanitization-algorithm-3
// says to invoke sanitization "when an input element is first created";
@ -1389,7 +1381,7 @@ fn create_element_for_token(
// Step 9.
if will_execute_script {
// Steps 9.1 - 9.2.
ScriptThread::pop_current_element_queue(CanGc::note());
ScriptThread::pop_current_element_queue(can_gc);
// Step 9.3.
document.decrement_throw_on_dynamic_markup_insertion_counter();
}

View file

@ -87,7 +87,7 @@ impl MicrotaskQueue {
cx: JSContext,
target_provider: F,
globalscopes: Vec<DomRoot<GlobalScope>>,
_can_gc: CanGc,
can_gc: CanGc,
) where
F: Fn(PipelineId) -> Option<DomRoot<GlobalScope>>,
{
@ -128,14 +128,14 @@ impl MicrotaskQueue {
},
Microtask::MediaElement(ref task) => {
let _realm = task.enter_realm();
task.handler(CanGc::note());
task.handler(can_gc);
},
Microtask::ImageElement(ref task) => {
let _realm = task.enter_realm();
task.handler(CanGc::note());
task.handler(can_gc);
},
Microtask::CustomElementReaction => {
ScriptThread::invoke_backup_element_queue(CanGc::note());
ScriptThread::invoke_backup_element_queue(can_gc);
},
Microtask::NotifyMutationObservers => {
MutationObserver::notify_mutation_observers();

View file

@ -1124,6 +1124,7 @@ impl Runnable {
}
}
#[derive(Clone, Copy, Debug)]
pub struct CanGc(());
impl CanGc {

View file

@ -1448,9 +1448,9 @@ impl ScriptThread {
/// Starts the script thread. After calling this method, the script thread will loop receiving
/// messages on its port.
pub fn start(&self, _can_gc: CanGc) {
pub fn start(&self, can_gc: CanGc) {
debug!("Starting script thread.");
while self.handle_msgs(CanGc::note()) {
while self.handle_msgs(can_gc) {
// Go on...
debug!("Running script thread.");
}
@ -1790,7 +1790,7 @@ impl ScriptThread {
}
/// Handle incoming messages from other tasks and the task queue.
fn handle_msgs(&self, _can_gc: CanGc) -> bool {
fn handle_msgs(&self, can_gc: CanGc) -> bool {
use self::MixedMessage::{
FromConstellation, FromDevtools, FromImageCache, FromScript, FromWebGPUServer,
};
@ -1918,7 +1918,7 @@ impl ScriptThread {
// Run the "update the rendering" task.
task.run_box();
// Always perform a microtrask checkpoint after running a task.
self.perform_a_microtask_checkpoint(CanGc::note());
self.perform_a_microtask_checkpoint(can_gc);
rendering_update_already_prioritized = true;
}
},
@ -1975,7 +1975,7 @@ impl ScriptThread {
// If we've received the closed signal from the BHM, only handle exit messages.
match msg {
FromConstellation(ConstellationControlMsg::ExitScriptThread) => {
self.handle_exit_script_thread_msg(CanGc::note());
self.handle_exit_script_thread_msg(can_gc);
return false;
},
FromConstellation(ConstellationControlMsg::ExitPipeline(
@ -1985,7 +1985,7 @@ impl ScriptThread {
self.handle_exit_pipeline_msg(
pipeline_id,
discard_browsing_context,
CanGc::note(),
can_gc,
);
},
_ => {},
@ -1996,11 +1996,11 @@ impl ScriptThread {
let result = self.profile_event(category, pipeline_id, move || {
match msg {
FromConstellation(ConstellationControlMsg::ExitScriptThread) => {
self.handle_exit_script_thread_msg(CanGc::note());
self.handle_exit_script_thread_msg(can_gc);
return Some(false);
},
FromConstellation(inner_msg) => {
self.handle_msg_from_constellation(inner_msg, CanGc::note())
self.handle_msg_from_constellation(inner_msg, can_gc)
},
FromScript(inner_msg) => self.handle_msg_from_script(inner_msg),
FromDevtools(inner_msg) => self.handle_msg_from_devtools(inner_msg),
@ -2017,7 +2017,7 @@ impl ScriptThread {
// https://html.spec.whatwg.org/multipage/#event-loop-processing-model step 6
// TODO(#32003): A microtask checkpoint is only supposed to be performed after running a task.
self.perform_a_microtask_checkpoint(CanGc::note());
self.perform_a_microtask_checkpoint(can_gc);
}
{
@ -3159,7 +3159,7 @@ impl ScriptThread {
&self,
id: &PipelineId,
metadata: Option<Metadata>,
_can_gc: CanGc,
can_gc: CanGc,
) -> Option<DomRoot<ServoParser>> {
let idx = self
.incomplete_loads
@ -3198,7 +3198,7 @@ impl ScriptThread {
};
let load = self.incomplete_loads.borrow_mut().remove(idx);
metadata.map(|meta| self.load(meta, load, CanGc::note()))
metadata.map(|meta| self.load(meta, load, can_gc))
},
None => {
assert!(self.closed_pipelines.borrow().contains(id));
@ -3340,7 +3340,7 @@ impl ScriptThread {
}
/// Handles a request to exit the script thread and shut down layout.
fn handle_exit_script_thread_msg(&self, _can_gc: CanGc) {
fn handle_exit_script_thread_msg(&self, can_gc: CanGc) {
debug!("Exiting script thread.");
let mut pipeline_ids = Vec::new();
@ -3360,7 +3360,7 @@ impl ScriptThread {
);
for pipeline_id in pipeline_ids {
self.handle_exit_pipeline_msg(pipeline_id, DiscardBrowsingContext::Yes, CanGc::note());
self.handle_exit_pipeline_msg(pipeline_id, DiscardBrowsingContext::Yes, can_gc);
}
self.background_hang_monitor.unregister();
@ -3784,7 +3784,7 @@ impl ScriptThread {
referrer_policy,
Some(status_code),
incomplete.canceller,
CanGc::note(),
can_gc,
);
document.set_ready_state(DocumentReadyState::Loading);
@ -3826,9 +3826,9 @@ impl ScriptThread {
document.set_navigation_start(incomplete.navigation_start);
if is_html_document == IsHTMLDocument::NonHTMLDocument {
ServoParser::parse_xml_document(&document, None, final_url, CanGc::note());
ServoParser::parse_xml_document(&document, None, final_url, can_gc);
} else {
ServoParser::parse_html_document(&document, None, final_url, CanGc::note());
ServoParser::parse_html_document(&document, None, final_url, can_gc);
}
if incomplete.activity == DocumentActivity::FullyActive {

View file

@ -250,11 +250,11 @@ impl ServiceWorkerManager {
None
}
fn handle_message(&mut self, _can_gc: CanGc) {
fn handle_message(&mut self, can_gc: CanGc) {
while let Ok(message) = self.receive_message() {
let should_continue = match message {
Message::FromConstellation(msg) => {
self.handle_message_from_constellation(msg, CanGc::note())
self.handle_message_from_constellation(msg, can_gc)
},
Message::FromResource(msg) => self.handle_message_from_resource(msg),
};