Issue with HtmlOptionsCollection - Bug in WebIDLParser?

22 views
Skip to first unread message

olen...@gmail.com

unread,
Nov 28, 2014, 11:15:39 AM11/28/14
to shar...@googlegroups.com
Hello,

(working with 5.4.7)

When I compile this code:

    ...
       
public HtmlSelectElement SelectElement { get { return this.Element.As<HtmlSelectElement>(); } }

   
...

       
public JsArray<string> Values
       
{
           
get
           
{
               
JsArray<string> result = new JsArray<string>();
               
foreach (HtmlOptionElement option in this.SelectElement.options)
               
{
                    result
.Add(option.value);
               
}
               
return result;
           
}
       
}
   
...

that javascript is generated:

DropDownControl.prototype.get_Values = function (){
   
var result =  [];
   
for (var option in this.get_SelectElement().options){
        result
.push(option.value);
   
}
   
return result;
};


And it doesn't works since it iterates throught the properties of the HtmlOptionsElement instead of the items of the collection.

If I change

foreach (HtmlOptionElement option in this.SelectElement.options)


to

HtmlCollection options = this.SelectElement.options;
foreach (HtmlOptionElement option in this.SelectElement.options)

the javascript is now:

    for (var $i2 = 0,$l2 = options.length,option = options[$i2]; $i2 < $l2; $i2++, option = options[$i2]){
        result
.push(option.value);


and works as expected.

I believe the JsType attribute declaration on the HtmlOptionsCollection should be

[JsType(JsMode.Prototype, NativeEnumerator = false, NativeArrayEnumerator = true, Export = false, PropertiesAsFields = true, NativeCasts = true, Name = "HTMLOptionsCollection")]

instead of

[JsType(JsMode.Prototype, Export = false, PropertiesAsFields = true, NativeCasts = true, Name = "HTMLOptionsCollection")]

but since its code is generated from the WebIDLParser, I thought it would not be a good idea to make a change on GitHub...
So I suppose the modification should be made to the WebIDLParser.

Honestly I don't have enought time to spend on this issue to make the change by myself. Modifying the WebIDLParser does not seems to be trivial, especially when it will comes to make the tests.
I will just use the hack described above.

If someone does, all my thanks in advance!

Regards,

olen...@gmail.com

unread,
Nov 28, 2014, 12:31:02 PM11/28/14
to shar...@googlegroups.com, olen...@gmail.com

Sorry, there was a mistake in my original mail,

You should not read

HtmlCollection options = this.SelectElement.options;
foreach (HtmlOptionElement option in this.SelectElement.options)

but

HtmlCollection options = this.SelectElement.options;
foreach (HtmlOptionElement option in options)

regards
Reply all
Reply to author
Forward
0 new messages