Skip to content

Commit

Permalink
[Truffle] Implement Exception#set_backtrace.
Browse files Browse the repository at this point in the history
* But we don't use it when displaying the backtrace yet!
  • Loading branch information
eregon committed May 15, 2015
1 parent 7751d72 commit e4ac055
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 13 deletions.
9 changes: 0 additions & 9 deletions spec/truffle/tags/core/exception/set_backtrace_tags.txt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.source.SourceSection;

import org.jruby.truffle.nodes.objectstorage.ReadHeadObjectFieldNode;
import org.jruby.truffle.runtime.RubyCallStack;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.UndefinedPlaceholder;
Expand Down Expand Up @@ -51,16 +53,21 @@ public RubyBasicObject initialize(RubyException exception, RubyString message) {
@CoreMethod(names = "backtrace")
public abstract static class BacktraceNode extends CoreMethodArrayArgumentsNode {

@Child ReadHeadObjectFieldNode readCustomBacktrace;

public BacktraceNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
readCustomBacktrace = new ReadHeadObjectFieldNode("@custom_backtrace");
}

@Specialization
public Object backtrace(RubyException exception) {
if (exception.getBacktrace() == null) {
return nil();
} else {
if (readCustomBacktrace.isSet(exception)) {
return readCustomBacktrace.execute(exception);
} else if (exception.getBacktrace() != null) {
return exception.asRubyStringArray();
} else {
return nil();
}
}

Expand Down
29 changes: 28 additions & 1 deletion truffle/src/main/ruby/core/rubinius/common/exception.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,38 @@ def backtrace?
backtrace ? true : false # Truffle: simplified
end

def set_backtrace(bt)
if false # bt.kind_of? Rubinius::Backtrace # Truffle: not supported
@backtrace = bt
else
# See if we stashed a Backtrace object away, and use it.
if false # hidden_bt = Rubinius::Backtrace.detect_backtrace(bt) # Truffle: not yet supported
@backtrace = hidden_bt
else
type_error = TypeError.new "backtrace must be Array of String"
case bt
when Array
if bt.all? { |s| s.kind_of? String }
@custom_backtrace = bt
else
raise type_error
end
when String
@custom_backtrace = [bt]
when nil
@custom_backtrace = nil
else
raise type_error
end
end
end
end

def set_context(ctx)
if ctx.kind_of? Exception
@parent = ctx
else
# set_backtrace(ctx) # Truffle: we don't support set_backtrace yet
set_backtrace(ctx)
end
end

Expand Down

0 comments on commit e4ac055

Please sign in to comment.