Browse Source

correctly set scope/method for array.push closure (see #5792 failing test)

Nicolas Cannasse 8 years ago
parent
commit
df85f23f35
1 changed files with 2 additions and 3 deletions
  1. 2 3
      src/generators/genjs.ml

+ 2 - 3
src/generators/genjs.ml

@@ -515,6 +515,7 @@ and gen_expr ctx e =
 	| TField (x,FClosure (Some ({cl_path=[],"Array"},_), {cf_name="push"})) ->
 		(* see https://github.com/HaxeFoundation/haxe/issues/1997 *)
 		add_feature ctx "use.$arrayPushClosure";
+		add_feature ctx "use.$bind";
 		print ctx "$arrayPushClosure(";
 		gen_value ctx x;
 		print ctx ")"
@@ -1488,9 +1489,7 @@ let generate com =
 		newline ctx;
 	end;
 	if has_feature ctx "use.$arrayPushClosure" then begin
-		print ctx "function $arrayPushClosure(a) {";
-		print ctx " return function(x) { a.push(x); }; ";
-		print ctx "}";
+		print ctx "function $arrayPushClosure(a) { return $bind(a,function(x) { return this.push(x); }); }";
 		newline ctx
 	end;
 	List.iter (gen_block_element ~after:true ctx) (List.rev ctx.inits);