-
-
Notifications
You must be signed in to change notification settings - Fork 945
[ji] support java.lang.Throwable#backtrace_locations #9461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,6 +44,7 @@ | |
| import org.jruby.runtime.JavaInternalBlockBody; | ||
| import org.jruby.runtime.Signature; | ||
| import org.jruby.runtime.ThreadContext; | ||
| import org.jruby.runtime.backtrace.RubyStackTraceElement; | ||
| import org.jruby.runtime.backtrace.TraceType; | ||
| import org.jruby.runtime.builtin.IRubyObject; | ||
| import org.jruby.util.RubyStringBuilder; | ||
|
|
@@ -223,9 +224,8 @@ public static class Throwable { | |
| public static IRubyObject backtrace(final ThreadContext context, final IRubyObject self) { | ||
| final Ruby runtime = context.runtime; | ||
| java.lang.Throwable throwable = unwrapIfJavaObject(self); | ||
| // TODO instead this should get aligned with NativeException !?! | ||
| StackTraceElement[] stackTrace = throwable.getStackTrace(); | ||
| if ( stackTrace == null ) return context.nil; // never actually happens | ||
| if ( stackTrace == null ) return context.nil; | ||
| final int len = stackTrace.length; | ||
| if ( len == 0 ) return RubyArray.newEmptyArray(runtime); | ||
| IRubyObject[] backtrace = new IRubyObject[len]; | ||
|
|
@@ -235,6 +235,20 @@ public static IRubyObject backtrace(final ThreadContext context, final IRubyObje | |
| return RubyArray.newArrayMayCopy(runtime, backtrace); | ||
| } | ||
|
|
||
| @JRubyMethod | ||
| public static IRubyObject backtrace_locations(final ThreadContext context, final IRubyObject self) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This and
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah the preamble, but even if we dry out the loop mapping with a function you still need to return a different array. |
||
| java.lang.Throwable throwable = unwrapIfJavaObject(self); | ||
| StackTraceElement[] stackTrace = throwable.getStackTrace(); | ||
| if ( stackTrace == null ) return context.nil; | ||
| final int len = stackTrace.length; | ||
| if ( len == 0 ) return RubyArray.newEmptyArray(context.runtime); | ||
| RubyStackTraceElement[] rubyStackTrace = new RubyStackTraceElement[len]; | ||
| for ( int i = 0; i < len; i++ ) { | ||
| rubyStackTrace[i] = new RubyStackTraceElement(stackTrace[i]); | ||
| } | ||
| return RubyThread.Location.newLocationArray(context.runtime, rubyStackTrace); | ||
| } | ||
|
|
||
| @Deprecated(since = "10.0.0.0") | ||
| public static IRubyObject set_backtrace(final IRubyObject self, final IRubyObject backtrace) { | ||
| return set_backtrace(((RubyBasicObject) self).getCurrentContext(), self, backtrace); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would a new overload of
newLocationmake sense here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure, literally would be the same as doing
new Location()directly.