Skip to content

Commit

Permalink
A singleton class adopts the frozen/tainted/untrusted state of its pa…
Browse files Browse the repository at this point in the history
…rent
  • Loading branch information
jfirebaugh committed Mar 15, 2012
1 parent 085fd6d commit c22cb9b
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions vm/builtin/object.cpp
Expand Up @@ -460,15 +460,22 @@ namespace rubinius {

Class* Object::singleton_class(STATE) {
if(reference_p()) {
if(SingletonClass* sc = try_as<SingletonClass>(klass())) {
/* This test is very important! SingletonClasses can get their klass()
* hooked up to the SingletonClass of a parent class, so that the MOP
* works properly. BUT we should not return that parent singleton
* class, we need to only return a SingletonClass that is for this!
*/
if(sc->attached_instance() == this) return sc;
SingletonClass* sc = try_as<SingletonClass>(klass());

/* This test is very important! SingletonClasses can get their klass()
* hooked up to the SingletonClass of a parent class, so that the MOP
* works properly. BUT we should not return that parent singleton
* class, we need to only return a SingletonClass that is for this!
*/
if(!sc || sc->attached_instance() != this) {
sc = SingletonClass::attach(state, this);
}
return SingletonClass::attach(state, this);

sc->set_frozen(is_frozen_p());
sc->set_tainted(is_tainted_p());
sc->set_untrusted(is_untrusted_p());

return sc;
}

return class_object(state);
Expand Down

0 comments on commit c22cb9b

Please sign in to comment.