Closed Bug 851726 Opened 11 years ago Closed 8 years ago

Implement support for arrays in WebIDL

Categories

(Core :: DOM: Core & HTML, defect)

defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: reuben, Unassigned)

References

()

Details

      No description provided.
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
(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.
(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]);
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]);
(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"
(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.
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.
Depends on: 923919
IDL arrays no longer exist in the spec.
Status: NEW → RESOLVED
Closed: 8 years ago
Resolution: --- → INVALID
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.