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.
Allow refinements in one eval to be seen in the next.
Browse files Browse the repository at this point in the history
This change just carries the original dynamic scope along into
the cloned binding used for an eval. This allows the "cref" data
for refinements to be progressively updated.

Fixes #4478.
headius committed Feb 9, 2017
1 parent fc8508a commit 55b3080
Showing 2 changed files with 29 additions and 11 deletions.
21 changes: 10 additions & 11 deletions core/src/main/java/org/jruby/RubyBasicObject.java
Original file line number Diff line number Diff line change
@@ -1759,8 +1759,16 @@ protected IRubyObject yieldUnder(final ThreadContext context, RubyModule under,
}

private Block setupBlock(Block block, EvalType evalType) {
// FIXME: This is an ugly hack to resolve JRUBY-1381; I'm not proud of it
return block.cloneBlockForEval(this, evalType);
if (block.getProcObject() == null) {
// FIXME: This is an ugly hack to resolve JRUBY-1381; I'm not proud of it
block = block.cloneBlockForEval(this, evalType);
} else {
block = block.deepCloneBlockForEval(this, evalType);
}

block.getBinding().setVisibility(PUBLIC);

return block;
}

/**
@@ -1775,18 +1783,9 @@ private Block setupBlock(Block block, EvalType evalType) {
protected IRubyObject yieldUnder(final ThreadContext context, RubyModule under, Block block, EvalType evalType) {
context.preExecuteUnder(this, under, block);

IRubyObject savedBindingSelf = block.getBinding().getSelf();
IRubyObject savedFrameSelf = block.getBinding().getFrame().getSelf();
Visibility savedVisibility = block.getBinding().getVisibility();
block.getBinding().setVisibility(PUBLIC);

try {
return setupBlock(block, evalType).yieldNonArray(context, this, this); //, context.getRubyClass());
} finally {
block.getBinding().setVisibility(savedVisibility);
block.getBinding().setSelf(savedBindingSelf);
block.getBinding().getFrame().setSelf(savedFrameSelf);

context.postExecuteUnder();
}
}
19 changes: 19 additions & 0 deletions core/src/main/java/org/jruby/runtime/Block.java
Original file line number Diff line number Diff line change
@@ -192,6 +192,15 @@ public Block cloneBlock() {
return newBlock;
}

public Block cloneBlockAndBinding() {
Block newBlock = new Block(body, binding.clone());

newBlock.type = type;
newBlock.escapeBlock = this;

return newBlock;
}

public Block cloneBlockAndFrame() {
Binding oldBinding = binding;
Binding binding = new Binding(
@@ -221,6 +230,16 @@ public Block cloneBlockForEval(IRubyObject self, EvalType evalType) {
return block;
}

public Block deepCloneBlockForEval(IRubyObject self, EvalType evalType) {
Block block = cloneBlockAndBinding();

block.getBinding().setSelf(self);
block.getBinding().getFrame().setSelf(self);
block.setEvalType(evalType);

return block;
}

/**
* What is the arity of this block?
*

0 comments on commit 55b3080

Please sign in to comment.