Skip to content

Commit

Permalink
Adding JSimpleDebugger
Browse files Browse the repository at this point in the history
  • Loading branch information
Bogomil Shopov committed May 27, 2011
1 parent 8f2fbc8 commit 38b17aa
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
45 changes: 45 additions & 0 deletions JSimpleDebugger/JSimpleDebugger.js
@@ -0,0 +1,45 @@
//define contstants
const {Cu} = require("chrome");

//import LightweightThemeManager - the one responsible for handling Personas.
const Iservices = Cu.import('resource://gre/modules/Services.jsm').Services;

const econsole = Iservices.console;
//define class element
var JSimpleDebugger =
{
//define function element
write: function (args, callback)
{
econsole.logStringMessage(args);
},
dump: function(obj,level,callback)
{
//based on http://binnyva.blogspot.com/2005/10/dump-function-javascript-equivalent-of.html
var dumped_text = "";
if(!level) level = 0;

//The padding given at the beginning of the line.
var level_padding = "";
for(var j=0;j<level+1;j++) level_padding += " ";

if(typeof(obj) == 'object') {
for(var item in obj) {
var value = obj[item];

if(typeof(value) == 'object') {
dumped_text += level_padding + "'" + item + "' ...\n";
dumped_text += dump(value,level+1);
} else {
dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
}
}
}
econsole.logStringMessage(dumped_text);


}

}
//export object to be visible from your code
exports.JSimpleDebugger = JSimpleDebugger;
28 changes: 28 additions & 0 deletions JSimpleDebugger/Readme.md
@@ -0,0 +1,28 @@
__About__

Using this Library you can actually put debug messages in your Firefox error console by calling 2 methods:
1. .write (string)
2. .dump(object)

__Follow__

You can follow me on twitter: https://twitter.com/bogomep and identi.ca: http://identi.ca/bogomep


__The License__

All files in this REPO are under this LICENSE:

DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004

Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>

Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.

DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

0. You just DO WHAT THE FUCK YOU WANT TO.
16 changes: 16 additions & 0 deletions JSimpleDebugger/main.js
@@ -0,0 +1,16 @@
//import it
const sd = require('JSimpleDebugger').JSimpleDebugger;


//define an array
var jarray = ['baba','kaka', 'tete'];

//dump the object into console
sd.dump(jarray);


//define a string
var jstring = "I love Open Web!";

//write a line of text
sd.write(jstring);

0 comments on commit 38b17aa

Please sign in to comment.