Skip to content

Commit

Permalink
Add an optional mapping parameter to ->__xpath(), without test
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Maischein committed Apr 4, 2012
1 parent 403f418 commit 8d9c8a3
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lib/MozRepl/RemoteObject.pm
Expand Up @@ -1364,21 +1364,28 @@ on HTMLdocument nodes.
=cut =cut


sub __xpath { sub __xpath {
my ($self,$query,$ref) = @_; # $self is a HTMLdocument my ($self,$query,$ref,$cont) = @_; # $self is a HTMLdocument
$ref ||= $self; $ref ||= $self;
my $js = <<'JS'; my $js = <<'JS';
function(doc,q,ref) { function(doc,q,ref,cont) {
var xres = doc.evaluate(q,ref,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null ); var xres = doc.evaluate(q,ref,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null );
var map;
if( cont ) {
map = cont;
} else {
// Default is identity
map = function(e){ return e };
};
var res = []; var res = [];
for ( var i=0 ; i < xres.snapshotLength; i++ ) for ( var i=0 ; i < xres.snapshotLength; i++ )
{ {
res.push( xres.snapshotItem(i)); res.push( map(xres.snapshotItem(i)));
}; };
return res return res
} }
JS JS
my $snap = $self->bridge->declare($js,'list'); my $snap = $self->bridge->declare($js,'list');
$snap->($self,$query,$ref); $snap->($self,$query,$ref,$cont);
} }


=head2 C<< $obj->__click >> =head2 C<< $obj->__click >>
Expand Down

0 comments on commit 8d9c8a3

Please sign in to comment.