refactor: add CanGc as argument to Promise::resolve (#35616)

Signed-off-by: Yerkebulan Tulibergenov <yerkebulan@gmail.com>
This commit is contained in:
Yerkebulan Tulibergenov 2025-02-23 04:12:21 -08:00 committed by GitHub
parent adb831eefe
commit 0383ba9a5b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
57 changed files with 330 additions and 294 deletions

View file

@ -589,7 +589,7 @@ impl AsyncBluetoothListener for Bluetooth {
BluetoothResponse::RequestDevice(device) => {
let mut device_instance_map = self.device_instance_map.borrow_mut();
if let Some(existing_device) = device_instance_map.get(&device.id.clone()) {
return promise.resolve_native(&**existing_device);
return promise.resolve_native(&**existing_device, can_gc);
}
let bt_device = BluetoothDevice::new(
&self.global(),
@ -609,12 +609,12 @@ impl AsyncBluetoothListener for Bluetooth {
});
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetooth-requestdevice
// Step 5.
promise.resolve_native(&bt_device);
promise.resolve_native(&bt_device, can_gc);
},
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetooth-getavailability
// Step 2 - 3.
BluetoothResponse::GetAvailability(is_available) => {
promise.resolve_native(&is_available);
promise.resolve_native(&is_available, can_gc);
},
_ => promise.reject_error(Error::Type("Something went wrong...".to_owned())),
}
@ -655,7 +655,7 @@ impl PermissionAlgorithm for Bluetooth {
// Step 3.
if let PermissionState::Denied = status.get_state() {
status.set_devices(Vec::new());
return promise.resolve_native(status);
return promise.resolve_native(status, CanGc::note());
}
// Step 4.
@ -727,7 +727,7 @@ impl PermissionAlgorithm for Bluetooth {
// https://w3c.github.io/permissions/#dom-permissions-query
// Step 7.
promise.resolve_native(status);
promise.resolve_native(status, CanGc::note());
}
// https://webbluetoothcg.github.io/web-bluetooth/#request-the-bluetooth-permission

View file

@ -327,14 +327,14 @@ impl BluetoothDeviceMethods<crate::DomTypeHolder> for BluetoothDevice {
}
impl AsyncBluetoothListener for BluetoothDevice {
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-bluetoothdevice-unwatchadvertisements
BluetoothResponse::WatchAdvertisements(_result) => {
// Step 3.1.
self.watching_advertisements.set(true);
// Step 3.2.
promise.resolve_native(&());
promise.resolve_native(&(), can_gc);
},
_ => promise.reject_error(Error::Type("Something went wrong...".to_owned())),
}

View file

@ -112,7 +112,7 @@ impl AsyncBluetoothListener for BluetoothPermissionResult {
// https://w3c.github.io/permissions/#dom-permissions-request
// Step 8.
return promise.resolve_native(self);
return promise.resolve_native(self, can_gc);
}
let bt_device = BluetoothDevice::new(
&self.global(),
@ -135,7 +135,7 @@ impl AsyncBluetoothListener for BluetoothPermissionResult {
// https://w3c.github.io/permissions/#dom-permissions-request
// Step 8.
promise.resolve_native(self);
promise.resolve_native(self, can_gc);
},
_ => promise.reject_error(Error::Type("Something went wrong...".to_owned())),
}

View file

@ -309,11 +309,10 @@ 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),
can_gc,
));
);
return;
}
let mut descriptors = vec![];
@ -321,7 +320,7 @@ impl AsyncBluetoothListener for BluetoothRemoteGATTCharacteristic {
let bt_descriptor = device.get_or_create_descriptor(&descriptor, self, can_gc);
descriptors.push(bt_descriptor);
}
promise.resolve_native(&descriptors);
promise.resolve_native(&descriptors, can_gc);
},
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-readvalue
BluetoothResponse::ReadValue(result) => {
@ -337,7 +336,7 @@ impl AsyncBluetoothListener for BluetoothRemoteGATTCharacteristic {
.fire_bubbling_event(atom!("characteristicvaluechanged"), can_gc);
// Step 5.5.4.
promise.resolve_native(&value);
promise.resolve_native(&value, can_gc);
},
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-writevalue
BluetoothResponse::WriteValue(result) => {
@ -348,7 +347,7 @@ impl AsyncBluetoothListener for BluetoothRemoteGATTCharacteristic {
*self.value.borrow_mut() = Some(ByteString::new(result));
// Step 7.5.3.
promise.resolve_native(&());
promise.resolve_native(&(), can_gc);
},
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-startnotifications
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattcharacteristic-stopnotifications
@ -358,7 +357,7 @@ impl AsyncBluetoothListener for BluetoothRemoteGATTCharacteristic {
// (StartNotification) Step 11.
// (StopNotification) Step 5.
promise.resolve_native(self);
promise.resolve_native(self, can_gc);
},
_ => promise.reject_error(Error::Type("Something went wrong...".to_owned())),
}

View file

@ -181,7 +181,7 @@ impl BluetoothRemoteGATTDescriptorMethods<crate::DomTypeHolder> for BluetoothRem
}
impl AsyncBluetoothListener for BluetoothRemoteGATTDescriptor {
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-bluetoothremotegattdescriptor-readvalue
BluetoothResponse::ReadValue(result) => {
@ -193,7 +193,7 @@ impl AsyncBluetoothListener for BluetoothRemoteGATTDescriptor {
*self.value.borrow_mut() = Some(value.clone());
// Step 5.4.3.
promise.resolve_native(&value);
promise.resolve_native(&value, can_gc);
},
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattdescriptor-writevalue
BluetoothResponse::WriteValue(result) => {
@ -205,7 +205,7 @@ impl AsyncBluetoothListener for BluetoothRemoteGATTDescriptor {
// Step 7.4.3.
// TODO: Resolve promise with undefined instead of a value.
promise.resolve_native(&());
promise.resolve_native(&(), can_gc);
},
_ => promise.reject_error(Error::Type("Something went wrong...".to_owned())),
}

View file

@ -164,18 +164,17 @@ impl AsyncBluetoothListener for BluetoothRemoteGATTServer {
self.connected.set(connected);
// Step 5.2.5.
promise.resolve_native(self);
promise.resolve_native(self, can_gc);
},
// https://webbluetoothcg.github.io/web-bluetooth/#getgattchildren
// Step 7.
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),
can_gc,
));
);
return;
}
let mut services = vec![];
@ -183,7 +182,7 @@ impl AsyncBluetoothListener for BluetoothRemoteGATTServer {
let bt_service = device.get_or_create_service(&service, self, can_gc);
services.push(bt_service);
}
promise.resolve_native(&services);
promise.resolve_native(&services, can_gc);
},
_ => promise.reject_error(Error::Type("Something went wrong...".to_owned())),
}

View file

@ -172,11 +172,10 @@ impl AsyncBluetoothListener for BluetoothRemoteGATTService {
// 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),
can_gc,
));
);
return;
}
let mut characteristics = vec![];
@ -185,17 +184,16 @@ impl AsyncBluetoothListener for BluetoothRemoteGATTService {
device.get_or_create_characteristic(&characteristic, self, can_gc);
characteristics.push(bt_characteristic);
}
promise.resolve_native(&characteristics);
promise.resolve_native(&characteristics, can_gc);
},
// https://webbluetoothcg.github.io/web-bluetooth/#getgattchildren
// 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),
can_gc,
));
);
}
let mut services = vec![];
for service in services_vec {
@ -203,7 +201,7 @@ impl AsyncBluetoothListener for BluetoothRemoteGATTService {
device.get_or_create_service(&service, &device.get_gatt(), can_gc);
services.push(bt_service);
}
promise.resolve_native(&services);
promise.resolve_native(&services, can_gc);
},
_ => promise.reject_error(Error::Type("Something went wrong...".to_owned())),
}