Browse Source

forbid static 'length' (issue since object is a Function)

Nicolas Cannasse 13 years ago
parent
commit
8e0c264665
2 changed files with 6 additions and 3 deletions
  1. 1 0
      doc/CHANGES.txt
  2. 5 3
      genjs.ml

+ 1 - 0
doc/CHANGES.txt

@@ -5,6 +5,7 @@
 	flash : fixed Xml.parent() when no parent
 	flash : fixed haxe.io.Bytes.blit when len=0
 	js/php/flash8 : fixed haxe.Int32.mul overflow on 52 bits
+	js : forbid static 'length' (issue since object is a Function)
 
 2012-04-14: 2.09
 	all : optimized const == const and const != const (with different const types)

+ 5 - 3
genjs.ml

@@ -809,14 +809,16 @@ let generate_package_create ctx (p,_) =
 	| [] -> print ctx "var "
 	| _ -> loop [] p
 
-let check_field_name c f =
+let check_field_name c f stat =
 	match f.cf_name with
 	| "prototype" | "__proto__" | "constructor" ->
 		error ("The field name '" ^ f.cf_name ^ "'  is not allowed in JS") (match f.cf_expr with None -> c.cl_pos | Some e -> e.epos);
+	| "length" when stat ->
+		error ("The field name '" ^ f.cf_name ^ "'  is not allowed for statics in JS") (match f.cf_expr with None -> c.cl_pos | Some e -> e.epos);
 	| _ -> ()
 
 let gen_class_static_field ctx c f =
-	check_field_name c f;
+	check_field_name c f true;
 	match f.cf_expr with
 	| None ->
 		print ctx "%s%s = null" (s_path ctx c.cl_path) (field f.cf_name);
@@ -835,7 +837,7 @@ let gen_class_static_field ctx c f =
 			ctx.statics <- (c,f.cf_name,e) :: ctx.statics
 
 let gen_class_field ctx c f =
-	check_field_name c f;
+	check_field_name c f false;
 	newprop ctx;
 	print ctx "%s: " (anon_field f.cf_name);
 	match f.cf_expr with