@@ -1570,19 +1570,19 @@ public IRubyObject send19(ThreadContext context, IRubyObject[] args, Block block
15701570
15711571 @ JRubyMethod (name = "instance_eval" )
15721572 public IRubyObject instance_eval19 (ThreadContext context , Block block ) {
1573- return specificEval (context , getInstanceEvalClass (), block );
1573+ return specificEval (context , getInstanceEvalClass (), block , EvalType . INSTANCE_EVAL );
15741574 }
15751575 @ JRubyMethod (name = "instance_eval" )
15761576 public IRubyObject instance_eval19 (ThreadContext context , IRubyObject arg0 , Block block ) {
1577- return specificEval (context , getInstanceEvalClass (), arg0 , block );
1577+ return specificEval (context , getInstanceEvalClass (), arg0 , block , EvalType . INSTANCE_EVAL );
15781578 }
15791579 @ JRubyMethod (name = "instance_eval" )
15801580 public IRubyObject instance_eval19 (ThreadContext context , IRubyObject arg0 , IRubyObject arg1 , Block block ) {
1581- return specificEval (context , getInstanceEvalClass (), arg0 , arg1 , block );
1581+ return specificEval (context , getInstanceEvalClass (), arg0 , arg1 , block , EvalType . INSTANCE_EVAL );
15821582 }
15831583 @ JRubyMethod (name = "instance_eval" )
15841584 public IRubyObject instance_eval19 (ThreadContext context , IRubyObject arg0 , IRubyObject arg1 , IRubyObject arg2 , Block block ) {
1585- return specificEval (context , getInstanceEvalClass (), arg0 , arg1 , arg2 , block );
1585+ return specificEval (context , getInstanceEvalClass (), arg0 , arg1 , arg2 , block , EvalType . INSTANCE_EVAL );
15861586 }
15871587
15881588 @ JRubyMethod (name = "instance_exec" , optional = 3 , rest = true )
@@ -1599,7 +1599,7 @@ public IRubyObject instance_exec19(ThreadContext context, IRubyObject[] args, Bl
15991599 klazz = getSingletonClass ();
16001600 }
16011601
1602- return yieldUnder (context , klazz , args , block );
1602+ return yieldUnder (context , klazz , args , block , EvalType . INSTANCE_EVAL );
16031603 }
16041604
16051605 /**
@@ -1611,7 +1611,7 @@ public IRubyObject instance_exec19(ThreadContext context, IRubyObject[] args, Bl
16111611 * it possible to emulate both instance_eval and instance_exec
16121612 * with this implementation.
16131613 */
1614- protected IRubyObject yieldUnder (final ThreadContext context , RubyModule under , IRubyObject [] args , Block block ) {
1614+ protected IRubyObject yieldUnder (final ThreadContext context , RubyModule under , IRubyObject [] args , Block block , EvalType evalType ) {
16151615 context .preExecuteUnder (under , block );
16161616
16171617 Visibility savedVisibility = block .getBinding ().getVisibility ();
@@ -1620,10 +1620,10 @@ protected IRubyObject yieldUnder(final ThreadContext context, RubyModule under,
16201620 try {
16211621 if (args .length == 1 ) {
16221622 IRubyObject valueInYield = args [0 ];
1623- return setupBlock (block ).yieldNonArray (context , valueInYield , this , context .getRubyClass ());
1623+ return setupBlock (block , evalType ).yieldNonArray (context , valueInYield , this , context .getRubyClass ());
16241624 } else {
16251625 IRubyObject valueInYield = RubyArray .newArrayNoCopy (context .runtime , args );
1626- return setupBlock (block ).yieldArray (context , valueInYield , this , context .getRubyClass ());
1626+ return setupBlock (block , evalType ).yieldArray (context , valueInYield , this , context .getRubyClass ());
16271627 }
16281628 //TODO: Should next and return also catch here?
16291629 } catch (JumpException .BreakJump bj ) {
@@ -1635,11 +1635,12 @@ protected IRubyObject yieldUnder(final ThreadContext context, RubyModule under,
16351635 }
16361636 }
16371637
1638- private Block setupBlock (Block block ) {
1638+ private Block setupBlock (Block block , EvalType evalType ) {
16391639 // FIXME: This is an ugly hack to resolve JRUBY-1381; I'm not proud of it
16401640 block = block .cloneBlock ();
16411641 block .getBinding ().setSelf (this );
16421642 block .getBinding ().getFrame ().setSelf (this );
1643+ block .setEvalType (evalType );
16431644
16441645 return block ;
16451646 }
@@ -1653,14 +1654,14 @@ private Block setupBlock(Block block) {
16531654 * it possible to emulate both instance_eval and instance_exec
16541655 * with this implementation.
16551656 */
1656- protected IRubyObject yieldUnder (final ThreadContext context , RubyModule under , Block block ) {
1657+ protected IRubyObject yieldUnder (final ThreadContext context , RubyModule under , Block block , EvalType evalType ) {
16571658 context .preExecuteUnder (under , block );
16581659
16591660 Visibility savedVisibility = block .getBinding ().getVisibility ();
16601661 block .getBinding ().setVisibility (PUBLIC );
16611662
16621663 try {
1663- return setupBlock (block ).yieldNonArray (context , this , this , context .getRubyClass ());
1664+ return setupBlock (block , evalType ).yieldNonArray (context , this , this , context .getRubyClass ());
16641665 //TODO: Should next and return also catch here?
16651666 } catch (JumpException .BreakJump bj ) {
16661667 return (IRubyObject ) bj .getValue ();
@@ -1682,9 +1683,9 @@ protected IRubyObject yieldUnder(final ThreadContext context, RubyModule under,
16821683 * arguments in the args-array is optional, but can contain the
16831684 * filename and line of the string under evaluation.
16841685 */
1685- public IRubyObject specificEval (ThreadContext context , RubyModule mod , Block block ) {
1686+ public IRubyObject specificEval (ThreadContext context , RubyModule mod , Block block , EvalType evalType ) {
16861687 if (block .isGiven ()) {
1687- return yieldUnder (context , mod , block );
1688+ return yieldUnder (context , mod , block , evalType );
16881689 } else {
16891690 throw context .runtime .newArgumentError ("block not supplied" );
16901691 }
@@ -1700,7 +1701,7 @@ public IRubyObject specificEval(ThreadContext context, RubyModule mod, Block blo
17001701 * arguments in the args-array is optional, but can contain the
17011702 * filename and line of the string under evaluation.
17021703 */
1703- public IRubyObject specificEval (ThreadContext context , RubyModule mod , IRubyObject arg , Block block ) {
1704+ public IRubyObject specificEval (ThreadContext context , RubyModule mod , IRubyObject arg , Block block , EvalType evalType ) {
17041705 if (block .isGiven ()) {
17051706 throw context .runtime .newArgumentError (1 , 0 );
17061707 }
@@ -1716,7 +1717,7 @@ public IRubyObject specificEval(ThreadContext context, RubyModule mod, IRubyObje
17161717 String file = "(eval)" ;
17171718 int line = 0 ;
17181719
1719- return evalUnder (context , mod , evalStr , file , line );
1720+ return evalUnder (context , mod , evalStr , file , line , evalType );
17201721 }
17211722
17221723 /** specific_eval
@@ -1729,7 +1730,7 @@ public IRubyObject specificEval(ThreadContext context, RubyModule mod, IRubyObje
17291730 * arguments in the args-array is optional, but can contain the
17301731 * filename and line of the string under evaluation.
17311732 */
1732- public IRubyObject specificEval (ThreadContext context , RubyModule mod , IRubyObject arg0 , IRubyObject arg1 , Block block ) {
1733+ public IRubyObject specificEval (ThreadContext context , RubyModule mod , IRubyObject arg0 , IRubyObject arg1 , Block block , EvalType evalType ) {
17331734 if (block .isGiven ()) {
17341735 throw context .runtime .newArgumentError (2 , 0 );
17351736 }
@@ -1745,7 +1746,7 @@ public IRubyObject specificEval(ThreadContext context, RubyModule mod, IRubyObje
17451746 String file = arg1 .convertToString ().asJavaString ();
17461747 int line = 0 ;
17471748
1748- return evalUnder (context , mod , evalStr , file , line );
1749+ return evalUnder (context , mod , evalStr , file , line , evalType );
17491750 }
17501751
17511752 /** specific_eval
@@ -1758,7 +1759,7 @@ public IRubyObject specificEval(ThreadContext context, RubyModule mod, IRubyObje
17581759 * arguments in the args-array is optional, but can contain the
17591760 * filename and line of the string under evaluation.
17601761 */
1761- public IRubyObject specificEval (ThreadContext context , RubyModule mod , IRubyObject arg0 , IRubyObject arg1 , IRubyObject arg2 , Block block ) {
1762+ public IRubyObject specificEval (ThreadContext context , RubyModule mod , IRubyObject arg0 , IRubyObject arg1 , IRubyObject arg2 , Block block , EvalType evalType ) {
17621763 if (block .isGiven ()) {
17631764 throw context .runtime .newArgumentError (2 , 0 );
17641765 }
@@ -1774,7 +1775,7 @@ public IRubyObject specificEval(ThreadContext context, RubyModule mod, IRubyObje
17741775 String file = arg1 .convertToString ().asJavaString ();
17751776 int line = (int )(arg2 .convertToInteger ().getLongValue () - 1 );
17761777
1777- return evalUnder (context , mod , evalStr , file , line );
1778+ return evalUnder (context , mod , evalStr , file , line , evalType );
17781779 }
17791780
17801781 protected RubyModule getInstanceEvalClass () {
@@ -1790,12 +1791,12 @@ protected RubyModule getInstanceEvalClass() {
17901791 * Evaluates the string src with self set to the current object,
17911792 * using the module under as the context.
17921793 */
1793- public IRubyObject evalUnder (final ThreadContext context , RubyModule under , RubyString src , String file , int line ) {
1794+ public IRubyObject evalUnder (final ThreadContext context , RubyModule under , RubyString src , String file , int line , EvalType evalType ) {
17941795 Visibility savedVisibility = context .getCurrentVisibility ();
17951796 context .setCurrentVisibility (PUBLIC );
17961797 context .preExecuteUnder (under , Block .NULL_BLOCK );
17971798 try {
1798- return Interpreter .evalSimple (context , this , src , file , line );
1799+ return Interpreter .evalSimple (context , this , src , file , line , evalType );
17991800 } finally {
18001801 context .postExecuteUnder ();
18011802 context .setCurrentVisibility (savedVisibility );
@@ -2471,16 +2472,16 @@ public RubyArray to_a() {
24712472 * k.instance_eval { @secret } #=> 99
24722473 */
24732474 public IRubyObject instance_eval (ThreadContext context , Block block ) {
2474- return specificEval (context , getInstanceEvalClass (), block );
2475+ return specificEval (context , getInstanceEvalClass (), block , EvalType . INSTANCE_EVAL );
24752476 }
24762477 public IRubyObject instance_eval (ThreadContext context , IRubyObject arg0 , Block block ) {
2477- return specificEval (context , getInstanceEvalClass (), arg0 , block );
2478+ return specificEval (context , getInstanceEvalClass (), arg0 , block , EvalType . INSTANCE_EVAL );
24782479 }
24792480 public IRubyObject instance_eval (ThreadContext context , IRubyObject arg0 , IRubyObject arg1 , Block block ) {
2480- return specificEval (context , getInstanceEvalClass (), arg0 , arg1 , block );
2481+ return specificEval (context , getInstanceEvalClass (), arg0 , arg1 , block , EvalType . INSTANCE_EVAL );
24812482 }
24822483 public IRubyObject instance_eval (ThreadContext context , IRubyObject arg0 , IRubyObject arg1 , IRubyObject arg2 , Block block ) {
2483- return specificEval (context , getInstanceEvalClass (), arg0 , arg1 , arg2 , block );
2484+ return specificEval (context , getInstanceEvalClass (), arg0 , arg1 , arg2 , block , EvalType . INSTANCE_EVAL );
24842485 }
24852486
24862487 /** rb_obj_instance_exec
@@ -2514,7 +2515,7 @@ public IRubyObject instance_exec(ThreadContext context, IRubyObject[] args, Bloc
25142515 klazz = getSingletonClass ();
25152516 }
25162517
2517- return yieldUnder (context , klazz , args , block );
2518+ return yieldUnder (context , klazz , args , block , EvalType . INSTANCE_EVAL );
25182519 }
25192520
25202521 /** rb_obj_extend
0 commit comments