Class CallStack

java.lang.Object
bsh.CallStack
All Implemented Interfaces:
Serializable

public final class CallStack extends Object implements Serializable
A stack of NameSpaces representing the call path. Each method invocation, for example, pushes a new NameSpace onto the stack. The top of the stack is always the current namespace of evaluation.

This is used to support the this.caller magic reference and to print script "stack traces" when evaluation errors occur.

Note: How can this be thread safe, you might ask? Wouldn't a thread executing various beanshell methods be mutating the callstack? Don't we need one CallStack per Thread in the interpreter? The answer is that we do. Any java.lang.Thread enters our script via an external (hard) Java reference via a This type interface, e.g. the Runnable interface implemented by This or an arbitrary interface implemented by XThis. In that case the This invokeMethod() method (called by any interface that it exposes) creates a new CallStack for each external call.

See Also:
  • Constructor Details

    • CallStack

      public CallStack()
    • CallStack

      public CallStack(NameSpace namespace)
  • Method Details

    • clear

      public void clear()
    • push

      public void push(NameSpace ns)
    • top

      public NameSpace top()
    • get

      public NameSpace get(int depth)
      zero based.
    • set

      public void set(int depth, NameSpace ns)
      This is kind of crazy, but used by the setNameSpace command. zero based.
    • pop

      public NameSpace pop()
    • swap

      public NameSpace swap(NameSpace newTop)
      Swap in the value as the new top of the stack and return the old value.
    • depth

      public int depth()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • copy

      public CallStack copy()
      Occasionally we need to freeze the callstack for error reporting purposes, etc.