Explorar el Código

Finish removing JS stack emulation.

Bruno Garcia hace 13 años
padre
commit
597910e745
Se han modificado 6 ficheros con 17 adiciones y 63 borrados
  1. 0 8
      genjs.ml
  2. 4 4
      std/haxe/Stack.hx
  3. 1 10
      std/haxe/macro/DefaultJSGenerator.hx
  4. 1 7
      std/haxe/macro/JSGenApi.hx
  5. 11 28
      std/js/Lib.hx
  6. 0 6
      typer.ml

+ 0 - 8
genjs.ml

@@ -40,7 +40,6 @@ type ctx = {
 	com : Common.context;
 	buf : Buffer.t;
 	packages : (string list,unit) Hashtbl.t;
-	stack : Codegen.stack_context;
 	smap : sourcemap;
 	js_modern : bool;
 	mutable current : tclass;
@@ -954,7 +953,6 @@ let generate_type ctx = function
 let alloc_ctx com =
 	let ctx = {
 		com = com;
-		stack = Codegen.stack_init com false;
 		buf = Buffer.create 16000;
 		packages = Hashtbl.create 0;
 		smap = {
@@ -1012,12 +1010,6 @@ function $extend(from, fields) {
 	List.iter (generate_type ctx) com.types;
 	print ctx "js.Boot.__res = {}";
 	newline ctx;
-	if com.debug then begin
-		print ctx "%s = []" ctx.stack.Codegen.stack_var;
-		newline ctx;
-		print ctx "%s = []" ctx.stack.Codegen.stack_exc_var;
-		newline ctx;
-	end;
 	print ctx "js.Boot.__init()";
 	newline ctx;
 	List.iter (fun e ->

+ 4 - 4
std/haxe/Stack.hx

@@ -52,7 +52,7 @@ class Stack {
 			var a = makeStack( new flash.errors.Error().getStackTrace() );
 			a.shift(); // remove Stack.callstack()
 			return a;
-		#elseif (flash || js)
+		#elseif flash
 			return makeStack("$s");
 		#elseif php
 			return makeStack("%s");
@@ -85,7 +85,7 @@ class Stack {
 				i--;
 			}
 			return a;
-		#elseif (flash || js)
+		#elseif flash
 			return makeStack("$e");
 		#elseif php
 			return makeStack("%e");
@@ -168,8 +168,8 @@ class Stack {
 				s = r.matchedRight();
 			}
 			return a;
-		#elseif (flash || js)
-			var a : Array<String> = untyped #if flash __eval__(s) #else try __js__("eval")(s) catch( e : Dynamic ) [] #end;
+		#elseif flash
+			var a : Array<String> = untyped __eval__(s);
 			var m = new Array();
 			for( i in 0...a.length - if(s == "$s") 2 else 0 ) {
 				var d = a[i].split("::");

+ 1 - 10
std/haxe/macro/DefaultJSGenerator.hx

@@ -112,7 +112,6 @@ class DefaultJSGenerator {
 		if( f.expr == null )
 			print("null");
 		else {
-			api.setDebugInfos(c, f.name, false);
 			genExpr(f.expr);
 		}
 		newline();
@@ -127,7 +126,6 @@ class DefaultJSGenerator {
 		} else switch( f.kind ) {
 		case FMethod(_):
 			fprint("$p$field = ");
-			api.setDebugInfos(c, f.name, true);
 			genExpr(f.expr);
 			newline();
 		default:
@@ -139,7 +137,6 @@ class DefaultJSGenerator {
 		genPackage(c.pack);
 		var p = getPath(c);
 		fprint("$p = ");
-		api.setDebugInfos(c, "new", false);
 		if( c.constructor != null )
 			genExpr(c.constructor.get().expr);
 		else
@@ -239,12 +236,6 @@ class DefaultJSGenerator {
 		newline();
 		print("js.Boot.__res = {}");
 		newline();
-		if( Context.defined("debug") ) {
-			fprint("${api.stackVar} = []");
-			newline();
-			fprint("${api.excVar} = []");
-			newline();
-		}
 		print("js.Boot.__init()");
 		newline();
 		for( e in inits ) {
@@ -270,4 +261,4 @@ class DefaultJSGenerator {
 	}
 	#end
 
-}
+}

+ 1 - 7
std/haxe/macro/JSGenApi.hx

@@ -35,10 +35,6 @@ typedef JSGenApi = {
 	var types : Array<Type>;
 	/** the main call expression, if a -main class is defined **/
 	var main : Null<TypedExpr>;
-	/** the variable used to store the temporary stack in debug mode **/
-	var stackVar(default,null) : String;
-	/** the variable used to store the temporary exception in debug mode **/
-	var excVar(default,null) : String;
 	/** generate the JS code for any given typed expression **/
 	function generateStatement( e : TypedExpr ) : String;
 	/** generate the JS code for a given typed expression-value **/
@@ -51,6 +47,4 @@ typedef JSGenApi = {
 	function quoteString( s : String ) : String;
 	/** create the metadata expression for the given type **/
 	function buildMetaData( t : BaseType ) : Null<TypedExpr>;
-	/** set the current class/method for debug stack management **/
-	function setDebugInfos( c : ClassType, meth : String, isStatic : Bool ) : Void;
-}
+}

+ 11 - 28
std/js/Lib.hx

@@ -50,34 +50,17 @@ class Lib {
 		onerror = f;
 	}
 
-	static function __init__() untyped {
-		if( __js__("typeof document") != "undefined" )
-			document = __js__("document");
-		if( __js__("typeof window") != "undefined" ) {
-			window = __js__("window");
-			#if debug
-	__js__('window.onerror = function(msg,url,line) {
-			var stack = $s.copy();
-			var f = js.Lib.onerror;
-			$s.splice(0,$s.length);
-			if( f == null ) {
-				var i = stack.length;
-				var s = "";
-				while( --i >= 0 )
-					s += "Called from "+stack[i]+"\\n";
-				alert(msg+"\\n\\n"+s);
-				return false;
-			}
-			return f(msg,stack);
-		}');
-			#else
-	__js__('window.onerror = function(msg,url,line) {
-			var f = js.Lib.onerror;
-			if( f == null )
-				return false;
-			return f(msg,[url+":"+line]);
-		}');
-			#end
+	static function __init__() {
+		if( typeof("document") != "undefined" )
+			document = untyped __js__("document");
+		if( typeof("window") != "undefined" ) {
+			window = untyped __js__("window");
+			window.onerror = function( msg, url, line ) {
+				var f = Lib.onerror;
+				if( f == null )
+					return false;
+				return f(msg, [url+":"+line]);
+			};
 		}
 	}
 

+ 0 - 6
typer.ml

@@ -2330,10 +2330,6 @@ let make_macro_api ctx p =
 						| None -> Interp.VNull
 						| Some e -> Interp.encode_texpr e
 					));
-					(* TODO(bruno): Deprecated, remove *)
-					"setDebugInfos", Interp.VFunction (Interp.Fun3 (fun c m s ->
-						Interp.VNull
-					));
 					"generateStatement", Interp.VFunction (Interp.Fun1 (fun v ->
 						match v with
 						| Interp.VAbstract (Interp.ATExpr e) ->
@@ -2349,8 +2345,6 @@ let make_macro_api ctx p =
 						);
 						Interp.VNull
 					));
-					"stackVar", Interp.enc_string (js_ctx.Genjs.stack.Codegen.stack_var);
-					"excVar", Interp.enc_string (js_ctx.Genjs.stack.Codegen.stack_exc_var);
 				] in
 				let t = macro_timer ctx "jsGenerator" in
 				gen jsctx;