Mathias Panzenböck avatar Mathias Panzenböck committed b12828c

I think more compliance tests cannot be fulfilled

Comments (0)

Files changed (5)

 
 		// remove one stack level:
 		if (typeof(window) != 'undefined') {
-			if (window.Components) {
+			if (window.netscape) {
 				// Mozilla:
 				this.stack = err.stack.substring(err.stack.indexOf('\n')+1);
 			}
-const system = require('system');
+var system = require('system');
+var assert = require('assert');
 
 exports.log = function () {
 	var args = [];
 exports.debug = exports.log;
 exports.warn  = exports.error;
 
-exports.trace = function (e) {
-	if (e === undefined) {
-		e = new Error();
-	}
-	if (typeof(window) != 'undefined' && window.Components) {
+
+if (typeof(window) != 'undefined' && window.netscape) {
+	exports.trace = function (e) {
+		if (e === undefined) {
+			e = new Error();
+		}
 		exports.error('Taraceback (most recent call last):');
 		stack = e.stack.split('\n');
 		for (var i = stack.length - 2; i > 0; -- i) {
 			var m = /^(.*)@([^@]*):(\d+)$/.exec(stack[i]);
 			exports.error('  File '+JSON.stringify(m[2])+', line '+m[3]+', in '+m[1]);
 		}
-	}
-	else if ((typeof(window) != 'undefined' && window.chrome)
-			|| typeof(process) != 'undefined') {
-		exports.error('Taraceback (most recent call last):');
-		stack = e.stack.split('\n');
-		for (var i = stack.length - 1; i > 0; -- i) {
-			var m = /^\s*at (.*)\s*\((?:[^:]*|(.*):(\d+):\d+)\)\)?$/.exec(stack[i]);
-			var file = m[2] !== undefined ? JSON.stringify(m[2]) : '<unknown source>';
-			var line = m[3] !== undefined ? m[3] : '<unknown>';
-			exports.error('  File '+file+', line '+line+', in '+m[1]);
+	};
+
+	exports.exception = function (e) {
+		exports.trace(e);
+		exports.error(e.name+': '+e.message);
+	};
+}
+else {
+	exports.trace = function (e) {
+		if (e === undefined) {
+			try {
+				throw new Error();
+			}
+			catch (err) {
+				e = err;
+			}
 		}
-	}
-	else {
+		
 		exports.error(e.stack);
-	}
-};
+	};
 
-exports.exception = function (e) {
-	exports.trace(e);
-	exports.error(e.name+': '+e.message);
-};
+	exports.exception = function (e) {
+		exports.error(e.stack);
+	};
+}
 
 exports.assert = function (expression) {
 	if (!expression) {
 		}
 		var msg = args.join(' ');
 		system.stderr.writeLine(msg);
-		throw new Error('Assertion Failed: ' + msg);
+		assert.fail(false, true, msg);
 	}
 };
 	
 	return data;
 };
+
+exports.tr = function (moduleName, lang) {
+	var orig  = _load(moduleName, '.i18n');
+	var trans = exports.load(moduleName, lang);
+	var tbl   = {};
+
+	for (name in orig) {
+		var otext = orig[name];
+		var ttext = trans[name];
+		tbl[otext] = ttext === undefined ? otext : ttext;
+	}
+
+	delete orig;
+	delete trans;
+
+	return function (text) {
+		return tbl[text];
+	};
+};
 		property(this, 'parent', function () {
 			return parent;
 		});
+
+		this.toString = function () {
+			return id;
+		};
 	}
 
 	var main = new ModuleInfo(
 
 	function make_require (parent, main, getters) {
 		function _require (moduleName, opts) {
-			return __require(moduleName, opts, parent);
+			return __require(moduleName, opts, parent, main);
 		}
 		
 		property(_require, 'Module', function () {
 		property(_require, 'Resolver', function () {
 			return Resolver;
 		});
+		/*
+		 * curryId should inject id of the calling module and thus would need stack inspection
+		property(_require, 'curryId', function () {
+			return function (f) {
+				return function () {
+					var args = [parent.id];
+					for (var i = 0; i < arguments.length; ++ i) {
+						args.push(arguments[i]);
+					}
+					return f.apply(null, args);
+				};
+			};
+		});
+		*/
 
 		if (getters) {
 			for (name in getters) {
 		return _require;
 	}
 
-	function __require (moduleName, opts, parent) {
+	function __require (moduleName, opts, parent, main) {
 		var resolver = new Resolver(moduleName, '.js', parent);
 
 		if (opts === undefined) {
 				require: null,
 				module:  null,
 			};
-	
+
 			if (opts.globals) {
 				for (argname in opts.globals) {
 					if (!/^[_a-zA-Z][_a-zA-Z0-9]*$/.test(argname) || argname in globals) {
 				}
 			}
 
+			if (!('print' in globals)) {
+				// lazy loading print function:
+				globals.print = function () {
+					var system = globals.require('system');
+					globals.print = function () {
+						var args = [];
+						for (var i = 0; i < arguments.length; ++ i) {
+							args.push(arguments[i]);
+						}
+						system.stdout.print.apply(system.stdout, args);
+					};
+					
+					var args = [];
+					for (var i = 0; i < arguments.length; ++ i) {
+						args.push(arguments[i]);
+					}
+					system.stdout.print.apply(system.stdout, args);
+				};
+
+				globals.document = document;
+			}
+
 			if (!('document' in globals)) {
 				globals.document = document;
 			}
 				globals.window = window;
 			}
 
+			if (!('JSON' in globals)) {
+				globals.JSON = JSON;
+			}
+
+			// hide leakage:
 			for (name in window) {
 				if (!(name in globals)) {
 					globals[name] = undefined;
 					globals.module  = newModule;
 					globals.require = make_require(newModule, opts.asmain ? newModule : main);
 					var program = _eval(
-						'(function (globals) { with (globals) { ' +
-						xhr.responseText+' }})');
-					new program(globals);
-							
+						'(function () { with (this) { '+xhr.responseText+' }})');
+					program.call(globals);
+					
 					delete loading[resolver.id];
 					loaded[resolver.id] = exports;
 				}
 			xhr.send(null);
 	
 			if (err != null) {
-				err.stack = new Error().stack;
+				if (window.netscape) {
+					err.stack = new Error().stack;
+				}
 				throw err;
 			}
 		}
-const console = require('console');
-const assert  = require('assert');
+var console = require('console');
+var assert  = require('assert');
 
 exports.run = function (test) {
 	var startup  = test.startup  || function () {};
 
 	return count;
 };
+
+exports.assert = function (guard, message) {
+	if (guard) {
+		console.info('PASS', message);
+	}
+	else {
+		console.error('FAIL', message);
+	}
+};
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.