Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement Map() #401

Closed
jasonwilliams opened this issue May 13, 2020 · 10 comments · Fixed by #550
Closed

implement Map() #401

jasonwilliams opened this issue May 13, 2020 · 10 comments · Fixed by #550
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers
Milestone

Comments

@jasonwilliams
Copy link
Member

jasonwilliams commented May 13, 2020

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

@jasonwilliams jasonwilliams added enhancement New feature or request good first issue Good for newcomers labels May 13, 2020
@hello2dj
Copy link
Contributor

I can take a stap at this

@jasonwilliams
Copy link
Member Author

Assigned

@hello2dj
Copy link
Contributor

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?

@hello2dj
Copy link
Contributor

#419 I will wait for this PR.

@HalidOdat HalidOdat mentioned this issue Jun 6, 2020
8 tasks
@hello2dj hello2dj removed their assignment Jun 30, 2020
@hello2dj
Copy link
Contributor

sorry, I'm too busy to have time to do this. I will unassign me.

@joshwd36
Copy link
Contributor

joshwd36 commented Jul 5, 2020

I'm happy to take a look at this

@HalidOdat
Copy link
Member

I'm happy to take a look at this

Sure! Tell us if you need any help or have any question :)

@joshwd36
Copy link
Contributor

joshwd36 commented Jul 5, 2020

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?

@HalidOdat
Copy link
Member

HalidOdat commented Jul 5, 2020

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.

@joshwd36
Copy link
Contributor

joshwd36 commented Jul 5, 2020

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 Map that would hold a HashMap<Value, Value>.

Thank you! I'll try that out

@Razican Razican added this to the v0.10.0 milestone Sep 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants