ECMASCript feature
Map objects are collections of key/value pairs where both the keys and values may be arbitrary ECMAScript language values. A distinct key value may only occur in one key/value pair within the Map's collection. Distinct key values are discriminated using the SameValueZero comparison algorithm.
I would like to see Map implemented. ECMAScript specification.
Example code
let myMap = new Map()
let keyString = 'a string'
let keyObj = {}
let keyFunc = function() {}
// setting the values
myMap.set(keyString, "value associated with 'a string'")
myMap.set(keyObj, 'value associated with keyObj')
myMap.set(keyFunc, 'value associated with keyFunc')
myMap.size // 3
// getting the values
myMap.get(keyString) // "value associated with 'a string'"
myMap.get(keyObj) // "value associated with keyObj"
myMap.get(keyFunc) // "value associated with keyFunc"
myMap.get('a string') // "value associated with 'a string'"
// because keyString === 'a string'
myMap.get({}) // undefined, because keyObj !== {}
myMap.get(function() {}) // undefined, because keyFunc !== function () {}
Example to work from
Array is implemented here: https://github.com/jasonwilliams/boa/blob/master/boa/src/builtins/array/mod.rs
Contributing
https://github.com/jasonwilliams/boa/blob/master/CONTRIBUTING.md
I can take a stap at this
Assigned
Oh sorry, I've been very busy recently. I'll start as soon as possible.
Before I start to do it. I need some help, List Type I will use Array(https://github.com/jasonwilliams/boa/blob/master/boa/src/builtins/array/mod.rs). Someone has other suggestions?
https://github.com/boa-dev/boa/pull/419 I will wait for this PR.
sorry, I'm too busy to have time to do this. I will unassign me.
I'm happy to take a look at this
I'm happy to take a look at this
Sure! Tell us if you need any help or have any question :)
Thank you! I've been having a go at it, and I was wondering what the best way to store the data would be? With arrays, the data is stored in fields which makes sense with how the API looks, but with Map the data is hidden and only accessed through methods on the object. Should it be stored as a field of the rust struct, similar to bigint and the like, or something else?
I was wondering what the best way to store the data would be? With arrays, the data is stored in fields which makes sense with how the API looks, but with Map the data is hidden and only accessed through methods on the object. Should it be stored as a field of the rust struct, similar to bigint and the like, or something else?
Good question! The best way to store it would be in here and create a field Map that would hold a HashMap<Value, Value>. #419 implemented Hash, PartialEq and Eq based on the SameValueZero algorithm, that Map and Set uses. So the HashMap should work without additional work.
I was wondering what the best way to store the data would be? With arrays, the data is stored in fields which makes sense with how the API looks, but with Map the data is hidden and only accessed through methods on the object. Should it be stored as a field of the rust struct, similar to bigint and the like, or something else?
Good question! The beast way to store it would be in here and create a field
Mapthat would hold aHashMap<Value, Value>.
Thank you! I'll try that out
Most helpful comment
I'm happy to take a look at this