Skip to content

Commit

Permalink
[js] fix __id__ handling for the first time `ObjectMap.set(obj, value…
Browse files Browse the repository at this point in the history
…)` (fixes #9026)
  • Loading branch information
RealyUniqueName committed Dec 12, 2019
1 parent 77947f8 commit 3e260bb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
1 change: 1 addition & 0 deletions extra/CHANGES.txt
Expand Up @@ -3,6 +3,7 @@
Bugfixes:

java : fix boolean arguments for `Type.createInstance(cls, args)` (#9025)
js : fix multiple appearances of the first object added to `ObjectMap` is passed to `ObjectMap.set(obj, v)` multiple times (#9026)
windows : fix adding neko to PATH env var running windows installer (#9021)

2019-11-29: 4.0.3
Expand Down
14 changes: 8 additions & 6 deletions std/js/_std/haxe/ds/ObjectMap.hx
Expand Up @@ -43,18 +43,20 @@ class ObjectMap<K:{}, V> implements haxe.Constraints.IMap<K, V> {
return untyped obj.__id__;
}

var h:{};
var h:{__keys__:{}};

public function new():Void {
h = {__keys__: {}};
}

public function set(key:K, value:V):Void
untyped {
var id:Int = getId(key) || assignId(key);
h[id] = value;
h.__keys__[id] = key;
public function set(key:K, value:V):Void {
var id = getId(key);
if(id == null) {
id = assignId(key);
}
Syntax.code('{0}[{1}] = {2}', h, id, value);
Syntax.code('{0}[{1}] = {2}', h.__keys__, id, key);
}

public inline function get(key:K):Null<V> {
return untyped h[getId(key)];
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/src/unit/issues/Issue9026.hx
@@ -0,0 +1,12 @@
package unit.issues;

class Issue9026 extends unit.Test {
function test() {
var key = {};
var map: Map<{}, Int> = new Map();
map[key] = 10;
map[key] = 20;
eq(20, map.get(key));
eq(1, Lambda.count(map));
}
}

0 comments on commit 3e260bb

Please sign in to comment.