Skip to content

Commit

Permalink
[Truffle] Handle bare Kernel#raise.
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvdrum committed Mar 12, 2015
1 parent 487b2c8 commit 422d2b3
Showing 1 changed file with 16 additions and 1 deletion.
Expand Up @@ -25,6 +25,7 @@
import org.jruby.common.IRubyWarnings;
import org.jruby.runtime.Visibility;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.ThreadLocalObjectNode;
import org.jruby.truffle.nodes.cast.NumericToFloatNode;
import org.jruby.truffle.nodes.cast.NumericToFloatNodeFactory;
import org.jruby.truffle.nodes.coerce.ToStrNodeFactory;
Expand Down Expand Up @@ -1515,6 +1516,7 @@ public RubyArray methods(RubyBasicObject self, UndefinedPlaceholder includeInher
@CoreMethod(names = "raise", isModuleFunction = true, optional = 3)
public abstract static class RaiseNode extends CoreMethodNode {

@Child private ReadInstanceVariableNode getLastExceptionNode;
@Child private CallDispatchHeadNode initialize;

public RaiseNode(RubyContext context, SourceSection sourceSection) {
Expand All @@ -1531,7 +1533,20 @@ public RaiseNode(RaiseNode prev) {
public Object raise(VirtualFrame frame, UndefinedPlaceholder undefined1, UndefinedPlaceholder undefined2, UndefinedPlaceholder undefined3) {
notDesignedForCompilation();

return raise(frame, getContext().getCoreLibrary().getRuntimeErrorClass(), getContext().makeString("re-raised - don't have the current exception yet!"), undefined1);
if (getLastExceptionNode == null) {
CompilerDirectives.transferToInterpreter();
getLastExceptionNode = insert(new ReadInstanceVariableNode(getContext(), getSourceSection(), "$!",
new ThreadLocalObjectNode(getContext(), getSourceSection()),
true));
}

final Object lastException = getLastExceptionNode.execute(frame);

if (lastException == getContext().getCoreLibrary().getNilObject()) {
return raise(frame, getContext().makeString(""), UndefinedPlaceholder.INSTANCE, UndefinedPlaceholder.INSTANCE);
}

throw new RaiseException((RubyException) lastException);
}

@Specialization
Expand Down

0 comments on commit 422d2b3

Please sign in to comment.