[Project_owners] getElementsByTagName() problem

HJ bugs4hj at yahoo.com
Wed Apr 12 12:05:23 EDT 2006


Eric H. Jung wrote:
> Thank you all for the help!
> 
>> also having looked at the document, it appears to be for an internet
>> bank, I hope your intentions are good!
> 
> This is for the PasswordMaker extension, which has evolved into a Roboform-like utility.

I don't know how exactly it works, but you probably need to use 
'content' to get to the...content :)

>> The problem with recursive JS functions is that the end user most likely 
>> ends up with a sluggish feeling browser.
> 
> How is recursion any less performant or more sluggish than repeatedly calling a function within a
> loop (as in your code)?

What?  You've never seen the "Too many recursions" errors?
Also, recursions stacks up quite a bit, and that leads to a sluggish 
feeling browser.

>> Ok, this looks like some dialog window so why don't you pass on the 
>> window used to open the dialog, because that saves you the above lines.
> 
> Actually, it is called from a browser.xul overlay :(

Right, so use something like this:

window.openDialog("chrome://passwordmaker/content/somePWDDialog.xul", 
                      null, "chrome, dialog, all", window, infoFields);

and define infoFields[] only once, that also saves a little time (the 
faster the better).

p.s. replace 'null' with a name if you want.

>> Why this difficult?  I mean, all frames end up in content.frames so why 
>> don't you use that instead?
> 
> Because I didn't know about content.frames :)
>
>> I hate code duplication so I would use something like this:
> 
> Is the SpiderMonkey compiler capable of function inlining? If not, I would suggest that code
> duplication might actually lead to faster code in many cases (ignoring the fact that the one-time
> compile may take longer as code size increases).

In that case use something like this:

getInputFields(aWindow, aInfoFields)
{
   var frames = (aWindow.frames.length) ? aWindow.frames : aWindow.document;

   for (var fIndex = 0; fIndex < frames.length; fIndex++)
   {
     if (!frames[fIndex].length) {
       var inputElements = 
aFrames.contentDocument.getElementsByName('input');

       for (var i = 0; i < inputElements.length; i++) {
         aInfoFields.push(inputElements[i]);
       }
     } else {
       frames.push(frames[iFrame]);
     }
   }
   window.arguments[1] = aInfoFields;
}

And I should have done so, but like I said, I just types it out of the 
blue ;)

Now I seriously need a cup of coffee and a proper breakfast!

Later,
/HJ


More information about the Project_owners mailing list