Browse Source

Fixed protocol organizer registration

Nicolas Petton 11 years ago
parent
commit
dffc2564aa
4 changed files with 42 additions and 34 deletions
  1. 11 10
      js/Kernel-Classes.deploy.js
  2. 12 11
      js/Kernel-Classes.js
  3. 16 11
      js/boot.js
  4. 3 2
      st/Kernel-Classes.st

+ 11 - 10
js/Kernel-Classes.deploy.js

@@ -485,18 +485,19 @@ smalltalk.method({
 selector: "removeCompiledMethod:",
 fn: function (aMethod){
 var self=this;
-return smalltalk.withContext(function($ctx1) { 
var $1,$2,$3;
+return smalltalk.withContext(function($ctx1) { 
var $1,$2;
 _st(self)._basicRemoveCompiledMethod_(aMethod);
-$1=_st(_st(self)._protocols())._includes_(_st(aMethod)._category());
-if(! smalltalk.assert($1)){
-_st(_st(self)._organization())._removeElement_(_st(aMethod)._protocol());
-};
-$2=_st((smalltalk.MethodRemoved || MethodRemoved))._new();
-_st($2)._method_(aMethod);
-$3=_st($2)._yourself();
-_st(_st((smalltalk.SystemAnnouncer || SystemAnnouncer))._current())._announce_($3);
+_st(_st(self)._methods())._detect_ifNone_((function(each){
+return smalltalk.withContext(function($ctx2) {
return _st(_st(each)._protocol()).__eq(_st(aMethod)._protocol());
+}, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}),(function(){
+return smalltalk.withContext(function($ctx2) {
return _st(_st(self)._organization())._removeElement_(_st(aMethod)._protocol());
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
+$1=_st((smalltalk.MethodRemoved || MethodRemoved))._new();
+_st($1)._method_(aMethod);
+$2=_st($1)._yourself();
+_st(_st((smalltalk.SystemAnnouncer || SystemAnnouncer))._current())._announce_($2);
 return self}, function($ctx1) {$ctx1.fill(self,"removeCompiledMethod:",{aMethod:aMethod}, smalltalk.Behavior)})},
-messageSends: ["basicRemoveCompiledMethod:", "ifFalse:", "removeElement:", "protocol", "organization", "includes:", "category", "protocols", "announce:", "method:", "new", "yourself", "current"]}),
+messageSends: ["basicRemoveCompiledMethod:", "detect:ifNone:", "=", "protocol", "removeElement:", "organization", "methods", "announce:", "method:", "new", "yourself", "current"]}),
 smalltalk.Behavior);
 
 smalltalk.addMethod(

+ 12 - 11
js/Kernel-Classes.js

@@ -642,20 +642,21 @@ selector: "removeCompiledMethod:",
 category: 'compiling',
 fn: function (aMethod){
 var self=this;
-return smalltalk.withContext(function($ctx1) { 
var $1,$2,$3;
+return smalltalk.withContext(function($ctx1) { 
var $1,$2;
 _st(self)._basicRemoveCompiledMethod_(aMethod);
-$1=_st(_st(self)._protocols())._includes_(_st(aMethod)._category());
-if(! smalltalk.assert($1)){
-_st(_st(self)._organization())._removeElement_(_st(aMethod)._protocol());
-};
-$2=_st((smalltalk.MethodRemoved || MethodRemoved))._new();
-_st($2)._method_(aMethod);
-$3=_st($2)._yourself();
-_st(_st((smalltalk.SystemAnnouncer || SystemAnnouncer))._current())._announce_($3);
+_st(_st(self)._methods())._detect_ifNone_((function(each){
+return smalltalk.withContext(function($ctx2) {
return _st(_st(each)._protocol()).__eq(_st(aMethod)._protocol());
+}, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}),(function(){
+return smalltalk.withContext(function($ctx2) {
return _st(_st(self)._organization())._removeElement_(_st(aMethod)._protocol());
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
+$1=_st((smalltalk.MethodRemoved || MethodRemoved))._new();
+_st($1)._method_(aMethod);
+$2=_st($1)._yourself();
+_st(_st((smalltalk.SystemAnnouncer || SystemAnnouncer))._current())._announce_($2);
 return self}, function($ctx1) {$ctx1.fill(self,"removeCompiledMethod:",{aMethod:aMethod}, smalltalk.Behavior)})},
 args: ["aMethod"],
-source: "removeCompiledMethod: aMethod\x0a\x09self basicRemoveCompiledMethod: aMethod.\x0a    \x0a    (self protocols includes: aMethod category)\x0a    \x09ifFalse: [ self organization removeElement: aMethod protocol ].\x0a    \x0a    SystemAnnouncer current\x0a   \x09\x09announce: (MethodRemoved new\x0a            method: aMethod;\x0a            yourself)",
-messageSends: ["basicRemoveCompiledMethod:", "ifFalse:", "removeElement:", "protocol", "organization", "includes:", "category", "protocols", "announce:", "method:", "new", "yourself", "current"],
+source: "removeCompiledMethod: aMethod\x0a\x09self basicRemoveCompiledMethod: aMethod.\x0a    \x0a    self methods \x0a    \x09detect: [ :each | each protocol = aMethod protocol ]\x0a  \x09\x09ifNone: [ self organization removeElement: aMethod protocol ].\x0a    \x0a    SystemAnnouncer current\x0a   \x09\x09announce: (MethodRemoved new\x0a            method: aMethod;\x0a            yourself)",
+messageSends: ["basicRemoveCompiledMethod:", "detect:ifNone:", "=", "protocol", "removeElement:", "organization", "methods", "announce:", "method:", "new", "yourself", "current"],
 referencedClasses: ["MethodRemoved", "SystemAnnouncer"]
 }),
 smalltalk.Behavior);

+ 16 - 11
js/boot.js

@@ -485,6 +485,8 @@ function Smalltalk() {
 		klass.methods[method.selector] = method;
 		method.methodClass = klass;
 
+        // During the bootstrap, #addCompiledMethod is not used.
+        // Therefore we populate the organizer here too
         klass.organization.elements.addElement(method.category);
 
         for(var i=0; i<method.messageSends.length; i++) {
@@ -503,17 +505,20 @@ function Smalltalk() {
 	    delete klass.methods[method.selector];
 
 		var selectors = Object.keys(klass.methods);
-		var shouldDeleteProtocol = true;
-
-		for(var i = 0, l = selectors.length; i<l; i++) {
-            if(klass.methods[selectors[i]].category === protocol) {
-                shouldDeleteProtocol = false;
-				break;
-            };
-        };
-        if(shouldDeleteProtocol) {
-            klass.organization.elements.removeElement(protocol)
-        };
+        // Do *not* delete protocols from here.
+        // This is handled by #removeCompiledMethod
+        //
+		// var shouldDeleteProtocol = true;
+
+		// for(var i = 0, l = selectors.length; i<l; i++) {
+        //     if(klass.methods[selectors[i]].category === protocol) {
+        //         shouldDeleteProtocol = false;
+		// 		break;
+        //     };
+        // };
+        // if(shouldDeleteProtocol) {
+        //     klass.organization.elements.removeElement(protocol)
+        // };
     };
 
 	/* Handles unhandled errors during message sends */

+ 3 - 2
st/Kernel-Classes.st

@@ -215,8 +215,9 @@ compile: aString category: anotherString
 removeCompiledMethod: aMethod
 	self basicRemoveCompiledMethod: aMethod.
     
-    (self protocols includes: aMethod category)
-    	ifFalse: [ self organization removeElement: aMethod protocol ].
+    self methods 
+    	detect: [ :each | each protocol = aMethod protocol ]
+  		ifNone: [ self organization removeElement: aMethod protocol ].
     
     SystemAnnouncer current
    		announce: (MethodRemoved new