Browse Source

- js : package names are now checked at runtime to avoid clashes with existing libs
- js.Boot prevent error in environemnts that do not have a predefined document or window object

Franco Ponticelli 16 years ago
parent
commit
210cd06a8c
3 changed files with 5 additions and 7 deletions
  1. 1 0
      doc/CHANGES.txt
  2. 2 5
      genjs.ml
  3. 2 2
      std/js/Boot.hx

+ 1 - 0
doc/CHANGES.txt

@@ -1,6 +1,7 @@
 2010-??-??: 2.05
 	all : allow -D noopt to turn off optimizer
 	js : added js.Scroll
+	js : package names are now checked at runtime to avoid clashes with existing libs
 
 2009-07-26: 2.04
 	flash9 : fixed get_full_path error with -D fdb

+ 2 - 5
genjs.ml

@@ -24,7 +24,6 @@ type ctx = {
 	buf : Buffer.t;
 	packages : (string list,unit) Hashtbl.t;
 	stack : Codegen.stack_context;
-	check_package : bool;
 	mutable current : tclass;
 	mutable statics : (tclass * string * texpr) list;
 	mutable inits : texpr list;
@@ -581,11 +580,10 @@ let generate_package_create ctx (p,_) =
 			Hashtbl.add ctx.packages (p :: acc) ();
 			(match acc with
 			| [] ->
-				if ctx.check_package then print ctx "try { if( %s == null ) %s = {}; } catch(_) { %s = {}; } " p p p else print ctx "%s = {}" p;
+				print ctx "if(typeof %s=='undefined') %s = {}" p p;
 			| _ -> 
 				let p = String.concat "." (List.rev acc) ^ (field p) in
-		        if ctx.check_package then print ctx "if( !%s ) " p;
-				print ctx "%s = {}" p);
+		        print ctx "if(!%s) %s = {}" p p);
 			newline ctx;
 			loop (p :: acc) l
 	in
@@ -699,7 +697,6 @@ let generate com =
 		com = com;
 		stack = Codegen.stack_init com false;
 		buf = Buffer.create 16000;
-		check_package = Common.defined com "check-js-packages";
 		packages = Hashtbl.create 0;
 		statics = [];
 		inits = [];

+ 2 - 2
std/js/Boot.hx

@@ -193,8 +193,8 @@ class Boot {
 
 	private static function __init() {
 		untyped {
-			Lib.isIE = (document.all != null && window.opera == null );
-			Lib.isOpera = (window.opera != null );
+			Lib.isIE = (document && document.all != null && window && window.opera == null );
+			Lib.isOpera = (window && window.opera != null );
 			Array.prototype.copy = Array.prototype.slice;
 			Array.prototype.insert = function(i,x) {
 				this.splice(i,0,x);