@JRubyMethod(optional = 2, compat = CompatVersion.RUBY2_0)
  public IRubyObject backtrace_locations(ThreadContext context, IRubyObject[] args) {
    ThreadContext myContext = getContext();

    if (myContext == null) return context.nil;

    Ruby runtime = context.runtime;
    Integer[] ll = RubyKernel.levelAndLengthFromArgs(runtime, args, 0);
    Integer level = ll[0], length = ll[1];

    return myContext.createCallerLocations(level, length, getNativeThread().getStackTrace());
  }
  @JRubyMethod(name = "backtrace", optional = 2, compat = CompatVersion.RUBY2_0)
  public IRubyObject backtrace20(ThreadContext context, IRubyObject[] args) {
    ThreadContext myContext = getContext();

    // context can be nil if we have not started or GC has claimed our context
    if (myContext == null) return context.nil;

    Thread nativeThread = getNativeThread();

    // nativeThread can be null if the thread has terminated and GC has claimed it
    if (nativeThread == null) return context.nil;

    Ruby runtime = context.runtime;
    Integer[] ll = RubyKernel.levelAndLengthFromArgs(runtime, args, 0);
    Integer level = ll[0], length = ll[1];

    return myContext.createCallerBacktrace(level, length, getNativeThread().getStackTrace());
  }
Ejemplo n.º 3
0
  @JRubyMethod(optional = 3)
  public IRubyObject raise(IRubyObject[] args, Block block) {
    Ruby runtime = getRuntime();
    ThreadContext context = runtime.getCurrentContext();
    if (this == context.getThread()) {
      return RubyKernel.raise(context, runtime.getKernel(), args, block);
    }

    debug(this, "before raising");
    RubyThread currentThread = getRuntime().getCurrentContext().getThread();

    debug(this, "raising");
    IRubyObject exception = prepareRaiseException(runtime, args, block);

    runtime
        .getThreadService()
        .deliverEvent(
            new ThreadService.Event(
                currentThread, this, ThreadService.Event.Type.RAISE, exception));

    return this;
  }