浏览代码

added js IE/Operator class reflection.

Nicolas Cannasse 19 年之前
父节点
当前提交
30d4f22185
共有 3 个文件被更改,包括 14 次插入7 次删除
  1. 11 1
      genjs.ml
  2. 2 3
      std/Reflect.hx
  3. 1 3
      std/Type.hx

+ 11 - 1
genjs.ml

@@ -584,7 +584,15 @@ let generate_class ctx c =
 	generate_package_create ctx c.cl_path;
 	print ctx "%s = " p;
 	(match c.cl_constructor with
-	| Some { cf_expr = Some e } -> gen_value ctx (Transform.block_vars e)
+	| Some { cf_expr = Some e } -> 
+		(match Transform.block_vars e with
+		| { eexpr = TFunction f } ->
+			let args  = List.map arg_name f.tf_args in
+			let a, args = (match args with [] -> "p" , ["p"] | x :: _ -> x, args) in
+			print ctx "function(%s) { if( %s === $_ ) return; " (String.concat "," (List.map ident args)) a;
+			gen_expr ctx (block f.tf_expr);
+			print ctx "}";
+		| _ -> assert false)
 	| _ -> print ctx "function() { }");
 	newline ctx;
 	print ctx "%s.__name__ = [%s]" p (String.concat "," (List.map (fun s -> Printf.sprintf "\"%s\"" (Ast.s_escape s)) (fst c.cl_path @ [snd c.cl_path])));
@@ -656,6 +664,8 @@ let generate file types hres =
 		id_counter = 0;
 	} in
 	List.iter (generate_type ctx) types;
+	print ctx "$_ = {}";
+	newline ctx;
 	print ctx "js.Boot.__res = {}";
 	newline ctx;
 	Hashtbl.iter (fun name data ->

+ 2 - 3
std/Reflect.hx

@@ -60,9 +60,8 @@ class Reflect {
 		#else neko
 			return untyped __dollar__call(__dollar__objget(cl,__dollar__hash("new".__s)),cl,args.__a);
 		#else js
-			var o = { __constructor__ : cl, __proto__ : cl.prototype };
-			cl.apply(o,args);
-			return o;
+			if( args.length >= 6 ) throw "Too many arguments";
+			return untyped __new__(cl,args[0],args[1],args[2],args[3],args[4],args[5]);
 		#else error
 		#end
 	}

+ 1 - 3
std/Type.hx

@@ -231,9 +231,7 @@ class Type {
 			o.__proto__ = cl.prototype;
 			return o;
 		#else js
-			var o = __js__("{}");
-			o.__proto__ = cl.prototype;
-			return o;
+			return __new__(cl,__js__("$_"));
 		#else neko
 			var o = __dollar__new(null);
 			__dollar__objsetproto(o,cl.prototype);