Skip to content

Commit

Permalink
[Truffle] Fix issue with rescue using ===
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisseaton committed Dec 22, 2016
1 parent 92994e7 commit 82f9332
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
1 change: 0 additions & 1 deletion spec/truffle/tags/language/rescue_tags.txt

This file was deleted.

Expand Up @@ -23,7 +23,7 @@ public RescueAnyNode(RubyContext context, SourceSection sourceSection, RubyNode

@Override
public boolean canHandle(VirtualFrame frame, DynamicObject exception) {
return getIsANode().executeIsA(exception, coreLibrary().getStandardErrorClass());
return matches(frame, exception, coreLibrary().getStandardErrorClass());
}

}
Expand Up @@ -32,7 +32,7 @@ public boolean canHandle(VirtualFrame frame, DynamicObject exception) {
for (RubyNode handlingClassNode : handlingClassNodes) {
final DynamicObject handlingClass = (DynamicObject) handlingClassNode.execute(frame);

if (getIsANode().executeIsA(exception, handlingClass)) {
if (matches(frame, exception, handlingClass)) {
return true;
}
}
Expand Down
Expand Up @@ -14,15 +14,20 @@
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.core.cast.BooleanCastNode;
import org.jruby.truffle.core.cast.BooleanCastNodeGen;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.dispatch.DispatchHeadNode;
import org.jruby.truffle.language.dispatch.DispatchHeadNodeFactory;
import org.jruby.truffle.language.objects.IsANode;
import org.jruby.truffle.language.objects.IsANodeGen;

public abstract class RescueNode extends RubyNode {

@Child private RubyNode body;

@Child private IsANode isANode;
@Child private DispatchHeadNode threequalsNode;
@Child private BooleanCastNode booleanCastNode;

public RescueNode(RubyContext context, SourceSection sourceSection, RubyNode body) {
super(context, sourceSection);
Expand All @@ -41,13 +46,14 @@ public void executeVoid(VirtualFrame frame) {
body.executeVoid(frame);
}

protected IsANode getIsANode() {
if (isANode == null) {
protected boolean matches(VirtualFrame frame, Object exception, Object handlingClass) {
if (threequalsNode == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
isANode = insert(IsANodeGen.create(getContext(), null, null, null));
threequalsNode = insert(DispatchHeadNodeFactory.createMethodCall(getContext()));
booleanCastNode = insert(BooleanCastNodeGen.create(null));
}

return isANode;
return booleanCastNode.executeToBoolean(threequalsNode.dispatch(frame, handlingClass, "===", null, new Object[]{exception}));
}

}
Expand Up @@ -30,7 +30,7 @@ public boolean canHandle(VirtualFrame frame, DynamicObject exception) {
final DynamicObject handlingClasses = (DynamicObject) handlingClassesArray.execute(frame);

for (Object handlingClass : ArrayOperations.toIterable(handlingClasses)) {
if (getIsANode().executeIsA(exception, (DynamicObject) handlingClass)) {
if (matches(frame, exception, (DynamicObject) handlingClass)) {
return true;
}
}
Expand Down

0 comments on commit 82f9332

Please sign in to comment.