Browse Source

Fix fields (js)

Pascal Peridont 19 years ago
parent
commit
6af3f99bf1
1 changed files with 17 additions and 7 deletions
  1. 17 7
      std/Reflect.hx

+ 17 - 7
std/Reflect.hx

@@ -261,6 +261,7 @@ class Reflect {
 		Returns the list of fields of an object, excluding its prototype (class methods).
 	**/
 	public static function fields( o : Dynamic ) : Array<String> {
+		if( o == null ) return new Array();
 		return untyped {
 		#if flash
 			var a = __keys__(o);
@@ -273,14 +274,23 @@ class Reflect {
 			}
 			a;
 		#else js
-			var a = js.Boot.__keys(o);
+			var a = new Array();
+			var t;
+			try{ t = o.__proto__; }catch(e : Dynamic){ t = null; }
+			if( t != null ) o.__proto__ = null;
+			untyped __js__("
+				for(var i in o)
+					a.push(i);
+			");
+			if( t != null ) o.__proto__ = t;
 			var i = 0;
-			while( i < a.length ) {
-				if( !o.hasOwnProperty(a[i]) )
-					a.splice(i,1);
-				else
-					++i;
-			}
+			if( o.hasOwnProperty != null )
+				while( i < a.length ) {
+					if( !o.hasOwnProperty(a[i]) )
+						a.splice(i,1);
+					else
+						++i;
+				}
 			a;
 		#else neko
 			if( __dollar__typeof(o) != __dollar__tobject )