Forráskód Böngészése

prevent access to sys package and Sys class for not-system platforms

Nicolas Cannasse 13 éve
szülő
commit
6a817f73d4
6 módosított fájl, 25 hozzáadás és 7 törlés
  1. 3 0
      common.ml
  2. 1 1
      doc/CHANGES.txt
  3. 2 1
      doc/ImportAll.hx
  4. 15 4
      main.ml
  5. 1 0
      std/Sys.hx
  6. 3 1
      typer.ml

+ 3 - 0
common.ml

@@ -209,6 +209,9 @@ let init_platform com pf =
 	let name = platform_name pf in
 	let forbid acc p = if p = name || PMap.mem p acc then acc else PMap.add p Forbidden acc in
 	com.package_rules <- List.fold_left forbid com.package_rules (List.map platform_name platforms);
+	(match pf with
+	| Cpp | Php | Neko -> ()
+	| _ -> com.package_rules <- PMap.add "sys" Forbidden com.package_rules);
 	define com name
 
 let error msg p = raise (Abort (msg,p))

+ 1 - 1
doc/CHANGES.txt

@@ -34,7 +34,7 @@
 	js : added --js-modern for wrapping output in a closure and ES5 strict mode
 	all : null, true and false are now keywords
 	all : neko.io.Path, cpp.io.Path and php.io.Path are now haxe.io.Path
-	neko, cpp, php : added Sys class and sys.io package
+	neko, cpp, php : added Sys class and sys.io package and "sys" define
 	all : allow to access root package with __ prefix (__.Type for example)
 
 2011-09-25: 2.08

+ 2 - 1
doc/ImportAll.hx

@@ -26,7 +26,7 @@ import haxe.macro.Context;
 
 class ImportAll {
 
-	public static function run( ?pack ) {
+	public static function run( ?pack ) {	
 		if( pack == null ) {
 			pack = "";
 			haxe.macro.Compiler.define("doc_gen");
@@ -73,6 +73,7 @@ class ImportAll {
 					switch( cl ) {
 					case "ImportAll", "neko.db.MacroManager": continue;
 					case "haxe.TimerQueue": if( Context.defined("neko") || Context.defined("php") || Context.defined("cpp") ) continue;
+					case "Sys": if( !(Context.defined("neko") || Context.defined("php") || Context.defined("cpp")) ) continue;
 					case "haxe.web.Request": if( !(Context.defined("neko") || Context.defined("php") || Context.defined("js")) ) continue;
 					case "haxe.macro.ExampleJSGenerator","haxe.macro.Context", "haxe.macro.Compiler": if( !Context.defined("neko") ) continue;
 					case "haxe.remoting.SocketWrapper": if( !Context.defined("flash") ) continue;

+ 15 - 4
main.ml

@@ -908,10 +908,21 @@ try
 				add_std "flash8";
 			end;
 			"swf"
-		| Neko -> add_std "neko"; "n"
-		| Js -> add_std "js"; "js"
-		| Php -> add_std "php"; "php"
-		| Cpp -> add_std "cpp"; "cpp"
+		| Neko ->
+			Common.define com "sys";
+			add_std "neko";
+			"n"
+		| Js ->
+			add_std "js";
+			"js"
+		| Php ->
+			Common.define com "sys";
+			add_std "php";
+			"php"
+		| Cpp ->
+			Common.define com "sys";
+			add_std "cpp";
+			"cpp"
 	) in
 	(* if we are at the last compilation step, allow all packages accesses - in case of macros or opening another project file *)
 	if com.display && not ctx.has_next then com.package_rules <- PMap.foldi (fun p r acc -> match r with Forbidden -> acc | _ -> PMap.add p r acc) com.package_rules PMap.empty;

+ 1 - 0
std/Sys.hx

@@ -26,6 +26,7 @@
 /**
 	This class gives you access to many base functionalities of system platforms. Looks in [sys] sub packages for more system APIs.
 **/
+@:require(sys)
 extern class Sys {
 
 	/**

+ 3 - 1
typer.ml

@@ -341,7 +341,9 @@ let rec acc_get ctx g p =
 		assert false
 
 let error_require r p =
-	let r = try
+	let r = if r = "sys" then
+		"a system platform (php,neko,cpp,etc.)"
+	else try
 		if String.sub r 0 5 <> "flash" then raise Exit;
 		let _, v = ExtString.String.replace (String.sub r 5 (String.length r - 5)) "_" "." in
 		"flash version " ^ v ^ " (use -swf-version " ^ v ^ ")"