in reply to Re^2: MozRepl/Client.pm does not support firefox 7.0
in thread MozRepl/Client.pm does not support firefox 7.0

I dive out the problem might be that firefox 7 does not support anonymous functions.

sub browser { my ($self,$repl) = @_; $repl ||= $self->repl; print "repl: $repl\n"; return $repl->declare(<<'JS')->(); function () { var wm = Components.classes["@mozilla.org/appshell/window-medi +ator;1"] .getService(Components.interfaces.nsIWindow +Mediator); var win = wm.getMostRecentWindow('navigator:browser'); if (! win) { // No browser windows are open, so open a new one. win = window.open('about:blank'); }; return win.gBrowser //return win.getBrowser() } JS }; sub declare { my ($self,$js,$context) = @_; print "1:$self; 2:$js;3:$context\n "; if (! $self->{functions}->{$js}) { $self->{functions}->{$js} = $self->expr($js); # Weaken the backlink of the function my $res = $self->{functions}->{$js}; my $ref = ref $res; bless $res, "$ref\::HashAccess"; weaken $res->{bridge}; $res->{return_context} = $context; bless $res => $ref; }; $self->{functions}->{$js} };

If I manually change the function () to function abc(), then repl can not get any references:

Can't bless non-reference value at C:/Perl/site/lib/MozRepl/RemoteObject.pm

How to solve this issue?

Replies are listed 'Best First'.
Re^4: MozRepl/Client.pm does not support firefox 7.0
by Corion (Patriarch) on Sep 23, 2011 at 07:25 UTC

    Ouch! I'm sorry - I encountered the same issue and locally already fixed it without bumping the MozRepl::RemoteObject version and without releasing it to CPAN.

    If you're in a bind, the current version from Github should make "everything just work again", even with Firefox 7.

    The (ugly) change is that

    eval "function() {}";

    does not return an anonymous function in Javascript (on Firefox 7) anymore. The change is to use:

    eval "expr_=function() {}; expr";

    Update: Now released as v0.28 on CPAN.

      The (ugly) change is that eval "function() {}"; does not return an anonymous function in Javascript (on Firefox 7) anymore

      How odd. I remember that being a bug once in firefox2/3

      What if you use return function(){};?

        I don't know how (in Javascript) eval and return interact. It might be worth investigating if the problem comes up again in a different place.

        So far, there is only one piece in MozRepl::RemoteObject needing functions, the implementation of ->declare(), and that one was easily patched to support the temporary assignment to a variable. Changing the Javascript code to become eval "return $expr" does not work in the general case because $expr is allowed to contain multiple statements. I don't want to implement a JS parser just to find the last statement in some block and put the return before it, so I just change the call sites of that code instead.

Re^4: MozRepl/Client.pm does not support firefox 7.0
by Anonymous Monk on Sep 23, 2011 at 04:22 UTC

    I dive out the problem might be that firefox 7 does not support anonymous functions.

    No, firefox 7 supports and depends on anonymous functions

    If I manually change the function () to function abc(), then repl can not get any references

    :) yeah, don't do that

    You're essentially changing return sub { print "call me" }; to sub named { print "call me" };

    "sub {}" returns a function, but "sub name {}" returns nothing.

    You're barking up the wrong tree :)