Skip to content

Commit d342d71

Browse files
committed
Thread::Backtrace::Location#absolute_path should be nil for core methods defined in Ruby
1 parent 8484c42 commit d342d71

File tree

4 files changed

+19
-33
lines changed

4 files changed

+19
-33
lines changed

spec/ruby/core/thread/backtrace/location/absolute_path_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,19 @@
3636
end
3737
end
3838

39+
context "when used in a core method" do
40+
it "returns nil" do
41+
location = nil
42+
tap { location = caller_locations(1, 1)[0] }
43+
location.label.should == "tap"
44+
if location.path.start_with?("<internal:")
45+
location.absolute_path.should == nil
46+
else
47+
location.absolute_path.should == File.realpath(__FILE__)
48+
end
49+
end
50+
end
51+
3952
context "canonicalization" do
4053
platform_is_not :windows do
4154
before :each do

spec/truffle/thread/backtrace/location/absolute_path_spec.rb

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/main/java/org/truffleruby/core/thread/ThreadBacktraceLocationNodes.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.oracle.truffle.api.dsl.Specialization;
2828
import com.oracle.truffle.api.source.Source;
2929
import com.oracle.truffle.api.source.SourceSection;
30+
import org.truffleruby.language.backtrace.BacktraceFormatter;
3031

3132
@CoreModule(value = "Thread::Backtrace::Location", isClass = true)
3233
public class ThreadBacktraceLocationNodes {
@@ -47,15 +48,17 @@ public abstract static class AbsolutePathNode extends UnaryCoreMethodNode {
4748

4849
@TruffleBoundary
4950
@Specialization
50-
protected RubyString absolutePath(RubyBacktraceLocation threadBacktraceLocation,
51+
protected Object absolutePath(RubyBacktraceLocation threadBacktraceLocation,
5152
@Cached StringNodes.MakeStringNode makeStringNode) {
5253
final SourceSection sourceSection = getAvailableSourceSection(getContext(), threadBacktraceLocation);
5354

5455
if (sourceSection == null) {
5556
return coreStrings().UNKNOWN.createInstance(getContext());
5657
} else {
5758
final Source source = sourceSection.getSource();
58-
if (source.getPath() != null) { // A normal file
59+
if (BacktraceFormatter.isRubyCore(getContext(), source)) {
60+
return nil;
61+
} else if (source.getPath() != null) { // A normal file
5962
final String path = getContext().getSourcePath(source);
6063
final String canonicalPath = getContext().getFeatureLoader().canonicalize(path);
6164
final Rope cachedRope = getContext()

src/main/java/org/truffleruby/language/backtrace/BacktraceFormatter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ public static boolean isUserSourceSection(RubyContext context, SourceSection sou
345345
return isAvailable(sourceSection) && !isRubyCore(context, sourceSection.getSource());
346346
}
347347

348-
private static boolean isRubyCore(RubyContext context, Source source) {
348+
public static boolean isRubyCore(RubyContext context, Source source) {
349349
final String path = RubyContext.getPath(source);
350350
return path.startsWith(context.getCoreLibrary().coreLoadPath);
351351
}

0 commit comments

Comments
 (0)