Bug #3362

reverse() modifies its argument

Added by Michael Kay over 1 year ago. Updated about 1 year ago.

Start date:
Due date:
% Done:


Applies to JS Branch:
Fix Committed on JS Branch:
Fixed in JS Release:
SEF Generated with:
Contact person:
Additional contact persons:


After calling reverse($var), the value of $var is changed to be in reverse order.

reverse is implemented as arg[0].expand().reverse() where arg[0] is an iterator. The problem is that (a) if arg[0] is a ForArray iterator, then expand() returns the original array, and (b) the Javascript function reverse() modifies its argument in-situ.

So the code needs to ensure that the array is copied before calling reverse()@, or perhaps to avoid the @expand() operation and prepend each item returned by the iterator to a target array.

(Reported informally by John Lumley)


#1 Updated by Michael Kay over 1 year ago

  • Description updated (diff)

#2 Updated by Michael Kay over 1 year ago

  • Status changed from New to In Progress
  • Priority changed from Low to Normal

I changed the code to use args[0].expand().slice().reverse() (which copies the array before reversing it).

Not yet tested.

#3 Updated by Debbie Lockett over 1 year ago

  • Applies to JS Branch 1.0 added

#4 Updated by Debbie Lockett over 1 year ago

  • Status changed from In Progress to Resolved
  • Fix Committed on JS Branch 1.0 added

XSLT 3.0 test sequence-2002 added.

(Note that fix was added to code before split into 1.0 and trunk branches, which is why this is only marked as applying to 1.0 branch.)

#5 Updated by Debbie Lockett about 1 year ago

  • Status changed from Resolved to Closed
  • % Done changed from 0 to 100
  • Fixed in JS Release set to Saxon-JS 1.0.2

Bug fix applied in Saxon-JS 1.0.2 maintenance release.

Please register to edit this issue

Also available in: Atom PDF Tracking page