in reply to Re: How to glue JavaScript and DOM
in thread How to glue JavaScript and DOM

1. var metas = document.getElementsByTagName('meta') is supposed to return an array containin the lines that has the meta tag.. since this is not supported by SpiderMonkey per se, i wrote a perl code somethin like
function_get("getElementsByTagName", sub { #use HTML::TagParser, my @array = $p->getElementsByTagName('@_); #$p must point to # the html file containin the page from which meta tags are # to be taken return @array; });
So ideally i must get an array, but I m not..2. handle of the callin object: eg: javascript has lines like write
metas[i].getAttribute('name'); //metas is the array obtained from the +above snippet<code>
So to write a perl function similar to the one that i wrote for getElementsByTagName as shown above, i need to get a handle for this metas array object in perl.. How do i get this is my question..I guess I have it more clear now.. Please tell me if it's still hazy

Replies are listed 'Best First'.
Re^3: How to glue JavaScript and DOM
by Joost (Canon) on Feb 26, 2008 at 14:22 UTC
    1. var metas = document.getElementsByTagName('meta') is supposed to return an array containin the lines that has the meta tag.
    document.getElementsByTagName is supposed to return a NodeList, not a plain array of Nodes.

    function_get("getElementsByTagName", sub { #use HTML::TagParser, my @array = $p->getElementsByTagName('@_); #$p must point to # the html file containin the page from which meta tags are # to be taken return @array; });
    That defines a global getElementsByTagName function. You want set it as a property of the document object instead. That way, you should get the document object as the first argument when called.

    update: in fact, function_get() does not exist in JavaScript::SpiderMonkey. There is a function_set, but that's a method. Have you actually read the documentation?

    So to write a perl function similar to the one that i wrote for getElementsByTagName as shown above, i need to get a handle for this metas array object in perl.. How do i get this is my question..
    Again, metas is not an array. Also, metas[i].getAttribute refers to the getAttribute property of whatever is element i in metas, so you'd better make sure that that property exists. As far as I can tell, your code does nothing of the kind.

      oops, typographical error.. meant function_set only..
      getElementsByTagName returns NodeList in both javascript and perl(method of HTML::DOM and other similar modules), however the formats are differents. can u please suggest me how to make the NodeList of Perl compatible with that of javascript???
        If you want to glue that many objects to the javascript interpreter, I think JavaScript::SpiderMonkey is going to be a big pain in the ass. From looking at the docs, JE should be easier to use (plus, it's pure perl so it will be easier to run anywhere and probably easier to hack).

        None of the javascript modules that I know can take a random perl object and just import it into the interpreter. You will have to define the interface for all of them. With JE::Types at least it seems like you can do that with reasonable ease.