Mathias Panzenböck avatar Mathias Panzenböck committed daf049f

console.js: partial implementation of console object

Comments (0)

Files changed (2)

+syntax: glob
+.*
+*~
+const system = require('system');
+
+exports.log = function () {
+	var args = [];
+	for (var i = 0; i < arguments.length; ++ i) {
+		args.push(arguments[i]);
+	}
+	system.stdout.writeLine(args.join(' '));
+};
+
+exports.error = function () {
+	var args = [];
+	for (var i = 0; i < arguments.length; ++ i) {
+		args.push(arguments[i]);
+	}
+	system.stderr.writeLine(args.join(' '));
+};
+
+exports.dir = function (obj) {
+	var buf = [];
+	for (name in obj) {
+		buf.push(name+': '+obj[name]+'\n');
+	}
+	system.stdout.write(buf.join(''));
+};
+
+exports.info  = exports.log;
+exports.debug = exports.log;
+exports.warn  = exports.error;
+
+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]);
+	}
+};
+
+exports.exception = function (e) {
+	exports.trace(e);
+	exports.error(e.name+': '+e.message);
+};
+
+exports.assert = function (expression) {
+	if (!expression) {
+		var args = [];
+		for (var i = 1; i < arguments.length; ++ i) {
+			args.push(arguments[i]);
+		}
+		var msg = args.join(' ');
+		system.stderr.writeLine(msg);
+		throw new Error('Assertion Failed: ' + msg);
+	}
+};
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.