|
75 | 75 | import static org.jruby.api.Error.typeError; |
76 | 76 | import static org.jruby.api.Warn.warn; |
77 | 77 | import static org.jruby.ir.runtime.IRRuntimeHelpers.dupIfKeywordRestAtCallsite; |
| 78 | +import static org.jruby.ir.runtime.IRRuntimeHelpers.getCurrentClassBase; |
78 | 79 | import static org.jruby.runtime.Helpers.invokeChecked; |
79 | 80 | import static org.jruby.runtime.ThreadContext.*; |
80 | 81 | import static org.jruby.runtime.Visibility.*; |
@@ -1882,12 +1883,15 @@ public IRubyObject specificEval(ThreadContext context, RubyModule mod, IRubyObje |
1882 | 1883 | return evalUnder(context, mod, evalStr, file, line, evalType); |
1883 | 1884 | } |
1884 | 1885 |
|
| 1886 | + @Deprecated(since = "10.0") |
1885 | 1887 | protected RubyModule getInstanceEvalClass() { |
1886 | | - if (isImmediate()) { |
1887 | | - // Ruby uses Qnil here, we use "dummy" because we need a class |
1888 | | - return getRuntime().getDummy(); |
1889 | | - } |
1890 | | - return getSingletonClass(); |
| 1888 | + return getInstanceEvalClass(getCurrentContext()); |
| 1889 | + } |
| 1890 | + |
| 1891 | + protected RubyModule getInstanceEvalClass(ThreadContext context) { |
| 1892 | + return isImmediate() ? |
| 1893 | + context.runtime.getDummy() : // MRI uses Qnil here, we use "dummy" because we need a class |
| 1894 | + singletonClass(context); |
1891 | 1895 | } |
1892 | 1896 |
|
1893 | 1897 | /** |
@@ -2543,25 +2547,25 @@ public RubyArray to_a(ThreadContext context) { |
2543 | 2547 | reads = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE}, |
2544 | 2548 | writes = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE}) |
2545 | 2549 | public IRubyObject instance_eval(ThreadContext context, Block block) { |
2546 | | - return specificEval(context, getInstanceEvalClass(), block, EvalType.INSTANCE_EVAL); |
| 2550 | + return specificEval(context, getInstanceEvalClass(context), block, EvalType.INSTANCE_EVAL); |
2547 | 2551 | } |
2548 | 2552 | @JRubyMethod(name = "instance_eval", |
2549 | 2553 | reads = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE}, |
2550 | 2554 | writes = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE}) |
2551 | 2555 | public IRubyObject instance_eval(ThreadContext context, IRubyObject arg0, Block block) { |
2552 | | - return specificEval(context, getInstanceEvalClass(), arg0, block, EvalType.INSTANCE_EVAL); |
| 2556 | + return specificEval(context, getInstanceEvalClass(context), arg0, block, EvalType.INSTANCE_EVAL); |
2553 | 2557 | } |
2554 | 2558 | @JRubyMethod(name = "instance_eval", |
2555 | 2559 | reads = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE}, |
2556 | 2560 | writes = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE}) |
2557 | 2561 | public IRubyObject instance_eval(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Block block) { |
2558 | | - return specificEval(context, getInstanceEvalClass(), arg0, arg1, block, EvalType.INSTANCE_EVAL); |
| 2562 | + return specificEval(context, getInstanceEvalClass(context), arg0, arg1, block, EvalType.INSTANCE_EVAL); |
2559 | 2563 | } |
2560 | 2564 | @JRubyMethod(name = "instance_eval", |
2561 | 2565 | reads = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE}, |
2562 | 2566 | writes = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE}) |
2563 | 2567 | public IRubyObject instance_eval(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) { |
2564 | | - return specificEval(context, getInstanceEvalClass(), arg0, arg1, arg2, block, EvalType.INSTANCE_EVAL); |
| 2568 | + return specificEval(context, getInstanceEvalClass(context), arg0, arg1, arg2, block, EvalType.INSTANCE_EVAL); |
2565 | 2569 | } |
2566 | 2570 |
|
2567 | 2571 | // This is callable and will work but the rest = true is put so we can match the expected arity error message |
@@ -2601,14 +2605,9 @@ public IRubyObject instance_eval(ThreadContext context, IRubyObject[] args, Bloc |
2601 | 2605 | reads = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE}, |
2602 | 2606 | writes = {LASTLINE, BACKREF, VISIBILITY, BLOCK, SELF, METHODNAME, LINE, CLASS, FILENAME, SCOPE}) |
2603 | 2607 | public IRubyObject instance_exec(ThreadContext context, IRubyObject[] args, Block block) { |
2604 | | - if (!block.isGiven()) { |
2605 | | - throw context.runtime.newLocalJumpErrorNoBlock(); |
2606 | | - } |
2607 | | - |
2608 | | - RubyModule klazz = isImmediate() ? // MRI uses Qnil here, we use "dummy" because we need a class |
2609 | | - context.runtime.getDummy() : singletonClass(context); |
| 2608 | + if (!block.isGiven()) throw context.runtime.newLocalJumpErrorNoBlock(); |
2610 | 2609 |
|
2611 | | - return yieldUnder(context, klazz, args, block, EvalType.INSTANCE_EVAL); |
| 2610 | + return yieldUnder(context, getInstanceEvalClass(context), args, block, EvalType.INSTANCE_EVAL); |
2612 | 2611 | } |
2613 | 2612 |
|
2614 | 2613 | /** rb_obj_extend |
|
0 commit comments