W3C home > Mailing lists > Public > public-script-coord@w3.org > July to September 2016

Re: Using objects for a mapping argument

From: Jeffrey Yasskin <jyasskin@google.com>
Date: Mon, 26 Sep 2016 11:13:22 -0700
Message-ID: <CANh-dXkHW9UUJBGUvS7gRV8NMn_NLqMF8A5D+icW61k1+4D1vg@mail.gmail.com>
To: Domenic Denicola <d@domenic.me>
Cc: public-script-coord <public-script-coord@w3.org>
On Sun, Sep 25, 2016 at 7:52 AM, Domenic Denicola <d@domenic.me> wrote:
> From: Jeffrey Yasskin [mailto:jyasskin@google.com]
>
>> Does this make sense, or should I have my users express these arguments
in some other way?
>
> It's hard for me to judge what the best user-facing API is without some
sample code, so I'll refrain from commenting on that.

There's some sample code at
https://api.csswg.org/bikeshed/?url=https://raw.githubusercontent.com/jyasskin/web-bluetooth-1/masked-data-prefixes/scanning.bs#example-ibeacon.
The API I'm suggesting looks like:

navigator.bluetooth.requestLEScan({
  filters: [{
    manufacturerData: {
      0x004C: {  // Apple's company id.
        dataPrefix: new Uint8Array([
          0x02, 0x15, // iBeacon identifier.
          0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15  // My
beacon UUID.
        ]),
      },
    },
  }],
  options: {
    keepRepeatedDevices: true,
  }
})

The more WebIDL-friendly version would look like:

navigator.bluetooth.requestLEScan({
  filters: [{
    manufacturerData: [{
      id: 0x004C,  // Apple's company id.
      dataPrefix: new Uint8Array([
        0x02, 0x15, // iBeacon identifier.
        0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15  // My beacon
UUID.
      ]),
    }],
  }],
  options: {
    keepRepeatedDevices: true,
  }
})

> However, the prose to process it is problematic in a number of ways. For
example, it checks the public `length` property, and uses
`Array.prototype.map.call` directly. (Whose behavior will vary if the user
overrides any of: window.Array, Array.prototype, Array.prototype.map,
Function.prototype.call.) This doesn't really matter anyway, as sequences
are not JavaScript arrays; they are Web IDL data types. They do not have
.length properties, and you cannot call map on them. And you shouldn't be
using the public, overridable BluetoothUUID.getService method; use the
algorithm instead.
>

I dealt with users overriding the builtins using a paragraph at
https://webbluetoothcg.github.io/web-bluetooth/#terminology saying that
when the spec uses a name like `BluetoothUUID.getService`, that has to be
interpreted as referring to its original value, not anything the user has
set it to. I figure it's silly to force specifications to use a parallel
library that people have to learn separately from the built-in JS library.

I'm just using the array methods to map a function over a sequence. In at
least one place, I forgot and just wrote a_sequence.map(). Have other specs
picked a different convenient way to say that?

>> If this makes sense, would you like me to propose some WebIDL operations
that would make it easier?
>
> The actual [[OwnPropertyKeys]] steps look pretty reasonable, and yeah,
maybe factoring them out into some kind of phrase that lets you extract
things in this sort of scenario makes sense. This might tie into the
discussions around OpenEndedDictionary?

Is there a good bug to follow for that?

Thanks,
Jeffrey
Received on Monday, 26 September 2016 18:14:12 UTC

This archive was generated by hypermail 2.3.1 : Monday, 26 September 2016 18:14:13 UTC