JS XPCOM - Returning an array.

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

JS XPCOM - Returning an array.

gavr

I am writing an xpcom component using JavaScript.  I have touble in
returning an array from the component.

Here is what i did.

IDL :
   void getCalendars(out PRUint32 count,
                      [array, size_is(count), retval] out calICalendar
aCalendars);

Component's JS:
    getCalendars: function(cnt) {
     return this.calManager.getCalendars({});
  },

Usage :
 var calInterface = Components.classes["@test.com/calappinterface;1"]
                  .createInstance(Components.interfaces.omICalAppInterface);
var arr = calInterface.getCalendars({});
alert(arr.length);

Now, it always returns zero sized array. I have checked the call
this.calManager.getCalendars({}) in the components js - it works fine.
The problem is only in returning it.

Any help will be higly appreciated.

_______________________________________________
dev-tech-xpcom mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xpcom
Reply | Threaded
Open this post in threaded view
|

Re: JS XPCOM - Returning an array.

James Ross
gavr wrote:
> IDL :
>    void getCalendars(out PRUint32 count,
>                       [array, size_is(count), retval] out calICalendar
> aCalendars);
>
> Component's JS:
>     getCalendars: function(cnt) {
>      return this.calManager.getCalendars({});
>   },

I believe you need to pass the length via the count parameter as well:

   getCalendars: function(count) {
     var rv = this.calManager.getCalendars({});
     count.value = rv.length;
     return rv;
   }

--
James Ross <[hidden email]>
ChatZilla and Venkman Developer
_______________________________________________
dev-tech-xpcom mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xpcom
Reply | Threaded
Open this post in threaded view
|

Re: JS XPCOM - Returning an array.

Igor Tandetnik
James Ross <[hidden email]> wrote:

> gavr wrote:
>> IDL :
>>    void getCalendars(out PRUint32 count,
>>                       [array, size_is(count), retval] out
>> calICalendar aCalendars);
>>
>> Component's JS:
>>     getCalendars: function(cnt) {
>>      return this.calManager.getCalendars({});
>>   },
>
> I believe you need to pass the length via the count parameter as well:
>
>   getCalendars: function(count) {
>     var rv = this.calManager.getCalendars({});
>     count.value = rv.length;
>     return rv;
>   }

Or simply

   getCalendars: function(count) {
     return this.calManager.getCalendars(count);
   }

Igor Tandetnik


_______________________________________________
dev-tech-xpcom mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xpcom
Reply | Threaded
Open this post in threaded view
|

Re: JS XPCOM - Returning an array.

vangapallypoorna
In reply to this post by gavr
On Mar 25, 4:36 pm, "gavr" <[hidden email]> wrote:

> I am writing an xpcom component using JavaScript.  I have touble in
> returning an array from the component.
>
> Here is what i did.
>
> IDL :
>    void getCalendars(out PRUint32 count,
>                       [array, size_is(count), retval] out calICalendar
> aCalendars);
>
> Component's JS:
>     getCalendars: function(cnt) {
>      return this.calManager.getCalendars({});
>   },
>
> Usage :
>  var calInterface = Components.classes["@test.com/calappinterface;1"]
>                   .createInstance(Components.interfaces.omICalAppInterface);
> var arr = calInterface.getCalendars({});
> alert(arr.length);
>
> Now, it always returns zero sized array. I have checked the call
> this.calManager.getCalendars({}) in the components js - it works fine.
> The problem is only in returning it.
>
> Any help will be higly appreciated.

Hi Gavr,

Can you please send me your complete example for the same, I am also
looking into similar work, we can work together.

Thanks
Poornachander

_______________________________________________
dev-tech-xpcom mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xpcom