0

This is for a Firefox addon, its a bit puzzling as after a certain point no code is being executed.

if (self.xmlDoc == null) return false;


    var domain_and_full_destination=processing_domain.split("  ");

    if(domain_and_full_destination[0]=="xxx.org")
    {
        //window.stop(); // Totally stop the page from loading.

        self.root_node = '';
        self.root_node = self.xmlDoc.getElementsByTagName('joe_biden_is_a_moron');
        var destinations_array= new Array();

        for (var cci = 0; cci <= self.root_node.length; cci++)
        {
            self.second_node = '';
            self.second_node = self.root_node[cci];
            destinations_array[cci]=self.second_node.getElementsByTagName('riaum')[0].firstChild.nodeValue;
        }


alert(domain_and_full_destination[0]+"\n");

The if goes on, but I cut it short because I want to know why the alert is never getting called?

Putting my alert in the for loop gets called, but anything after the for loop never executes.

No errors in the Firefox error console either.

pimvdb
  • 151,816
  • 78
  • 307
  • 352
Ryan
  • 9,821
  • 22
  • 66
  • 101
  • Can you clarify which alert are you referring to? I see two of them above. – Amulya Khare Aug 27 '11 at 19:13
  • Why don't you set a breakpoint in Firebug and find out for yourself? This is not a real question. – Tomalak Aug 27 '11 at 19:13
  • Sorry, took out one alert. I dont know how to use Firebug... – Ryan Aug 27 '11 at 19:15
  • 1
    I guess you'll solve this one by learning how to use it. – JJJ Aug 27 '11 at 19:22
  • @Juhana, if anyone tells you you are helpful... they are lying to you. – Ryan Aug 27 '11 at 19:24
  • one possible reason maybe that there is no firstChild `self.second_node.getElementsByTagName('riaum')[0].firstChild`. One would need to run your code to actually debug it for you. Why don't you put an alert after each statement and manually check each step ( if the for loop has few iterations) or you can always learn how to debug with Firebug. – Amulya Khare Aug 27 '11 at 19:24
  • Isn't there a } missing before the alert()? – ott-- Aug 27 '11 at 19:26
  • All you have to do is look at the error console in any browser to see what javascript error is being reported. It's absolutely silly to develop in javascript and not know how to use the most basic tools. You should invest the time (a few minutes) to learn how to view the error console in your favorite browser and learn how to use the debugger in your favorite browser (perhaps an hour to learn the basics). There is a ton of helpful intro doc on the web - all you have to do is Google and read. – jfriend00 Aug 27 '11 at 19:26
  • Read my OP, there is no errors in the error console – Ryan Aug 27 '11 at 19:28
  • AFAIK extension errors don't show up in the error console by default. I wasn't kidding, you'll do yourself a favor by learning the tools. – JJJ Aug 27 '11 at 19:31
  • @juhana... ok, will dl FB, any tuts you recommend? – Ryan Aug 27 '11 at 19:33
  • 1
    Here are some pointers: http://stackoverflow.com/questions/6239118/how-can-i-debug-a-firefox-extension-with-firebug – JJJ Aug 27 '11 at 19:34

4 Answers4

1

missing a close bracket for if statement...?

Ivo Stoykov

i100
  • 4,529
  • 1
  • 22
  • 20
  • No, i checked that first, I just posted the first few lines till it stopped working... no use posting the other stuff if its not reaching there... – Ryan Aug 27 '11 at 19:27
1

You mention that for loop gets called but can you alert just before for loop ends to see if it iterates / exits the loop.

Placing alerts can help you debug if you are a beginner and do not know how to use debugging tools. However in the longer run you may want to use these tools to help you get the job done much faster.

Amulya Khare
  • 7,718
  • 2
  • 23
  • 38
  • yep, it is popping the alert as long as i put it at the end of the for, but not outside – Ryan Aug 27 '11 at 19:46
  • For each iteration from `0` to `self.root_node.length`? As you mention that it throws an exception.. would mean at one point it should not pop an alert. – Amulya Khare Aug 27 '11 at 19:48
1

Are you sure it's not throwing? You're doing something wrong there.

for (var cci = 0; cci <= self.root_node.length; cci++)

should be

for (var cci = 0; cci < self.root_node.length; cci++)

The fact that you used <= there means that, on the last iteration of the loop, self.second_node is actually set to undefined, which would make self.second_node.getElementsByTagName('riaum') throw an exception.

chjj
  • 14,322
  • 3
  • 32
  • 24
  • Ok, made the change you suggested and now it is throwing: `Error: self.second_node is undefined` – Ryan Aug 27 '11 at 19:43
  • ok, using alerts I see that there were just 2 results but it was counting 0,1,2 which was causing the problem. Still dont know why exactly it did not show in the error consol in the beginning but your answer was the closest so am accepting it. Thakns everyone! – Ryan Aug 27 '11 at 19:59
0

try to devide this line into few variables

destinations_array[cci]=self.second_node.getElementsByTagName('riaum')[0].firstChild.nodeValue;

i.e.

var riaum = self.second_node.getElementsByTagName('riaum')[0] || null;
var child = riaum.firstChild || '';
var nodeVal = child.nodeValue || '?';
destinations_array[cci]=nodeVal;

you have to add checks what's in vars...

HTH

Ivo Stoykov

i100
  • 4,529
  • 1
  • 22
  • 20