Implement support for arrays in WebIDL

RESOLVED INVALID

Status

()

Core
DOM
RESOLVED INVALID
5 years ago
a year ago

People

(Reporter: reuben, Unassigned)

Tracking

Trunk
Points:
---
Dependency tree / graph

Firefox Tracking Flags

(Not tracked)

Details

(URL)

Comment hidden (empty)
Reuben, which arrays do we need here?  Readonly, fixed-length, or variable-length?  Also, what's the inner type?  I'd be interested in seeing the IDL we're looking at here; is there a spec for it?

Note also 850159.
Depends on: 850159
(Reporter)

Comment 2

5 years ago
(In reply to Boris Zbarsky (:bz) from comment #1)
> Reuben, which arrays do we need here?  Readonly, fixed-length, or
> variable-length? Also, what's the inner type?

Variable-length, DOMString, and ContactFields.

> I'd be interested in seeing the IDL we're looking at here;
> is there a spec for it? Note also 850159.

https://mxr.mozilla.org/mozilla-central/source/dom/interfaces/contacts/nsIDOMContactProperties.idl
That's xpidl, not WebIDL.

What I'm trying to understand is whether the right thing is in fact IDL arrays or sequences.  And that depends on what the interface is actually meant to behave like, hence the question about a spec.
(Reporter)

Comment 4

5 years ago
(In reply to Boris Zbarsky (:bz) from comment #3)
> That's xpidl, not WebIDL.
> 
> What I'm trying to understand is whether the right thing is in fact IDL
> arrays or sequences.  And that depends on what the interface is actually
> meant to behave like, hence the question about a spec.

Oh, yea, I meant to also link to https://wiki.mozilla.org/WebAPI/ContactsAPI. It's not a spec but it explains the reasons behind the arrays. I just looked at the DAP Contacts spec and it uses sequences, so maybe I can use that.
Well, here are some litmus tests.  If I have a ContactProperties in myContactProperties, what should the following snippets of JS alert?

1)  alert(myContactProperties.name === myContactProperties.name)

2)  myContactProperties.name.length = 100000;
    alert(myContactProperties.name.length);
    alert(myContactProperties.name[99999]);

3)  myContactProperties.name[0] = "foopy";
    alert(mycontactProperties.name[0]);

4)  var contact = new Contact(myContactProperties);
    alert(contact.name === myContactProperties.name);
    contact.name[0] = "Hey";
    alert(myContactProperties.name[0]);
(Reporter)

Comment 6

5 years ago
1) true

2) 100000
   undefined

3) foopy (ReferenceError: mycontactProperties is not defined :)

4) false
   foopy
OK.  What about:

5)  var contact = new Contact(myContactProperties);
    contact.name[0] = "Hey";
    alert(contact.name[0]);
(Reporter)

Comment 8

5 years ago
(In reply to Boris Zbarsky (:bz) from comment #7)
> OK.  What about:
> 
> 5)  var contact = new Contact(myContactProperties);
>     contact.name[0] = "Hey";
>     alert(contact.name[0]);

"Hey"
(Reporter)

Comment 9

5 years ago
(I'm receiving delayed bugmail every now and then, feel free to ping me on IRC for these questions.)
OK.  So it sounds like we really do want IDL arrays here, writable and variable-length ones, but want to make a copy on construction of the Contact?

Note that the WebIDL behavior for DOMString[] on length being increased is not what you might want here (it'll fill it with "undefined" strings); might be worth raising a WebIDL spec issue on that.

But OK, it sounds like we need to do a bunch of work to make this work.

Updated

5 years ago
Duplicate of this bug: 585381
(Reporter)

Updated

5 years ago
No longer blocks: 850430
Would be useful in Bug 882145, but I think we can work around it, so I'm not marking it as dependent.

Our current take on http://dev.w3.org/2011/webrtc/editor/getusermedia.html#dictionary-mediatrackconstraints-members

 typedef object MediaTrackConstraint;

 dictionary MediaTrackConstraints {
     MediaTrackConstraintSet mandatory;
 // Bug 882145
 //    MediaTrackConstraint[] _optional;
     MediaTrackConstraint _optional;
 };

Given how the spec is written, there doesn't seem to be a better webidl construct for MediaTrackConstraint than object, and since the array is of objects, treating the whole array as an object is not much of a hardship. FYI.
Sorry, make that:

 typedef object MediaTrackConstraint;

 dictionary MediaTrackConstraints {
     MediaTrackConstraintSet mandatory;
 // Bug 851726
 //    MediaTrackConstraint[] _optional;
     object _optional;
 };
It really makes no sense to put an IDL array in a dictionary.  The point of IDL arrays is to pass by reference, but dictionaries are always passed by value anyway...

You could happily make that sequence<object>, I think.
Of course, that worked fine - Thanks, I keep forgetting that (as does the WebRTC working group which makes me feel better). Definitely not a blocker then. Please ignore.
IDL arrays no longer exist in the spec.
Status: NEW → RESOLVED
Last Resolved: a year ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.