Similar to https://github.com/boa-dev/boa/issues/13 but for the Array
Implementation happens here: https://github.com/boa-dev/boa/blob/master/boa/src/builtins/array/mod.rs
@jasonwilliams For the array, what is a Javascript array represented as in Boa? From my investigation appears to be as an Object, so in the underlying Rust a hashmap mapping from index to value: is that accurate?
Does that mean in Boa there's no Javascript difference between arrays and objects? Is that intentional or just because Array isn't implemented yet? Should we have an "Array" entry in the ValueData enum?
That's a very good point, and yes, what you said is accurate. There is no Array primitive value in JavaScript, so we can't have an array datatype in the value enum. (for now) An Array is just an Object with a prototype of Array methods.
V8 do some optimisations with arrays with a backing store: https://v8.dev/blog/fast-properties
I'm not sure we need to worry about fast property access just yet.
For now we just need to create a global constructor (Array), similar to what we do with strings.
Arrays are then objects who's prototype is set to Array.prototype.
I think my main questions would likely be whether in order to implement the majority of Array prototype methods we should be converting to real Rust arrays/Vectors/etc under the covers or just using hashmaps for now?
I would go hashmaps for now, you will hit way too many edge/corner cases if you try to convert them to Rust Vectors (i.e length shouldn't be counted). It's not the most performant but the most correct. We can fix speed later on with some optimisations.
I will give it some thought, but https://v8.dev/blog/fast-properties is worth reading through, plus https://v8.dev/blog/elements-kinds
I'll take a look at indexOf and lastIndexOf.
@simonbrahan ok great
I'd like to take a look at map.
I'll like to work on slice
@IovoslavIovchev can you put yourself on (or reply to) this issue https://github.com/jasonwilliams/boa/issues/176
@muskuloes same for https://github.com/jasonwilliams/boa/issues/177
Can I take includes?
A lot of these methods have already been implemented. Such as every, find, some and some others.
I think we should update the check list. :)
I updated the checklist. I noticed that the Array.prototype.includes() does not have documentation.
I updated the checklist. I noticed that the
Array.prototype.includes()does not have documentation.
I will add documentation for it.
Hey, like String the links are out of date now.
Array can now be found here!
Hey, like String the links are out of date now.
Array can now be found here!
Yep! I updated the link, and once again, this might be blocked in #419.
I'd like to take a look at reduce
I'd like to take a look at
reduce
Go ahead! :D
Also Since I did reduce, reduceRight should be pretty straightforward to implement.
@joshwd36 has implemented Array.prototype.keys(), Array.prototype.entries(), Array.prototype.values() and Array.prototype@@iterator in #704
Hi all, I would like to work on Array.prototype.flat and Array.prototype.flatMap if those are available.
Go ahead @davidmikulis :)
The Pull Request for Array.prototype.flat and Array.prototype.flatMap is available at #1132 for whenever anyone has time to review. Thanks!
Should Array.prototype.toSource() be implemented at all? MDN Web Docs shows that there's barely any support for this method, as it was deprecated many years ago.
Should
Array.prototype.toSource()be implemented at all? MDN Web Docs shows that there's barely any support for this method, as it was deprecated many years ago.
It shouldn't be implemented, since it's not in the spec.