Browse Source

added $hxClasses

Nicolas Cannasse 14 years ago
parent
commit
5405b744c4
6 changed files with 19 additions and 26 deletions
  1. 1 1
      doc/CHANGES.txt
  2. 3 3
      genjs.ml
  3. 2 2
      std/Date.hx
  4. 3 0
      std/Math.hx
  5. 8 8
      std/js/_std/Std.hx
  6. 2 12
      std/js/_std/Type.hx

+ 1 - 1
doc/CHANGES.txt

@@ -15,7 +15,7 @@
 	js : replaced $closure by function.$bind + changes in output format
 	all : allowed @:extern on static methods (no generate + no closure + force inlining)
 	all : added documentation in --display infos + display overloads in completion
-	js : removed --js-namespace
+	js : removed --js-namespace, added $hxClasses
 
 2011-09-25: 2.08
 	js : added js.JQuery

+ 3 - 3
genjs.ml

@@ -706,7 +706,7 @@ let generate_class ctx c =
 	ctx.id_counter <- 0;
 	let p = s_path ctx c.cl_path in
 	generate_package_create ctx c.cl_path;
-	print ctx "%s = " p;
+	print ctx "%s = $hxClasses[\"%s\"] = " p p;
 	(match c.cl_constructor with
 	| Some { cf_expr = Some e } -> gen_constructor ctx e
 	| _ -> print ctx "function() { }");
@@ -745,7 +745,7 @@ let generate_enum ctx e =
 	let p = s_path ctx e.e_path in
 	generate_package_create ctx e.e_path;
 	let ename = List.map (fun s -> Printf.sprintf "\"%s\"" (Ast.s_escape s)) (fst e.e_path @ [snd e.e_path]) in
-	print ctx "%s = { __ename__ : [%s], __constructs__ : [%s] }" p (String.concat "," ename) (String.concat "," (List.map (fun s -> Printf.sprintf "\"%s\"" s) e.e_names));
+	print ctx "%s = $hxClasses[\"%s\"] = { __ename__ : [%s], __constructs__ : [%s] }" p p (String.concat "," ename) (String.concat "," (List.map (fun s -> Printf.sprintf "\"%s\"" s) e.e_names));
 	newline ctx;
 	List.iter (fun n ->
 		let f = PMap.find n e.e_constrs in
@@ -824,7 +824,7 @@ let generate com =
 	| Some g -> g()
 	| None ->
 	let ctx = alloc_ctx com in
-	print ctx "var $_, $estr = function() { return js.Boot.__string_rec(this,''); }
+	print ctx "var $_, $hxClasses = {}, $estr = function() { return js.Boot.__string_rec(this,''); }
 function $extend(from, fields) {
 	function inherit() {}; inherit.prototype = from; var proto = new inherit();
 	for (var name in fields) proto[name] = fields[name];

+ 2 - 2
std/Date.hx

@@ -165,8 +165,8 @@ extern class Date
 		#elseif flash
 		d.prototype[__unprotect__("__class__")] = d;
 		d[__unprotect__("__name__")] = ["Date"];
-		#else
-		d.prototype.__class__ = d;
+		#elseif js
+		d.prototype.__class__ = $hxClasses['Date'] = d;
 		d.__name__ = ["Date"];
 		#end
 	}

+ 3 - 0
std/Math.hx

@@ -65,6 +65,9 @@ extern class Math
 		Math.NaN = Number["NaN"];
 		Math.NEGATIVE_INFINITY = Number["NEGATIVE_INFINITY"];
 		Math.POSITIVE_INFINITY = Number["POSITIVE_INFINITY"];
+	#end
+	#if js
+		$hxClasses['Math'] = Math;
 	#end
 		Math.isFinite = function(i) {
 			return

+ 8 - 8
std/js/_std/Std.hx

@@ -61,18 +61,18 @@
 	}
 
 	static function __init__() : Void untyped {
-		String.prototype.__class__ = String;
+		String.prototype.__class__ = $hxClasses['String'] = String;
 		String.__name__ = ["String"];
-		Array.prototype.__class__ = Array;
+		Array.prototype.__class__ = $hxClasses['Array'] = Array;
 		Array.__name__ = ["Array"];
-		Int = { __name__ : ["Int"] };
-		Dynamic = { __name__ : ["Dynamic"] };
-		Float = __js__("Number");
+		Int = $hxClasses['Int'] = { __name__ : ["Int"] };
+		Dynamic = $hxClasses['Dynamic'] = { __name__ : ["Dynamic"] };
+		Float = $hxClasses['Float'] = __js__("Number");
 		Float.__name__ = ["Float"];
-		Bool = { __ename__ : ["Bool"] };
-		Class = { __name__ : ["Class"] };
+		Bool = $hxClasses['Bool'] = { __ename__ : ["Bool"] };
+		Class = $hxClasses['Class'] = { __name__ : ["Class"] };
 		Enum = {};
-		Void = { __ename__ : ["Void"] };
+		Void = $hxClasses['Void'] = { __ename__ : ["Void"] };
 	}
 
 }

+ 2 - 12
std/js/_std/Type.hx

@@ -67,12 +67,7 @@ enum ValueType {
 	}
 
 	public static function resolveClass( name : String ) : Class<Dynamic> untyped {
-		var cl : Class<Dynamic>;
-		try {
-			cl = eval(name);
-		} catch( e : Dynamic ) {
-			cl = null;
-		}
+		var cl : Class<Dynamic> = $hxClasses[name];
 		// ensure that this is a class
 		if( cl == null || cl.__name__ == null )
 			return null;
@@ -80,12 +75,7 @@ enum ValueType {
 	}
 
 	public static function resolveEnum( name : String ) : Enum<Dynamic> untyped {
-		var e : Dynamic;
-		try {
-			e = eval(name);
-		} catch( err : Dynamic ) {
-			e = null;
-		}
+		var e : Dynamic = $hxClasses[name];
 		// ensure that this is an enum
 		if( e == null || e.__ename__ == null )
 			return null;