mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-18 06:45:33 +00:00
servo: Merge #14429 - Replace Syntax with TypeError in bluetoothuuid.rs (from szeged:syntax-to-type-error); r=jdm
<!-- Please describe your changes on the following line: --> 1. Replacing `SyntaxError` with `TypeError` in `bluetoothuuid.rs` due to the specification change. This indicates changes in the existing tests. The error strings are from the chromium implementation. 2. We missed out a `$` character from the end of the `VALID_UUID_REGEX` global variable. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors <!-- Either: --> - [x] There are tests for these changes OR <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: b54cfc9f259e72ea26e68ec8a7b1d617cf0812d3
This commit is contained in:
parent
c2fe6c7932
commit
bdf073c6ea
@ -99,7 +99,7 @@ const SERIAL_NUMBER_STRING_UUID: &'static str = "00002a25-0000-1000-8000-00805f9
|
||||
|
||||
// Descriptor UUIDs
|
||||
const BLOCKLIST_EXCLUDE_READS_DESCRIPTOR_UUID: &'static str = "aaaaaaaa-aaaa-1181-0510-810819516110";
|
||||
const BLOCKLIST_DESCRIPTOR_UUID: &'static str = "07711111-6104-0970-7011-1107105110aaa";
|
||||
const BLOCKLIST_DESCRIPTOR_UUID: &'static str = "07711111-6104-0970-7011-1107105110aa";
|
||||
// https://www.bluetooth.com/specifications/gatt/
|
||||
// viewer?attributeXmlFile=org.bluetooth.descriptor.gatt.characteristic_user_description.xml
|
||||
const CHARACTERISTIC_USER_DESCRIPTION_UUID: &'static str = "00002901-0000-1000-8000-00805f9b34fb";
|
||||
|
@ -3,7 +3,7 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use dom::bindings::codegen::UnionTypes::StringOrUnsignedLong;
|
||||
use dom::bindings::error::Error::Syntax;
|
||||
use dom::bindings::error::Error::Type;
|
||||
use dom::bindings::error::Fallible;
|
||||
use dom::bindings::reflector::Reflector;
|
||||
use dom::bindings::str::DOMString;
|
||||
@ -267,7 +267,19 @@ const BASE_UUID: &'static str = "-0000-1000-8000-00805f9b34fb";
|
||||
const SERVICE_PREFIX: &'static str = "org.bluetooth.service";
|
||||
const CHARACTERISTIC_PREFIX: &'static str = "org.bluetooth.characteristic";
|
||||
const DESCRIPTOR_PREFIX: &'static str = "org.bluetooth.descriptor";
|
||||
const VALID_UUID_REGEX: &'static str = "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
|
||||
const VALID_UUID_REGEX: &'static str = "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$";
|
||||
// https://cs.chromium.org/chromium/src/third_party/WebKit/Source/modules/bluetooth/BluetoothUUID.cpp?l=314
|
||||
const UUID_ERROR_MESSAGE: &'static str = "It must be a valid UUID alias (e.g. 0x1234), \
|
||||
UUID (lowercase hex characters e.g. '00001234-0000-1000-8000-00805f9b34fb'),\nor recognized standard name from";
|
||||
// https://cs.chromium.org/chromium/src/third_party/WebKit/Source/modules/bluetooth/BluetoothUUID.cpp?l=321
|
||||
const SERVICES_ERROR_MESSAGE: &'static str = "https://developer.bluetooth.org/gatt/services/Pages/ServicesHome.aspx\
|
||||
\ne.g. 'alert_notification'.";
|
||||
// https://cs.chromium.org/chromium/src/third_party/WebKit/Source/modules/bluetooth/BluetoothUUID.cpp?l=327
|
||||
const CHARACTERISTIC_ERROR_MESSAGE: &'static str = "https://developer.bluetooth.org/gatt/characteristics/Pages/\
|
||||
CharacteristicsHome.aspx\ne.g. 'aerobic_heart_rate_lower_limit'.";
|
||||
// https://cs.chromium.org/chromium/src/third_party/WebKit/Source/modules/bluetooth/BluetoothUUID.cpp?l=333
|
||||
const DESCRIPTOR_ERROR_MESSAGE: &'static str = "https://developer.bluetooth.org/gatt/descriptors/Pages/\
|
||||
DescriptorsHomePage.aspx\ne.g. 'gatt.characteristic_presentation_format'.";
|
||||
|
||||
impl BluetoothUUID {
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothuuid-canonicaluuid
|
||||
@ -325,22 +337,35 @@ fn resolve_uuid_name(
|
||||
prefix: &str)
|
||||
-> Fallible<DOMString> {
|
||||
match name {
|
||||
// Step 1
|
||||
// Step 1.
|
||||
StringOrUnsignedLong::UnsignedLong(unsigned32) => {
|
||||
Ok(canonical_uuid(unsigned32))
|
||||
},
|
||||
StringOrUnsignedLong::String(dstring) => {
|
||||
// Step 2
|
||||
// Step 2.
|
||||
let regex = Regex::new(VALID_UUID_REGEX).unwrap();
|
||||
if regex.is_match(&*dstring) {
|
||||
Ok(dstring)
|
||||
} else {
|
||||
// Step 3
|
||||
// Step 3.
|
||||
let concatenated = format!("{}.{}", prefix, dstring);
|
||||
let is_in_table = assigned_numbers_table.iter().find(|p| p.0 == concatenated);
|
||||
match is_in_table {
|
||||
Some(&(_, alias)) => Ok(canonical_uuid(alias)),
|
||||
None => Err(Syntax),
|
||||
None => {
|
||||
let (attribute_type, error_url_message) = match prefix {
|
||||
SERVICE_PREFIX => ("Service", SERVICES_ERROR_MESSAGE),
|
||||
CHARACTERISTIC_PREFIX => ("Characteristic", CHARACTERISTIC_ERROR_MESSAGE),
|
||||
DESCRIPTOR_PREFIX => ("Descriptor", DESCRIPTOR_ERROR_MESSAGE),
|
||||
_ => unreachable!(),
|
||||
};
|
||||
// Step 4.
|
||||
return Err(Type(format!("Invalid {} name : '{}'.\n{} {}",
|
||||
attribute_type,
|
||||
dstring,
|
||||
UUID_ERROR_MESSAGE,
|
||||
error_url_message)));
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -56,7 +56,7 @@ bad1c9a2-9a5b-4015-8b60-1579bbbf2135 exclude-reads
|
||||
00002903-0000-1000-8000-00805f9b34fb exclude-writes
|
||||
|
||||
# Blocklisted descriptor used to test.
|
||||
07711111-6104-0970-7011-1107105110aaa
|
||||
07711111-6104-0970-7011-1107105110aa
|
||||
|
||||
# Blocklisted descriptor used to test.
|
||||
aaaaaaaa-aaaa-1181-0510-810819516110 exclude-reads
|
||||
aaaaaaaa-aaaa-1181-0510-810819516110 exclude-reads
|
||||
|
Loading…
x
Reference in New Issue
Block a user