mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
refactor: add CanGc as argument to Promise::reject_error (#35646)
Signed-off-by: Yerkebulan Tulibergenov <yerkebulan@gmail.com>
This commit is contained in:
parent
c844ed232a
commit
38b71087bd
43 changed files with 323 additions and 249 deletions
|
@ -131,7 +131,7 @@ where
|
|||
.handle_response(response, &promise, can_gc),
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetooth-requestdevice
|
||||
// Step 3 - 4.
|
||||
Err(error) => promise.reject_error(error.convert()),
|
||||
Err(error) => promise.reject_error(error.convert(), can_gc),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -170,6 +170,7 @@ impl Bluetooth {
|
|||
filters: &Option<Vec<BluetoothLEScanFilterInit>>,
|
||||
optional_services: &[BluetoothServiceUUID],
|
||||
sender: IpcSender<BluetoothResponseResult>,
|
||||
can_gc: CanGc,
|
||||
) {
|
||||
// TODO: Step 1: Triggered by user activation.
|
||||
|
||||
|
@ -179,7 +180,7 @@ impl Bluetooth {
|
|||
if let Some(filters) = filters {
|
||||
// Step 2.1.
|
||||
if filters.is_empty() {
|
||||
p.reject_error(Type(FILTER_EMPTY_ERROR.to_owned()));
|
||||
p.reject_error(Type(FILTER_EMPTY_ERROR.to_owned()), can_gc);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -192,7 +193,7 @@ impl Bluetooth {
|
|||
// Step 2.4.2.
|
||||
Ok(f) => uuid_filters.push(f),
|
||||
Err(e) => {
|
||||
p.reject_error(e);
|
||||
p.reject_error(e, can_gc);
|
||||
return;
|
||||
},
|
||||
}
|
||||
|
@ -206,7 +207,7 @@ impl Bluetooth {
|
|||
let uuid = match BluetoothUUID::service(opt_service.clone()) {
|
||||
Ok(u) => u.to_string(),
|
||||
Err(e) => {
|
||||
p.reject_error(e);
|
||||
p.reject_error(e, can_gc);
|
||||
return;
|
||||
},
|
||||
};
|
||||
|
@ -229,7 +230,7 @@ impl Bluetooth {
|
|||
if let PermissionState::Denied =
|
||||
descriptor_permission_state(PermissionName::Bluetooth, None)
|
||||
{
|
||||
return p.reject_error(Error::NotFound);
|
||||
return p.reject_error(Error::NotFound, can_gc);
|
||||
}
|
||||
|
||||
// Note: Step 3, 6 - 8 are implemented in
|
||||
|
@ -307,13 +308,13 @@ where
|
|||
let canonicalized = match uuid_canonicalizer(u) {
|
||||
Ok(canonicalized_uuid) => canonicalized_uuid.to_string(),
|
||||
Err(e) => {
|
||||
p.reject_error(e);
|
||||
p.reject_error(e, can_gc);
|
||||
return p;
|
||||
},
|
||||
};
|
||||
// Step 2.
|
||||
if uuid_is_blocklisted(canonicalized.as_ref(), Blocklist::All) {
|
||||
p.reject_error(Security);
|
||||
p.reject_error(Security, can_gc);
|
||||
return p;
|
||||
}
|
||||
Some(canonicalized)
|
||||
|
@ -323,7 +324,7 @@ where
|
|||
|
||||
// Step 3 - 4.
|
||||
if !connected {
|
||||
p.reject_error(Network);
|
||||
p.reject_error(Network, can_gc);
|
||||
return p;
|
||||
}
|
||||
|
||||
|
@ -550,13 +551,19 @@ impl BluetoothMethods<crate::DomTypeHolder> for Bluetooth {
|
|||
if (option.filters.is_some() && option.acceptAllDevices) ||
|
||||
(option.filters.is_none() && !option.acceptAllDevices)
|
||||
{
|
||||
p.reject_error(Error::Type(OPTIONS_ERROR.to_owned()));
|
||||
p.reject_error(Error::Type(OPTIONS_ERROR.to_owned()), can_gc);
|
||||
return p;
|
||||
}
|
||||
|
||||
// Step 2.
|
||||
let sender = response_async(&p, self);
|
||||
self.request_bluetooth_devices(&p, &option.filters, &option.optionalServices, sender);
|
||||
self.request_bluetooth_devices(
|
||||
&p,
|
||||
&option.filters,
|
||||
&option.optionalServices,
|
||||
sender,
|
||||
can_gc,
|
||||
);
|
||||
//Note: Step 3 - 4. in response function, Step 5. in handle_response function.
|
||||
p
|
||||
}
|
||||
|
@ -616,7 +623,7 @@ impl AsyncBluetoothListener for Bluetooth {
|
|||
BluetoothResponse::GetAvailability(is_available) => {
|
||||
promise.resolve_native(&is_available, can_gc);
|
||||
},
|
||||
_ => promise.reject_error(Error::Type("Something went wrong...".to_owned())),
|
||||
_ => promise.reject_error(Error::Type("Something went wrong...".to_owned()), can_gc),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -689,7 +696,7 @@ impl PermissionAlgorithm for Bluetooth {
|
|||
for filter in filters {
|
||||
match canonicalize_filter(filter) {
|
||||
Ok(f) => scan_filters.push(f),
|
||||
Err(error) => return promise.reject_error(error),
|
||||
Err(error) => return promise.reject_error(error, CanGc::note()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -710,7 +717,7 @@ impl PermissionAlgorithm for Bluetooth {
|
|||
match receiver.recv().unwrap() {
|
||||
Ok(true) => (),
|
||||
Ok(false) => continue,
|
||||
Err(error) => return promise.reject_error(error.convert()),
|
||||
Err(error) => return promise.reject_error(error.convert(), CanGc::note()),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -739,7 +746,7 @@ impl PermissionAlgorithm for Bluetooth {
|
|||
) {
|
||||
// Step 1.
|
||||
if descriptor.filters.is_some() == descriptor.acceptAllDevices {
|
||||
return promise.reject_error(Error::Type(OPTIONS_ERROR.to_owned()));
|
||||
return promise.reject_error(Error::Type(OPTIONS_ERROR.to_owned()), CanGc::note());
|
||||
}
|
||||
|
||||
// Step 2.
|
||||
|
@ -750,6 +757,7 @@ impl PermissionAlgorithm for Bluetooth {
|
|||
&descriptor.filters,
|
||||
&descriptor.optionalServices,
|
||||
sender,
|
||||
CanGc::note(),
|
||||
);
|
||||
|
||||
// NOTE: Step 3. is in BluetoothPermissionResult's `handle_response` function.
|
||||
|
|
|
@ -336,7 +336,7 @@ impl AsyncBluetoothListener for BluetoothDevice {
|
|||
// Step 3.2.
|
||||
promise.resolve_native(&(), can_gc);
|
||||
},
|
||||
_ => promise.reject_error(Error::Type("Something went wrong...".to_owned())),
|
||||
_ => promise.reject_error(Error::Type("Something went wrong...".to_owned()), can_gc),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -137,7 +137,7 @@ impl AsyncBluetoothListener for BluetoothPermissionResult {
|
|||
// Step 8.
|
||||
promise.resolve_native(self, can_gc);
|
||||
},
|
||||
_ => promise.reject_error(Error::Type("Something went wrong...".to_owned())),
|
||||
_ => promise.reject_error(Error::Type("Something went wrong...".to_owned()), can_gc),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -154,13 +154,13 @@ impl BluetoothRemoteGATTCharacteristicMethods<crate::DomTypeHolder>
|
|||
|
||||
// Step 1.
|
||||
if uuid_is_blocklisted(self.uuid.as_ref(), Blocklist::Reads) {
|
||||
p.reject_error(Security);
|
||||
p.reject_error(Security, can_gc);
|
||||
return p;
|
||||
}
|
||||
|
||||
// Step 2.
|
||||
if !self.Service().Device().get_gatt().Connected() {
|
||||
p.reject_error(Network);
|
||||
p.reject_error(Network, can_gc);
|
||||
return p;
|
||||
}
|
||||
|
||||
|
@ -168,7 +168,7 @@ impl BluetoothRemoteGATTCharacteristicMethods<crate::DomTypeHolder>
|
|||
|
||||
// Step 5.1.
|
||||
if !self.Properties().Read() {
|
||||
p.reject_error(NotSupported);
|
||||
p.reject_error(NotSupported, can_gc);
|
||||
return p;
|
||||
}
|
||||
|
||||
|
@ -192,7 +192,7 @@ impl BluetoothRemoteGATTCharacteristicMethods<crate::DomTypeHolder>
|
|||
|
||||
// Step 1.
|
||||
if uuid_is_blocklisted(self.uuid.as_ref(), Blocklist::Writes) {
|
||||
p.reject_error(Security);
|
||||
p.reject_error(Security, can_gc);
|
||||
return p;
|
||||
}
|
||||
|
||||
|
@ -203,13 +203,13 @@ impl BluetoothRemoteGATTCharacteristicMethods<crate::DomTypeHolder>
|
|||
};
|
||||
|
||||
if vec.len() > MAXIMUM_ATTRIBUTE_LENGTH {
|
||||
p.reject_error(InvalidModification);
|
||||
p.reject_error(InvalidModification, can_gc);
|
||||
return p;
|
||||
}
|
||||
|
||||
// Step 4.
|
||||
if !self.Service().Device().get_gatt().Connected() {
|
||||
p.reject_error(Network);
|
||||
p.reject_error(Network, can_gc);
|
||||
return p;
|
||||
}
|
||||
|
||||
|
@ -220,7 +220,7 @@ impl BluetoothRemoteGATTCharacteristicMethods<crate::DomTypeHolder>
|
|||
self.Properties().WriteWithoutResponse() ||
|
||||
self.Properties().AuthenticatedSignedWrites())
|
||||
{
|
||||
p.reject_error(NotSupported);
|
||||
p.reject_error(NotSupported, can_gc);
|
||||
return p;
|
||||
}
|
||||
|
||||
|
@ -243,19 +243,19 @@ impl BluetoothRemoteGATTCharacteristicMethods<crate::DomTypeHolder>
|
|||
|
||||
// Step 1.
|
||||
if uuid_is_blocklisted(self.uuid.as_ref(), Blocklist::Reads) {
|
||||
p.reject_error(Security);
|
||||
p.reject_error(Security, can_gc);
|
||||
return p;
|
||||
}
|
||||
|
||||
// Step 2.
|
||||
if !self.Service().Device().get_gatt().Connected() {
|
||||
p.reject_error(Network);
|
||||
p.reject_error(Network, can_gc);
|
||||
return p;
|
||||
}
|
||||
|
||||
// Step 5.
|
||||
if !(self.Properties().Notify() || self.Properties().Indicate()) {
|
||||
p.reject_error(NotSupported);
|
||||
p.reject_error(NotSupported, can_gc);
|
||||
return p;
|
||||
}
|
||||
|
||||
|
@ -359,7 +359,7 @@ impl AsyncBluetoothListener for BluetoothRemoteGATTCharacteristic {
|
|||
// (StopNotification) Step 5.
|
||||
promise.resolve_native(self, can_gc);
|
||||
},
|
||||
_ => promise.reject_error(Error::Type("Something went wrong...".to_owned())),
|
||||
_ => promise.reject_error(Error::Type("Something went wrong...".to_owned()), can_gc),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,7 +102,7 @@ impl BluetoothRemoteGATTDescriptorMethods<crate::DomTypeHolder> for BluetoothRem
|
|||
|
||||
// Step 1.
|
||||
if uuid_is_blocklisted(self.uuid.as_ref(), Blocklist::Reads) {
|
||||
p.reject_error(Security);
|
||||
p.reject_error(Security, can_gc);
|
||||
return p;
|
||||
}
|
||||
|
||||
|
@ -114,7 +114,7 @@ impl BluetoothRemoteGATTDescriptorMethods<crate::DomTypeHolder> for BluetoothRem
|
|||
.get_gatt()
|
||||
.Connected()
|
||||
{
|
||||
p.reject_error(Network);
|
||||
p.reject_error(Network, can_gc);
|
||||
return p;
|
||||
}
|
||||
|
||||
|
@ -139,7 +139,7 @@ impl BluetoothRemoteGATTDescriptorMethods<crate::DomTypeHolder> for BluetoothRem
|
|||
|
||||
// Step 1.
|
||||
if uuid_is_blocklisted(self.uuid.as_ref(), Blocklist::Writes) {
|
||||
p.reject_error(Security);
|
||||
p.reject_error(Security, can_gc);
|
||||
return p;
|
||||
}
|
||||
|
||||
|
@ -149,7 +149,7 @@ impl BluetoothRemoteGATTDescriptorMethods<crate::DomTypeHolder> for BluetoothRem
|
|||
ArrayBufferViewOrArrayBuffer::ArrayBuffer(ab) => ab.to_vec(),
|
||||
};
|
||||
if vec.len() > MAXIMUM_ATTRIBUTE_LENGTH {
|
||||
p.reject_error(InvalidModification);
|
||||
p.reject_error(InvalidModification, can_gc);
|
||||
return p;
|
||||
}
|
||||
|
||||
|
@ -161,7 +161,7 @@ impl BluetoothRemoteGATTDescriptorMethods<crate::DomTypeHolder> for BluetoothRem
|
|||
.get_gatt()
|
||||
.Connected()
|
||||
{
|
||||
p.reject_error(Network);
|
||||
p.reject_error(Network, can_gc);
|
||||
return p;
|
||||
}
|
||||
|
||||
|
@ -207,7 +207,7 @@ impl AsyncBluetoothListener for BluetoothRemoteGATTDescriptor {
|
|||
// TODO: Resolve promise with undefined instead of a value.
|
||||
promise.resolve_native(&(), can_gc);
|
||||
},
|
||||
_ => promise.reject_error(Error::Type("Something went wrong...".to_owned())),
|
||||
_ => promise.reject_error(Error::Type("Something went wrong...".to_owned()), can_gc),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -155,9 +155,9 @@ impl AsyncBluetoothListener for BluetoothRemoteGATTServer {
|
|||
// Step 5.2.3
|
||||
if self.Device().is_represented_device_null() {
|
||||
if let Err(e) = self.Device().garbage_collect_the_connection() {
|
||||
return promise.reject_error(e);
|
||||
return promise.reject_error(e, can_gc);
|
||||
}
|
||||
return promise.reject_error(Error::Network);
|
||||
return promise.reject_error(Error::Network, can_gc);
|
||||
}
|
||||
|
||||
// Step 5.2.4.
|
||||
|
@ -184,7 +184,7 @@ impl AsyncBluetoothListener for BluetoothRemoteGATTServer {
|
|||
}
|
||||
promise.resolve_native(&services, can_gc);
|
||||
},
|
||||
_ => promise.reject_error(Error::Type("Something went wrong...".to_owned())),
|
||||
_ => promise.reject_error(Error::Type("Something went wrong...".to_owned()), can_gc),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -203,7 +203,7 @@ impl AsyncBluetoothListener for BluetoothRemoteGATTService {
|
|||
}
|
||||
promise.resolve_native(&services, can_gc);
|
||||
},
|
||||
_ => promise.reject_error(Error::Type("Something went wrong...".to_owned())),
|
||||
_ => promise.reject_error(Error::Type("Something went wrong...".to_owned()), can_gc),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue