changed: #trapMethodForNumArgs:
authorClaus Gittinger <cg@exept.de>
Sun, 30 Oct 2011 11:05:02 +0100
changeset 13805 dec466a100bc
parent 13804 986cd3fc109d
child 13806 fe8f1301f1bc
changed: #trapMethodForNumArgs: fix for non-methods (inherited, instrumented and wrapped methods)
Method.st
--- a/Method.st	Fri Oct 28 13:26:32 2011 +0200
+++ b/Method.st	Sun Oct 30 11:05:02 2011 +0100
@@ -326,7 +326,13 @@
 !Method class methodsFor:'trap methods'!
 
 trapMethodForNumArgs:numArgs
-    |trapSel|
+    "return a method which will raise an invalid code object exception.
+     Before recompiling methods (due to changed variable scopes, for example),
+     all method's code is replaced by this. If recompilation fails, this code
+     remains in the method to make it trap, whenever executed later.
+     Otherwise, if recompilation succeeeds, that code will vanish after the compile"
+
+    |trapSel trapMethod|
 
     trapSel := #(
                   #'invalidCodeObject'
@@ -347,11 +353,14 @@
                   #'invalidCodeObjectWith:with:with:with:with:with:with:with:with:with:with:with:with:with:with:'
                 ) at:(numArgs + 1).
 
-    ^ self compiledMethodAt:trapSel.
+    (trapMethod := self compiledMethodAt:trapSel) isNil ifTrue:[
+        trapMethod := Method compiledMethodAt:trapSel.
+    ].
+    ^ trapMethod.
 
     "Created: / 04-11-1996 / 21:58:58 / cg"
-    "Modified: / 08-09-2011 / 05:35:33 / cg"
     "Modified: / 14-09-2011 / 11:23:09 / sr"
+    "Modified (comment): / 30-10-2011 / 11:04:24 / cg"
 ! !
 
 !Method methodsFor:'Compatibility-Squeak'!
@@ -3574,11 +3583,11 @@
 !Method class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Method.st,v 1.377 2011-09-14 09:25:43 sr Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Method.st,v 1.378 2011-10-30 10:05:02 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/Method.st,v 1.377 2011-09-14 09:25:43 sr Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Method.st,v 1.378 2011-10-30 10:05:02 cg Exp $'
 !
 
 version_SVN