Permalink
Browse files

Add an optional mapping parameter to ->__xpath(), without test

  • Loading branch information...
1 parent 403f418 commit 8d9c8a32437c5ce337b042974b139a58e0ac41a3 Max Maischein committed Apr 4, 2012
Showing with 11 additions and 4 deletions.
  1. +11 −4 lib/MozRepl/RemoteObject.pm
@@ -1364,21 +1364,28 @@ on HTMLdocument nodes.
=cut
sub __xpath {
- my ($self,$query,$ref) = @_; # $self is a HTMLdocument
+ my ($self,$query,$ref,$cont) = @_; # $self is a HTMLdocument
$ref ||= $self;
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 map;
+ if( cont ) {
+ map = cont;
+ } else {
+ // Default is identity
+ map = function(e){ return e };
+ };
var res = [];
for ( var i=0 ; i < xres.snapshotLength; i++ )
{
- res.push( xres.snapshotItem(i));
+ res.push( map(xres.snapshotItem(i)));
};
return res
}
JS
my $snap = $self->bridge->declare($js,'list');
- $snap->($self,$query,$ref);
+ $snap->($self,$query,$ref,$cont);
}
=head2 C<< $obj->__click >>

0 comments on commit 8d9c8a3

Please sign in to comment.