sub js_call_to_perl_struct { my ($self,$js,$context) = @_; $context ||= ''; $self->{stats}->{roundtrip}++; my $repl = $self->repl; if (! $repl) { # Likely during global destruction return }; my $queue = join '', map( { /;$/? $_ : "$_;" } map { s/\s*$//; $_ } @{ $self->queue }); @{ $self->queue } = (); #warn "<<$js>>"; my @js; if ($queue) { push @js, $self->repl_API('q', $queue); }; push @js, $self->repl_API('ejs', $js, $context ); $js = join ";", @js; if (defined wantarray) { #warn $js; # When going async, we would want to turn this into a callback my $res = $self->execute_command($js); $res =~ s/^(?:\.+\>\s+)+//g; while ($res !~ /\S/) { # Gobble up continuation prompts warn "No result yet from repl"; $res = $self->execute_command(";"); # no-op $res =~ s/^(?:\.+\>\s+)+//g; }; my $d = $self->to_perl($res); if ($d->{status} eq 'ok') { return $d->{result} } else { croak ((ref $self).": $d->{name}: $d->{message}"); }; } else { #warn "Executing $js"; # When going async, we would want to turn this into a callback # This produces additional, bogus prompts... $self->execute_command($js); () }; }; #### my $res = $self->execute_command($js); #### repl.ejs(" var f=function() {\n var wm = Components.classes[\"@mozilla.org/appshell/window-mediator;1\"]\n.getService(Components.interfaces.nsIWindowMediator);\n var win = wm.getMostRecentWindow('navigator:browser');\n if (! win) {\n// No browser windows are open, so open a new one.\n win = window.open('about:blank');\n };\n return win.getBrowser()\n }\n;\n; f","" );