what does Zotero.debug do exactly?

40 views
Skip to first unread message

acrymble

unread,
May 13, 2008, 9:09:25 AM5/13/08
to zotero-dev
I am working on a translator, and I thought I understood Zotero.debug,
but now I'm not so sure.

I thought that if I run Firefox in the command prompt,
Zotero.debug(variable here); would tell me the contents of a variable.
I've been unable to get this to show anything, however I can use it to
display variable properties such as Zotero.debug(variable.length);

In the following piece of code, I just tried to use it to see the
contents of "i" to correct an error that read: "childNodes[0] has no
properties" and to my surprise, the Zotero.debug has somehow solved
the error.

var contentInfo = new Object();
var metaTagHTML = doc.getElementsByTagName("td");
var contentInfo = new Array();
var headers = new Array();
var headersCounter = 0;
var contentInfoCounter = 0;

for (var i = 0; i < metaTagHTML.length; i++) {
if (i%2==0) {
Zotero.debug(i);
if (metaTagHTML[i].childNodes[1].length>0){
headers.push(metaTagHTML[i].childNodes[0].nodeValue);
Zotero.Utilities.cleanTags.toString(headers[headersCounter]);
} else {
headers[headersCounter].push(" ");
}
}

What exactly has my Zotero.debug done?

Thanks,

Adam

Dan Stillman

unread,
May 13, 2008, 2:26:26 PM5/13/08
to zoter...@googlegroups.com
On 5/13/08 9:09 AM, acrymble wrote:
> I am working on a translator, and I thought I understood Zotero.debug,
> but now I'm not so sure.
>
> I thought that if I run Firefox in the command prompt,
> Zotero.debug(variable here); would tell me the contents of a variable.
> I've been unable to get this to show anything, however I can use it to
> display variable properties such as Zotero.debug(variable.length);
>

Zotero.debug() won't work if you try to pass it DOM objects or other
objects with recursive structures, but it should display scalar values
and regular JS objects just fine. There's another function, safeDebug(),
that casts all values to strings and therefore won't recurse, so it's
safe to use on DOM objects, but it's not currently available from within
translators.

Also, Scaffold overrides Zotero.debug() with its own modified version,
so you won't see debug output in the console when you're running a
translator from Scaffold (but you should see it within Scaffold).

> In the following piece of code, I just tried to use it to see the
> contents of "i" to correct an error that read: "childNodes[0] has no
> properties" and to my surprise, the Zotero.debug has somehow solved
> the error.
>

Are you sure this is reproducible after a restart of Firefox? Neither
version of Zotero.debug() should have any effect on the value passed to it.

Reply all
Reply to author
Forward
0 new messages