Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Wifi API question

17 views
Skip to first unread message

David Bruant

unread,
Jun 23, 2013, 10:28:42 AM6/23/13
to dev-w...@lists.mozilla.org
Hi,

I'm having fun documenting the Wifi API :-)

I have a question regarding something I read on the IDL file [1] (I
don't have a device with remote debugging working around me, I'll
probably test when I do)
/**
* Returns the list of currently available networks.
* onsuccess: We have obtained the current list of networks.
request.value
* is an object whose property names are SSIDs and
values are
* network objects.
* onerror: We were unable to obtain a list of property names.
*/
nsIDOMDOMRequest getNetworks();

In theory, it feels like a good idea, but in practice, objects in
JavaScript aren't that nice. I worry that naive code playing with this
kind of objects may break in a way or another if someone has fun
renaming its SSID to "__proto__", "__noSuchMethod__" (magic property
names) or "hasOwnProperty" (shadowing issues with Object.prototype).

After some investigation, it looks like it's actually an array or
array-like object [2]. Is the comment outdated?
I don't have strong opinions (yet :-) ) on what the API should look
like, but for string->value data structures, please prefer ES6 Maps [3]
as they won't have the magic property and shadowing/collision hazards
that objects have.

David

[1] http://mxr.mozilla.org/mozilla-central/source/dom/wifi/nsIWifi.idl?raw=1
[2]
https://github.com/mozilla-b2g/gaia/blob/079b57f45f2e272ceb4e0f3f067cc3d829b3f2b4/apps/settings/js/wifi.js#L331-L334
[3]
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map

Jonas Sicking

unread,
Jun 24, 2013, 1:08:54 PM6/24/13
to David Bruant, Blake Kaplan, dev-webapi
I agree, using SSIDs as property names would seem problem. Either using an
array or a Map seems like good solutions.

/ Jonas
> _______________________________________________
> dev-webapi mailing list
> dev-w...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-webapi

Blake Kaplan

unread,
Jun 25, 2013, 3:13:44 PM6/25/13
to dev-w...@lists.mozilla.org
On 6/23/13 10:28 AM, David Bruant wrote:
> After some investigation, it looks like it's actually an array or
> array-like object [2]. Is the comment outdated?

Oops, yeah. We changed the return value of getNetworks from being a map
to an array in [1]. The comment should say that we simply return an
array now with each element being a unique SSID. It probably isn't worth
going back to an associative array because the keys now would have to be
based on SSID + security (and possibly other criteria in the future) and
no would longer have meaning.

Good catch and thanks for pointing this out.

[1] https://bugzilla.mozilla.org/show_bug.cgi?id=736104
--
Blake Kaplan
0 new messages