Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only consider breaks that originated from this proc's frame.
Browse files Browse the repository at this point in the history
The old logic here was turning all breaks that pass through an
escaped proc into LongJumpError, even if they originated in a
different frame/proc that could still validly handle the break.
This commit modifies the logic to ignore the exception altogether
(re-throwing it) if it is not associated with this proc/frame (by
checking jumpTarget).

Fixes #1270
headius committed Mar 2, 2015
1 parent b596b5a commit 9e2a88e
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions core/src/main/java/org/jruby/RubyProc.java
Original file line number Diff line number Diff line change
@@ -298,15 +298,17 @@ public IRubyObject call(ThreadContext context, IRubyObject[] args, IRubyObject s
}

private IRubyObject handleBreakJump(Ruby runtime, Block newBlock, JumpException.BreakJump bj, int jumpTarget) {
switch(newBlock.type) {
case LAMBDA:
if (bj.getTarget() == jumpTarget) return (IRubyObject) bj.getValue();

throw runtime.newLocalJumpError(RubyLocalJumpError.Reason.BREAK, (IRubyObject)bj.getValue(), "unexpected break");
case PROC:
if (newBlock.isEscaped()) throw runtime.newLocalJumpError(RubyLocalJumpError.Reason.BREAK, (IRubyObject)bj.getValue(), "break from proc-closure");
if (bj.getTarget() == jumpTarget) {
switch (newBlock.type) {
case LAMBDA:
return (IRubyObject) bj.getValue();
case PROC:
if (newBlock.isEscaped()) {
throw runtime.newLocalJumpError(RubyLocalJumpError.Reason.BREAK, (IRubyObject) bj.getValue(), "break from proc-closure");
}
}
}

throw bj;
}

0 comments on commit 9e2a88e

Please sign in to comment.