Open Bug 552215 Opened 14 years ago Updated 2 years ago

Treat ctype arrays like.. arrays!

Categories

(Core :: js-ctypes, defect, P3)

x86
macOS
defect

Tracking

()

People

(Reporter: Mardak, Unassigned)

References

(Depends on 1 open bug, Blocks 1 open bug)

Details

Right now if a type is an array, say an array of IP addresses, you can't use javascript Array methods to process the array.

For example, if "addresses" is a ctypes.uint8_t.array(4).ptr.array(3) -- a 3-size array pointers to a 4-size array of chars.

Doing something like Array.slice(addresses) to convert it into a real array results in [,,].

If I manually iterate the array and push items into a real array, it works:
real = [];
for (i = 0; i < addresses.length; i++) real.push(addresses[i]);

I even tried adding Array.prototype to the prototype chain, and that didn't work. So it seems like the Array methods don't like working on these ctype arrays as "this" even though they provide a .length and [0], [1], etc.

Potentially this could even work with bug 552214's undefined array lengths. Once the array length is known to the coder, s/he could perhaps set the length on the array and magic happens! :)
Oh. The actual example I was trying to do would be..

print(Array.map(addresses, function(ip) ip.content).join("\n"));
P3, nice to have. (I don't *think* anything here would break compat, so no rush.)
Priority: -- → P3
The bug here is that many Array methods ask "do you have element i?" and for CData objects of array type, we come back with the wrong answer.

There's no convenient way to fix it. Typed arrays jump through all kinds of hoops to get this and tracing to work.
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.