mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
fix mrb_mod_cv_set and add test for Module#class_variable_set
This commit is contained in:
+5
-3
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user