Skip to content

Commit

Permalink
Use target self as frame self for instance_eval. Fixes #2301.
Browse files Browse the repository at this point in the history
This is a bit of a scary change, so pushing to a test branch for
now.
  • Loading branch information
headius committed Dec 15, 2014
1 parent 69317cc commit 7178caa
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/RubyBasicObject.java
Expand Up @@ -1688,7 +1688,7 @@ public IRubyObject instance_exec19(ThreadContext context, IRubyObject[] args, Bl
* with this implementation.
*/
protected IRubyObject yieldUnder(final ThreadContext context, RubyModule under, IRubyObject[] args, Block block, EvalType evalType) {
context.preExecuteUnder(under, block);
context.preExecuteUnder(this, under, block);

IRubyObject savedBindingSelf = block.getBinding().getSelf();
IRubyObject savedFrameSelf = block.getBinding().getFrame().getSelf();
Expand Down Expand Up @@ -1730,7 +1730,7 @@ private Block setupBlock(Block block, EvalType evalType) {
* with this implementation.
*/
protected IRubyObject yieldUnder(final ThreadContext context, RubyModule under, Block block, EvalType evalType) {
context.preExecuteUnder(under, block);
context.preExecuteUnder(this, under, block);

IRubyObject savedBindingSelf = block.getBinding().getSelf();
IRubyObject savedFrameSelf = block.getBinding().getFrame().getSelf();
Expand Down Expand Up @@ -1873,7 +1873,7 @@ protected RubyModule getInstanceEvalClass() {
public IRubyObject evalUnder(final ThreadContext context, RubyModule under, RubyString src, String file, int line, EvalType evalType) {
Visibility savedVisibility = context.getCurrentVisibility();
context.setCurrentVisibility(PUBLIC);
context.preExecuteUnder(under, Block.NULL_BLOCK);
context.preExecuteUnder(this, under, Block.NULL_BLOCK);
try {
return Interpreter.evalSimple(context, this, src, file, line, evalType);
} finally {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyModule.java
Expand Up @@ -1669,7 +1669,7 @@ private DynamicMethod createProcMethod(String name, Visibility visibility, RubyP

@Deprecated
public IRubyObject executeUnder(ThreadContext context, org.jruby.runtime.callback.Callback method, IRubyObject[] args, Block block) {
context.preExecuteUnder(this, block);
context.preExecuteUnder(this, this, block);
try {
return method.execute(this, args, block);
} finally {
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/runtime/ThreadContext.java
Expand Up @@ -881,14 +881,14 @@ public void postNodeEval() {
}

// XXX: Again, screwy evaling under previous frame's scope
public void preExecuteUnder(RubyModule executeUnderClass, Block block) {
public void preExecuteUnder(IRubyObject executeUnderObj, RubyModule executeUnderClass, Block block) {
Frame frame = getCurrentFrame();

DynamicScope scope = getCurrentScope();
StaticScope sScope = runtime.getStaticScopeFactory().newBlockScope(scope.getStaticScope());
sScope.setModule(executeUnderClass);
pushScope(DynamicScope.newDynamicScope(sScope, scope));
pushCallFrame(frame.getKlazz(), frame.getName(), frame.getSelf(), block);
pushCallFrame(frame.getKlazz(), frame.getName(), executeUnderObj, block);
getCurrentFrame().setVisibility(getPreviousFrame().getVisibility());
}

Expand Down

0 comments on commit 7178caa

Please sign in to comment.