Skip to content
Permalink
Browse files
Use target self as frame self for instance_eval. Fixes #2301.
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 7178caaee28cdb68bf9a96c3bafa2d109c31b9e2
@@ -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();
@@ -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();
@@ -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 {
@@ -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 {
@@ -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());
}

0 comments on commit 7178caa

Please sign in to comment.