fix mrb_mod_cv_set and add test for Module#class_variable_set

This commit is contained in:
skandhas
2012-12-21 16:17:13 +08:00
parent d06512b093
commit f612f32aef
2 changed files with 20 additions and 3 deletions
+5 -3
View File
@@ -698,6 +698,8 @@ mrb_cv_get(mrb_state *mrb, mrb_value mod, mrb_sym sym)
void
mrb_mod_cv_set(mrb_state *mrb, struct RClass * c, mrb_sym sym, mrb_value v)
{
struct RClass * cls = c;
while (c) {
if (c->iv) {
iv_tbl *t = c->iv;
@@ -710,11 +712,11 @@ mrb_mod_cv_set(mrb_state *mrb, struct RClass * c, mrb_sym sym, mrb_value v)
c = c->super;
}
if (!c->iv) {
c->iv = iv_new(mrb);
if (!cls->iv) {
cls->iv = iv_new(mrb);
}
iv_put(mrb, c->iv, sym, v);
iv_put(mrb, cls->iv, sym, v);
}
void
+15
View File
@@ -54,6 +54,21 @@ assert('Module#class_variable_get', '15.2.2.4.17') do
Test4ClassVariableGet.class_variable_get(:@@cv) == 99
end
assert('Module#class_variable_set', '15.2.2.4.18') do
class Test4ClassVariableSet
@@foo = 100
def foo
@@foo
end
end
Test4ClassVariableSet.class_variable_set(:@@cv, 99)
Test4ClassVariableSet.class_variable_set(:@@foo, 101)
Test4ClassVariableSet.class_variables.include? :@@cv and
Test4ClassVariableSet.class_variable_get(:@@cv) == 99 and
Test4ClassVariableSet.new.foo == 101
end
assert('Module#class_variables', '15.2.2.4.19') do
class Test4ClassVariables1