Browse Source

added "is" feature (removes js.Boot.__instanceof if no typed catch is made)

Simon Krajewski 13 years ago
parent
commit
ee3e82d5f8
3 changed files with 4 additions and 2 deletions
  1. 1 1
      std/js/Boot.hx
  2. 2 0
      typecore.ml
  3. 1 1
      typer.ml

+ 1 - 1
std/js/Boot.hx

@@ -146,7 +146,7 @@ class Boot {
 		return __interfLoop(cc.__super__,cl);
 	}
 
-	private static function __instanceof(o : Dynamic,cl) {
+	@:feature("is") private static function __instanceof(o : Dynamic,cl) {
 		untyped {
 			try {
 				if( __js__("o instanceof cl") ) {

+ 2 - 0
typecore.ml

@@ -38,6 +38,7 @@ type macro_mode =
 
 type feature =
 	| FtTypedCast
+	| FtIs
 
 type typer_globals = {
 	types_module : (path, path) Hashtbl.t;
@@ -237,6 +238,7 @@ let create_fake_module ctx file =
 
 let feature_name = function
 	| FtTypedCast -> "typed_cast"
+	| FtIs -> "is"
 
 let activate_feature ctx ft = Hashtbl.replace ctx.g.features (feature_name ft) ft
 let has_feature ctx s = Hashtbl.mem ctx.g.features s

+ 1 - 1
typer.ml

@@ -1744,6 +1744,7 @@ and type_expr ctx ?(need_val=true) (e,p) =
 					List.iter (fun pt ->
 						if pt != t_dynamic then error "Catch class parameter must be Dynamic" p;
 					) params;
+					activate_feature ctx FtIs;
 					(match path with
 					| x :: _ , _ -> x
 					| [] , name -> name)
@@ -2133,7 +2134,6 @@ let dce_check_class ctx c =
 		| "EReg.new"
 		| "js.Boot.__init" | "flash._Boot.RealBoot.new"
 		| "js.Boot.__string_rec" (* used by $estr *)
-		| "js.Boot.__instanceof" (* used by catch( e : T ) *)
 			-> true
 		| _ -> false
 	in