Skip to content

Commit

Permalink
Showing 3 changed files with 11 additions and 36 deletions.
1 change: 0 additions & 1 deletion spec/truffle/tags/core/kernel/caller_tags.txt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -297,40 +297,6 @@ public RubySymbol calleeName(VirtualFrame frame) {
}
}

@CoreMethod(names = "caller", isModuleFunction = true, optional = 1)
public abstract static class CallerNode extends CoreMethodArrayArgumentsNode {

public CallerNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization
public Object caller(UndefinedPlaceholder omit) {
return caller(1);
}

@Specialization
public Object caller(int omit) {
notDesignedForCompilation();

omit += 1; // Always ignore this node

Backtrace backtrace = RubyCallStack.getBacktrace(this);
List<Activation> activations = backtrace.getActivations();
int size = activations.size() - omit;

if (size < 0) {
return nil();
}

Object[] callers = new Object[size];
for (int n = 0; n < size; n++) {
callers[n] = getContext().makeString(MRIBacktraceFormatter.formatCallerLine(activations, n + omit));
}
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), callers, callers.length);
}
}

@CoreMethod(names = "caller_locations", isModuleFunction = true, optional = 2)
public abstract static class CallerLocationsNode extends CoreMethodArrayArgumentsNode {

12 changes: 11 additions & 1 deletion truffle/src/main/ruby/core/kernel.rb
Original file line number Diff line number Diff line change
@@ -13,9 +13,19 @@ def printf(*args)
end
module_function :printf


alias_method :trust, :untaint
alias_method :untrust, :taint
alias_method :untrusted?, :tainted?

def caller(start = 1, limit = nil)
start += 1
if limit.nil?
args = [start]
else
args = [start, limit]
end
caller_locations(*args).map(&:inspect)
end
module_function :caller

end

0 comments on commit 16c4f9c

Please sign in to comment.