Skip to content
Permalink
Browse files
[Truffle] Clear $! when leaving a try-rescue-ensure block.
  • Loading branch information
chrisseaton committed Dec 29, 2014
1 parent fdfe94d commit 3792e0f62b2e578da31d0a6629f19e2792643008
@@ -15,7 +15,9 @@
import com.oracle.truffle.api.nodes.*;
import com.oracle.truffle.api.utilities.*;
import org.jruby.truffle.nodes.*;
import org.jruby.truffle.nodes.literal.ObjectLiteralNode;
import org.jruby.truffle.nodes.methods.ExceptionTranslatingNode;
import org.jruby.truffle.nodes.objects.WriteInstanceVariableNode;
import org.jruby.truffle.runtime.*;
import org.jruby.truffle.runtime.control.*;

@@ -28,6 +30,7 @@ public class TryNode extends RubyNode {
@Child protected ExceptionTranslatingNode tryPart;
@Children final RescueNode[] rescueParts;
@Child protected RubyNode elsePart;
@Child protected WriteInstanceVariableNode clearExceptionVariableNode;

private final BranchProfile elseProfile = BranchProfile.create();
private final BranchProfile controlFlowProfile = BranchProfile.create();
@@ -38,6 +41,10 @@ public TryNode(RubyContext context, SourceSection sourceSection, ExceptionTransl
this.tryPart = tryPart;
this.rescueParts = rescueParts;
this.elsePart = elsePart;
clearExceptionVariableNode = new WriteInstanceVariableNode(context, sourceSection, "$!",
new ObjectLiteralNode(context, sourceSection, context.getCoreLibrary().getGlobalVariablesObject()),
new ObjectLiteralNode(context, sourceSection, context.getCoreLibrary().getNilObject()),
true);
}

@Override
@@ -60,6 +67,8 @@ public Object execute(VirtualFrame frame) {
} catch (RetryException e) {
continue;
}
} finally {
clearExceptionVariableNode.execute(frame);
}

elseProfile.enter();
@@ -105,7 +105,7 @@ public Object isDefined(VirtualFrame frame) {
if (isGlobal) {
final RubyBasicObject recieverValue = (RubyBasicObject) receiver.execute(frame);

if (readNode.getName().equals("$~")) {
if (readNode.getName().equals("$~") || readNode.getName().equals("$!")) {
return getContext().makeString("global-variable");
} else if (readNode.isSet(recieverValue)) {
if (readNode.execute(recieverValue) == getContext().getCoreLibrary().getNilObject()) {
@@ -1,2 +1 @@
fails:Predefined global $! remains nil after a failed core class "checked" coercion against a class that defines method_missing
fails:Predefined global $_ is Thread-local

0 comments on commit 3792e0f

Please sign in to comment.