Browse Source

calling foo(null) when foo parameter has default value will no longer use default value (in js/flash8/flash9)

Nicolas Cannasse 15 years ago
parent
commit
90b665c4e3
3 changed files with 12 additions and 1 deletions
  1. 6 1
      codegen.ml
  2. 1 0
      doc/CHANGES.txt
  3. 5 0
      genswf8.ml

+ 6 - 1
codegen.ml

@@ -1015,7 +1015,12 @@ let rec is_volatile t =
 
 let set_default ctx a c t p =
 	let ve = mk (TLocal a) t p in
-	mk (TIf (mk (TBinop (OpEq,ve,mk (TConst TNull) t p)) ctx.basic.tbool p, mk (TBinop (OpAssign,ve,mk (TConst c) t p)) t p,None)) ctx.basic.tvoid p
+	let cond =  match ctx.platform with
+		| Js -> TCall (mk (TLocal "__js__") t_dynamic p,[mk (TConst (TString (a ^ "=== undefined"))) ctx.basic.tstring p])
+		| Flash -> TCall (mk (TLocal "__physeq__") t_dynamic p,[ve;mk (TCall (mk (TLocal "__undefined__") t_dynamic p,[])) t_dynamic p])
+		| _ -> TBinop (OpEq,ve,mk (TConst TNull) t p)
+	in
+	mk (TIf (mk cond ctx.basic.tbool p, mk (TBinop (OpAssign,ve,mk (TConst c) t p)) t p,None)) ctx.basic.tvoid p
 
 let bytes_serialize data =
 	let b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789%:" in

+ 1 - 0
doc/CHANGES.txt

@@ -16,6 +16,7 @@
 	         (this can be disabled with -D dontWaitStage)
 	all : added haxe.Timer.measure
 	all : added Lambda.indexOf and Lambda.concat
+	js, flash8: changed behavior when explicitely using 'null' for optional param with default value
 
 2010-08-14: 2.06
 	neko : change serializer to be able to handle instances of basic classes from other modules

+ 5 - 0
genswf8.ml

@@ -93,6 +93,7 @@ type push_style =
 	| VReg of int
 	| VThis
 	| VNull
+	| VUndefined
 	| VSuper
 
 let stack_delta = function
@@ -242,6 +243,8 @@ let push ctx items =
 			PReg 1
 		| VNull ->
 			PNull
+		| VUndefined ->
+			PUndefined
 		| VSuper ->
 			PReg 2
 		| VReg n ->
@@ -884,6 +887,8 @@ and gen_call ctx e el =
 		write ctx AEval
 	| TLocal "__gettimer__", [] ->
 		write ctx AGetTimer
+	| TLocal "__undefined__", [] ->
+		push ctx [VUndefined]		
 	| TLocal "__geturl__" , url :: target :: post ->
 		gen_expr ctx true url;
 		gen_expr ctx true target;