Browse Source

ObjectMap fixes

Simon Krajewski 12 years ago
parent
commit
47d6893e84

+ 4 - 1
std/flash/_std/haxe/ds/ObjectMap.hx

@@ -23,7 +23,10 @@ class ObjectMap<K,V> extends flash.utils.Dictionary {
 	}
 	}
 
 
 	public function iterator() : Iterator<V> {
 	public function iterator() : Iterator<V> {
-		return untyped __keys__(this).iterator();
+		var ret = [];
+		for (i in keys())
+			ret.push(get(i));
+		return ret.iterator();
 	}
 	}
 
 
 	public function toString() : String {
 	public function toString() : String {

+ 2 - 2
std/flash8/_std/haxe/ds/ObjectMap.hx

@@ -80,8 +80,8 @@ class ObjectMap <K:{ }, V> {
 		return untyped {
 		return untyped {
 			ref : h,
 			ref : h,
 			it : __hkeys__(h.__keys__)["iterator"](),
 			it : __hkeys__(h.__keys__)["iterator"](),
-			hasNext : function() { return __h__.it[__unprotect__("hasNext")](); },
-			next : function() { var i = __h__.it[__unprotect__("next")](); return __h__.ref["$" +i]; }
+			hasNext : function() { return __this__.it[__unprotect__("hasNext")](); },
+			next : function() { var i = __this__.it[__unprotect__("next")](); return __this__.ref["$" +i]; }
 		};
 		};
 	}
 	}
 	
 	

+ 7 - 2
std/php/_std/haxe/ds/ObjectMap.hx

@@ -29,13 +29,17 @@ class ObjectMap <K:{ }, V> {
 	}
 	}
 	
 	
 	var h : ArrayAccess<V>;
 	var h : ArrayAccess<V>;
+	var hk : ArrayAccess<K>;
 	
 	
 	public function new(weakKeys:Bool = false):Void {
 	public function new(weakKeys:Bool = false):Void {
 		h = untyped __call__('array');
 		h = untyped __call__('array');
+		hk = untyped __call__('array');
 	}
 	}
 	
 	
 	public function set(key:K, value:V):Void untyped {
 	public function set(key:K, value:V):Void untyped {
-		untyped h[getId(key)] = value;
+		var id = getId(key);
+		untyped h[id] = value;
+		untyped hk[id] = key;
 	}
 	}
 	
 	
 	public function get(key:K):Null<V> {
 	public function get(key:K):Null<V> {
@@ -54,13 +58,14 @@ class ObjectMap <K:{ }, V> {
 		var id = getId(key);
 		var id = getId(key);
 		if (untyped __call__("array_key_exists", id, h)) {
 		if (untyped __call__("array_key_exists", id, h)) {
 			untyped __call__("unset", h[id]);
 			untyped __call__("unset", h[id]);
+			untyped __call__("unset", hk[id]);
 			return true;
 			return true;
 		} else
 		} else
 			return false;
 			return false;
 	}
 	}
 	
 	
 	public inline function keys() : Iterator<K> {
 	public inline function keys() : Iterator<K> {
-		return untyped __call__("new _hx_array_iterator", __call__("array_keys", h));
+		return untyped __call__("new _hx_array_iterator", __call__("array_values", hk));
 	}
 	}
 	
 	
 	public inline function iterator() : Iterator<V> {
 	public inline function iterator() : Iterator<V> {