Add support for JavaScript Array in binding layer
- [ ] Add array support in binding layer
- [x] create array / check if object is array / ...
- [ ] add support to easily iterate over array elements (esp. for sparse array, maybe in jerry?)
- [ ] ... (TBD)
- [ ] Use array support in IoT.js
- [ ] in
i2cmodule, many APIs should use array as input parameter or callback argument - [x] in
buffermodule, enablenew Buffer(array) - [x] in
http_incomingmodule, IncomingMessage.headers should be array type - ... (TBD)
- [ ] in
I think it will be better to support more APIs in binding layer. For example, push(add) and pop(remove) for numbered index and named index will be very helpful.
I made a PR for array creating and checking for char array. Please see #460.
Is there any progress in this issue? If anyone did not made a progress, I want to handle it.
We intentionally don't put more time into this issue since we don't want to make APIs bigger. We want to keep APIs minimal.
All the issues posted are in progress or in pending for some reason. Therefore I recommend you suggest your proposal in issue. You can refer to the guide in Development-Process, especially in Feature development process.
buffer module, enable new Buffer(array) - done
in http_incoming module, IncomingMessage.headers should be array type - landed in #776
add support to easily iterate over array elements - We want to keep the API minimal. Let's discuss this item when we need this API.
@glistening Right now, there is no support to easily iterate over JS array elements on the C side.
This feature will be extremely useful in a OCF Things SDK I am currently working on.
Is support for this planned in the near future, or will it not be supported to keep APIs minimal?
Note - While it would be great to have support in binding for Array Iteration, there are some workarounds which can be used right now. Currently I convert the array to object on the JS side, pass the object to C side, iterate over the elements of the object and create a new array on the C side.
For example, this Array -
['a','b','c']
Becomes -
{ 0: 'a', 1: 'b', 2: 'c' }
@akhilkedia you can call jerry_get_array_length and jerry_get_property_by_index directly until the IoT.js binding hasn't done.
@LaszloLango Thanks!