Project

Profile

Help

Bug #3362

closed

reverse() modifies its argument

Added by Michael Kay almost 7 years ago. Updated over 6 years ago.

Status:
Closed
Priority:
Normal
Category:
-
Sprint/Milestone:
-
Start date:
2017-07-22
Due date:
% Done:

100%

Estimated time:
Applies to JS Branch:
1.0
Fix Committed on JS Branch:
1.0
Fixed in JS Release:
SEF Generated with:
Platforms:
Company:
-
Contact person:
-
Additional contact persons:
-

Description

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)

Please register to edit this issue

Also available in: Atom PDF Tracking page