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

View file

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

View file

@ -309,14 +309,16 @@ impl AsyncBluetoothListener for BluetoothRemoteGATTCharacteristic {
// Step 7.
BluetoothResponse::GetDescriptors(descriptors_vec, single) => {
if single {
promise.resolve_native(
&device.get_or_create_descriptor(&descriptors_vec[0], self),
);
promise.resolve_native(&device.get_or_create_descriptor(
&descriptors_vec[0],
self,
can_gc,
));
return;
}
let mut 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);
}
promise.resolve_native(&descriptors);

View file

@ -148,7 +148,7 @@ impl BluetoothRemoteGATTServerMethods<crate::DomTypeHolder> for BluetoothRemoteG
}
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 {
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-connect
BluetoothResponse::GATTServerConnect(connected) => {
@ -171,12 +171,16 @@ impl AsyncBluetoothListener for BluetoothRemoteGATTServer {
BluetoothResponse::GetPrimaryServices(services_vec, single) => {
let device = self.Device();
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;
}
let mut 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);
}
promise.resolve_native(&services);

View file

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

View file

@ -2937,7 +2937,7 @@ impl Document {
.unwrap();
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
@ -2957,7 +2957,7 @@ impl Document {
.asap_in_order_scripts_list
.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()
{
element.execute(result);
element.execute(result, CanGc::note());
} else {
break;
}

View file

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

View file

@ -317,7 +317,7 @@ impl Activatable for HTMLAnchorElement {
}
//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 mouse_event = event.downcast::<MouseEvent>().unwrap();
let mut ismap_suffix = None;
@ -327,7 +327,7 @@ impl Activatable for HTMLAnchorElement {
if let Some(element) = target.downcast::<Element>() {
if target.is::<HTMLImageElement>() && element.has_attribute(&local_name!("ismap")) {
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!(
"?{},{}",
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));
} else {
// Step 27.i: otherwise.
self.execute(result);
self.execute(result, can_gc);
}
},
ScriptType::Module => {
@ -917,7 +917,7 @@ impl HTMLScriptElement {
}
/// <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.
let doc = self.owner_document();
if self.parser_inserted.get() && *doc != *self.parser_document {
@ -928,7 +928,7 @@ impl HTMLScriptElement {
// Step 2.
Err(e) => {
warn!("error loading script {:?}", e);
self.dispatch_error_event(CanGc::note());
self.dispatch_error_event(can_gc);
return;
},
@ -967,12 +967,12 @@ impl HTMLScriptElement {
match script.type_ {
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());
},
ScriptType::Module => {
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.
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 {
fn new_inherited(global: &GlobalScope, direction: RTCRtpTransceiverDirection) -> Self {
let sender = RTCRtpSender::new(global, CanGc::note());
fn new_inherited(
global: &GlobalScope,
direction: RTCRtpTransceiverDirection,
can_gc: CanGc,
) -> Self {
let sender = RTCRtpSender::new(global, can_gc);
Self {
reflector_: Reflector::new(),
direction: Cell::new(direction),
@ -38,7 +42,7 @@ impl RTCRtpTransceiver {
can_gc: CanGc,
) -> DomRoot<Self> {
reflect_dom_object(
Box::new(Self::new_inherited(global, direction)),
Box::new(Self::new_inherited(global, direction, can_gc)),
global,
can_gc,
)

View file

@ -332,7 +332,7 @@ impl ServoParser {
assert_eq!(script_nesting_level, 0);
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);
if !self.suspended.get() && !self.aborted.get() {