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

MapInstance.Set() does not overwrite existing values #63

Closed
kpreisser opened this issue Oct 24, 2016 · 1 comment
Closed

MapInstance.Set() does not overwrite existing values #63

kpreisser opened this issue Oct 24, 2016 · 1 comment

Comments

@kpreisser
Copy link
Collaborator

kpreisser commented Oct 24, 2016

Hi,

when running the following code in Firefox, Chrome or other browsers:

new Map().set(1, 2).set(0, 9).set(1, 8).get(1);

the return value is 8 (as set(1, 8) should overwrite the existing entry with value 2).
However, on Jurassic it returns 2.

MapInstance.Set() looks like the following:

    [JSInternalFunction(Name = "set")]
    public MapInstance Set(object key, object value)
    {
        if (this.store.ContainsKey(key))
            return this;
        if (key is double && TypeUtilities.IsNegativeZero((double)key))
            key = 0;
        var node = this.list.AddLast(new KeyValuePair<object, object>(key, value));
        this.store.Add(key, node);
        return this;
    }

So it checks whether the key already exists, but in that case does not set the new value.
ES2015 says at 23.1.3.9:

5. Repeat for each Record {[[key]], [[value]]} p that is an element of entries,
a. If p.[[key]] is not empty and SameValueZero(p.[[key]], key) is true, then
i. Set p.[[value]] to value.
ii. Return M.

So it seems the first if branch misses the code to set the new value.

Thanks!

@paulbartrum
Copy link
Owner

Fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants