Re: Array property of custom object

Mihai Dobrescu <[email protected]>
Newsgroups gmane.comp.mozilla.devel.jseng
Message-ID <[email protected]>
On Monday, May 2, 2016 at 8:08:32 PM UTC+3, Boris Zbarsky wrote:
> On 5/2/16 8:07 AM, Mihai Dobrescu wrote:
> > So, to be clear, I would expect to have a callback with the index of the array as parameter too... I guess here starts my confusion?
> 
> OK.  Can you please back up and clearly describe what you're trying to do?
> 
> If your object is `o` and script does `o.arr`, what sort of thing should 
> it get?  Should it get an actual JS Array in the Array.isArray() sense? 
>   Should it get something that allows indexing into it (more details 
> below) but isn't actually an Array?  Something else?
> 
> When script does `var x = o.arr[5]`, what should happen? Should the 
> value just be read directly out of the storage of `o.arr` (whatever that 
> is)? Should some code you control run and allow you to provide the value 
> being returned? Something else?
> 
> When script does `o.arr[5] = 7`, what should happen?  Should the value 
> just be written into the storage of `o.arr` (whatever that is)?  Should 
> some code you control run and do something with the value being 
> provided?  Something else?
> 
> -Boris

OK, I use objects with private data. For instance a structure instance defined like (this is a simple example) :

typedef struct S {
	int id;	
	char info[100];
} Data;

In my case, I access "info" as char array (due to some API specs I wrap).

For "id" I use JS_PSGS macro to define it as a property for an object "jsData". It is used a wrapper of type jsInt with private data int.
The Set/Get methods will always work with the private data.

For "info", I need some Array wrapper for objects of type jsChar (it is not a string). jsChar will have some private data of type char.

So, I expect to access somehow a "jsData"'s property named "info", of type Array, in order to individually set or get each array's element.
I could write functions for that, but it is not natural. It is possible to need to loop through the array's elements too.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.