Prechádzať zdrojové kódy

fixes for variable protection.

Nicolas Cannasse 19 rokov pred
rodič
commit
e631e21100
4 zmenil súbory, kde vykonal 50 pridanie a 55 odobranie
  1. 4 4
      std/Hash.hx
  2. 4 4
      std/Reflect.hx
  3. 15 17
      std/flash/Boot.hx
  4. 27 30
      std/flash/FlashXml__.hx

+ 4 - 4
std/Hash.hx

@@ -83,7 +83,7 @@ class Hash<T> {
 	**/
 	public function exists( key : String ) : Bool {
 		#if flash
-		return untyped h.hasOwnProperty(key);
+		return untyped h["hasOwnProperty"](key);
 		#else js
 		return Reflect.hasField(h,key);
 		#else neko
@@ -98,7 +98,7 @@ class Hash<T> {
 	**/
 	public function remove( key : String ) : Bool {
 		#if flash
-		if( untyped !h.hasOwnProperty(key) ) return false;
+		if( untyped !h["hasOwnProperty"](key) ) return false;
 		untyped __delete__(h,key);
 		return true;
 		#else js
@@ -133,8 +133,8 @@ class Hash<T> {
 		return untyped {
 			ref : h,
 			it : keys(),
-			hasNext : function() { return this.it.hasNext(); },
-			next : function() { var i = this.it.next(); return this.ref[i]; }
+			hasNext : function() { return this.it[__unprotect__("hasNext")](); },
+			next : function() { var i = this.it[__unprotect__("next")](); return this.ref[i]; }
 		};
 		#else js
 		return untyped {

+ 4 - 4
std/Reflect.hx

@@ -193,7 +193,7 @@ class Reflect {
 	public static function hasField( o : Dynamic, field : String ) : Bool {
 		untyped{
 		#if flash
-			return this.hasOwnProperty.call(o,field);
+			return this["hasOwnProperty"]["call"](o,field);
 		#else js
 			if( o.hasOwnProperty != null )
 				return o.hasOwnProperty(field);
@@ -255,7 +255,7 @@ class Reflect {
 	public static function callMethod( o : Dynamic, func : Dynamic, args : Array<Dynamic> ) : Dynamic {
 		return untyped
 		#if flash
-			func.apply(o,args)
+			func["apply"](o,args)
 		#else js
 			func.apply(o,args)
 		#else neko
@@ -421,7 +421,7 @@ class Reflect {
 	public static function isFunction( f : Dynamic ) : Bool {
 		return untyped
 		#if flash
-			f.call == _global["Function"].call && f.__interfaces__ == null
+			f["call"] == _global["Function"].call && f.__interfaces__ == null
 		#else js
 			f != null && f.call == isFunction.call && f.__interfaces__ == null
 		#else neko
@@ -437,7 +437,7 @@ class Reflect {
 	public static function deleteField( o : Dynamic, f : String ) : Bool {
 		#if flash
 			untyped {
-				if( this.hasOwnProperty.call(o,f) == null ) return false;
+				if( this["hasOwnProperty"].call(o,f) == null ) return false;
 				__delete__(o,f);
 				return true;
 			}

+ 15 - 17
std/flash/Boot.hx

@@ -28,7 +28,7 @@ class Boot {
 
 	private static var exc : Array<Dynamic>;
 
-	private static function __string_rec(o,s) {
+	private static function __string_rec(o : Dynamic,s : String) {
 		untyped {
 			if( s.length >= 20 )
 				return "<...>"; // too much deep recursion
@@ -41,11 +41,11 @@ class Boot {
 			case "object":
 				if( __instanceof__(o,Array) ) {
 					if( o.__enum__ != null ) {
-						if( o.length == 1 )
+						if( o["length"] == 1 )
 							return o[0];
 						var str = o[0]+"(";
 						s += "    ";
-						for( i in 1...o.length ) {
+						for( i in 1...o["length"] ) {
 							if( i != 1 )
 								str += "," + __string_rec(o[i],s);
 							else
@@ -53,7 +53,7 @@ class Boot {
 						}
 						return str + ")";
 					}
-					var l = o.length;
+					var l = o["length"];
 					var i;
 					var str = "[";
 					s += "    ";
@@ -62,7 +62,7 @@ class Boot {
 					str += "]";
 					return str;
 				}
-				var s2 = o.toString();
+				var s2 = o["toString"]();
 				if( (__typeof__(s2) == "string" || __instanceof__(s2,String)) && s2 != "[object Object]" && s2 != "[type Function]" )
 					return s2;
 				var k;
@@ -73,7 +73,7 @@ class Boot {
 				for( k in (__keys__(o)).iterator() ) {
 					if( str.length != 2 )
 						str += ",\n";
-					if( k == "__construct__" && __typeof__(o[k]) == "function" )
+					if( k == __unprotect__("__construct__") && __typeof__(o[k]) == "function" )
 						str += s + k + " : <function>";
 					else
 						str += s + k + " : "+__string_rec(o[k],s);
@@ -160,7 +160,7 @@ class Boot {
 				root.__trace_lines = new Array<String>();
 			}
 			var s = inf.fileName+(if( inf.lineNumber == null ) "" else ":"+inf.lineNumber)+": "+__string_rec(v,"");
-			var lines = root.__trace_lines.concat(s.split("\n"));
+			var lines = root.__trace_lines["concat"](s.split("\n"));
 			root.__trace_lines = lines;
 			var nlines = Stage.height / 16;
 			if( lines.length > nlines )
@@ -179,23 +179,16 @@ class Boot {
 	private static function __init(current) {
 		untyped {
 			var obj = _global["Object"];
-			if( flash.text == null )
-				flash.text = __new__(obj);
-			flash.text.StyleSheet = TextField["StyleSheet"];
-			flash.system = __new__(obj);
-			flash.system.Capabilities = System.capabilities;
-			flash.system.Security = System.security;
-			flash.system.IME = System["IME"];
 			Array.prototype.copy = Array.prototype.slice;
 			Array.prototype.insert = function(i,x) {
-				this.splice(i,0,x);
+				this["splice"](i,0,x);
 			};
 			Array.prototype.remove = function(obj) {
 				var i = 0;
-				var l = this.length;
+				var l = this["length"];
 				while( i < l ) {
 					if( this[i] == obj ) {
-						this.splice(i,1);
+						this["splice"](i,1);
 						return true;
 					}
 					i++;
@@ -247,6 +240,11 @@ class Boot {
 			flash.NetConnection = _global["NetConnection"];
 			flash.NetStream = _global["NetStream"];
 
+			flash.text.StyleSheet = TextField["StyleSheet"];
+			flash.system.Capabilities = System.capabilities;
+			flash.system.Security = System.security;
+			flash.system.IME = System["IME"];
+
 			Lib._global = _global;
 			Lib._root = _root;
 			Lib.current = current;

+ 27 - 30
std/flash/FlashXml__.hx

@@ -41,13 +41,13 @@ class FlashXml__ {
 		r.__x = o;
 		o.__w = r;
 
-		r.nodeType = switch( o.nodeType ) {
+		r.nodeType = switch( untyped o["nodeType"] ) {
 			case 1:
 				Xml.Element;
 			case 3:
 				Xml.PCData;
 			default:
-				throw "unknow nodeType: "+o.nodeType;
+				throw "unknow nodeType: "+untyped o["nodeType"];
 		}
 
 		return untyped r;
@@ -110,43 +110,43 @@ class FlashXml__ {
 	}
 
 	public function firstChild(){
-		return convert(this.__x.firstChild);
+		return convert(this.__x[untyped "firstChild"]);
 	}
 
 	public function firstElement(){
-		var e : Dynamic = __x.firstChild;
+		var e : Dynamic = __x[untyped "firstChild"];
 		while( e != null && e.nodeType != 1 )
-			e = e.nextSibling;
+			e = e[untyped "nextSibling"];
 		return convert(e);
 	}
 
 	private function setNodeName( n : String ) : String {
 		if( nodeType != Xml.Element )
 			throw "bad nodeType";
-		return __x.nodeName = n;
+		return __x[untyped "nodeName"] = n;
 	}
 
 	private function setNodeValue( v : String ) : String {
 		if( nodeType == Xml.Element || nodeType == Xml.Document )
 			throw "bad nodeType";
-		return __x.nodeValue = v;
+		return __x[untyped "nodeValue"] = v;
 	}
 
 	private function getNodeName() : String {
 		if( nodeType != Xml.Element )
 			throw "bad nodeType";
-		return __x.nodeName;
+		return __x[untyped "nodeName"];
 	}
 
 	private function getNodeValue() : String {
 		if( nodeType == Xml.Element || nodeType == Xml.Document )
 			throw "bad nodeType";
-		return __x.nodeValue;
+		return __x[untyped "nodeValue"];
 	}
 
-	public function iterator(){
+	public function iterator() : Iterator<Xml> {
 		return untyped {
-			cur: this.__x.firstChild,
+			cur: this.__x[untyped "firstChild"],
 			hasNext : function(){
 				return this.cur != null;
 			},
@@ -158,9 +158,9 @@ class FlashXml__ {
 		}
 	}
 
-	public function elements(){
+	public function elements() : Iterator<Xml> {
 		return untyped {
-			cur: this.__x.firstChild,
+			cur: this.__x[untyped "firstChild"],
 			hasNext : function() {
 				var r = this.cur;
 				while( r != null && r.nodeType != 1 )
@@ -184,7 +184,7 @@ class FlashXml__ {
 
 	public function elementsNamed( nodeName : String ){
 		return untyped {
-			cur: this.__x.firstChild,
+			cur: this.__x[untyped "firstChild"],
 			hasNext : function() {
 				var r = this.cur;
 				while( r != null && (r.nodeType != 1 || r.nodeName != nodeName) )
@@ -209,62 +209,59 @@ class FlashXml__ {
 	public function get( k : String ) : String {
 		if( nodeType != Xml.Element )
 			throw "bad nodeType";
-		return Reflect.field(__x.attributes,k);
+		return Reflect.field(__x[untyped "attributes"],k);
 	}
 
 	public function set( k : String, v : String ) : Void {
 		if( nodeType != Xml.Element )
 			throw "bad nodeType";
-		return Reflect.setField(__x.attributes,k,v);
+		return Reflect.setField(__x[untyped "attributes"],k,v);
 	}
 
 	public function exists( k : String ) : Bool {
 		if( nodeType != Xml.Element )
 			throw "bad nodeType";
-		return Reflect.hasField(__x.attributes,k);
+		return Reflect.hasField(__x[untyped "attributes"],k);
 	}
 
 	public function remove( k : String ) : Void {
 		if( nodeType != Xml.Element )
 			throw "bad nodeType";
-		Reflect.deleteField(__x.attributes,k);
+		Reflect.deleteField(__x[untyped "attributes"],k);
 	}
 
 	public function attributes() : Iterator<String> {
 		if( nodeType != Xml.Element )
 			throw "bad nodeType";
-		return untyped __keys__(__x.attributes).iterator();
+		return untyped __keys__(__x["attributes"]).iterator();
 	}
 
 	public function addChild( child : Xml ) {
-		untyped __x.appendChild(child.__x);
+		untyped __x[untyped "appendChild"](child.__x);
 	}
 
 	public function removeChild( child : Xml ) : Bool {
-		untyped if( child.__x.parentNode != __x )
+		untyped if( child.__x["parentNode"] != __x )
 			return false;
-		untyped child.__x.removeNode();
+		untyped child.__x["removeNode"]();
 		return true;
 	}
 
 	public function insertChild( x : Xml, pos : Int ) : Void {
-		var i = 0;
-		for( c in iterator() ){
-			if( i == pos )
-				untyped __x.insertBefore(x.__x,c.__x);
-			i++;
-		}
+		var c : Array<Dynamic> = __x[untyped "childNodes"];
+		if( pos <= c.length )
+			__x[untyped "insertBefore"](untyped x.__x,c[pos]);
 	}
 
 	public function toString() {
 		if( nodeType == Xml.Document ){
 			var s = "";
 			for( c in iterator() )
-				untyped s += c.__x.toString();
+				s += c.toString();
 			return s;
 		}
 		if( nodeType == Xml.CData )
-			return "<![CDATA["+__x.nodeValue+"]]>";
+			return "<![CDATA["+__x[untyped "nodeValue"]+"]]>";
 		return __x.toString();
 	}