refactor: propagate CanGc arguments through callers (#35565)

Signed-off-by: Auguste Baum <auguste.apple@gmail.com>
This commit is contained in:
Auguste Baum 2025-02-21 18:35:17 +01:00 committed by GitHub
parent 085cd981aa
commit ca1f0486ba
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 62 additions and 42 deletions

View file

@ -46,6 +46,7 @@ impl BiquadFilterNode {
window: &Window, window: &Window,
context: &BaseAudioContext, context: &BaseAudioContext,
options: &BiquadFilterOptions, options: &BiquadFilterOptions,
can_gc: CanGc,
) -> Fallible<BiquadFilterNode> { ) -> Fallible<BiquadFilterNode> {
let node_options = let node_options =
options options
@ -70,7 +71,7 @@ impl BiquadFilterNode {
options.gain, // default value options.gain, // default value
f32::MIN, // min value f32::MIN, // min value
f32::MAX, // max value f32::MAX, // max value
CanGc::note(), can_gc,
); );
let q = AudioParam::new( let q = AudioParam::new(
window, window,
@ -82,7 +83,7 @@ impl BiquadFilterNode {
options.q, // default value options.q, // default value
f32::MIN, // min value f32::MIN, // min value
f32::MAX, // max value f32::MAX, // max value
CanGc::note(), can_gc,
); );
let frequency = AudioParam::new( let frequency = AudioParam::new(
window, window,
@ -94,7 +95,7 @@ impl BiquadFilterNode {
options.frequency, // default value options.frequency, // default value
f32::MIN, // min value f32::MIN, // min value
f32::MAX, // max value f32::MAX, // max value
CanGc::note(), can_gc,
); );
let detune = AudioParam::new( let detune = AudioParam::new(
window, window,
@ -106,7 +107,7 @@ impl BiquadFilterNode {
options.detune, // default value options.detune, // default value
f32::MIN, // min value f32::MIN, // min value
f32::MAX, // max value f32::MAX, // max value
CanGc::note(), can_gc,
); );
Ok(BiquadFilterNode { Ok(BiquadFilterNode {
node, node,
@ -135,7 +136,7 @@ impl BiquadFilterNode {
options: &BiquadFilterOptions, options: &BiquadFilterOptions,
can_gc: CanGc, can_gc: CanGc,
) -> Fallible<DomRoot<BiquadFilterNode>> { ) -> Fallible<DomRoot<BiquadFilterNode>> {
let node = BiquadFilterNode::new_inherited(window, context, options)?; let node = BiquadFilterNode::new_inherited(window, context, options, can_gc)?;
Ok(reflect_dom_object_with_proto( Ok(reflect_dom_object_with_proto(
Box::new(node), Box::new(node),
window, window,

View file

@ -103,6 +103,7 @@ impl BluetoothDevice {
&self, &self,
service: &BluetoothServiceMsg, service: &BluetoothServiceMsg,
server: &BluetoothRemoteGATTServer, server: &BluetoothRemoteGATTServer,
can_gc: CanGc,
) -> DomRoot<BluetoothRemoteGATTService> { ) -> DomRoot<BluetoothRemoteGATTService> {
let service_map_ref = &self.attribute_instance_map.service_map; let service_map_ref = &self.attribute_instance_map.service_map;
let mut service_map = service_map_ref.borrow_mut(); let mut service_map = service_map_ref.borrow_mut();
@ -115,7 +116,7 @@ impl BluetoothDevice {
DOMString::from(service.uuid.clone()), DOMString::from(service.uuid.clone()),
service.is_primary, service.is_primary,
service.instance_id.clone(), service.instance_id.clone(),
CanGc::note(), can_gc,
); );
service_map.insert(service.instance_id.clone(), Dom::from_ref(&bt_service)); service_map.insert(service.instance_id.clone(), Dom::from_ref(&bt_service));
bt_service bt_service
@ -125,6 +126,7 @@ impl BluetoothDevice {
&self, &self,
characteristic: &BluetoothCharacteristicMsg, characteristic: &BluetoothCharacteristicMsg,
service: &BluetoothRemoteGATTService, service: &BluetoothRemoteGATTService,
can_gc: CanGc,
) -> DomRoot<BluetoothRemoteGATTCharacteristic> { ) -> DomRoot<BluetoothRemoteGATTCharacteristic> {
let characteristic_map_ref = &self.attribute_instance_map.characteristic_map; let characteristic_map_ref = &self.attribute_instance_map.characteristic_map;
let mut characteristic_map = characteristic_map_ref.borrow_mut(); let mut characteristic_map = characteristic_map_ref.borrow_mut();
@ -142,7 +144,7 @@ impl BluetoothDevice {
characteristic.authenticated_signed_writes, characteristic.authenticated_signed_writes,
characteristic.reliable_write, characteristic.reliable_write,
characteristic.writable_auxiliaries, characteristic.writable_auxiliaries,
CanGc::note(), can_gc,
); );
let bt_characteristic = BluetoothRemoteGATTCharacteristic::new( let bt_characteristic = BluetoothRemoteGATTCharacteristic::new(
&service.global(), &service.global(),
@ -150,7 +152,7 @@ impl BluetoothDevice {
DOMString::from(characteristic.uuid.clone()), DOMString::from(characteristic.uuid.clone()),
&properties, &properties,
characteristic.instance_id.clone(), characteristic.instance_id.clone(),
CanGc::note(), can_gc,
); );
characteristic_map.insert( characteristic_map.insert(
characteristic.instance_id.clone(), characteristic.instance_id.clone(),
@ -174,6 +176,7 @@ impl BluetoothDevice {
&self, &self,
descriptor: &BluetoothDescriptorMsg, descriptor: &BluetoothDescriptorMsg,
characteristic: &BluetoothRemoteGATTCharacteristic, characteristic: &BluetoothRemoteGATTCharacteristic,
can_gc: CanGc,
) -> DomRoot<BluetoothRemoteGATTDescriptor> { ) -> DomRoot<BluetoothRemoteGATTDescriptor> {
let descriptor_map_ref = &self.attribute_instance_map.descriptor_map; let descriptor_map_ref = &self.attribute_instance_map.descriptor_map;
let mut descriptor_map = descriptor_map_ref.borrow_mut(); let mut descriptor_map = descriptor_map_ref.borrow_mut();
@ -185,7 +188,7 @@ impl BluetoothDevice {
characteristic, characteristic,
DOMString::from(descriptor.uuid.clone()), DOMString::from(descriptor.uuid.clone()),
descriptor.instance_id.clone(), descriptor.instance_id.clone(),
CanGc::note(), can_gc,
); );
descriptor_map.insert( descriptor_map.insert(
descriptor.instance_id.clone(), descriptor.instance_id.clone(),

View file

@ -309,14 +309,16 @@ impl AsyncBluetoothListener for BluetoothRemoteGATTCharacteristic {
// Step 7. // Step 7.
BluetoothResponse::GetDescriptors(descriptors_vec, single) => { BluetoothResponse::GetDescriptors(descriptors_vec, single) => {
if single { if single {
promise.resolve_native( promise.resolve_native(&device.get_or_create_descriptor(
&device.get_or_create_descriptor(&descriptors_vec[0], self), &descriptors_vec[0],
); self,
can_gc,
));
return; return;
} }
let mut descriptors = vec![]; let mut descriptors = vec![];
for descriptor in descriptors_vec { for descriptor in descriptors_vec {
let bt_descriptor = device.get_or_create_descriptor(&descriptor, self); let bt_descriptor = device.get_or_create_descriptor(&descriptor, self, can_gc);
descriptors.push(bt_descriptor); descriptors.push(bt_descriptor);
} }
promise.resolve_native(&descriptors); promise.resolve_native(&descriptors);

View file

@ -148,7 +148,7 @@ impl BluetoothRemoteGATTServerMethods<crate::DomTypeHolder> for BluetoothRemoteG
} }
impl AsyncBluetoothListener for BluetoothRemoteGATTServer { impl AsyncBluetoothListener for BluetoothRemoteGATTServer {
fn handle_response(&self, response: BluetoothResponse, promise: &Rc<Promise>, _can_gc: CanGc) { fn handle_response(&self, response: BluetoothResponse, promise: &Rc<Promise>, can_gc: CanGc) {
match response { match response {
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-connect // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-connect
BluetoothResponse::GATTServerConnect(connected) => { BluetoothResponse::GATTServerConnect(connected) => {
@ -171,12 +171,16 @@ impl AsyncBluetoothListener for BluetoothRemoteGATTServer {
BluetoothResponse::GetPrimaryServices(services_vec, single) => { BluetoothResponse::GetPrimaryServices(services_vec, single) => {
let device = self.Device(); let device = self.Device();
if single { if single {
promise.resolve_native(&device.get_or_create_service(&services_vec[0], self)); promise.resolve_native(&device.get_or_create_service(
&services_vec[0],
self,
can_gc,
));
return; return;
} }
let mut services = vec![]; let mut services = vec![];
for service in services_vec { for service in services_vec {
let bt_service = device.get_or_create_service(&service, self); let bt_service = device.get_or_create_service(&service, self, can_gc);
services.push(bt_service); services.push(bt_service);
} }
promise.resolve_native(&services); promise.resolve_native(&services);

View file

@ -165,22 +165,24 @@ impl BluetoothRemoteGATTServiceMethods<crate::DomTypeHolder> for BluetoothRemote
} }
impl AsyncBluetoothListener for BluetoothRemoteGATTService { impl AsyncBluetoothListener for BluetoothRemoteGATTService {
fn handle_response(&self, response: BluetoothResponse, promise: &Rc<Promise>, _can_gc: CanGc) { fn handle_response(&self, response: BluetoothResponse, promise: &Rc<Promise>, can_gc: CanGc) {
let device = self.Device(); let device = self.Device();
match response { match response {
// https://webbluetoothcg.github.io/web-bluetooth/#getgattchildren // https://webbluetoothcg.github.io/web-bluetooth/#getgattchildren
// Step 7. // Step 7.
BluetoothResponse::GetCharacteristics(characteristics_vec, single) => { BluetoothResponse::GetCharacteristics(characteristics_vec, single) => {
if single { if single {
promise.resolve_native( promise.resolve_native(&device.get_or_create_characteristic(
&device.get_or_create_characteristic(&characteristics_vec[0], self), &characteristics_vec[0],
); self,
can_gc,
));
return; return;
} }
let mut characteristics = vec![]; let mut characteristics = vec![];
for characteristic in characteristics_vec { for characteristic in characteristics_vec {
let bt_characteristic = let bt_characteristic =
device.get_or_create_characteristic(&characteristic, self); device.get_or_create_characteristic(&characteristic, self, can_gc);
characteristics.push(bt_characteristic); characteristics.push(bt_characteristic);
} }
promise.resolve_native(&characteristics); promise.resolve_native(&characteristics);
@ -189,13 +191,16 @@ impl AsyncBluetoothListener for BluetoothRemoteGATTService {
// Step 7. // Step 7.
BluetoothResponse::GetIncludedServices(services_vec, single) => { BluetoothResponse::GetIncludedServices(services_vec, single) => {
if single { if single {
return promise.resolve_native( return promise.resolve_native(&device.get_or_create_service(
&device.get_or_create_service(&services_vec[0], &device.get_gatt()), &services_vec[0],
); &device.get_gatt(),
can_gc,
));
} }
let mut services = vec![]; let mut services = vec![];
for service in services_vec { for service in services_vec {
let bt_service = device.get_or_create_service(&service, &device.get_gatt()); let bt_service =
device.get_or_create_service(&service, &device.get_gatt(), can_gc);
services.push(bt_service); services.push(bt_service);
} }
promise.resolve_native(&services); promise.resolve_native(&services);

View file

@ -2937,7 +2937,7 @@ impl Document {
.unwrap(); .unwrap();
scripts.swap_remove(idx); scripts.swap_remove(idx);
} }
element.execute(result); element.execute(result, CanGc::note());
} }
// https://html.spec.whatwg.org/multipage/#list-of-scripts-that-will-execute-in-order-as-soon-as-possible // https://html.spec.whatwg.org/multipage/#list-of-scripts-that-will-execute-in-order-as-soon-as-possible
@ -2957,7 +2957,7 @@ impl Document {
.asap_in_order_scripts_list .asap_in_order_scripts_list
.take_next_ready_to_be_executed() .take_next_ready_to_be_executed()
{ {
element.execute(result); element.execute(result, CanGc::note());
} }
} }
@ -2985,7 +2985,7 @@ impl Document {
} }
if let Some((element, result)) = self.deferred_scripts.take_next_ready_to_be_executed() if let Some((element, result)) = self.deferred_scripts.take_next_ready_to_be_executed()
{ {
element.execute(result); element.execute(result, CanGc::note());
} else { } else {
break; break;
} }

View file

@ -36,6 +36,7 @@ impl GainNode {
window: &Window, window: &Window,
context: &BaseAudioContext, context: &BaseAudioContext,
options: &GainOptions, options: &GainOptions,
can_gc: CanGc,
) -> Fallible<GainNode> { ) -> Fallible<GainNode> {
let node_options = let node_options =
options options
@ -58,7 +59,7 @@ impl GainNode {
*options.gain, // default value *options.gain, // default value
f32::MIN, // min value f32::MIN, // min value
f32::MAX, // max value f32::MAX, // max value
CanGc::note(), can_gc,
); );
Ok(GainNode { Ok(GainNode {
node, node,
@ -83,7 +84,7 @@ impl GainNode {
options: &GainOptions, options: &GainOptions,
can_gc: CanGc, can_gc: CanGc,
) -> Fallible<DomRoot<GainNode>> { ) -> Fallible<DomRoot<GainNode>> {
let node = GainNode::new_inherited(window, context, options)?; let node = GainNode::new_inherited(window, context, options, can_gc)?;
Ok(reflect_dom_object_with_proto( Ok(reflect_dom_object_with_proto(
Box::new(node), Box::new(node),
window, window,

View file

@ -317,7 +317,7 @@ impl Activatable for HTMLAnchorElement {
} }
//https://html.spec.whatwg.org/multipage/#the-a-element:activation-behaviour //https://html.spec.whatwg.org/multipage/#the-a-element:activation-behaviour
fn activation_behavior(&self, event: &Event, target: &EventTarget, _can_gc: CanGc) { fn activation_behavior(&self, event: &Event, target: &EventTarget, can_gc: CanGc) {
let element = self.as_element(); let element = self.as_element();
let mouse_event = event.downcast::<MouseEvent>().unwrap(); let mouse_event = event.downcast::<MouseEvent>().unwrap();
let mut ismap_suffix = None; let mut ismap_suffix = None;
@ -327,7 +327,7 @@ impl Activatable for HTMLAnchorElement {
if let Some(element) = target.downcast::<Element>() { if let Some(element) = target.downcast::<Element>() {
if target.is::<HTMLImageElement>() && element.has_attribute(&local_name!("ismap")) { if target.is::<HTMLImageElement>() && element.has_attribute(&local_name!("ismap")) {
let target_node = element.upcast::<Node>(); let target_node = element.upcast::<Node>();
let rect = target_node.bounding_content_box_or_zero(CanGc::note()); let rect = target_node.bounding_content_box_or_zero(can_gc);
ismap_suffix = Some(format!( ismap_suffix = Some(format!(
"?{},{}", "?{},{}",
mouse_event.ClientX().to_f32().unwrap() - rect.origin.x.to_f32_px(), mouse_event.ClientX().to_f32().unwrap() - rect.origin.x.to_f32_px(),

View file

@ -860,7 +860,7 @@ impl HTMLScriptElement {
doc.set_pending_parsing_blocking_script(self, Some(result)); doc.set_pending_parsing_blocking_script(self, Some(result));
} else { } else {
// Step 27.i: otherwise. // Step 27.i: otherwise.
self.execute(result); self.execute(result, can_gc);
} }
}, },
ScriptType::Module => { ScriptType::Module => {
@ -917,7 +917,7 @@ impl HTMLScriptElement {
} }
/// <https://html.spec.whatwg.org/multipage/#execute-the-script-block> /// <https://html.spec.whatwg.org/multipage/#execute-the-script-block>
pub(crate) fn execute(&self, result: ScriptResult) { pub(crate) fn execute(&self, result: ScriptResult, can_gc: CanGc) {
// Step 1. // Step 1.
let doc = self.owner_document(); let doc = self.owner_document();
if self.parser_inserted.get() && *doc != *self.parser_document { if self.parser_inserted.get() && *doc != *self.parser_document {
@ -928,7 +928,7 @@ impl HTMLScriptElement {
// Step 2. // Step 2.
Err(e) => { Err(e) => {
warn!("error loading script {:?}", e); warn!("error loading script {:?}", e);
self.dispatch_error_event(CanGc::note()); self.dispatch_error_event(can_gc);
return; return;
}, },
@ -967,12 +967,12 @@ impl HTMLScriptElement {
match script.type_ { match script.type_ {
ScriptType::Classic => { ScriptType::Classic => {
self.run_a_classic_script(&script, CanGc::note()); self.run_a_classic_script(&script, can_gc);
document.set_current_script(old_script.as_deref()); document.set_current_script(old_script.as_deref());
}, },
ScriptType::Module => { ScriptType::Module => {
assert!(document.GetCurrentScript().is_none()); assert!(document.GetCurrentScript().is_none());
self.run_a_module_script(&script, false, CanGc::note()); self.run_a_module_script(&script, false, can_gc);
}, },
} }
@ -983,7 +983,7 @@ impl HTMLScriptElement {
// Step 6. // Step 6.
if script.external { if script.external {
self.dispatch_load_event(CanGc::note()); self.dispatch_load_event(can_gc);
} }
} }

View file

@ -23,8 +23,12 @@ pub(crate) struct RTCRtpTransceiver {
} }
impl RTCRtpTransceiver { impl RTCRtpTransceiver {
fn new_inherited(global: &GlobalScope, direction: RTCRtpTransceiverDirection) -> Self { fn new_inherited(
let sender = RTCRtpSender::new(global, CanGc::note()); global: &GlobalScope,
direction: RTCRtpTransceiverDirection,
can_gc: CanGc,
) -> Self {
let sender = RTCRtpSender::new(global, can_gc);
Self { Self {
reflector_: Reflector::new(), reflector_: Reflector::new(),
direction: Cell::new(direction), direction: Cell::new(direction),
@ -38,7 +42,7 @@ impl RTCRtpTransceiver {
can_gc: CanGc, can_gc: CanGc,
) -> DomRoot<Self> { ) -> DomRoot<Self> {
reflect_dom_object( reflect_dom_object(
Box::new(Self::new_inherited(global, direction)), Box::new(Self::new_inherited(global, direction, can_gc)),
global, global,
can_gc, can_gc,
) )

View file

@ -332,7 +332,7 @@ impl ServoParser {
assert_eq!(script_nesting_level, 0); assert_eq!(script_nesting_level, 0);
self.script_nesting_level.set(script_nesting_level + 1); self.script_nesting_level.set(script_nesting_level + 1);
script.execute(result); script.execute(result, can_gc);
self.script_nesting_level.set(script_nesting_level); self.script_nesting_level.set(script_nesting_level);
if !self.suspended.get() && !self.aborted.get() { if !self.suspended.get() && !self.aborted.get() {