private static String createRawBacktraceStringFromThrowable(Throwable t) { try { return ThreadContext.createRawBacktraceStringFromThrowable(t, false); } catch(NoSuchMethodError e) { try { Method method = ThreadContext.class.getMethod("createRawBacktraceStringFromThrowable", Throwable.class); return method.invoke(null, t).toString(); } catch(Exception ee) { return "can not produce raw stacktrace: " + ee.getMessage(); } } }
public void preExecuteUnder(IRubyObject executeUnderObj, RubyModule executeUnderClass, Block block) { Frame frame = getCurrentFrame(); DynamicScope scope = getCurrentScope(); StaticScope sScope = runtime.getStaticScopeFactory().newBlockScope(scope.getStaticScope()); sScope.setModule(executeUnderClass); pushScope(DynamicScope.newDynamicScope(sScope, scope)); pushCallFrame(frame.getKlazz(), frame.getName(), executeUnderObj, block); getCurrentFrame().setVisibility(getPreviousFrame().getVisibility()); }
public static ThreadContext newContext(Ruby runtime) { ThreadContext context = new ThreadContext(runtime); return context; }
protected void pre(ThreadContext context, StaticScope staticScope, RubyModule implementationClass, IRubyObject self, String name, Block block) { // update call stacks (push: frame, class, needsDynamicScope, etc.) context.preMethodFrameOnly(implementationClass, name, self, block); if (needsDynamicScope) { // Add a parent-link to current dynscope to support non-local returns cheaply // This doesn't affect variable scoping since local variables will all have // the right needsDynamicScope depth. context.pushScope(DynamicScope.newDynamicScope(staticScope, context.getCurrentScope())); } context.setCurrentVisibility(getVisibility()); }
public void prepareTopLevel(RubyClass objectClass, IRubyObject topSelf) { pushFrame(); setCurrentVisibility(Visibility.PRIVATE); Frame frame = getCurrentFrame(); frame.setSelf(topSelf); getCurrentScope().getStaticScope().setModule(objectClass); }
@JRubyMethod(module = true) public static synchronized IRubyObject nprocessors(ThreadContext context, IRubyObject recv) { int nprocs = Runtime.getRuntime().availableProcessors(); return RubyFixnum.newFixnum(context.getRuntime(), nprocs); }
/** * Return a binding representing the current call's state * @return the current binding */ public Binding currentBinding() { Frame frame = getCurrentFrame().capture(); BacktraceElement elt = backtrace[backtraceIndex]; return new Binding(frame, getCurrentScope(), elt.getMethod(), elt.getFilename(), elt.getLine()); }
/** * Create an Array with backtrace information for Kernel#caller * @param runtime * @param level * @return an Array with the backtrace */ public IRubyObject createCallerBacktrace(int level, StackTraceElement[] stacktrace) { return createCallerBacktrace(level, null, stacktrace); }
@JRubyMethod(name = "initialize", visibility = Visibility.PRIVATE) @Override public IRubyObject initialize(ThreadContext context) { binding = context.currentBinding(); return this; }
private static RubyClass pollAndGetClass(ThreadContext context, IRubyObject self) { context.callThreadPoll(); RubyClass selfType = self.getMetaClass(); return selfType; }
private static IRubyObject callerLocationsInternal(ThreadContext context, IRubyObject level, IRubyObject length) { Integer[] ll = levelAndLengthFromArgs(context, level, length, 1); Integer levelInt = ll[0], lengthInt = ll[1]; return context.createCallerLocations(levelInt, lengthInt, Thread.currentThread().getStackTrace()); }
protected static RubyModule getRubyClass(final Ruby runtime) { ThreadContext context = runtime.getCurrentContext(); StaticScope scope = context.getCurrentScope().getStaticScope(); RubyModule rubyClass = scope.getModule(); return rubyClass; }
private static RubyStackTraceElement[] getRubyStackTrace(Ruby runtime) { ThreadContext context = runtime.getCurrentContext(); RubyStackTraceElement[] stack = context.createWarningBacktrace(runtime); return stack; }
private static void expandBacktraceStack(ThreadContext context) { int newSize = context.backtrace.length * 2; context.backtrace = fillNewBacktrace(context, new BacktraceElement[newSize], newSize); }
@Override public Object execute(RipperParser p, Object yyVal, Object[] yyVals, int yyTop) { yyVal = p.getContext().getRuntime().getFalse(); return yyVal; } };
@Override protected void pre(InterpreterContext ic, ThreadContext context, IRubyObject self, String name, Block block, RubyModule implClass) { // update call stacks (push: frame, class, scope, etc.) context.preMethodFrameOnly(getImplementationClass(), name, self, block); if (ic.pushNewDynScope()) { // Add a parent-link to current dynscope to support non-local returns cheaply // This doesn't affect variable scoping since local variables will all have // the right scope depth. context.pushScope(DynamicScope.newDynamicScope(ic.getStaticScope(), context.getCurrentScope())); } context.setCurrentVisibility(getVisibility()); }
public void prepareTopLevel(RubyClass objectClass, IRubyObject topSelf) { pushFrame(); setCurrentVisibility(Visibility.PRIVATE); Frame frame = getCurrentFrame(); frame.setSelf(topSelf); getCurrentScope().getStaticScope().setModule(objectClass); }
/** * Return a binding representing the current call's state but with the * specified visibility and self. * @param self the self object to use * @param visibility the visibility to use * @return the current binding using the specified self and visibility */ public Binding currentBinding(IRubyObject self, Visibility visibility) { Frame frame = getCurrentFrame().capture(); BacktraceElement elt = backtrace[backtraceIndex]; return new Binding(self, frame, visibility, getCurrentScope(), elt.getMethod(), elt.getFilename(), elt.getLine()); }
/** * Create an Array with backtrace information for Kernel#caller * @param runtime * @param level * @return an Array with the backtrace */ public IRubyObject createCallerBacktrace(int level, StackTraceElement[] stacktrace) { return createCallerBacktrace(level, null, stacktrace); }
public static Block newCallClosure(IRubyObject self, RubyModule imClass, Signature signature, BlockCallback callback, ThreadContext context) { Binding binding = context.currentBinding(self, Visibility.PUBLIC); BlockBody body = new CallBlock(signature, callback, context); return new Block(body, binding); }