From e3139c157de13f1fdd08c0101abce4e421051d82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Beaufort?= Date: Tue, 27 Apr 2021 15:15:39 +0200 Subject: [PATCH] Use sequence instead of map for data filters --- index.bs | 182 +++++++++++++++++++++++++++++----------------------- scanning.bs | 2 +- 2 files changed, 103 insertions(+), 81 deletions(-) diff --git a/index.bs b/index.bs index ae87e66..510fd40 100644 --- a/index.bs +++ b/index.bs @@ -519,14 +519,20 @@ that UAs will choose not to prompt. BufferSource mask; }; + dictionary BluetoothManufacturerDataFilterInit : BluetoothDataFilterInit { + required unsigned short companyIdentifier; + }; + + dictionary BluetoothServiceDataFilterInit : BluetoothDataFilterInit { + required BluetoothServiceUUID service; + }; + dictionary BluetoothLEScanFilterInit { sequence services; DOMString name; DOMString namePrefix; - // Maps unsigned shorts to BluetoothDataFilters. - object manufacturerData; - // Maps BluetoothServiceUUIDs to BluetoothDataFilters. - object serviceData; + sequence manufacturerData; + sequence serviceData; }; dictionary RequestDeviceOptions { @@ -585,11 +591,11 @@ device has to: * have a name starting with namePrefix if that member is present, *
advertise manufacturer specific data matching - all of the key/value pairs in manufacturerData if that member is present, and
*
advertise service data matching all of the - key/value pairs in serviceData if that member is present.
@@ -853,7 +859,7 @@ values of filters passed to
-        [{manufacturerData: {17: {}}}]
+[{ manufacturerData: [{ companyIdentifier: 17 }] }]
       
D1 @@ -861,7 +867,7 @@ values of filters passed to
-        [{serviceData: {"A": {}}}]
+[{ serviceData: [{ service: "A" }] }]
       
D2 @@ -869,8 +875,10 @@ values of filters passed to
-        [{manufacturerData: {17: {}}},
-          {serviceData: {"A": {}}}]
+[
+  { manufacturerData: [{ companyIdentifier: 17 }] },
+  { serviceData: [{ service: "A" }] },
+]
       
D1, D2 @@ -878,8 +886,12 @@ values of filters passed to
-        [{manufacturerData: {17: {}},
-          serviceData: {"A": {}}}]
+[
+  {
+    manufacturerData: [{ companyIdentifier: 17 }],
+    serviceData: [{ service: "A" }],
+  },
+]
       
<none> @@ -887,9 +899,13 @@ values of filters passed to
-        [{manufacturerData: {
-            17: {dataPrefix: new Uint8Array([1, 2, 3])},
-        }}]
+[
+  {
+    manufacturerData: [
+      { companyIdentifier: 17, dataPrefix: new Uint8Array([1, 2, 3]) },
+    ],
+  },
+]
       
D1 @@ -897,9 +913,13 @@ values of filters passed to
-        [{manufacturerData: {
-            17: {dataPrefix: new Uint8Array([1, 2, 3, 4])},
-        }}]
+[
+  {
+    manufacturerData: [
+      { companyIdentifier: 17, dataPrefix: new Uint8Array([1, 2, 3, 4]) },
+    ],
+  },
+]
       
<none> @@ -907,9 +927,13 @@ values of filters passed to
-        [{manufacturerData: {
-            17: {dataPrefix: new Uint8Array([1])},
-        }}]
+[
+  {
+    manufacturerData: [
+      { companyIdentifier: 17, dataPrefix: new Uint8Array([1]) },
+    ],
+  },
+]
       
D1 @@ -917,10 +941,17 @@ values of filters passed to
-        [{manufacturerData: {
-            17: {dataPrefix: new Uint8Array([0x91, 0xAA]),
-                mask: new Uint8Array([0x0F, 0x57])},
-        }}]
+[
+  {
+    manufacturerData: [
+      {
+        companyIdentifier: 17,
+        dataPrefix: new Uint8Array([0x91, 0xAA]),
+        mask: new Uint8Array([0x0f, 0x57]),
+      },
+    ],
+  },
+]
       
D1 @@ -928,10 +959,14 @@ values of filters passed to
-        [{manufacturerData: {
-            17: {},
-            18: {},
-        }}]
+[
+  {
+    manufacturerData: [
+      { companyIdentifier: 17 },
+      { companyIdentifier: 18 },
+    ]
+  }
+]
       
<none> @@ -1002,7 +1037,7 @@ To accept all devices, use {{acceptAllDevices}} instead.
         requestDevice({
-          filters:[{namePrefix: ""}]
+          filters: [{namePrefix: ""}]
         })
       
@@ -1014,7 +1049,7 @@ To accept all devices, use {{acceptAllDevices}} instead.
         requestDevice({
-          filters:[{manufacturerData: {}}]
+          filters: [{manufacturerData: []}]
         })
       
@@ -1027,7 +1062,7 @@ To accept all devices, use {{acceptAllDevices}} instead.
         requestDevice({
-          filters:[{serviceData: {}}]
+          filters: [{serviceData: []}]
         })
       
@@ -1136,23 +1171,19 @@ following steps return `match`: response, or a service discovery response indicating that the device supports a primary (vs included) service with UUID uuid, return `mismatch`. -1. If - filter.{{BluetoothLEScanFilterInit/manufacturerData}} - is present then for each |manufacturerId| in - |filter|.manufacturerData.{{Object/[[OwnPropertyKeys]]}}(), if +1. For each manufacturerData in + |filter|.{{BluetoothLEScanFilterInit/manufacturerData}}, if device hasn't advertised manufacturer specific data with a - company identifier code that stringifies in base 10 to |manufacturerId| and - with data that matches - |filter|.{{BluetoothLEScanFilterInit/manufacturerData}}[|manufacturerId|] - return `mismatch`. -1. If filter.{{BluetoothLEScanFilterInit/serviceData}} - is present then for each |uuid| in - |filter|.{{BluetoothLEScanFilterInit/serviceData}}.{{Object/[[OwnPropertyKeys]]}}(), + company identifier code equal to + |manufacturerData|.{{BluetoothManufacturerDataFilterInit/companyIdentifier}} + and with data that matches + |manufacturerData| return `mismatch`. +1. For each serviceData in + |filter|.{{BluetoothLEScanFilterInit/serviceData}}, if device hasn't advertised service data with a UUID whose - 128-bit form is |uuid| and with data that matches - |filter|.{{BluetoothLEScanFilterInit/serviceData}}[|uuid|], - return `mismatch`. + 128-bit form is |serviceData|.{{BluetoothServiceDataFilterInit/service}} and + with data that matches + |serviceData| return `mismatch`. 1. Return `match`. @@ -1400,51 +1431,42 @@ returned from the following steps: filter.namePrefix. 1. Set |canonicalizedFilter|.manufacturerData to `{}`. 1. If |filter|.{{BluetoothLEScanFilterInit/manufacturerData}} is - present, do the following sub-steps for each |key| in - |filter|.manufacturerData.{{Object/[[OwnPropertyKeys]]}}(). If - there are no such keys, throw a {{TypeError}} and abort these steps. - 1. Let |manufacturerId| be CanonicalNumericIndexString(|key|). - 1. If |manufacturerId| is `undefined` or `-0`, or IsInteger(|manufacturerId|) is `false`, or - |manufacturerId| is outside the range from 0–65535 inclusive, throw a - {{TypeError}} and abort these steps. - 1. Let |dataFilter| be - |filter|.manufacturerData[|key|], converted - to an IDL value of type {{BluetoothDataFilterInit}}. If this - conversion throws an exception, propagate it and abort these steps. - 1. Let |canonicalizedDataFilter| be the result of canonicalizing |dataFilter|, + present and + |filter|.{{BluetoothLEScanFilterInit/manufacturerData}}.length === 0, + throw a {{TypeError}} and abort these steps. +1. For each |manufacturerData| in + |filter|.{{BluetoothLEScanFilterInit/manufacturerData}}, do the following sub-steps: + 1. If |manufacturerData|.{{BluetoothManufacturerDataFilterInit/companyIdentifier}} + is present in |canonicalizedFilter|.manufacturerData, + throw a {{TypeError}} and abort these steps. + 1. Let |canonicalizedManufacturerDataFilter| be the result of canonicalizing |manufacturerData|, converted to an ECMAScript value. If this throws an exception, propagate that exception and abort these steps. 1. Call CreateDataProperty - (|canonicalizedFilter|.manufacturerData, |key|, - |canonicalizedDataFilter|). + (|canonicalizedFilter|.manufacturerData, + |manufacturerData|.{{BluetoothManufacturerDataFilterInit/companyIdentifier}}, + |canonicalizedManufacturerDataFilter|). 1. Set |canonicalizedFilter|.serviceData to `{}`. 1. If |filter|.{{BluetoothLEScanFilterInit/serviceData}} is - present, do the following sub-steps for each |key| in - |filter|.serviceData.{{Object/[[OwnPropertyKeys]]}}(). If there - are no such keys, throw a {{TypeError}} and abort these steps. - 1. Let |serviceName| be CanonicalNumericIndexString(|key|). - 1. If |serviceName| is `undefined`, set |serviceName| to |key|. + present and + |filter|.{{BluetoothLEScanFilterInit/serviceData}}.length === 0, + throw a {{TypeError}} and abort these steps. +1. For each |serviceData| in + |filter|.{{BluetoothLEScanFilterInit/serviceData}}, do the following sub-steps: 1. Let |service| be - {{BluetoothUUID/getService()|BluetoothUUID.getService}}(|serviceName|). - 1. If the previous step threw an exception, throw that exception and abort - these steps. + {{BluetoothUUID/getService()|BluetoothUUID.getService}}(|serviceData|.{{BluetoothServiceDataFilterInit/service}}). + If this throws an exception, propagate that exception and abort these + steps. 1. If |service| is blocklisted, throw a {{SecurityError}} and abort these steps. - 1. Let |dataFilter| be |filter|.serviceData[|key|], - converted to an IDL value of type {{BluetoothDataFilterInit}}. - If this conversion throws an exception, propagate it and abort these - steps. - 1. Let |canonicalizedDataFilter| be the result of canonicalizing |dataFilter|, + 1. Let |canonicalizedServiceDataFilter| be the result of canonicalizing |serviceData|, converted to an ECMAScript value. If this throws an exception, propagate that exception and abort these steps. 1. Call CreateDataProperty(|canonicalizedFilter|.serviceData, - |service|, |canonicalizedDataFilter|). + |service|, |canonicalizedServiceDataFilter|). 1. Return |canonicalizedFilter|. diff --git a/scanning.bs b/scanning.bs index c08967c..71fe649 100644 --- a/scanning.bs +++ b/scanning.bs @@ -57,9 +57,9 @@ spec: webidl spec:web-bluetooth type: dfn text: read only arraybuffer - type:enum-value; for:PermissionName; text:"bluetooth" spec: permissions-1 type: enum-value + text: "bluetooth" text: "denied" text: "granted"