Browse Source

.callback changed to .bind (includes a few tmp fixes until we allow again .bind method calls)

Nicolas Cannasse 12 years ago
parent
commit
5eb6488750

+ 4 - 4
std/haxe/remoting/LocalConnection.hx

@@ -122,8 +122,8 @@ class LocalConnection implements AsyncConnection, implements Dynamic<AsyncConnec
 		},[]);
 		#if flash9
 			l.client = {
-				remotingCall : remotingCall.callback(c),
-				remotingResult : remotingResult.callback(c),
+				remotingCall : remotingCall.bind(c),
+				remotingResult : remotingResult.bind(c),
 			};
 			l.addEventListener(flash.events.StatusEvent.STATUS, function(s:flash.events.StatusEvent) {
 				if( s.level != "status" )
@@ -139,8 +139,8 @@ class LocalConnection implements AsyncConnection, implements Dynamic<AsyncConnec
 				for( d in allowDomains )
 					l.allowDomain(d);
 		#else
-			Reflect.setField(l,"remotingCall",remotingCall.callback(c));
-			Reflect.setField(l,"remotingResult",remotingResult.callback(c));
+			Reflect.setField(l,"remotingCall",remotingCall.bind(c));
+			Reflect.setField(l,"remotingResult",remotingResult.bind(c));
 			l.onStatus = function(s:Dynamic) {
 				if( s[untyped "level"] != "status" )
 					c.__data.error("Failed to send data on LocalConnection");

+ 1 - 1
std/neko/net/ServerLoop.hx

@@ -182,7 +182,7 @@ class ServerLoop<ClientData> {
 	**/
 	public function run( host : sys.net.Host, port : Int ) {
 		var serv = new Socket();
-		serv.bind(host,port);
+		(serv.bind)(host,port);
 		serv.listen(listenCount);
 		socks = [serv];
 		while( true ) {

+ 7 - 7
std/neko/net/ThreadServer.hx

@@ -98,7 +98,7 @@ class ThreadServer<Client,Message> {
 				break;
 			pos += m.bytes;
 			len -= m.bytes;
-			work(clientMessage.callback(c.client,m.msg));
+			work(clientMessage.bind(c.client,m.msg));
 		}
 		if( pos > 0 )
 			c.buf.blit(0,c.buf,pos,len);
@@ -115,7 +115,7 @@ class ThreadServer<Client,Message> {
 					t.socks.remove(s);
 					if( !Std.is(e,haxe.io.Eof) && !Std.is(e,haxe.io.Error) )
 						logError(e);
-					work(doClientDisconnected.callback(s,infos.client));
+					work(doClientDisconnected.bind(s,infos.client));
 				}
 			}
 		while( true ) {
@@ -126,7 +126,7 @@ class ThreadServer<Client,Message> {
 				t.socks.push(m.s);
 			else if( t.socks.remove(m.s) ) {
 				var infos : ClientInfos<Client> = m.s.custom;
-				work(doClientDisconnected.callback(m.s,infos.client));
+				work(doClientDisconnected.bind(m.s,infos.client));
 			}
 		}
 	}
@@ -161,7 +161,7 @@ class ThreadServer<Client,Message> {
 		if( neko.vm.Thread.current() == worker )
 			onError(e,stack);
 		else
-			work(onError.callback(e,stack));
+			work(onError.bind(e,stack));
 	}
 
 	function addClient( sock : sys.net.Socket ) {
@@ -208,18 +208,18 @@ class ThreadServer<Client,Message> {
 				p : new neko.net.Poll(maxSockPerThread),
 			};
 			threads.push(t);
-			t.t = neko.vm.Thread.create(runThread.callback(t));
+			t.t = neko.vm.Thread.create(runThread.bind(t));
 		}
 	}
 
 	public function addSocket( s : sys.net.Socket ) {
 		s.setBlocking(false);
-		work(addClient.callback(s));
+		work(addClient.bind(s));
 	}
 
 	public function run( host, port ) {
 		sock = new sys.net.Socket();
-		sock.bind(new sys.net.Host(host),port);
+		(sock.bind)(new sys.net.Host(host),port);
 		sock.listen(listen);
 		init();
 		while( true ) {

+ 2 - 2
tests/unit/Test.hx

@@ -86,7 +86,7 @@ package unit;
 
 	function async<Args,T>( f : Args -> (T -> Void) -> Void, args : Args, v : T, ?pos : haxe.PosInfos ) {
 		if( asyncWaits.length >= AMAX ) {
-			asyncCache.push(async.callback(f,args,v,pos));
+			asyncCache.push(async.bind(f,args,v,pos));
 			return;
 		}
 		asyncWaits.push(pos);
@@ -104,7 +104,7 @@ package unit;
 
 	function asyncExc<Args>( seterror : (Dynamic -> Void) -> Void, f : Args -> (Dynamic -> Void) -> Void, args : Args, ?pos : haxe.PosInfos ) {
 		if( asyncWaits.length >= AMAX ) {
-		asyncCache.push(asyncExc.callback(seterror,f,args,pos));
+		asyncCache.push(asyncExc.bind(seterror,f,args,pos));
 			return;
 		}
 		asyncWaits.push(pos);

+ 8 - 8
tests/unit/TestMisc.hx

@@ -134,7 +134,7 @@ class TestMisc extends Test {
 		var c = new MyClass(100);
 		var add = c.add;
 		eq( c.add(1,2), 103 );
-		eq( c.add.callback(1)(2), 103 );
+		eq( c.add.bind(1)(2), 103 );
 		eq( add(1,2), 103 );
 
 		var x = 4;
@@ -177,8 +177,8 @@ class TestMisc extends Test {
 
 	function testCaptureUnique2() {
 		// another more specialized test (was actually the original broken code - but not reproducible when optimization is off)
-		var foo = id.callback(3);
-		var bar = sq.callback(5);
+		var foo = id.bind(3);
+		var bar = sq.bind(5);
 		eq( foo(), 3 );
 		eq( bar(), 25 );
 	}
@@ -249,35 +249,35 @@ class TestMisc extends Test {
 		var inst = new MyDynamicClass(100);
 		var add = inst.add;
 		eq( inst.add(1,2), 103 );
-		eq( inst.add.callback(1)(2), 103 );
+		eq( inst.add.bind(1)(2), 103 );
 		eq( add(1,2), 103 );
 
 		// check overriden dynamic method
 		var inst = new MyDynamicSubClass(100);
 		var add = inst.add;
 		eq( inst.add(1,2), 206 );
-		eq( inst.add.callback(1)(2), 206 );
+		eq( inst.add.bind(1)(2), 206 );
 		eq( add(1,2), 206 );
 
 		// check overriden dynamic method
 		var inst = new MyDynamicSubClass2(100);
 		var add = inst.add;
 		eq( inst.add(1,2), 206 );
-		eq( inst.add.callback(1)(2), 206 );
+		eq( inst.add.bind(1)(2), 206 );
 		eq( add(1,2), 206 );
 
 		// check redefined dynamic method
 		inst.add = function(x,y) return inst.get() * 2 + x + y;
 		var add = inst.add;
 		eq( inst.add(1,2), 203 );
-		eq( inst.add.callback(1)(2), 203 );
+		eq( inst.add.bind(1)(2), 203 );
 		eq( add(1,2), 203 );
 
 		// check inherited dynamic method
 		var inst = new MyOtherDynamicClass(0);
 		var add = inst.add;
 		eq( inst.add(1,2), 13 );
-		eq( inst.add.callback(1)(2), 13 );
+		eq( inst.add.bind(1)(2), 13 );
 		eq( add(1,2), 13 );
 
 		// check static dynamic

+ 36 - 36
tests/unit/TestType.hx

@@ -222,81 +222,81 @@ class TestType extends Test {
 
 		// all missing
 
-		typedAs(func.callback(), func);
-		typedAs(func.callback(_), func);
-		typedAs(func.callback(_, _), func);
-		typedAs(func.callback(_, _, _), func);
+		typedAs(func.bind(), func);
+		typedAs(func.bind(_), func);
+		typedAs(func.bind(_, _), func);
+		typedAs(func.bind(_, _, _), func);
 
 		// all given
 
-		typedAs(func.callback(22, "2", 13), tvoid);
+		typedAs(func.bind(22, "2", 13), tvoid);
 
 		// last missing
 
-		typedAs(func.callback(22, "2"), tfloat);
-		typedAs(func.callback(22, "2", _), tfloat);
+		typedAs(func.bind(22, "2"), tfloat);
+		typedAs(func.bind(22, "2", _), tfloat);
 
 		// first given
 
-		typedAs(func.callback(22), tstringfloat);
-		typedAs(func.callback(22, _), tstringfloat);
-		typedAs(func.callback(22, _, _), tstringfloat);
+		typedAs(func.bind(22), tstringfloat);
+		typedAs(func.bind(22, _), tstringfloat);
+		typedAs(func.bind(22, _, _), tstringfloat);
 
 		// mixed
 
-		typedAs(func.callback(_, _, 12), tintstring);
-		typedAs(func.callback(_, "22", _), tintfloat);
-		typedAs(func.callback(_, "22", 12), tint);
-		typedAs(func.callback(12, _, 12), tstring);
+		typedAs(func.bind(_, _, 12), tintstring);
+		typedAs(func.bind(_, "22", _), tintfloat);
+		typedAs(func.bind(_, "22", 12), tint);
+		typedAs(func.bind(12, _, 12), tstring);
 
 		// values
 
-		eq(1, func.callback()(1, "2", 3));
-		eq(2, func.callback(2)("2", 3));
-		eq(2, func.callback(2, "3")(3));
-		eq(2, func.callback(2, "3", 4)());
+		eq(1, func.bind()(1, "2", 3));
+		eq(2, func.bind(2)("2", 3));
+		eq(2, func.bind(2, "3")(3));
+		eq(2, func.bind(2, "3", 4)());
 
-		eq(1, func.callback(_, "2", 3)(1));
-		eq(1, func.callback(_, "2")(1, 3));
-		eq(1, func.callback(_)(1, "2", 3));
+		eq(1, func.bind(_, "2", 3)(1));
+		eq(1, func.bind(_, "2")(1, 3));
+		eq(1, func.bind(_)(1, "2", 3));
 
-		eq(1, func.callback(_, "2", _)(1, 2));
+		eq(1, func.bind(_, "2", _)(1, 2));
 
-		eq(1, func.callback().callback(_, "2", 3)(1));
-		eq(1, func.callback(1).callback("2", 3)());
-		eq(1, func.callback(1, _).callback("2")(3));
-		eq(1, func.callback(_, "2").callback(1)(3));
+		eq(1, func.bind().bind(_, "2", 3)(1));
+		eq(1, func.bind(1).bind("2", 3)());
+		eq(1, func.bind(1, _).bind("2")(3));
+		eq(1, func.bind(_, "2").bind(1)(3));
 
 		var a = 5;
 		var b = "foo";
-		var cb = func.callback(a);
+		var cb = func.bind(a);
 		a = 6;
 		func = function(a,b,c):Int return throw "error";
 		eq(5, cb(b, 0));
 
 		var optfunc = function(a:Int, b:Int, ?c:Int = 2) return a + b + c;
-		eq(6, optfunc.callback(1)(3));
-		eq(6, optfunc.callback(1, 3)());
+		eq(6, optfunc.bind(1)(3));
+		eq(6, optfunc.bind(1, 3)());
 
-		eq(7, optfunc.callback(_, _, _)(1, 2, 4));
-		eq(7, optfunc.callback(_, 2, _)(1, 4));
+		eq(7, optfunc.bind(_, _, _)(1, 2, 4));
+		eq(7, optfunc.bind(_, 2, _)(1, 4));
 
 		var foo = function ( x : Int, ?p : haxe.PosInfos ) { return "foo" + x; }
-		var f : Void -> String = foo.callback(0);
+		var f : Void -> String = foo.bind(0);
  		eq("foo0", f());
 
 		// TODO: this fails on flash 9
 		var foo = function(bar = 2) { return bar; };
 		#if (flash9)
-		t(typeError(foo.callback(_)));
+		t(typeError(foo.bind(_)));
 		#else
-		var l = foo.callback(_);
+		var l = foo.bind(_);
 		eq(2, l());
 		#end
 
 		// note that this does not
 		var foo = function(bar:Null<Int> = 2) { return bar; };
-		var l = foo.callback(_);
+		var l = foo.bind(_);
 		eq(2, l());
 	}
 
@@ -467,7 +467,7 @@ class TestType extends Test {
 		//typeError(pcc2.check(["foo"]));
 
 		var pcc2 = new ParamConstraintsClass2();
-		pcc2.bind("foo");
+		(pcc2.bind)("foo");
 		//typeError(pcc2.check([1]));
 		pcc2.check(["foo"]);
 

+ 5 - 5
tests/unit/TestXML.hx

@@ -164,12 +164,12 @@ class TestXML extends Test {
 		h.nodeName = "em";
 		eq( h.nodeName, "em" );
 
-		eq( Lambda.count({ iterator : x.elementsNamed.callback("em") }), 1 );
+		eq( Lambda.count({ iterator : x.elementsNamed.bind("em") }), 1 );
 
 		h.nodeName = "xhtml:em";
 
-		eq( Lambda.count({ iterator : x.elementsNamed.callback("xhtml:em") }), 1 );
-		eq( Lambda.count({ iterator : x.elementsNamed.callback("em") }), 0 );
+		eq( Lambda.count({ iterator : x.elementsNamed.bind("xhtml:em") }), 1 );
+		eq( Lambda.count({ iterator : x.elementsNamed.bind("em") }), 0 );
 
 		eq( h.nodeName, "xhtml:em" );
 	}
@@ -219,11 +219,11 @@ class TestXML extends Test {
 	}
 	
 	function testMore() {
-		var doc = Xml.parse("<a>A</a><i>I</i>"); 
+		var doc = Xml.parse("<a>A</a><i>I</i>");
 		var aElement = doc.elementsNamed('a').next();
 		var iElement = doc.elementsNamed('i').next();
 		iElement.addChild(aElement);
 		
-		eq(doc.toString(), "<i>I<a>A</a></i>");		
+		eq(doc.toString(), "<i>I<a>A</a></i>");
 	}
 }

+ 8 - 8
tests/unit/unitstd/haxe/macro/ExprTools.unit.hx

@@ -49,7 +49,7 @@ function extract(e) {
 		case haxe.macro.Expr.ExprDef.EConst(haxe.macro.Expr.Constant.CString(s)):
 			strings.push(s);
 		case haxe.macro.Expr.ExprDef.EConst(haxe.macro.Expr.Constant.CIdent(s)) if (s.charCodeAt(0) >= 'A'.code && s.charCodeAt(0) <= 'Z'.code):
-			upperIdents.push(s);			
+			upperIdents.push(s);
 		case _:
 			haxe.macro.ExprTools.iter(e, extract);
 	}
@@ -71,13 +71,13 @@ function check(e, exp, ?pos) {
 iter(econst, fail);
 iter(econtinue, fail);
 iter(ebreak, fail);
-iter(efield, seq.callback("EConst(CString(foo))"));
-iter(eparenthesis, seq.callback("EConst(CInt(1))"));
-iter(euntyped, seq.callback("EConst(CInt(1))"));
-iter(ethrow, seq.callback("EConst(CInt(1))"));
-iter(eunop, seq.callback("EConst(CInt(1))"));
-iter(ecast, seq.callback("EConst(CInt(1))"));
-iter(emeta, seq.callback("EConst(CInt(1))"));
+iter(efield, seq.bind("EConst(CString(foo))"));
+iter(eparenthesis, seq.bind("EConst(CInt(1))"));
+iter(euntyped, seq.bind("EConst(CInt(1))"));
+iter(ethrow, seq.bind("EConst(CInt(1))"));
+iter(eunop, seq.bind("EConst(CInt(1))"));
+iter(ecast, seq.bind("EConst(CInt(1))"));
+iter(emeta, seq.bind("EConst(CInt(1))"));
 check(earray, ["EConst(CInt(1))", "EConst(CInt(0))"]);
 check(ewhile1, ["EConst(CInt(1))", "EConst(CString(foo))"]);
 check(ewhile2, ["EConst(CInt(1))", "EConst(CString(foo))"]);