Bug #2402 ยป super_in_instance_eval_fix.diff
insns.def | ||
---|---|---|
ID id;
|
||
VALUE flag = VM_CALL_SUPER_BIT | VM_CALL_FCALL_BIT;
|
||
const rb_method_entry_t *me;
|
||
rb_control_frame_t *cfp = GET_CFP();
|
||
rb_control_frame_t *end_cfp = RUBY_VM_END_CONTROL_FRAME(th);
|
||
VALUE *lfp = GET_LFP();
|
||
VALUE *dfp = GET_DFP();
|
||
recv = GET_SELF();
|
||
recv = Qundef;
|
||
while (RUBY_VM_VALID_CONTROL_FRAME_P(cfp, end_cfp)) {
|
||
if ((cfp->dfp == lfp && cfp->iseq->type == ISEQ_TYPE_METHOD) ||
|
||
(cfp->me && cfp->me->def->type == VM_METHOD_TYPE_BMETHOD)) {
|
||
recv = cfp->self;
|
||
break;
|
||
}
|
||
cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
|
||
}
|
||
if (recv == Qundef) {
|
||
rb_raise(rb_eNoMethodError, "super called outside of method");
|
||
}
|
||
vm_search_superclass(GET_CFP(), GET_ISEQ(), recv, TOPN(num), &id, &klass);
|
||
me = rb_method_entry(klass, id);
|
||
test/ruby/test_eval.rb | ||
---|---|---|
assert_raise(ArgumentError) {eval("__ENCODING__".encode("utf-32be"))}
|
||
assert_raise(ArgumentError) {eval("__ENCODING__".encode("utf-32le"))}
|
||
end
|
||
def test_super_in_instance_eval
|
||
super_class = Class.new {
|
||
def foo
|
||
return [:super, self]
|
||
end
|
||
}
|
||
sub_class = Class.new(super_class) {
|
||
def foo
|
||
x = Object.new
|
||
x.instance_eval do
|
||
super()
|
||
end
|
||
end
|
||
}
|
||
obj = sub_class.new
|
||
assert_equal [:super, obj], obj.foo
|
||
end
|
||
def test_super_in_instance_eval_with_define_method
|
||
super_class = Class.new {
|
||
def foo
|
||
return [:super, self]
|
||
end
|
||
}
|
||
sub_class = Class.new(super_class) {
|
||
define_method(:foo) do
|
||
x = Object.new
|
||
x.instance_eval do
|
||
super()
|
||
end
|
||
end
|
||
}
|
||
obj = sub_class.new
|
||
assert_equal [:super, obj], obj.foo
|
||
end
|
||
end
|