Browse Source

boot.js: when installing a new method, ensure the propagation in all subclasses

Nicolas Petton 11 years ago
parent
commit
7cf762f656
1 changed files with 21 additions and 0 deletions
  1. 21 0
      js/boot.js

+ 21 - 0
js/boot.js

@@ -390,6 +390,17 @@ function Smalltalk() {
 		return subclasses;
 	};
 
+    st.allSubclasses = function(klass) {
+        var result, subclasses;
+        result = subclasses = st.subclasses(klass);
+        subclasses.forEach(function(subclass) {
+            result.push.apply(result, st.allSubclasses(subclass));
+        });
+
+        return result;
+    };
+
+
 	/* Create a new class wrapping a JavaScript constructor, and add it to the
 	   global smalltalk object. Package is lazily created if it does not exist with given name. */
 
@@ -500,6 +511,16 @@ function Smalltalk() {
         // Therefore we populate the organizer here too
         klass.organization.elements.addElement(method.category);
 
+        // If already initialized (else it will be done later anyway),
+        // re-initialize all subclasses to ensure the new method
+        // propagation (for wrapped classes, not using the prototype
+        // chain.
+        if(initialized) {
+            st.allSubclasses(klass).forEach(function(subclass) {
+                st.initClass(subclass);
+            });
+        }
+
         for(var i=0; i<method.messageSends.length; i++) {
             var dnuHandler = dnu.get(method.messageSends[i]);
             if(initialized) {