Skip to content

Commit

Permalink
Fix: handle stack frames in the correct order
Browse files Browse the repository at this point in the history
Commit f3c64ee removed `ObjArray` and
replaced its usage with standard JDK classes. In `Interpreter`, in
particular, an `ArrayDeque` is now used to store
`cx.previousInterpreterInvocations`, which is used to generate the
stack frame information. However, there is one place where `toArray`
is done, and the behavior for `ObjArray` and `ArrayDeque` are different
(swapped).
Unfortunately no tests actually ends up exercising this difference due
to the interpreter function peeling optimization done in
#1510.

We have discovered this problem because, in ServiceNow's fork, we
currently need to disable the function peeling optimization.
  • Loading branch information
andreabergia authored and gbrail committed Dec 24, 2024
1 parent a65afb3 commit d9f7210
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion rhino/src/main/java/org/mozilla/javascript/Interpreter.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -951,7 +952,10 @@ public void captureStackInfo(RhinoException ex) {
--previousCount;
}
array = new CallFrame[previousCount + 1];
cx.previousInterpreterInvocations.toArray(array);

ArrayList<Object> tempList = new ArrayList<>(cx.previousInterpreterInvocations);
Collections.reverse(tempList);
tempList.toArray(array);
}
array[array.length - 1] = (CallFrame) cx.lastInterpreterFrame;

Expand Down

0 comments on commit d9f7210

Please sign in to comment.